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');
383 * @class Roo.bootstrap.Body
384 * @extends Roo.bootstrap.Component
385 * Bootstrap Body class
389 * @param {Object} config The config object
392 Roo.bootstrap.Body = function(config){
394 config = config || {};
396 Roo.bootstrap.Body.superclass.constructor.call(this, config);
397 this.el = Roo.get(config.el ? config.el : document.body );
398 if (this.cls && this.cls.length) {
399 Roo.get(document.body).addClass(this.cls);
403 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, {
405 is_body : true,// just to make sure it's constructed?
410 onRender : function(ct, position)
412 /* Roo.log("Roo.bootstrap.Body - onRender");
413 if (this.cls && this.cls.length) {
414 Roo.get(document.body).addClass(this.cls);
433 * @class Roo.bootstrap.ButtonGroup
434 * @extends Roo.bootstrap.Component
435 * Bootstrap ButtonGroup class
436 * @cfg {String} size lg | sm | xs (default empty normal)
437 * @cfg {String} align vertical | justified (default none)
438 * @cfg {String} direction up | down (default down)
439 * @cfg {Boolean} toolbar false | true
440 * @cfg {Boolean} btn true | false
445 * @param {Object} config The config object
448 Roo.bootstrap.ButtonGroup = function(config){
449 Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
452 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, {
460 getAutoCreate : function(){
466 cfg.html = this.html || cfg.html;
477 if (['vertical','justified'].indexOf(this.align)!==-1) {
478 cfg.cls = 'btn-group-' + this.align;
480 if (this.align == 'justified') {
481 console.log(this.items);
485 if (['lg','sm','xs'].indexOf(this.size)!==-1) {
486 cfg.cls += ' btn-group-' + this.size;
489 if (this.direction == 'up') {
490 cfg.cls += ' dropup' ;
506 * @class Roo.bootstrap.Button
507 * @extends Roo.bootstrap.Component
508 * Bootstrap Button class
509 * @cfg {String} html The button content
510 * @cfg {String} weight (default | primary | success | info | warning | danger | link ) default
511 * @cfg {String} size ( lg | sm | xs)
512 * @cfg {String} tag ( a | input | submit)
513 * @cfg {String} href empty or href
514 * @cfg {Boolean} disabled default false;
515 * @cfg {Boolean} isClose default false;
516 * @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)
517 * @cfg {String} badge text for badge
518 * @cfg {String} theme default
519 * @cfg {Boolean} inverse
520 * @cfg {Boolean} toggle
521 * @cfg {String} ontext text for on toggle state
522 * @cfg {String} offtext text for off toggle state
523 * @cfg {Boolean} defaulton
524 * @cfg {Boolean} preventDefault default true
525 * @cfg {Boolean} removeClass remove the standard class..
526 * @cfg {String} target target for a href. (_self|_blank|_parent|_top| other)
529 * Create a new button
530 * @param {Object} config The config object
534 Roo.bootstrap.Button = function(config){
535 Roo.bootstrap.Button.superclass.constructor.call(this, config);
536 this.weightClass = ["btn-default",
548 * When a butotn is pressed
549 * @param {Roo.bootstrap.Button} this
550 * @param {Roo.EventObject} e
555 * After the button has been toggles
556 * @param {Roo.EventObject} e
557 * @param {boolean} pressed (also available as button.pressed)
563 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
581 preventDefault: true,
590 getAutoCreate : function(){
598 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
599 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
604 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
606 if (this.toggle == true) {
609 cls: 'slider-frame roo-button',
614 'data-off-text':'OFF',
615 cls: 'slider-button',
621 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
622 cfg.cls += ' '+this.weight;
631 cfg["aria-hidden"] = true;
633 cfg.html = "×";
639 if (this.theme==='default') {
640 cfg.cls = 'btn roo-button';
642 //if (this.parentType != 'Navbar') {
643 this.weight = this.weight.length ? this.weight : 'default';
645 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
647 cfg.cls += ' btn-' + this.weight;
649 } else if (this.theme==='glow') {
652 cfg.cls = 'btn-glow roo-button';
654 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
656 cfg.cls += ' ' + this.weight;
662 this.cls += ' inverse';
667 cfg.cls += ' active';
671 cfg.disabled = 'disabled';
675 Roo.log('changing to ul' );
677 this.glyphicon = 'caret';
680 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
682 //gsRoo.log(this.parentType);
683 if (this.parentType === 'Navbar' && !this.parent().bar) {
684 Roo.log('changing to li?');
693 href : this.href || '#'
696 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
697 cfg.cls += ' dropdown';
704 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
706 if (this.glyphicon) {
707 cfg.html = ' ' + cfg.html;
712 cls: 'glyphicon glyphicon-' + this.glyphicon
722 // cfg.cls='btn roo-button';
726 var value = cfg.html;
731 cls: 'glyphicon glyphicon-' + this.glyphicon,
750 cfg.cls += ' dropdown';
751 cfg.html = typeof(cfg.html) != 'undefined' ? cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
754 if (cfg.tag !== 'a' && this.href !== '') {
755 throw "Tag must be a to set href.";
756 } else if (this.href.length > 0) {
757 cfg.href = this.href;
760 if(this.removeClass){
765 cfg.target = this.target;
770 initEvents: function() {
771 // Roo.log('init events?');
772 // Roo.log(this.el.dom);
775 if (typeof (this.menu) != 'undefined') {
776 this.menu.parentType = this.xtype;
777 this.menu.triggerEl = this.el;
778 this.addxtype(Roo.apply({}, this.menu));
782 if (this.el.hasClass('roo-button')) {
783 this.el.on('click', this.onClick, this);
785 this.el.select('.roo-button').on('click', this.onClick, this);
788 if(this.removeClass){
789 this.el.on('click', this.onClick, this);
792 this.el.enableDisplayMode();
795 onClick : function(e)
802 Roo.log('button on click ');
803 if(this.preventDefault){
806 if (this.pressed === true || this.pressed === false) {
807 this.pressed = !this.pressed;
808 this.el[this.pressed ? 'addClass' : 'removeClass']('active');
809 this.fireEvent('toggle', this, e, this.pressed);
813 this.fireEvent('click', this, e);
817 * Enables this button
821 this.disabled = false;
822 this.el.removeClass('disabled');
826 * Disable this button
830 this.disabled = true;
831 this.el.addClass('disabled');
834 * sets the active state on/off,
835 * @param {Boolean} state (optional) Force a particular state
837 setActive : function(v) {
839 this.el[v ? 'addClass' : 'removeClass']('active');
842 * toggles the current active state
844 toggleActive : function()
846 var active = this.el.hasClass('active');
847 this.setActive(!active);
851 setText : function(str)
853 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
857 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
868 setWeight : function(str)
870 this.el.removeClass(this.weightClass);
871 this.el.addClass('btn-' + str);
885 * @class Roo.bootstrap.Column
886 * @extends Roo.bootstrap.Component
887 * Bootstrap Column class
888 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
889 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
890 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
891 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
892 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
893 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
894 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
895 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
898 * @cfg {Boolean} hidden (true|false) hide the element
899 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
900 * @cfg {String} fa (ban|check|...) font awesome icon
901 * @cfg {Number} fasize (1|2|....) font awsome size
903 * @cfg {String} icon (info-sign|check|...) glyphicon name
905 * @cfg {String} html content of column.
908 * Create a new Column
909 * @param {Object} config The config object
912 Roo.bootstrap.Column = function(config){
913 Roo.bootstrap.Column.superclass.constructor.call(this, config);
916 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
934 getAutoCreate : function(){
935 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
943 ['xs','sm','md','lg'].map(function(size){
944 //Roo.log( size + ':' + settings[size]);
946 if (settings[size+'off'] !== false) {
947 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
950 if (settings[size] === false) {
954 if (!settings[size]) { // 0 = hidden
955 cfg.cls += ' hidden-' + size;
958 cfg.cls += ' col-' + size + '-' + settings[size];
963 cfg.cls += ' hidden';
966 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
967 cfg.cls +=' alert alert-' + this.alert;
971 if (this.html.length) {
972 cfg.html = this.html;
976 if (this.fasize > 1) {
977 fasize = ' fa-' + this.fasize + 'x';
979 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
984 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
1003 * @class Roo.bootstrap.Container
1004 * @extends Roo.bootstrap.Component
1005 * Bootstrap Container class
1006 * @cfg {Boolean} jumbotron is it a jumbotron element
1007 * @cfg {String} html content of element
1008 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1009 * @cfg {String} panel (default|primary|success|info|warning|danger) render as panel - type - primary/success.....
1010 * @cfg {String} header content of header (for panel)
1011 * @cfg {String} footer content of footer (for panel)
1012 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1013 * @cfg {String} tag (header|aside|section) type of HTML tag.
1014 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1015 * @cfg {String} fa font awesome icon
1016 * @cfg {String} icon (info-sign|check|...) glyphicon name
1017 * @cfg {Boolean} hidden (true|false) hide the element
1018 * @cfg {Boolean} expandable (true|false) default false
1019 * @cfg {Boolean} expanded (true|false) default true
1020 * @cfg {String} rheader contet on the right of header
1021 * @cfg {Boolean} clickable (true|false) default false
1025 * Create a new Container
1026 * @param {Object} config The config object
1029 Roo.bootstrap.Container = function(config){
1030 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1036 * After the panel has been expand
1038 * @param {Roo.bootstrap.Container} this
1043 * After the panel has been collapsed
1045 * @param {Roo.bootstrap.Container} this
1050 * When a element is chick
1051 * @param {Roo.bootstrap.Container} this
1052 * @param {Roo.EventObject} e
1058 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1076 getChildContainer : function() {
1082 if (this.panel.length) {
1083 return this.el.select('.panel-body',true).first();
1090 getAutoCreate : function(){
1093 tag : this.tag || 'div',
1097 if (this.jumbotron) {
1098 cfg.cls = 'jumbotron';
1103 // - this is applied by the parent..
1105 // cfg.cls = this.cls + '';
1108 if (this.sticky.length) {
1110 var bd = Roo.get(document.body);
1111 if (!bd.hasClass('bootstrap-sticky')) {
1112 bd.addClass('bootstrap-sticky');
1113 Roo.select('html',true).setStyle('height', '100%');
1116 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1120 if (this.well.length) {
1121 switch (this.well) {
1124 cfg.cls +=' well well-' +this.well;
1133 cfg.cls += ' hidden';
1137 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1138 cfg.cls +=' alert alert-' + this.alert;
1143 if (this.panel.length) {
1144 cfg.cls += ' panel panel-' + this.panel;
1146 if (this.header.length) {
1150 if(this.expandable){
1152 cfg.cls = cfg.cls + ' expandable';
1156 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1164 cls : 'panel-title',
1165 html : (this.expandable ? ' ' : '') + this.header
1169 cls: 'panel-header-right',
1175 cls : 'panel-heading',
1176 style : this.expandable ? 'cursor: pointer' : '',
1184 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1189 if (this.footer.length) {
1191 cls : 'panel-footer',
1200 body.html = this.html || cfg.html;
1201 // prefix with the icons..
1203 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1206 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1211 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1212 cfg.cls = 'container';
1218 initEvents: function()
1220 if(this.expandable){
1221 var headerEl = this.headerEl();
1224 headerEl.on('click', this.onToggleClick, this);
1229 this.el.on('click', this.onClick, this);
1234 onToggleClick : function()
1236 var headerEl = this.headerEl();
1252 if(this.fireEvent('expand', this)) {
1254 this.expanded = true;
1256 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1258 this.el.select('.panel-body',true).first().removeClass('hide');
1260 var toggleEl = this.toggleEl();
1266 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1271 collapse : function()
1273 if(this.fireEvent('collapse', this)) {
1275 this.expanded = false;
1277 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1278 this.el.select('.panel-body',true).first().addClass('hide');
1280 var toggleEl = this.toggleEl();
1286 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1290 toggleEl : function()
1292 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1296 return this.el.select('.panel-heading .fa',true).first();
1299 headerEl : function()
1301 if(!this.el || !this.panel.length || !this.header.length){
1305 return this.el.select('.panel-heading',true).first()
1310 if(!this.el || !this.panel.length){
1314 return this.el.select('.panel-body',true).first()
1317 titleEl : function()
1319 if(!this.el || !this.panel.length || !this.header.length){
1323 return this.el.select('.panel-title',true).first();
1326 setTitle : function(v)
1328 var titleEl = this.titleEl();
1334 titleEl.dom.innerHTML = v;
1337 getTitle : function()
1340 var titleEl = this.titleEl();
1346 return titleEl.dom.innerHTML;
1349 setRightTitle : function(v)
1351 var t = this.el.select('.panel-header-right',true).first();
1357 t.dom.innerHTML = v;
1360 onClick : function(e)
1364 this.fireEvent('click', this, e);
1378 * @class Roo.bootstrap.Img
1379 * @extends Roo.bootstrap.Component
1380 * Bootstrap Img class
1381 * @cfg {Boolean} imgResponsive false | true
1382 * @cfg {String} border rounded | circle | thumbnail
1383 * @cfg {String} src image source
1384 * @cfg {String} alt image alternative text
1385 * @cfg {String} href a tag href
1386 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
1387 * @cfg {String} xsUrl xs image source
1388 * @cfg {String} smUrl sm image source
1389 * @cfg {String} mdUrl md image source
1390 * @cfg {String} lgUrl lg image source
1393 * Create a new Input
1394 * @param {Object} config The config object
1397 Roo.bootstrap.Img = function(config){
1398 Roo.bootstrap.Img.superclass.constructor.call(this, config);
1404 * The img click event for the img.
1405 * @param {Roo.EventObject} e
1411 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
1413 imgResponsive: true,
1423 getAutoCreate : function()
1425 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1426 return this.createSingleImg();
1431 cls: 'roo-image-responsive-group',
1436 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
1438 if(!_this[size + 'Url']){
1444 cls: (_this.imgResponsive) ? 'img-responsive' : '',
1445 html: _this.html || cfg.html,
1446 src: _this[size + 'Url']
1449 img.cls += ' roo-image-responsive-' + size;
1451 var s = ['xs', 'sm', 'md', 'lg'];
1453 s.splice(s.indexOf(size), 1);
1455 Roo.each(s, function(ss){
1456 img.cls += ' hidden-' + ss;
1459 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
1460 cfg.cls += ' img-' + _this.border;
1464 cfg.alt = _this.alt;
1477 a.target = _this.target;
1481 cfg.cn.push((_this.href) ? a : img);
1488 createSingleImg : function()
1492 cls: (this.imgResponsive) ? 'img-responsive' : '',
1494 src : 'about:blank' // just incase src get's set to undefined?!?
1497 cfg.html = this.html || cfg.html;
1499 cfg.src = this.src || cfg.src;
1501 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
1502 cfg.cls += ' img-' + this.border;
1519 a.target = this.target;
1524 return (this.href) ? a : cfg;
1527 initEvents: function()
1530 this.el.on('click', this.onClick, this);
1535 onClick : function(e)
1537 Roo.log('img onclick');
1538 this.fireEvent('click', this, e);
1541 * Sets the url of the image - used to update it
1542 * @param {String} url the url of the image
1545 setSrc : function(url)
1549 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1550 this.el.dom.src = url;
1554 this.el.select('img', true).first().dom.src = url;
1570 * @class Roo.bootstrap.Link
1571 * @extends Roo.bootstrap.Component
1572 * Bootstrap Link Class
1573 * @cfg {String} alt image alternative text
1574 * @cfg {String} href a tag href
1575 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
1576 * @cfg {String} html the content of the link.
1577 * @cfg {String} anchor name for the anchor link
1578 * @cfg {String} fa - favicon
1580 * @cfg {Boolean} preventDefault (true | false) default false
1584 * Create a new Input
1585 * @param {Object} config The config object
1588 Roo.bootstrap.Link = function(config){
1589 Roo.bootstrap.Link.superclass.constructor.call(this, config);
1595 * The img click event for the img.
1596 * @param {Roo.EventObject} e
1602 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
1606 preventDefault: false,
1612 getAutoCreate : function()
1614 var html = this.html || '';
1616 if (this.fa !== false) {
1617 html = '<i class="fa fa-' + this.fa + '"></i>';
1622 // anchor's do not require html/href...
1623 if (this.anchor === false) {
1625 cfg.href = this.href || '#';
1627 cfg.name = this.anchor;
1628 if (this.html !== false || this.fa !== false) {
1631 if (this.href !== false) {
1632 cfg.href = this.href;
1636 if(this.alt !== false){
1641 if(this.target !== false) {
1642 cfg.target = this.target;
1648 initEvents: function() {
1650 if(!this.href || this.preventDefault){
1651 this.el.on('click', this.onClick, this);
1655 onClick : function(e)
1657 if(this.preventDefault){
1660 //Roo.log('img onclick');
1661 this.fireEvent('click', this, e);
1674 * @class Roo.bootstrap.Header
1675 * @extends Roo.bootstrap.Component
1676 * Bootstrap Header class
1677 * @cfg {String} html content of header
1678 * @cfg {Number} level (1|2|3|4|5|6) default 1
1681 * Create a new Header
1682 * @param {Object} config The config object
1686 Roo.bootstrap.Header = function(config){
1687 Roo.bootstrap.Header.superclass.constructor.call(this, config);
1690 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
1698 getAutoCreate : function(){
1703 tag: 'h' + (1 *this.level),
1704 html: this.html || ''
1716 * Ext JS Library 1.1.1
1717 * Copyright(c) 2006-2007, Ext JS, LLC.
1719 * Originally Released Under LGPL - original licence link has changed is not relivant.
1722 * <script type="text/javascript">
1726 * @class Roo.bootstrap.MenuMgr
1727 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
1730 Roo.bootstrap.MenuMgr = function(){
1731 var menus, active, groups = {}, attached = false, lastShow = new Date();
1733 // private - called when first menu is created
1736 active = new Roo.util.MixedCollection();
1737 Roo.get(document).addKeyListener(27, function(){
1738 if(active.length > 0){
1746 if(active && active.length > 0){
1747 var c = active.clone();
1757 if(active.length < 1){
1758 Roo.get(document).un("mouseup", onMouseDown);
1766 var last = active.last();
1767 lastShow = new Date();
1770 Roo.get(document).on("mouseup", onMouseDown);
1775 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
1776 m.parentMenu.activeChild = m;
1777 }else if(last && last.isVisible()){
1778 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
1783 function onBeforeHide(m){
1785 m.activeChild.hide();
1787 if(m.autoHideTimer){
1788 clearTimeout(m.autoHideTimer);
1789 delete m.autoHideTimer;
1794 function onBeforeShow(m){
1795 var pm = m.parentMenu;
1796 if(!pm && !m.allowOtherMenus){
1798 }else if(pm && pm.activeChild && active != m){
1799 pm.activeChild.hide();
1803 // private this should really trigger on mouseup..
1804 function onMouseDown(e){
1805 Roo.log("on Mouse Up");
1807 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
1808 Roo.log("MenuManager hideAll");
1817 function onBeforeCheck(mi, state){
1819 var g = groups[mi.group];
1820 for(var i = 0, l = g.length; i < l; i++){
1822 g[i].setChecked(false);
1831 * Hides all menus that are currently visible
1833 hideAll : function(){
1838 register : function(menu){
1842 menus[menu.id] = menu;
1843 menu.on("beforehide", onBeforeHide);
1844 menu.on("hide", onHide);
1845 menu.on("beforeshow", onBeforeShow);
1846 menu.on("show", onShow);
1848 if(g && menu.events["checkchange"]){
1852 groups[g].push(menu);
1853 menu.on("checkchange", onCheck);
1858 * Returns a {@link Roo.menu.Menu} object
1859 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
1860 * be used to generate and return a new Menu instance.
1862 get : function(menu){
1863 if(typeof menu == "string"){ // menu id
1865 }else if(menu.events){ // menu instance
1868 /*else if(typeof menu.length == 'number'){ // array of menu items?
1869 return new Roo.bootstrap.Menu({items:menu});
1870 }else{ // otherwise, must be a config
1871 return new Roo.bootstrap.Menu(menu);
1878 unregister : function(menu){
1879 delete menus[menu.id];
1880 menu.un("beforehide", onBeforeHide);
1881 menu.un("hide", onHide);
1882 menu.un("beforeshow", onBeforeShow);
1883 menu.un("show", onShow);
1885 if(g && menu.events["checkchange"]){
1886 groups[g].remove(menu);
1887 menu.un("checkchange", onCheck);
1892 registerCheckable : function(menuItem){
1893 var g = menuItem.group;
1898 groups[g].push(menuItem);
1899 menuItem.on("beforecheckchange", onBeforeCheck);
1904 unregisterCheckable : function(menuItem){
1905 var g = menuItem.group;
1907 groups[g].remove(menuItem);
1908 menuItem.un("beforecheckchange", onBeforeCheck);
1920 * @class Roo.bootstrap.Menu
1921 * @extends Roo.bootstrap.Component
1922 * Bootstrap Menu class - container for MenuItems
1923 * @cfg {String} type (dropdown|treeview|submenu) type of menu
1924 * @cfg {bool} hidden if the menu should be hidden when rendered.
1925 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
1926 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
1930 * @param {Object} config The config object
1934 Roo.bootstrap.Menu = function(config){
1935 Roo.bootstrap.Menu.superclass.constructor.call(this, config);
1936 if (this.registerMenu && this.type != 'treeview') {
1937 Roo.bootstrap.MenuMgr.register(this);
1942 * Fires before this menu is displayed
1943 * @param {Roo.menu.Menu} this
1948 * Fires before this menu is hidden
1949 * @param {Roo.menu.Menu} this
1954 * Fires after this menu is displayed
1955 * @param {Roo.menu.Menu} this
1960 * Fires after this menu is hidden
1961 * @param {Roo.menu.Menu} this
1966 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
1967 * @param {Roo.menu.Menu} this
1968 * @param {Roo.menu.Item} menuItem The menu item that was clicked
1969 * @param {Roo.EventObject} e
1974 * Fires when the mouse is hovering over this menu
1975 * @param {Roo.menu.Menu} this
1976 * @param {Roo.EventObject} e
1977 * @param {Roo.menu.Item} menuItem The menu item that was clicked
1982 * Fires when the mouse exits this menu
1983 * @param {Roo.menu.Menu} this
1984 * @param {Roo.EventObject} e
1985 * @param {Roo.menu.Item} menuItem The menu item that was clicked
1990 * Fires when a menu item contained in this menu is clicked
1991 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
1992 * @param {Roo.EventObject} e
1996 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
1999 Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component, {
2003 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
2006 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
2008 registerMenu : true,
2010 menuItems :false, // stores the menu items..
2020 getChildContainer : function() {
2024 getAutoCreate : function(){
2026 //if (['right'].indexOf(this.align)!==-1) {
2027 // cfg.cn[1].cls += ' pull-right'
2033 cls : 'dropdown-menu' ,
2034 style : 'z-index:1000'
2038 if (this.type === 'submenu') {
2039 cfg.cls = 'submenu active';
2041 if (this.type === 'treeview') {
2042 cfg.cls = 'treeview-menu';
2047 initEvents : function() {
2049 // Roo.log("ADD event");
2050 // Roo.log(this.triggerEl.dom);
2052 this.triggerEl.on('click', this.onTriggerClick, this);
2054 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
2056 this.triggerEl.addClass('dropdown-toggle');
2059 this.el.on('touchstart' , this.onTouch, this);
2061 this.el.on('click' , this.onClick, this);
2063 this.el.on("mouseover", this.onMouseOver, this);
2064 this.el.on("mouseout", this.onMouseOut, this);
2068 findTargetItem : function(e)
2070 var t = e.getTarget(".dropdown-menu-item", this.el, true);
2074 //Roo.log(t); Roo.log(t.id);
2076 //Roo.log(this.menuitems);
2077 return this.menuitems.get(t.id);
2079 //return this.items.get(t.menuItemId);
2085 onTouch : function(e)
2087 Roo.log("menu.onTouch");
2088 //e.stopEvent(); this make the user popdown broken
2092 onClick : function(e)
2094 Roo.log("menu.onClick");
2096 var t = this.findTargetItem(e);
2097 if(!t || t.isContainer){
2102 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
2103 if(t == this.activeItem && t.shouldDeactivate(e)){
2104 this.activeItem.deactivate();
2105 delete this.activeItem;
2109 this.setActiveItem(t, true);
2117 Roo.log('pass click event');
2121 this.fireEvent("click", this, t, e);
2125 if(!t.href.length || t.href == '#'){
2126 (function() { _this.hide(); }).defer(100);
2131 onMouseOver : function(e){
2132 var t = this.findTargetItem(e);
2135 // if(t.canActivate && !t.disabled){
2136 // this.setActiveItem(t, true);
2140 this.fireEvent("mouseover", this, e, t);
2142 isVisible : function(){
2143 return !this.hidden;
2145 onMouseOut : function(e){
2146 var t = this.findTargetItem(e);
2149 // if(t == this.activeItem && t.shouldDeactivate(e)){
2150 // this.activeItem.deactivate();
2151 // delete this.activeItem;
2154 this.fireEvent("mouseout", this, e, t);
2159 * Displays this menu relative to another element
2160 * @param {String/HTMLElement/Roo.Element} element The element to align to
2161 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
2162 * the element (defaults to this.defaultAlign)
2163 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2165 show : function(el, pos, parentMenu){
2166 this.parentMenu = parentMenu;
2170 this.fireEvent("beforeshow", this);
2171 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
2174 * Displays this menu at a specific xy position
2175 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
2176 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2178 showAt : function(xy, parentMenu, /* private: */_e){
2179 this.parentMenu = parentMenu;
2184 this.fireEvent("beforeshow", this);
2185 //xy = this.el.adjustForConstraints(xy);
2189 this.hideMenuItems();
2190 this.hidden = false;
2191 this.triggerEl.addClass('open');
2193 if(this.el.getWidth() + xy[0] > Roo.lib.Dom.getViewWidth()){
2194 xy[0] = xy[0] - this.el.getWidth() + this.triggerEl.getWidth();
2197 if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
2202 this.fireEvent("show", this);
2208 this.doFocus.defer(50, this);
2212 doFocus : function(){
2214 this.focusEl.focus();
2219 * Hides this menu and optionally all parent menus
2220 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
2222 hide : function(deep)
2225 this.hideMenuItems();
2226 if(this.el && this.isVisible()){
2227 this.fireEvent("beforehide", this);
2228 if(this.activeItem){
2229 this.activeItem.deactivate();
2230 this.activeItem = null;
2232 this.triggerEl.removeClass('open');;
2234 this.fireEvent("hide", this);
2236 if(deep === true && this.parentMenu){
2237 this.parentMenu.hide(true);
2241 onTriggerClick : function(e)
2243 Roo.log('trigger click');
2245 var target = e.getTarget();
2247 Roo.log(target.nodeName.toLowerCase());
2249 if(target.nodeName.toLowerCase() === 'i'){
2255 onTriggerPress : function(e)
2257 Roo.log('trigger press');
2258 //Roo.log(e.getTarget());
2259 // Roo.log(this.triggerEl.dom);
2261 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
2262 var pel = Roo.get(e.getTarget());
2263 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
2264 Roo.log('is treeview or dropdown?');
2268 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
2272 if (this.isVisible()) {
2277 this.show(this.triggerEl, false, false);
2280 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
2287 hideMenuItems : function()
2289 Roo.log("hide Menu Items");
2293 //$(backdrop).remove()
2294 this.el.select('.open',true).each(function(aa) {
2296 aa.removeClass('open');
2297 //var parent = getParent($(this))
2298 //var relatedTarget = { relatedTarget: this }
2300 //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
2301 //if (e.isDefaultPrevented()) return
2302 //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
2305 addxtypeChild : function (tree, cntr) {
2306 var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
2308 this.menuitems.add(comp);
2329 * @class Roo.bootstrap.MenuItem
2330 * @extends Roo.bootstrap.Component
2331 * Bootstrap MenuItem class
2332 * @cfg {String} html the menu label
2333 * @cfg {String} href the link
2334 * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
2335 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
2336 * @cfg {Boolean} active used on sidebars to highlight active itesm
2337 * @cfg {String} fa favicon to show on left of menu item.
2338 * @cfg {Roo.bootsrap.Menu} menu the child menu.
2342 * Create a new MenuItem
2343 * @param {Object} config The config object
2347 Roo.bootstrap.MenuItem = function(config){
2348 Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
2353 * The raw click event for the entire grid.
2354 * @param {Roo.bootstrap.MenuItem} this
2355 * @param {Roo.EventObject} e
2361 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component, {
2365 preventDefault: false,
2366 isContainer : false,
2370 getAutoCreate : function(){
2372 if(this.isContainer){
2375 cls: 'dropdown-menu-item'
2389 if (this.fa !== false) {
2392 cls : 'fa fa-' + this.fa
2401 cls: 'dropdown-menu-item',
2404 if (this.parent().type == 'treeview') {
2405 cfg.cls = 'treeview-menu';
2408 cfg.cls += ' active';
2413 anc.href = this.href || cfg.cn[0].href ;
2414 ctag.html = this.html || cfg.cn[0].html ;
2418 initEvents: function()
2420 if (this.parent().type == 'treeview') {
2421 this.el.select('a').on('click', this.onClick, this);
2425 this.menu.parentType = this.xtype;
2426 this.menu.triggerEl = this.el;
2427 this.menu = this.addxtype(Roo.apply({}, this.menu));
2431 onClick : function(e)
2433 Roo.log('item on click ');
2435 if(this.preventDefault){
2438 //this.parent().hideMenuItems();
2440 this.fireEvent('click', this, e);
2459 * @class Roo.bootstrap.MenuSeparator
2460 * @extends Roo.bootstrap.Component
2461 * Bootstrap MenuSeparator class
2464 * Create a new MenuItem
2465 * @param {Object} config The config object
2469 Roo.bootstrap.MenuSeparator = function(config){
2470 Roo.bootstrap.MenuSeparator.superclass.constructor.call(this, config);
2473 Roo.extend(Roo.bootstrap.MenuSeparator, Roo.bootstrap.Component, {
2475 getAutoCreate : function(){
2494 * @class Roo.bootstrap.Modal
2495 * @extends Roo.bootstrap.Component
2496 * Bootstrap Modal class
2497 * @cfg {String} title Title of dialog
2498 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
2499 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
2500 * @cfg {Boolean} specificTitle default false
2501 * @cfg {Array} buttons Array of buttons or standard button set..
2502 * @cfg {String} buttonPosition (left|right|center) default right
2503 * @cfg {Boolean} animate default true
2504 * @cfg {Boolean} allow_close default true
2505 * @cfg {Boolean} fitwindow default false
2506 * @cfg {String} size (sm|lg) default empty
2510 * Create a new Modal Dialog
2511 * @param {Object} config The config object
2514 Roo.bootstrap.Modal = function(config){
2515 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2520 * The raw btnclick event for the button
2521 * @param {Roo.EventObject} e
2526 * Fire when dialog resize
2527 * @param {Roo.bootstrap.Modal} this
2528 * @param {Roo.EventObject} e
2532 this.buttons = this.buttons || [];
2535 this.tmpl = Roo.factory(this.tmpl);
2540 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
2542 title : 'test dialog',
2552 specificTitle: false,
2554 buttonPosition: 'right',
2573 onRender : function(ct, position)
2575 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2578 var cfg = Roo.apply({}, this.getAutoCreate());
2581 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2583 //if (!cfg.name.length) {
2587 cfg.cls += ' ' + this.cls;
2590 cfg.style = this.style;
2592 this.el = Roo.get(document.body).createChild(cfg, position);
2594 //var type = this.el.dom.type;
2597 if(this.tabIndex !== undefined){
2598 this.el.dom.setAttribute('tabIndex', this.tabIndex);
2601 this.dialogEl = this.el.select('.modal-dialog',true).first();
2602 this.bodyEl = this.el.select('.modal-body',true).first();
2603 this.closeEl = this.el.select('.modal-header .close', true).first();
2604 this.headerEl = this.el.select('.modal-header',true).first();
2605 this.titleEl = this.el.select('.modal-title',true).first();
2606 this.footerEl = this.el.select('.modal-footer',true).first();
2608 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2609 this.maskEl.enableDisplayMode("block");
2611 //this.el.addClass("x-dlg-modal");
2613 if (this.buttons.length) {
2614 Roo.each(this.buttons, function(bb) {
2615 var b = Roo.apply({}, bb);
2616 b.xns = b.xns || Roo.bootstrap;
2617 b.xtype = b.xtype || 'Button';
2618 if (typeof(b.listeners) == 'undefined') {
2619 b.listeners = { click : this.onButtonClick.createDelegate(this) };
2622 var btn = Roo.factory(b);
2624 btn.render(this.el.select('.modal-footer div').first());
2628 // render the children.
2631 if(typeof(this.items) != 'undefined'){
2632 var items = this.items;
2635 for(var i =0;i < items.length;i++) {
2636 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2640 this.items = nitems;
2642 // where are these used - they used to be body/close/footer
2646 //this.el.addClass([this.fieldClass, this.cls]);
2650 getAutoCreate : function(){
2655 html : this.html || ''
2660 cls : 'modal-title',
2664 if(this.specificTitle){
2670 if (this.allow_close) {
2682 if(this.size.length){
2683 size = 'modal-' + this.size;
2688 style : 'display: none',
2691 cls: "modal-dialog " + size,
2694 cls : "modal-content",
2697 cls : 'modal-header',
2702 cls : 'modal-footer',
2706 cls: 'btn-' + this.buttonPosition
2723 modal.cls += ' fade';
2729 getChildContainer : function() {
2734 getButtonContainer : function() {
2735 return this.el.select('.modal-footer div',true).first();
2738 initEvents : function()
2740 if (this.allow_close) {
2741 this.closeEl.on('click', this.hide, this);
2743 Roo.EventManager.onWindowResize(this.resize, this, true);
2750 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2751 if (this.fitwindow) {
2752 var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
2753 var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 60;
2758 setSize : function(w,h)
2768 if (!this.rendered) {
2772 this.el.setStyle('display', 'block');
2774 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
2777 this.el.addClass('in');
2780 this.el.addClass('in');
2784 // not sure how we can show data in here..
2786 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2789 Roo.get(document.body).addClass("x-body-masked");
2791 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2792 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2797 this.fireEvent('show', this);
2799 // set zindex here - otherwise it appears to be ignored...
2800 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2803 this.items.forEach( function(e) {
2804 e.layout ? e.layout() : false;
2812 if(this.fireEvent("beforehide", this) !== false){
2814 Roo.get(document.body).removeClass("x-body-masked");
2815 this.el.removeClass('in');
2816 this.el.select('.modal-dialog', true).first().setStyle('transform','');
2818 if(this.animate){ // why
2820 (function(){ _this.el.setStyle('display', 'none'); }).defer(150);
2822 this.el.setStyle('display', 'none');
2824 this.fireEvent('hide', this);
2828 addButton : function(str, cb)
2832 var b = Roo.apply({}, { html : str } );
2833 b.xns = b.xns || Roo.bootstrap;
2834 b.xtype = b.xtype || 'Button';
2835 if (typeof(b.listeners) == 'undefined') {
2836 b.listeners = { click : cb.createDelegate(this) };
2839 var btn = Roo.factory(b);
2841 btn.render(this.el.select('.modal-footer div').first());
2847 setDefaultButton : function(btn)
2849 //this.el.select('.modal-footer').()
2853 resizeTo: function(w,h)
2857 this.dialogEl.setWidth(w);
2858 if (this.diff === false) {
2859 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
2862 this.bodyEl.setHeight(h-this.diff);
2864 this.fireEvent('resize', this);
2867 setContentSize : function(w, h)
2871 onButtonClick: function(btn,e)
2874 this.fireEvent('btnclick', btn.name, e);
2877 * Set the title of the Dialog
2878 * @param {String} str new Title
2880 setTitle: function(str) {
2881 this.titleEl.dom.innerHTML = str;
2884 * Set the body of the Dialog
2885 * @param {String} str new Title
2887 setBody: function(str) {
2888 this.bodyEl.dom.innerHTML = str;
2891 * Set the body of the Dialog using the template
2892 * @param {Obj} data - apply this data to the template and replace the body contents.
2894 applyBody: function(obj)
2897 Roo.log("Error - using apply Body without a template");
2900 this.tmpl.overwrite(this.bodyEl, obj);
2906 Roo.apply(Roo.bootstrap.Modal, {
2908 * Button config that displays a single OK button
2917 * Button config that displays Yes and No buttons
2933 * Button config that displays OK and Cancel buttons
2948 * Button config that displays Yes, No and Cancel buttons
2972 * messagebox - can be used as a replace
2976 * @class Roo.MessageBox
2977 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
2981 Roo.Msg.alert('Status', 'Changes saved successfully.');
2983 // Prompt for user data:
2984 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
2986 // process text value...
2990 // Show a dialog using config options:
2992 title:'Save Changes?',
2993 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
2994 buttons: Roo.Msg.YESNOCANCEL,
3001 Roo.bootstrap.MessageBox = function(){
3002 var dlg, opt, mask, waitTimer;
3003 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
3004 var buttons, activeTextEl, bwidth;
3008 var handleButton = function(button){
3010 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
3014 var handleHide = function(){
3016 dlg.el.removeClass(opt.cls);
3019 // Roo.TaskMgr.stop(waitTimer);
3020 // waitTimer = null;
3025 var updateButtons = function(b){
3028 buttons["ok"].hide();
3029 buttons["cancel"].hide();
3030 buttons["yes"].hide();
3031 buttons["no"].hide();
3032 //dlg.footer.dom.style.display = 'none';
3035 dlg.footerEl.dom.style.display = '';
3036 for(var k in buttons){
3037 if(typeof buttons[k] != "function"){
3040 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
3041 width += buttons[k].el.getWidth()+15;
3051 var handleEsc = function(d, k, e){
3052 if(opt && opt.closable !== false){
3062 * Returns a reference to the underlying {@link Roo.BasicDialog} element
3063 * @return {Roo.BasicDialog} The BasicDialog element
3065 getDialog : function(){
3067 dlg = new Roo.bootstrap.Modal( {
3070 //constraintoviewport:false,
3072 //collapsible : false,
3077 //buttonAlign:"center",
3078 closeClick : function(){
3079 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3082 handleButton("cancel");
3087 dlg.on("hide", handleHide);
3089 //dlg.addKeyListener(27, handleEsc);
3091 this.buttons = buttons;
3092 var bt = this.buttonText;
3093 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3094 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3095 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3096 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3098 bodyEl = dlg.bodyEl.createChild({
3100 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3101 '<textarea class="roo-mb-textarea"></textarea>' +
3102 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
3104 msgEl = bodyEl.dom.firstChild;
3105 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3106 textboxEl.enableDisplayMode();
3107 textboxEl.addKeyListener([10,13], function(){
3108 if(dlg.isVisible() && opt && opt.buttons){
3111 }else if(opt.buttons.yes){
3112 handleButton("yes");
3116 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3117 textareaEl.enableDisplayMode();
3118 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3119 progressEl.enableDisplayMode();
3121 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
3122 var pf = progressEl.dom.firstChild;
3124 pp = Roo.get(pf.firstChild);
3125 pp.setHeight(pf.offsetHeight);
3133 * Updates the message box body text
3134 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3135 * the XHTML-compliant non-breaking space character '&#160;')
3136 * @return {Roo.MessageBox} This message box
3138 updateText : function(text)
3140 if(!dlg.isVisible() && !opt.width){
3141 dlg.dialogEl.setStyle({ 'max-width' : this.maxWidth});
3142 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
3144 msgEl.innerHTML = text || ' ';
3146 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3147 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3149 Math.min(opt.width || cw , this.maxWidth),
3150 Math.max(opt.minWidth || this.minWidth, bwidth)
3153 activeTextEl.setWidth(w);
3155 if(dlg.isVisible()){
3156 dlg.fixedcenter = false;
3158 // to big, make it scroll. = But as usual stupid IE does not support
3161 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3162 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3163 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3165 bodyEl.dom.style.height = '';
3166 bodyEl.dom.style.overflowY = '';
3169 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3171 bodyEl.dom.style.overflowX = '';
3174 dlg.setContentSize(w, bodyEl.getHeight());
3175 if(dlg.isVisible()){
3176 dlg.fixedcenter = true;
3182 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
3183 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3184 * @param {Number} value Any number between 0 and 1 (e.g., .5)
3185 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3186 * @return {Roo.MessageBox} This message box
3188 updateProgress : function(value, text){
3190 this.updateText(text);
3192 if (pp) { // weird bug on my firefox - for some reason this is not defined
3193 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3199 * Returns true if the message box is currently displayed
3200 * @return {Boolean} True if the message box is visible, else false
3202 isVisible : function(){
3203 return dlg && dlg.isVisible();
3207 * Hides the message box if it is displayed
3210 if(this.isVisible()){
3216 * Displays a new message box, or reinitializes an existing message box, based on the config options
3217 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3218 * The following config object properties are supported:
3220 Property Type Description
3221 ---------- --------------- ------------------------------------------------------------------------------------
3222 animEl String/Element An id or Element from which the message box should animate as it opens and
3223 closes (defaults to undefined)
3224 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3225 cancel:'Bar'}), or false to not show any buttons (defaults to false)
3226 closable Boolean False to hide the top-right close button (defaults to true). Note that
3227 progress and wait dialogs will ignore this property and always hide the
3228 close button as they can only be closed programmatically.
3229 cls String A custom CSS class to apply to the message box element
3230 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
3231 displayed (defaults to 75)
3232 fn Function A callback function to execute after closing the dialog. The arguments to the
3233 function will be btn (the name of the button that was clicked, if applicable,
3234 e.g. "ok"), and text (the value of the active text field, if applicable).
3235 Progress and wait dialogs will ignore this option since they do not respond to
3236 user actions and can only be closed programmatically, so any required function
3237 should be called by the same code after it closes the dialog.
3238 icon String A CSS class that provides a background image to be used as an icon for
3239 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3240 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
3241 minWidth Number The minimum width in pixels of the message box (defaults to 100)
3242 modal Boolean False to allow user interaction with the page while the message box is
3243 displayed (defaults to true)
3244 msg String A string that will replace the existing message box body text (defaults
3245 to the XHTML-compliant non-breaking space character ' ')
3246 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
3247 progress Boolean True to display a progress bar (defaults to false)
3248 progressText String The text to display inside the progress bar if progress = true (defaults to '')
3249 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
3250 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
3251 title String The title text
3252 value String The string value to set into the active textbox element if displayed
3253 wait Boolean True to display a progress bar (defaults to false)
3254 width Number The width of the dialog in pixels
3261 msg: 'Please enter your address:',
3263 buttons: Roo.MessageBox.OKCANCEL,
3266 animEl: 'addAddressBtn'
3269 * @param {Object} config Configuration options
3270 * @return {Roo.MessageBox} This message box
3272 show : function(options)
3275 // this causes nightmares if you show one dialog after another
3276 // especially on callbacks..
3278 if(this.isVisible()){
3281 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3282 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
3283 Roo.log("New Dialog Message:" + options.msg )
3284 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3285 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3288 var d = this.getDialog();
3290 d.setTitle(opt.title || " ");
3291 d.closeEl.setDisplayed(opt.closable !== false);
3292 activeTextEl = textboxEl;
3293 opt.prompt = opt.prompt || (opt.multiline ? true : false);
3298 textareaEl.setHeight(typeof opt.multiline == "number" ?
3299 opt.multiline : this.defaultTextHeight);
3300 activeTextEl = textareaEl;
3309 progressEl.setDisplayed(opt.progress === true);
3310 this.updateProgress(0);
3311 activeTextEl.dom.value = opt.value || "";
3313 dlg.setDefaultButton(activeTextEl);
3315 var bs = opt.buttons;
3319 }else if(bs && bs.yes){
3320 db = buttons["yes"];
3322 dlg.setDefaultButton(db);
3324 bwidth = updateButtons(opt.buttons);
3325 this.updateText(opt.msg);
3327 d.el.addClass(opt.cls);
3329 d.proxyDrag = opt.proxyDrag === true;
3330 d.modal = opt.modal !== false;
3331 d.mask = opt.modal !== false ? mask : false;
3333 // force it to the end of the z-index stack so it gets a cursor in FF
3334 document.body.appendChild(dlg.el.dom);
3335 d.animateTarget = null;
3336 d.show(options.animEl);
3342 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
3343 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3344 * and closing the message box when the process is complete.
3345 * @param {String} title The title bar text
3346 * @param {String} msg The message box body text
3347 * @return {Roo.MessageBox} This message box
3349 progress : function(title, msg){
3356 minWidth: this.minProgressWidth,
3363 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3364 * If a callback function is passed it will be called after the user clicks the button, and the
3365 * id of the button that was clicked will be passed as the only parameter to the callback
3366 * (could also be the top-right close button).
3367 * @param {String} title The title bar text
3368 * @param {String} msg The message box body text
3369 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3370 * @param {Object} scope (optional) The scope of the callback function
3371 * @return {Roo.MessageBox} This message box
3373 alert : function(title, msg, fn, scope)
3388 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
3389 * interaction while waiting for a long-running process to complete that does not have defined intervals.
3390 * You are responsible for closing the message box when the process is complete.
3391 * @param {String} msg The message box body text
3392 * @param {String} title (optional) The title bar text
3393 * @return {Roo.MessageBox} This message box
3395 wait : function(msg, title){
3406 waitTimer = Roo.TaskMgr.start({
3408 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3416 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3417 * If a callback function is passed it will be called after the user clicks either button, and the id of the
3418 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3419 * @param {String} title The title bar text
3420 * @param {String} msg The message box body text
3421 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3422 * @param {Object} scope (optional) The scope of the callback function
3423 * @return {Roo.MessageBox} This message box
3425 confirm : function(title, msg, fn, scope){
3429 buttons: this.YESNO,
3438 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3439 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
3440 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3441 * (could also be the top-right close button) and the text that was entered will be passed as the two
3442 * parameters to the callback.
3443 * @param {String} title The title bar text
3444 * @param {String} msg The message box body text
3445 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3446 * @param {Object} scope (optional) The scope of the callback function
3447 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3448 * property, or the height in pixels to create the textbox (defaults to false / single-line)
3449 * @return {Roo.MessageBox} This message box
3451 prompt : function(title, msg, fn, scope, multiline){
3455 buttons: this.OKCANCEL,
3460 multiline: multiline,
3467 * Button config that displays a single OK button
3472 * Button config that displays Yes and No buttons
3475 YESNO : {yes:true, no:true},
3477 * Button config that displays OK and Cancel buttons
3480 OKCANCEL : {ok:true, cancel:true},
3482 * Button config that displays Yes, No and Cancel buttons
3485 YESNOCANCEL : {yes:true, no:true, cancel:true},
3488 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3491 defaultTextHeight : 75,
3493 * The maximum width in pixels of the message box (defaults to 600)
3498 * The minimum width in pixels of the message box (defaults to 100)
3503 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
3504 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3507 minProgressWidth : 250,
3509 * An object containing the default button text strings that can be overriden for localized language support.
3510 * Supported properties are: ok, cancel, yes and no.
3511 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3524 * Shorthand for {@link Roo.MessageBox}
3526 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3527 Roo.Msg = Roo.Msg || Roo.MessageBox;
3536 * @class Roo.bootstrap.Navbar
3537 * @extends Roo.bootstrap.Component
3538 * Bootstrap Navbar class
3541 * Create a new Navbar
3542 * @param {Object} config The config object
3546 Roo.bootstrap.Navbar = function(config){
3547 Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3551 * @event beforetoggle
3552 * Fire before toggle the menu
3553 * @param {Roo.EventObject} e
3555 "beforetoggle" : true
3559 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component, {
3568 getAutoCreate : function(){
3571 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3575 initEvents :function ()
3577 //Roo.log(this.el.select('.navbar-toggle',true));
3578 this.el.select('.navbar-toggle',true).on('click', function() {
3579 if(this.fireEvent('beforetoggle', this) !== false){
3580 this.el.select('.navbar-collapse',true).toggleClass('in');
3590 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3592 var size = this.el.getSize();
3593 this.maskEl.setSize(size.width, size.height);
3594 this.maskEl.enableDisplayMode("block");
3603 getChildContainer : function()
3605 if (this.el.select('.collapse').getCount()) {
3606 return this.el.select('.collapse',true).first();
3639 * @class Roo.bootstrap.NavSimplebar
3640 * @extends Roo.bootstrap.Navbar
3641 * Bootstrap Sidebar class
3643 * @cfg {Boolean} inverse is inverted color
3645 * @cfg {String} type (nav | pills | tabs)
3646 * @cfg {Boolean} arrangement stacked | justified
3647 * @cfg {String} align (left | right) alignment
3649 * @cfg {Boolean} main (true|false) main nav bar? default false
3650 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3652 * @cfg {String} tag (header|footer|nav|div) default is nav
3658 * Create a new Sidebar
3659 * @param {Object} config The config object
3663 Roo.bootstrap.NavSimplebar = function(config){
3664 Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
3667 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar, {
3683 getAutoCreate : function(){
3687 tag : this.tag || 'div',
3700 this.type = this.type || 'nav';
3701 if (['tabs','pills'].indexOf(this.type)!==-1) {
3702 cfg.cn[0].cls += ' nav-' + this.type
3706 if (this.type!=='nav') {
3707 Roo.log('nav type must be nav/tabs/pills')
3709 cfg.cn[0].cls += ' navbar-nav'
3715 if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
3716 cfg.cn[0].cls += ' nav-' + this.arrangement;
3720 if (this.align === 'right') {
3721 cfg.cn[0].cls += ' navbar-right';
3725 cfg.cls += ' navbar-inverse';
3752 * @class Roo.bootstrap.NavHeaderbar
3753 * @extends Roo.bootstrap.NavSimplebar
3754 * Bootstrap Sidebar class
3756 * @cfg {String} brand what is brand
3757 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
3758 * @cfg {String} brand_href href of the brand
3759 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
3760 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
3761 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
3762 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
3765 * Create a new Sidebar
3766 * @param {Object} config The config object
3770 Roo.bootstrap.NavHeaderbar = function(config){
3771 Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
3775 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar, {
3782 desktopCenter : false,
3785 getAutoCreate : function(){
3788 tag: this.nav || 'nav',
3795 if (this.desktopCenter) {
3796 cn.push({cls : 'container', cn : []});
3803 cls: 'navbar-header',
3808 cls: 'navbar-toggle',
3809 'data-toggle': 'collapse',
3814 html: 'Toggle navigation'
3836 cls: 'collapse navbar-collapse',
3840 cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
3842 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
3843 cfg.cls += ' navbar-' + this.position;
3845 // tag can override this..
3847 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
3850 if (this.brand !== '') {
3853 href: this.brand_href ? this.brand_href : '#',
3854 cls: 'navbar-brand',
3862 cfg.cls += ' main-nav';
3870 getHeaderChildContainer : function()
3872 if (this.srButton && this.el.select('.navbar-header').getCount()) {
3873 return this.el.select('.navbar-header',true).first();
3876 return this.getChildContainer();
3880 initEvents : function()
3882 Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
3884 if (this.autohide) {
3889 Roo.get(document).on('scroll',function(e) {
3890 var ns = Roo.get(document).getScroll().top;
3891 var os = prevScroll;
3895 ft.removeClass('slideDown');
3896 ft.addClass('slideUp');
3899 ft.removeClass('slideUp');
3900 ft.addClass('slideDown');
3921 * @class Roo.bootstrap.NavSidebar
3922 * @extends Roo.bootstrap.Navbar
3923 * Bootstrap Sidebar class
3926 * Create a new Sidebar
3927 * @param {Object} config The config object
3931 Roo.bootstrap.NavSidebar = function(config){
3932 Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
3935 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar, {
3937 sidebar : true, // used by Navbar Item and NavbarGroup at present...
3939 getAutoCreate : function(){
3944 cls: 'sidebar sidebar-nav'
3966 * @class Roo.bootstrap.NavGroup
3967 * @extends Roo.bootstrap.Component
3968 * Bootstrap NavGroup class
3969 * @cfg {String} align (left|right)
3970 * @cfg {Boolean} inverse
3971 * @cfg {String} type (nav|pills|tab) default nav
3972 * @cfg {String} navId - reference Id for navbar.
3976 * Create a new nav group
3977 * @param {Object} config The config object
3980 Roo.bootstrap.NavGroup = function(config){
3981 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
3984 Roo.bootstrap.NavGroup.register(this);
3988 * Fires when the active item changes
3989 * @param {Roo.bootstrap.NavGroup} this
3990 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
3991 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
3998 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
4009 getAutoCreate : function()
4011 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
4018 if (['tabs','pills'].indexOf(this.type)!==-1) {
4019 cfg.cls += ' nav-' + this.type
4021 if (this.type!=='nav') {
4022 Roo.log('nav type must be nav/tabs/pills')
4024 cfg.cls += ' navbar-nav'
4027 if (this.parent() && this.parent().sidebar) {
4030 cls: 'dashboard-menu sidebar-menu'
4036 if (this.form === true) {
4042 if (this.align === 'right') {
4043 cfg.cls += ' navbar-right';
4045 cfg.cls += ' navbar-left';
4049 if (this.align === 'right') {
4050 cfg.cls += ' navbar-right';
4054 cfg.cls += ' navbar-inverse';
4062 * sets the active Navigation item
4063 * @param {Roo.bootstrap.NavItem} the new current navitem
4065 setActiveItem : function(item)
4068 Roo.each(this.navItems, function(v){
4073 v.setActive(false, true);
4080 item.setActive(true, true);
4081 this.fireEvent('changed', this, item, prev);
4086 * gets the active Navigation item
4087 * @return {Roo.bootstrap.NavItem} the current navitem
4089 getActive : function()
4093 Roo.each(this.navItems, function(v){
4104 indexOfNav : function()
4108 Roo.each(this.navItems, function(v,i){
4119 * adds a Navigation item
4120 * @param {Roo.bootstrap.NavItem} the navitem to add
4122 addItem : function(cfg)
4124 var cn = new Roo.bootstrap.NavItem(cfg);
4126 cn.parentId = this.id;
4127 cn.onRender(this.el, null);
4131 * register a Navigation item
4132 * @param {Roo.bootstrap.NavItem} the navitem to add
4134 register : function(item)
4136 this.navItems.push( item);
4137 item.navId = this.navId;
4142 * clear all the Navigation item
4145 clearAll : function()
4148 this.el.dom.innerHTML = '';
4151 getNavItem: function(tabId)
4154 Roo.each(this.navItems, function(e) {
4155 if (e.tabId == tabId) {
4165 setActiveNext : function()
4167 var i = this.indexOfNav(this.getActive());
4168 if (i > this.navItems.length) {
4171 this.setActiveItem(this.navItems[i+1]);
4173 setActivePrev : function()
4175 var i = this.indexOfNav(this.getActive());
4179 this.setActiveItem(this.navItems[i-1]);
4181 clearWasActive : function(except) {
4182 Roo.each(this.navItems, function(e) {
4183 if (e.tabId != except.tabId && e.was_active) {
4184 e.was_active = false;
4191 getWasActive : function ()
4194 Roo.each(this.navItems, function(e) {
4209 Roo.apply(Roo.bootstrap.NavGroup, {
4213 * register a Navigation Group
4214 * @param {Roo.bootstrap.NavGroup} the navgroup to add
4216 register : function(navgrp)
4218 this.groups[navgrp.navId] = navgrp;
4222 * fetch a Navigation Group based on the navigation ID
4223 * @param {string} the navgroup to add
4224 * @returns {Roo.bootstrap.NavGroup} the navgroup
4226 get: function(navId) {
4227 if (typeof(this.groups[navId]) == 'undefined') {
4229 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4231 return this.groups[navId] ;
4246 * @class Roo.bootstrap.NavItem
4247 * @extends Roo.bootstrap.Component
4248 * Bootstrap Navbar.NavItem class
4249 * @cfg {String} href link to
4250 * @cfg {String} html content of button
4251 * @cfg {String} badge text inside badge
4252 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4253 * @cfg {String} glyphicon name of glyphicon
4254 * @cfg {String} icon name of font awesome icon
4255 * @cfg {Boolean} active Is item active
4256 * @cfg {Boolean} disabled Is item disabled
4258 * @cfg {Boolean} preventDefault (true | false) default false
4259 * @cfg {String} tabId the tab that this item activates.
4260 * @cfg {String} tagtype (a|span) render as a href or span?
4261 * @cfg {Boolean} animateRef (true|false) link to element default false
4264 * Create a new Navbar Item
4265 * @param {Object} config The config object
4267 Roo.bootstrap.NavItem = function(config){
4268 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4273 * The raw click event for the entire grid.
4274 * @param {Roo.EventObject} e
4279 * Fires when the active item active state changes
4280 * @param {Roo.bootstrap.NavItem} this
4281 * @param {boolean} state the new state
4287 * Fires when scroll to element
4288 * @param {Roo.bootstrap.NavItem} this
4289 * @param {Object} options
4290 * @param {Roo.EventObject} e
4298 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
4306 preventDefault : false,
4313 getAutoCreate : function(){
4322 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4324 if (this.disabled) {
4325 cfg.cls += ' disabled';
4328 if (this.href || this.html || this.glyphicon || this.icon) {
4332 href : this.href || "#",
4333 html: this.html || ''
4338 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4341 if(this.glyphicon) {
4342 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
4347 cfg.cn[0].html += " <span class='caret'></span>";
4351 if (this.badge !== '') {
4353 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
4361 initEvents: function()
4363 if (typeof (this.menu) != 'undefined') {
4364 this.menu.parentType = this.xtype;
4365 this.menu.triggerEl = this.el;
4366 this.menu = this.addxtype(Roo.apply({}, this.menu));
4369 this.el.select('a',true).on('click', this.onClick, this);
4371 if(this.tagtype == 'span'){
4372 this.el.select('span',true).on('click', this.onClick, this);
4375 // at this point parent should be available..
4376 this.parent().register(this);
4379 onClick : function(e)
4381 if (e.getTarget('.dropdown-menu-item')) {
4382 // did you click on a menu itemm.... - then don't trigger onclick..
4387 this.preventDefault ||
4390 Roo.log("NavItem - prevent Default?");
4394 if (this.disabled) {
4398 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4399 if (tg && tg.transition) {
4400 Roo.log("waiting for the transitionend");
4406 //Roo.log("fire event clicked");
4407 if(this.fireEvent('click', this, e) === false){
4411 if(this.tagtype == 'span'){
4415 //Roo.log(this.href);
4416 var ael = this.el.select('a',true).first();
4419 if(ael && this.animateRef && this.href.indexOf('#') > -1){
4420 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4421 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4422 return; // ignore... - it's a 'hash' to another page.
4424 Roo.log("NavItem - prevent Default?");
4426 this.scrollToElement(e);
4430 var p = this.parent();
4432 if (['tabs','pills'].indexOf(p.type)!==-1) {
4433 if (typeof(p.setActiveItem) !== 'undefined') {
4434 p.setActiveItem(this);
4438 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4439 if (p.parentType == 'NavHeaderbar' && !this.menu) {
4440 // remove the collapsed menu expand...
4441 p.parent().el.select('.navbar-collapse',true).removeClass('in');
4445 isActive: function () {
4448 setActive : function(state, fire, is_was_active)
4450 if (this.active && !state && this.navId) {
4451 this.was_active = true;
4452 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4454 nv.clearWasActive(this);
4458 this.active = state;
4461 this.el.removeClass('active');
4462 } else if (!this.el.hasClass('active')) {
4463 this.el.addClass('active');
4466 this.fireEvent('changed', this, state);
4469 // show a panel if it's registered and related..
4471 if (!this.navId || !this.tabId || !state || is_was_active) {
4475 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4479 var pan = tg.getPanelByName(this.tabId);
4483 // if we can not flip to new panel - go back to old nav highlight..
4484 if (false == tg.showPanel(pan)) {
4485 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4487 var onav = nv.getWasActive();
4489 onav.setActive(true, false, true);
4498 // this should not be here...
4499 setDisabled : function(state)
4501 this.disabled = state;
4503 this.el.removeClass('disabled');
4504 } else if (!this.el.hasClass('disabled')) {
4505 this.el.addClass('disabled');
4511 * Fetch the element to display the tooltip on.
4512 * @return {Roo.Element} defaults to this.el
4514 tooltipEl : function()
4516 return this.el.select('' + this.tagtype + '', true).first();
4519 scrollToElement : function(e)
4521 var c = document.body;
4524 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4526 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4527 c = document.documentElement;
4530 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4536 var o = target.calcOffsetsTo(c);
4543 this.fireEvent('scrollto', this, options, e);
4545 Roo.get(c).scrollTo('top', options.value, true);
4558 * <span> icon </span>
4559 * <span> text </span>
4560 * <span>badge </span>
4564 * @class Roo.bootstrap.NavSidebarItem
4565 * @extends Roo.bootstrap.NavItem
4566 * Bootstrap Navbar.NavSidebarItem class
4567 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4568 * {Boolean} open is the menu open
4569 * {Boolean} buttonView use button as the tigger el rather that a (default false)
4570 * {String} buttonWeight (default|primary|success|info|warning|danger)the extra classes for the button
4571 * {String} buttonSize (sm|md|lg)the extra classes for the button
4572 * {Boolean} showArrow show arrow next to the text (default true)
4574 * Create a new Navbar Button
4575 * @param {Object} config The config object
4577 Roo.bootstrap.NavSidebarItem = function(config){
4578 Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4583 * The raw click event for the entire grid.
4584 * @param {Roo.EventObject} e
4589 * Fires when the active item active state changes
4590 * @param {Roo.bootstrap.NavSidebarItem} this
4591 * @param {boolean} state the new state
4599 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem, {
4601 badgeWeight : 'default',
4607 buttonWeight : 'default',
4613 getAutoCreate : function(){
4618 href : this.href || '#',
4624 if(this.buttonView){
4627 href : this.href || '#',
4628 cls: 'btn btn-' + this.buttonWeight + ' btn-' + this.buttonSize + 'roo-button-dropdown-toggle',
4641 cfg.cls += ' active';
4644 if (this.disabled) {
4645 cfg.cls += ' disabled';
4648 cfg.cls += ' open x-open';
4651 if (this.glyphicon || this.icon) {
4652 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
4653 a.cn.push({ tag : 'i', cls : c }) ;
4656 if(!this.buttonView){
4659 html : this.html || ''
4666 if (this.badge !== '') {
4667 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
4673 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
4676 a.cls += ' dropdown-toggle treeview' ;
4682 initEvents : function()
4684 if (typeof (this.menu) != 'undefined') {
4685 this.menu.parentType = this.xtype;
4686 this.menu.triggerEl = this.el;
4687 this.menu = this.addxtype(Roo.apply({}, this.menu));
4690 this.el.on('click', this.onClick, this);
4692 if(this.badge !== ''){
4693 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
4698 onClick : function(e)
4705 if(this.preventDefault){
4709 this.fireEvent('click', this);
4712 disable : function()
4714 this.setDisabled(true);
4719 this.setDisabled(false);
4722 setDisabled : function(state)
4724 if(this.disabled == state){
4728 this.disabled = state;
4731 this.el.addClass('disabled');
4735 this.el.removeClass('disabled');
4740 setActive : function(state)
4742 if(this.active == state){
4746 this.active = state;
4749 this.el.addClass('active');
4753 this.el.removeClass('active');
4758 isActive: function ()
4763 setBadge : function(str)
4769 this.badgeEl.dom.innerHTML = str;
4786 * @class Roo.bootstrap.Row
4787 * @extends Roo.bootstrap.Component
4788 * Bootstrap Row class (contains columns...)
4792 * @param {Object} config The config object
4795 Roo.bootstrap.Row = function(config){
4796 Roo.bootstrap.Row.superclass.constructor.call(this, config);
4799 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
4801 getAutoCreate : function(){
4820 * @class Roo.bootstrap.Element
4821 * @extends Roo.bootstrap.Component
4822 * Bootstrap Element class
4823 * @cfg {String} html contents of the element
4824 * @cfg {String} tag tag of the element
4825 * @cfg {String} cls class of the element
4826 * @cfg {Boolean} preventDefault (true|false) default false
4827 * @cfg {Boolean} clickable (true|false) default false
4830 * Create a new Element
4831 * @param {Object} config The config object
4834 Roo.bootstrap.Element = function(config){
4835 Roo.bootstrap.Element.superclass.constructor.call(this, config);
4841 * When a element is chick
4842 * @param {Roo.bootstrap.Element} this
4843 * @param {Roo.EventObject} e
4849 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
4854 preventDefault: false,
4857 getAutoCreate : function(){
4868 initEvents: function()
4870 Roo.bootstrap.Element.superclass.initEvents.call(this);
4873 this.el.on('click', this.onClick, this);
4878 onClick : function(e)
4880 if(this.preventDefault){
4884 this.fireEvent('click', this, e);
4887 getValue : function()
4889 return this.el.dom.innerHTML;
4892 setValue : function(value)
4894 this.el.dom.innerHTML = value;
4909 * @class Roo.bootstrap.Pagination
4910 * @extends Roo.bootstrap.Component
4911 * Bootstrap Pagination class
4912 * @cfg {String} size xs | sm | md | lg
4913 * @cfg {Boolean} inverse false | true
4916 * Create a new Pagination
4917 * @param {Object} config The config object
4920 Roo.bootstrap.Pagination = function(config){
4921 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
4924 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
4930 getAutoCreate : function(){
4936 cfg.cls += ' inverse';
4942 cfg.cls += " " + this.cls;
4960 * @class Roo.bootstrap.PaginationItem
4961 * @extends Roo.bootstrap.Component
4962 * Bootstrap PaginationItem class
4963 * @cfg {String} html text
4964 * @cfg {String} href the link
4965 * @cfg {Boolean} preventDefault (true | false) default true
4966 * @cfg {Boolean} active (true | false) default false
4967 * @cfg {Boolean} disabled default false
4971 * Create a new PaginationItem
4972 * @param {Object} config The config object
4976 Roo.bootstrap.PaginationItem = function(config){
4977 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
4982 * The raw click event for the entire grid.
4983 * @param {Roo.EventObject} e
4989 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
4993 preventDefault: true,
4998 getAutoCreate : function(){
5004 href : this.href ? this.href : '#',
5005 html : this.html ? this.html : ''
5015 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
5019 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
5025 initEvents: function() {
5027 this.el.on('click', this.onClick, this);
5030 onClick : function(e)
5032 Roo.log('PaginationItem on click ');
5033 if(this.preventDefault){
5041 this.fireEvent('click', this, e);
5057 * @class Roo.bootstrap.Slider
5058 * @extends Roo.bootstrap.Component
5059 * Bootstrap Slider class
5062 * Create a new Slider
5063 * @param {Object} config The config object
5066 Roo.bootstrap.Slider = function(config){
5067 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
5070 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
5072 getAutoCreate : function(){
5076 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
5080 cls: 'ui-slider-handle ui-state-default ui-corner-all'
5092 * Ext JS Library 1.1.1
5093 * Copyright(c) 2006-2007, Ext JS, LLC.
5095 * Originally Released Under LGPL - original licence link has changed is not relivant.
5098 * <script type="text/javascript">
5103 * @class Roo.grid.ColumnModel
5104 * @extends Roo.util.Observable
5105 * This is the default implementation of a ColumnModel used by the Grid. It defines
5106 * the columns in the grid.
5109 var colModel = new Roo.grid.ColumnModel([
5110 {header: "Ticker", width: 60, sortable: true, locked: true},
5111 {header: "Company Name", width: 150, sortable: true},
5112 {header: "Market Cap.", width: 100, sortable: true},
5113 {header: "$ Sales", width: 100, sortable: true, renderer: money},
5114 {header: "Employees", width: 100, sortable: true, resizable: false}
5119 * The config options listed for this class are options which may appear in each
5120 * individual column definition.
5121 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5123 * @param {Object} config An Array of column config objects. See this class's
5124 * config objects for details.
5126 Roo.grid.ColumnModel = function(config){
5128 * The config passed into the constructor
5130 this.config = config;
5133 // if no id, create one
5134 // if the column does not have a dataIndex mapping,
5135 // map it to the order it is in the config
5136 for(var i = 0, len = config.length; i < len; i++){
5138 if(typeof c.dataIndex == "undefined"){
5141 if(typeof c.renderer == "string"){
5142 c.renderer = Roo.util.Format[c.renderer];
5144 if(typeof c.id == "undefined"){
5147 if(c.editor && c.editor.xtype){
5148 c.editor = Roo.factory(c.editor, Roo.grid);
5150 if(c.editor && c.editor.isFormField){
5151 c.editor = new Roo.grid.GridEditor(c.editor);
5153 this.lookup[c.id] = c;
5157 * The width of columns which have no width specified (defaults to 100)
5160 this.defaultWidth = 100;
5163 * Default sortable of columns which have no sortable specified (defaults to false)
5166 this.defaultSortable = false;
5170 * @event widthchange
5171 * Fires when the width of a column changes.
5172 * @param {ColumnModel} this
5173 * @param {Number} columnIndex The column index
5174 * @param {Number} newWidth The new width
5176 "widthchange": true,
5178 * @event headerchange
5179 * Fires when the text of a header changes.
5180 * @param {ColumnModel} this
5181 * @param {Number} columnIndex The column index
5182 * @param {Number} newText The new header text
5184 "headerchange": true,
5186 * @event hiddenchange
5187 * Fires when a column is hidden or "unhidden".
5188 * @param {ColumnModel} this
5189 * @param {Number} columnIndex The column index
5190 * @param {Boolean} hidden true if hidden, false otherwise
5192 "hiddenchange": true,
5194 * @event columnmoved
5195 * Fires when a column is moved.
5196 * @param {ColumnModel} this
5197 * @param {Number} oldIndex
5198 * @param {Number} newIndex
5200 "columnmoved" : true,
5202 * @event columlockchange
5203 * Fires when a column's locked state is changed
5204 * @param {ColumnModel} this
5205 * @param {Number} colIndex
5206 * @param {Boolean} locked true if locked
5208 "columnlockchange" : true
5210 Roo.grid.ColumnModel.superclass.constructor.call(this);
5212 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5214 * @cfg {String} header The header text to display in the Grid view.
5217 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5218 * {@link Roo.data.Record} definition from which to draw the column's value. If not
5219 * specified, the column's index is used as an index into the Record's data Array.
5222 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5223 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5226 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5227 * Defaults to the value of the {@link #defaultSortable} property.
5228 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5231 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
5234 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
5237 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5240 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5243 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5244 * given the cell's data value. See {@link #setRenderer}. If not specified, the
5245 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
5246 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5249 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
5252 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
5255 * @cfg {String} cursor (Optional)
5258 * @cfg {String} tooltip (Optional)
5261 * @cfg {Number} xs (Optional)
5264 * @cfg {Number} sm (Optional)
5267 * @cfg {Number} md (Optional)
5270 * @cfg {Number} lg (Optional)
5273 * Returns the id of the column at the specified index.
5274 * @param {Number} index The column index
5275 * @return {String} the id
5277 getColumnId : function(index){
5278 return this.config[index].id;
5282 * Returns the column for a specified id.
5283 * @param {String} id The column id
5284 * @return {Object} the column
5286 getColumnById : function(id){
5287 return this.lookup[id];
5292 * Returns the column for a specified dataIndex.
5293 * @param {String} dataIndex The column dataIndex
5294 * @return {Object|Boolean} the column or false if not found
5296 getColumnByDataIndex: function(dataIndex){
5297 var index = this.findColumnIndex(dataIndex);
5298 return index > -1 ? this.config[index] : false;
5302 * Returns the index for a specified column id.
5303 * @param {String} id The column id
5304 * @return {Number} the index, or -1 if not found
5306 getIndexById : function(id){
5307 for(var i = 0, len = this.config.length; i < len; i++){
5308 if(this.config[i].id == id){
5316 * Returns the index for a specified column dataIndex.
5317 * @param {String} dataIndex The column dataIndex
5318 * @return {Number} the index, or -1 if not found
5321 findColumnIndex : function(dataIndex){
5322 for(var i = 0, len = this.config.length; i < len; i++){
5323 if(this.config[i].dataIndex == dataIndex){
5331 moveColumn : function(oldIndex, newIndex){
5332 var c = this.config[oldIndex];
5333 this.config.splice(oldIndex, 1);
5334 this.config.splice(newIndex, 0, c);
5335 this.dataMap = null;
5336 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5339 isLocked : function(colIndex){
5340 return this.config[colIndex].locked === true;
5343 setLocked : function(colIndex, value, suppressEvent){
5344 if(this.isLocked(colIndex) == value){
5347 this.config[colIndex].locked = value;
5349 this.fireEvent("columnlockchange", this, colIndex, value);
5353 getTotalLockedWidth : function(){
5355 for(var i = 0; i < this.config.length; i++){
5356 if(this.isLocked(i) && !this.isHidden(i)){
5357 this.totalWidth += this.getColumnWidth(i);
5363 getLockedCount : function(){
5364 for(var i = 0, len = this.config.length; i < len; i++){
5365 if(!this.isLocked(i)){
5370 return this.config.length;
5374 * Returns the number of columns.
5377 getColumnCount : function(visibleOnly){
5378 if(visibleOnly === true){
5380 for(var i = 0, len = this.config.length; i < len; i++){
5381 if(!this.isHidden(i)){
5387 return this.config.length;
5391 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5392 * @param {Function} fn
5393 * @param {Object} scope (optional)
5394 * @return {Array} result
5396 getColumnsBy : function(fn, scope){
5398 for(var i = 0, len = this.config.length; i < len; i++){
5399 var c = this.config[i];
5400 if(fn.call(scope||this, c, i) === true){
5408 * Returns true if the specified column is sortable.
5409 * @param {Number} col The column index
5412 isSortable : function(col){
5413 if(typeof this.config[col].sortable == "undefined"){
5414 return this.defaultSortable;
5416 return this.config[col].sortable;
5420 * Returns the rendering (formatting) function defined for the column.
5421 * @param {Number} col The column index.
5422 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5424 getRenderer : function(col){
5425 if(!this.config[col].renderer){
5426 return Roo.grid.ColumnModel.defaultRenderer;
5428 return this.config[col].renderer;
5432 * Sets the rendering (formatting) function for a column.
5433 * @param {Number} col The column index
5434 * @param {Function} fn The function to use to process the cell's raw data
5435 * to return HTML markup for the grid view. The render function is called with
5436 * the following parameters:<ul>
5437 * <li>Data value.</li>
5438 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5439 * <li>css A CSS style string to apply to the table cell.</li>
5440 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5441 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5442 * <li>Row index</li>
5443 * <li>Column index</li>
5444 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5446 setRenderer : function(col, fn){
5447 this.config[col].renderer = fn;
5451 * Returns the width for the specified column.
5452 * @param {Number} col The column index
5455 getColumnWidth : function(col){
5456 return this.config[col].width * 1 || this.defaultWidth;
5460 * Sets the width for a column.
5461 * @param {Number} col The column index
5462 * @param {Number} width The new width
5464 setColumnWidth : function(col, width, suppressEvent){
5465 this.config[col].width = width;
5466 this.totalWidth = null;
5468 this.fireEvent("widthchange", this, col, width);
5473 * Returns the total width of all columns.
5474 * @param {Boolean} includeHidden True to include hidden column widths
5477 getTotalWidth : function(includeHidden){
5478 if(!this.totalWidth){
5479 this.totalWidth = 0;
5480 for(var i = 0, len = this.config.length; i < len; i++){
5481 if(includeHidden || !this.isHidden(i)){
5482 this.totalWidth += this.getColumnWidth(i);
5486 return this.totalWidth;
5490 * Returns the header for the specified column.
5491 * @param {Number} col The column index
5494 getColumnHeader : function(col){
5495 return this.config[col].header;
5499 * Sets the header for a column.
5500 * @param {Number} col The column index
5501 * @param {String} header The new header
5503 setColumnHeader : function(col, header){
5504 this.config[col].header = header;
5505 this.fireEvent("headerchange", this, col, header);
5509 * Returns the tooltip for the specified column.
5510 * @param {Number} col The column index
5513 getColumnTooltip : function(col){
5514 return this.config[col].tooltip;
5517 * Sets the tooltip for a column.
5518 * @param {Number} col The column index
5519 * @param {String} tooltip The new tooltip
5521 setColumnTooltip : function(col, tooltip){
5522 this.config[col].tooltip = tooltip;
5526 * Returns the dataIndex for the specified column.
5527 * @param {Number} col The column index
5530 getDataIndex : function(col){
5531 return this.config[col].dataIndex;
5535 * Sets the dataIndex for a column.
5536 * @param {Number} col The column index
5537 * @param {Number} dataIndex The new dataIndex
5539 setDataIndex : function(col, dataIndex){
5540 this.config[col].dataIndex = dataIndex;
5546 * Returns true if the cell is editable.
5547 * @param {Number} colIndex The column index
5548 * @param {Number} rowIndex The row index - this is nto actually used..?
5551 isCellEditable : function(colIndex, rowIndex){
5552 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5556 * Returns the editor defined for the cell/column.
5557 * return false or null to disable editing.
5558 * @param {Number} colIndex The column index
5559 * @param {Number} rowIndex The row index
5562 getCellEditor : function(colIndex, rowIndex){
5563 return this.config[colIndex].editor;
5567 * Sets if a column is editable.
5568 * @param {Number} col The column index
5569 * @param {Boolean} editable True if the column is editable
5571 setEditable : function(col, editable){
5572 this.config[col].editable = editable;
5577 * Returns true if the column is hidden.
5578 * @param {Number} colIndex The column index
5581 isHidden : function(colIndex){
5582 return this.config[colIndex].hidden;
5587 * Returns true if the column width cannot be changed
5589 isFixed : function(colIndex){
5590 return this.config[colIndex].fixed;
5594 * Returns true if the column can be resized
5597 isResizable : function(colIndex){
5598 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5601 * Sets if a column is hidden.
5602 * @param {Number} colIndex The column index
5603 * @param {Boolean} hidden True if the column is hidden
5605 setHidden : function(colIndex, hidden){
5606 this.config[colIndex].hidden = hidden;
5607 this.totalWidth = null;
5608 this.fireEvent("hiddenchange", this, colIndex, hidden);
5612 * Sets the editor for a column.
5613 * @param {Number} col The column index
5614 * @param {Object} editor The editor object
5616 setEditor : function(col, editor){
5617 this.config[col].editor = editor;
5621 Roo.grid.ColumnModel.defaultRenderer = function(value)
5623 if(typeof value == "object") {
5626 if(typeof value == "string" && value.length < 1){
5630 return String.format("{0}", value);
5633 // Alias for backwards compatibility
5634 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
5637 * Ext JS Library 1.1.1
5638 * Copyright(c) 2006-2007, Ext JS, LLC.
5640 * Originally Released Under LGPL - original licence link has changed is not relivant.
5643 * <script type="text/javascript">
5647 * @class Roo.LoadMask
5648 * A simple utility class for generically masking elements while loading data. If the element being masked has
5649 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
5650 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
5651 * element's UpdateManager load indicator and will be destroyed after the initial load.
5653 * Create a new LoadMask
5654 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
5655 * @param {Object} config The config object
5657 Roo.LoadMask = function(el, config){
5658 this.el = Roo.get(el);
5659 Roo.apply(this, config);
5661 this.store.on('beforeload', this.onBeforeLoad, this);
5662 this.store.on('load', this.onLoad, this);
5663 this.store.on('loadexception', this.onLoadException, this);
5664 this.removeMask = false;
5666 var um = this.el.getUpdateManager();
5667 um.showLoadIndicator = false; // disable the default indicator
5668 um.on('beforeupdate', this.onBeforeLoad, this);
5669 um.on('update', this.onLoad, this);
5670 um.on('failure', this.onLoad, this);
5671 this.removeMask = true;
5675 Roo.LoadMask.prototype = {
5677 * @cfg {Boolean} removeMask
5678 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
5679 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
5683 * The text to display in a centered loading message box (defaults to 'Loading...')
5687 * @cfg {String} msgCls
5688 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
5690 msgCls : 'x-mask-loading',
5693 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
5699 * Disables the mask to prevent it from being displayed
5701 disable : function(){
5702 this.disabled = true;
5706 * Enables the mask so that it can be displayed
5708 enable : function(){
5709 this.disabled = false;
5712 onLoadException : function()
5716 if (typeof(arguments[3]) != 'undefined') {
5717 Roo.MessageBox.alert("Error loading",arguments[3]);
5721 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
5722 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
5729 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5734 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5738 onBeforeLoad : function(){
5740 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
5745 destroy : function(){
5747 this.store.un('beforeload', this.onBeforeLoad, this);
5748 this.store.un('load', this.onLoad, this);
5749 this.store.un('loadexception', this.onLoadException, this);
5751 var um = this.el.getUpdateManager();
5752 um.un('beforeupdate', this.onBeforeLoad, this);
5753 um.un('update', this.onLoad, this);
5754 um.un('failure', this.onLoad, this);
5765 * @class Roo.bootstrap.Table
5766 * @extends Roo.bootstrap.Component
5767 * Bootstrap Table class
5768 * @cfg {String} cls table class
5769 * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
5770 * @cfg {String} bgcolor Specifies the background color for a table
5771 * @cfg {Number} border Specifies whether the table cells should have borders or not
5772 * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
5773 * @cfg {Number} cellspacing Specifies the space between cells
5774 * @cfg {String} frame Specifies which parts of the outside borders that should be visible
5775 * @cfg {String} rules Specifies which parts of the inside borders that should be visible
5776 * @cfg {String} sortable Specifies that the table should be sortable
5777 * @cfg {String} summary Specifies a summary of the content of a table
5778 * @cfg {Number} width Specifies the width of a table
5779 * @cfg {String} layout table layout (auto | fixed | initial | inherit)
5781 * @cfg {boolean} striped Should the rows be alternative striped
5782 * @cfg {boolean} bordered Add borders to the table
5783 * @cfg {boolean} hover Add hover highlighting
5784 * @cfg {boolean} condensed Format condensed
5785 * @cfg {boolean} responsive Format condensed
5786 * @cfg {Boolean} loadMask (true|false) default false
5787 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
5788 * @cfg {Boolean} headerShow (true|false) generate thead, default true
5789 * @cfg {Boolean} rowSelection (true|false) default false
5790 * @cfg {Boolean} cellSelection (true|false) default false
5791 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
5792 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
5793 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
5797 * Create a new Table
5798 * @param {Object} config The config object
5801 Roo.bootstrap.Table = function(config){
5802 Roo.bootstrap.Table.superclass.constructor.call(this, config);
5807 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
5808 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
5809 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
5810 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
5812 this.sm = this.sm || {xtype: 'RowSelectionModel'};
5814 this.sm.grid = this;
5815 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
5816 this.sm = this.selModel;
5817 this.sm.xmodule = this.xmodule || false;
5820 if (this.cm && typeof(this.cm.config) == 'undefined') {
5821 this.colModel = new Roo.grid.ColumnModel(this.cm);
5822 this.cm = this.colModel;
5823 this.cm.xmodule = this.xmodule || false;
5826 this.store= Roo.factory(this.store, Roo.data);
5827 this.ds = this.store;
5828 this.ds.xmodule = this.xmodule || false;
5831 if (this.footer && this.store) {
5832 this.footer.dataSource = this.ds;
5833 this.footer = Roo.factory(this.footer);
5840 * Fires when a cell is clicked
5841 * @param {Roo.bootstrap.Table} this
5842 * @param {Roo.Element} el
5843 * @param {Number} rowIndex
5844 * @param {Number} columnIndex
5845 * @param {Roo.EventObject} e
5849 * @event celldblclick
5850 * Fires when a cell is double clicked
5851 * @param {Roo.bootstrap.Table} this
5852 * @param {Roo.Element} el
5853 * @param {Number} rowIndex
5854 * @param {Number} columnIndex
5855 * @param {Roo.EventObject} e
5857 "celldblclick" : true,
5860 * Fires when a row is clicked
5861 * @param {Roo.bootstrap.Table} this
5862 * @param {Roo.Element} el
5863 * @param {Number} rowIndex
5864 * @param {Roo.EventObject} e
5868 * @event rowdblclick
5869 * Fires when a row is double clicked
5870 * @param {Roo.bootstrap.Table} this
5871 * @param {Roo.Element} el
5872 * @param {Number} rowIndex
5873 * @param {Roo.EventObject} e
5875 "rowdblclick" : true,
5878 * Fires when a mouseover occur
5879 * @param {Roo.bootstrap.Table} this
5880 * @param {Roo.Element} el
5881 * @param {Number} rowIndex
5882 * @param {Number} columnIndex
5883 * @param {Roo.EventObject} e
5888 * Fires when a mouseout occur
5889 * @param {Roo.bootstrap.Table} this
5890 * @param {Roo.Element} el
5891 * @param {Number} rowIndex
5892 * @param {Number} columnIndex
5893 * @param {Roo.EventObject} e
5898 * Fires when a row is rendered, so you can change add a style to it.
5899 * @param {Roo.bootstrap.Table} this
5900 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
5904 * @event rowsrendered
5905 * Fires when all the rows have been rendered
5906 * @param {Roo.bootstrap.Table} this
5908 'rowsrendered' : true,
5910 * @event contextmenu
5911 * The raw contextmenu event for the entire grid.
5912 * @param {Roo.EventObject} e
5914 "contextmenu" : true,
5916 * @event rowcontextmenu
5917 * Fires when a row is right clicked
5918 * @param {Roo.bootstrap.Table} this
5919 * @param {Number} rowIndex
5920 * @param {Roo.EventObject} e
5922 "rowcontextmenu" : true,
5924 * @event cellcontextmenu
5925 * Fires when a cell is right clicked
5926 * @param {Roo.bootstrap.Table} this
5927 * @param {Number} rowIndex
5928 * @param {Number} cellIndex
5929 * @param {Roo.EventObject} e
5931 "cellcontextmenu" : true,
5933 * @event headercontextmenu
5934 * Fires when a header is right clicked
5935 * @param {Roo.bootstrap.Table} this
5936 * @param {Number} columnIndex
5937 * @param {Roo.EventObject} e
5939 "headercontextmenu" : true
5943 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
5969 rowSelection : false,
5970 cellSelection : false,
5973 // Roo.Element - the tbody
5975 // Roo.Element - thead element
5978 container: false, // used by gridpanel...
5982 getAutoCreate : function()
5984 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
5991 if (this.scrollBody) {
5992 cfg.cls += ' table-body-fixed';
5995 cfg.cls += ' table-striped';
5999 cfg.cls += ' table-hover';
6001 if (this.bordered) {
6002 cfg.cls += ' table-bordered';
6004 if (this.condensed) {
6005 cfg.cls += ' table-condensed';
6007 if (this.responsive) {
6008 cfg.cls += ' table-responsive';
6012 cfg.cls+= ' ' +this.cls;
6015 // this lot should be simplifed...
6018 cfg.align=this.align;
6021 cfg.bgcolor=this.bgcolor;
6024 cfg.border=this.border;
6026 if (this.cellpadding) {
6027 cfg.cellpadding=this.cellpadding;
6029 if (this.cellspacing) {
6030 cfg.cellspacing=this.cellspacing;
6033 cfg.frame=this.frame;
6036 cfg.rules=this.rules;
6038 if (this.sortable) {
6039 cfg.sortable=this.sortable;
6042 cfg.summary=this.summary;
6045 cfg.width=this.width;
6048 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
6051 if(this.store || this.cm){
6052 if(this.headerShow){
6053 cfg.cn.push(this.renderHeader());
6056 cfg.cn.push(this.renderBody());
6058 if(this.footerShow){
6059 cfg.cn.push(this.renderFooter());
6061 // where does this come from?
6062 //cfg.cls+= ' TableGrid';
6065 return { cn : [ cfg ] };
6068 initEvents : function()
6070 if(!this.store || !this.cm){
6073 if (this.selModel) {
6074 this.selModel.initEvents();
6078 //Roo.log('initEvents with ds!!!!');
6080 this.mainBody = this.el.select('tbody', true).first();
6081 this.mainHead = this.el.select('thead', true).first();
6088 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6089 e.on('click', _this.sort, _this);
6092 this.mainBody.on("click", this.onClick, this);
6093 this.mainBody.on("dblclick", this.onDblClick, this);
6095 // why is this done????? = it breaks dialogs??
6096 //this.parent().el.setStyle('position', 'relative');
6100 this.footer.parentId = this.id;
6101 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
6104 this.el.select('tfoot tr td').first().addClass('hide');
6108 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
6110 this.store.on('load', this.onLoad, this);
6111 this.store.on('beforeload', this.onBeforeLoad, this);
6112 this.store.on('update', this.onUpdate, this);
6113 this.store.on('add', this.onAdd, this);
6114 this.store.on("clear", this.clear, this);
6116 this.el.on("contextmenu", this.onContextMenu, this);
6118 this.mainBody.on('scroll', this.onBodyScroll, this);
6123 onContextMenu : function(e, t)
6125 this.processEvent("contextmenu", e);
6128 processEvent : function(name, e)
6130 if (name != 'touchstart' ) {
6131 this.fireEvent(name, e);
6134 var t = e.getTarget();
6136 var cell = Roo.get(t);
6142 if(cell.findParent('tfoot', false, true)){
6146 if(cell.findParent('thead', false, true)){
6148 if(e.getTarget().nodeName.toLowerCase() != 'th'){
6149 cell = Roo.get(t).findParent('th', false, true);
6151 Roo.log("failed to find th in thead?");
6152 Roo.log(e.getTarget());
6157 var cellIndex = cell.dom.cellIndex;
6159 var ename = name == 'touchstart' ? 'click' : name;
6160 this.fireEvent("header" + ename, this, cellIndex, e);
6165 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6166 cell = Roo.get(t).findParent('td', false, true);
6168 Roo.log("failed to find th in tbody?");
6169 Roo.log(e.getTarget());
6174 var row = cell.findParent('tr', false, true);
6175 var cellIndex = cell.dom.cellIndex;
6176 var rowIndex = row.dom.rowIndex - 1;
6180 this.fireEvent("row" + name, this, rowIndex, e);
6184 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6190 onMouseover : function(e, el)
6192 var cell = Roo.get(el);
6198 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6199 cell = cell.findParent('td', false, true);
6202 var row = cell.findParent('tr', false, true);
6203 var cellIndex = cell.dom.cellIndex;
6204 var rowIndex = row.dom.rowIndex - 1; // start from 0
6206 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
6210 onMouseout : function(e, el)
6212 var cell = Roo.get(el);
6218 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6219 cell = cell.findParent('td', false, true);
6222 var row = cell.findParent('tr', false, true);
6223 var cellIndex = cell.dom.cellIndex;
6224 var rowIndex = row.dom.rowIndex - 1; // start from 0
6226 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6230 onClick : function(e, el)
6232 var cell = Roo.get(el);
6234 if(!cell || (!this.cellSelection && !this.rowSelection)){
6238 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6239 cell = cell.findParent('td', false, true);
6242 if(!cell || typeof(cell) == 'undefined'){
6246 var row = cell.findParent('tr', false, true);
6248 if(!row || typeof(row) == 'undefined'){
6252 var cellIndex = cell.dom.cellIndex;
6253 var rowIndex = this.getRowIndex(row);
6255 // why??? - should these not be based on SelectionModel?
6256 if(this.cellSelection){
6257 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6260 if(this.rowSelection){
6261 this.fireEvent('rowclick', this, row, rowIndex, e);
6267 onDblClick : function(e,el)
6269 var cell = Roo.get(el);
6271 if(!cell || (!this.cellSelection && !this.rowSelection)){
6275 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6276 cell = cell.findParent('td', false, true);
6279 if(!cell || typeof(cell) == 'undefined'){
6283 var row = cell.findParent('tr', false, true);
6285 if(!row || typeof(row) == 'undefined'){
6289 var cellIndex = cell.dom.cellIndex;
6290 var rowIndex = this.getRowIndex(row);
6292 if(this.cellSelection){
6293 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6296 if(this.rowSelection){
6297 this.fireEvent('rowdblclick', this, row, rowIndex, e);
6301 sort : function(e,el)
6303 var col = Roo.get(el);
6305 if(!col.hasClass('sortable')){
6309 var sort = col.attr('sort');
6312 if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6316 this.store.sortInfo = {field : sort, direction : dir};
6319 Roo.log("calling footer first");
6320 this.footer.onClick('first');
6323 this.store.load({ params : { start : 0 } });
6327 renderHeader : function()
6335 this.totalWidth = 0;
6337 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6339 var config = cm.config[i];
6344 html: cm.getColumnHeader(i)
6349 if(typeof(config.sortable) != 'undefined' && config.sortable){
6351 c.html = '<i class="glyphicon"></i>' + c.html;
6354 if(typeof(config.lgHeader) != 'undefined'){
6355 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6358 if(typeof(config.mdHeader) != 'undefined'){
6359 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6362 if(typeof(config.smHeader) != 'undefined'){
6363 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6366 if(typeof(config.xsHeader) != 'undefined'){
6367 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6374 if(typeof(config.tooltip) != 'undefined'){
6375 c.tooltip = config.tooltip;
6378 if(typeof(config.colspan) != 'undefined'){
6379 c.colspan = config.colspan;
6382 if(typeof(config.hidden) != 'undefined' && config.hidden){
6383 c.style += ' display:none;';
6386 if(typeof(config.dataIndex) != 'undefined'){
6387 c.sort = config.dataIndex;
6392 if(typeof(config.align) != 'undefined' && config.align.length){
6393 c.style += ' text-align:' + config.align + ';';
6396 if(typeof(config.width) != 'undefined'){
6397 c.style += ' width:' + config.width + 'px;';
6398 this.totalWidth += config.width;
6400 this.totalWidth += 100; // assume minimum of 100 per column?
6403 if(typeof(config.cls) != 'undefined'){
6404 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6407 ['xs','sm','md','lg'].map(function(size){
6409 if(typeof(config[size]) == 'undefined'){
6413 if (!config[size]) { // 0 = hidden
6414 c.cls += ' hidden-' + size;
6418 c.cls += ' col-' + size + '-' + config[size];
6428 renderBody : function()
6438 colspan : this.cm.getColumnCount()
6448 renderFooter : function()
6458 colspan : this.cm.getColumnCount()
6472 // Roo.log('ds onload');
6477 var ds = this.store;
6479 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6480 e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6481 if (_this.store.sortInfo) {
6483 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6484 e.select('i', true).addClass(['glyphicon-arrow-up']);
6487 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6488 e.select('i', true).addClass(['glyphicon-arrow-down']);
6493 var tbody = this.mainBody;
6495 if(ds.getCount() > 0){
6496 ds.data.each(function(d,rowIndex){
6497 var row = this.renderRow(cm, ds, rowIndex);
6499 tbody.createChild(row);
6503 if(row.cellObjects.length){
6504 Roo.each(row.cellObjects, function(r){
6505 _this.renderCellObject(r);
6512 Roo.each(this.el.select('tbody td', true).elements, function(e){
6513 e.on('mouseover', _this.onMouseover, _this);
6516 Roo.each(this.el.select('tbody td', true).elements, function(e){
6517 e.on('mouseout', _this.onMouseout, _this);
6519 this.fireEvent('rowsrendered', this);
6520 //if(this.loadMask){
6521 // this.maskEl.hide();
6528 onUpdate : function(ds,record)
6530 this.refreshRow(record);
6534 onRemove : function(ds, record, index, isUpdate){
6535 if(isUpdate !== true){
6536 this.fireEvent("beforerowremoved", this, index, record);
6538 var bt = this.mainBody.dom;
6540 var rows = this.el.select('tbody > tr', true).elements;
6542 if(typeof(rows[index]) != 'undefined'){
6543 bt.removeChild(rows[index].dom);
6546 // if(bt.rows[index]){
6547 // bt.removeChild(bt.rows[index]);
6550 if(isUpdate !== true){
6551 //this.stripeRows(index);
6552 //this.syncRowHeights(index, index);
6554 this.fireEvent("rowremoved", this, index, record);
6558 onAdd : function(ds, records, rowIndex)
6560 //Roo.log('on Add called');
6561 // - note this does not handle multiple adding very well..
6562 var bt = this.mainBody.dom;
6563 for (var i =0 ; i < records.length;i++) {
6564 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6565 //Roo.log(records[i]);
6566 //Roo.log(this.store.getAt(rowIndex+i));
6567 this.insertRow(this.store, rowIndex + i, false);
6574 refreshRow : function(record){
6575 var ds = this.store, index;
6576 if(typeof record == 'number'){
6578 record = ds.getAt(index);
6580 index = ds.indexOf(record);
6582 this.insertRow(ds, index, true);
6584 this.onRemove(ds, record, index+1, true);
6586 //this.syncRowHeights(index, index);
6588 this.fireEvent("rowupdated", this, index, record);
6591 insertRow : function(dm, rowIndex, isUpdate){
6594 this.fireEvent("beforerowsinserted", this, rowIndex);
6596 //var s = this.getScrollState();
6597 var row = this.renderRow(this.cm, this.store, rowIndex);
6598 // insert before rowIndex..
6599 var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
6603 if(row.cellObjects.length){
6604 Roo.each(row.cellObjects, function(r){
6605 _this.renderCellObject(r);
6610 this.fireEvent("rowsinserted", this, rowIndex);
6611 //this.syncRowHeights(firstRow, lastRow);
6612 //this.stripeRows(firstRow);
6619 getRowDom : function(rowIndex)
6621 var rows = this.el.select('tbody > tr', true).elements;
6623 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
6626 // returns the object tree for a tr..
6629 renderRow : function(cm, ds, rowIndex)
6632 var d = ds.getAt(rowIndex);
6639 var cellObjects = [];
6641 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6642 var config = cm.config[i];
6644 var renderer = cm.getRenderer(i);
6648 if(typeof(renderer) !== 'undefined'){
6649 value = renderer(d.data[cm.getDataIndex(i)], false, d);
6651 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
6652 // and are rendered into the cells after the row is rendered - using the id for the element.
6654 if(typeof(value) === 'object'){
6664 rowIndex : rowIndex,
6669 this.fireEvent('rowclass', this, rowcfg);
6673 cls : rowcfg.rowClass,
6675 html: (typeof(value) === 'object') ? '' : value
6682 if(typeof(config.colspan) != 'undefined'){
6683 td.colspan = config.colspan;
6686 if(typeof(config.hidden) != 'undefined' && config.hidden){
6687 td.style += ' display:none;';
6690 if(typeof(config.align) != 'undefined' && config.align.length){
6691 td.style += ' text-align:' + config.align + ';';
6694 if(typeof(config.width) != 'undefined'){
6695 td.style += ' width:' + config.width + 'px;';
6698 if(typeof(config.cursor) != 'undefined'){
6699 td.style += ' cursor:' + config.cursor + ';';
6702 if(typeof(config.cls) != 'undefined'){
6703 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
6706 ['xs','sm','md','lg'].map(function(size){
6708 if(typeof(config[size]) == 'undefined'){
6712 if (!config[size]) { // 0 = hidden
6713 td.cls += ' hidden-' + size;
6717 td.cls += ' col-' + size + '-' + config[size];
6725 row.cellObjects = cellObjects;
6733 onBeforeLoad : function()
6735 //Roo.log('ds onBeforeLoad');
6739 //if(this.loadMask){
6740 // this.maskEl.show();
6748 this.el.select('tbody', true).first().dom.innerHTML = '';
6751 * Show or hide a row.
6752 * @param {Number} rowIndex to show or hide
6753 * @param {Boolean} state hide
6755 setRowVisibility : function(rowIndex, state)
6757 var bt = this.mainBody.dom;
6759 var rows = this.el.select('tbody > tr', true).elements;
6761 if(typeof(rows[rowIndex]) == 'undefined'){
6764 rows[rowIndex].dom.style.display = state ? '' : 'none';
6768 getSelectionModel : function(){
6770 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
6772 return this.selModel;
6775 * Render the Roo.bootstrap object from renderder
6777 renderCellObject : function(r)
6781 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
6783 var t = r.cfg.render(r.container);
6786 Roo.each(r.cfg.cn, function(c){
6788 container: t.getChildContainer(),
6791 _this.renderCellObject(child);
6796 getRowIndex : function(row)
6800 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
6811 * Returns the grid's underlying element = used by panel.Grid
6812 * @return {Element} The element
6814 getGridEl : function(){
6818 * Forces a resize - used by panel.Grid
6819 * @return {Element} The element
6821 autoSize : function()
6823 //var ctr = Roo.get(this.container.dom.parentElement);
6824 var ctr = Roo.get(this.el.dom);
6826 var thd = this.getGridEl().select('thead',true).first();
6827 var tbd = this.getGridEl().select('tbody', true).first();
6828 var tfd = this.getGridEl().select('tfoot', true).first();
6830 var cw = ctr.getWidth();
6834 tbd.setSize(ctr.getWidth(),
6835 ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
6837 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
6840 cw = Math.max(cw, this.totalWidth);
6841 this.getGridEl().select('tr',true).setWidth(cw);
6842 // resize 'expandable coloumn?
6844 return; // we doe not have a view in this design..
6847 onBodyScroll: function()
6849 //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
6850 this.mainHead.setStyle({
6851 'position' : 'relative',
6852 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
6857 var scrollHeight = this.mainBody.dom.scrollHeight;
6859 var scrollTop = Math.ceil(this.mainBody.getScroll().top);
6861 var height = this.mainBody.getHeight();
6863 if(scrollHeight - height == scrollTop) {
6865 var total = this.ds.getTotalCount();
6867 if(this.footer.cursor + this.footer.pageSize < total){
6869 this.footer.ds.load({
6871 start : this.footer.cursor + this.footer.pageSize,
6872 limit : this.footer.pageSize
6893 * @class Roo.bootstrap.TableCell
6894 * @extends Roo.bootstrap.Component
6895 * Bootstrap TableCell class
6896 * @cfg {String} html cell contain text
6897 * @cfg {String} cls cell class
6898 * @cfg {String} tag cell tag (td|th) default td
6899 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
6900 * @cfg {String} align Aligns the content in a cell
6901 * @cfg {String} axis Categorizes cells
6902 * @cfg {String} bgcolor Specifies the background color of a cell
6903 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
6904 * @cfg {Number} colspan Specifies the number of columns a cell should span
6905 * @cfg {String} headers Specifies one or more header cells a cell is related to
6906 * @cfg {Number} height Sets the height of a cell
6907 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
6908 * @cfg {Number} rowspan Sets the number of rows a cell should span
6909 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
6910 * @cfg {String} valign Vertical aligns the content in a cell
6911 * @cfg {Number} width Specifies the width of a cell
6914 * Create a new TableCell
6915 * @param {Object} config The config object
6918 Roo.bootstrap.TableCell = function(config){
6919 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
6922 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
6942 getAutoCreate : function(){
6943 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
6963 cfg.align=this.align
6969 cfg.bgcolor=this.bgcolor
6972 cfg.charoff=this.charoff
6975 cfg.colspan=this.colspan
6978 cfg.headers=this.headers
6981 cfg.height=this.height
6984 cfg.nowrap=this.nowrap
6987 cfg.rowspan=this.rowspan
6990 cfg.scope=this.scope
6993 cfg.valign=this.valign
6996 cfg.width=this.width
7015 * @class Roo.bootstrap.TableRow
7016 * @extends Roo.bootstrap.Component
7017 * Bootstrap TableRow class
7018 * @cfg {String} cls row class
7019 * @cfg {String} align Aligns the content in a table row
7020 * @cfg {String} bgcolor Specifies a background color for a table row
7021 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7022 * @cfg {String} valign Vertical aligns the content in a table row
7025 * Create a new TableRow
7026 * @param {Object} config The config object
7029 Roo.bootstrap.TableRow = function(config){
7030 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
7033 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
7041 getAutoCreate : function(){
7042 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
7052 cfg.align = this.align;
7055 cfg.bgcolor = this.bgcolor;
7058 cfg.charoff = this.charoff;
7061 cfg.valign = this.valign;
7079 * @class Roo.bootstrap.TableBody
7080 * @extends Roo.bootstrap.Component
7081 * Bootstrap TableBody class
7082 * @cfg {String} cls element class
7083 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
7084 * @cfg {String} align Aligns the content inside the element
7085 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
7086 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
7089 * Create a new TableBody
7090 * @param {Object} config The config object
7093 Roo.bootstrap.TableBody = function(config){
7094 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
7097 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
7105 getAutoCreate : function(){
7106 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
7120 cfg.align = this.align;
7123 cfg.charoff = this.charoff;
7126 cfg.valign = this.valign;
7133 // initEvents : function()
7140 // this.store = Roo.factory(this.store, Roo.data);
7141 // this.store.on('load', this.onLoad, this);
7143 // this.store.load();
7147 // onLoad: function ()
7149 // this.fireEvent('load', this);
7159 * Ext JS Library 1.1.1
7160 * Copyright(c) 2006-2007, Ext JS, LLC.
7162 * Originally Released Under LGPL - original licence link has changed is not relivant.
7165 * <script type="text/javascript">
7168 // as we use this in bootstrap.
7169 Roo.namespace('Roo.form');
7171 * @class Roo.form.Action
7172 * Internal Class used to handle form actions
7174 * @param {Roo.form.BasicForm} el The form element or its id
7175 * @param {Object} config Configuration options
7180 // define the action interface
7181 Roo.form.Action = function(form, options){
7183 this.options = options || {};
7186 * Client Validation Failed
7189 Roo.form.Action.CLIENT_INVALID = 'client';
7191 * Server Validation Failed
7194 Roo.form.Action.SERVER_INVALID = 'server';
7196 * Connect to Server Failed
7199 Roo.form.Action.CONNECT_FAILURE = 'connect';
7201 * Reading Data from Server Failed
7204 Roo.form.Action.LOAD_FAILURE = 'load';
7206 Roo.form.Action.prototype = {
7208 failureType : undefined,
7209 response : undefined,
7213 run : function(options){
7218 success : function(response){
7223 handleResponse : function(response){
7227 // default connection failure
7228 failure : function(response){
7230 this.response = response;
7231 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7232 this.form.afterAction(this, false);
7235 processResponse : function(response){
7236 this.response = response;
7237 if(!response.responseText){
7240 this.result = this.handleResponse(response);
7244 // utility functions used internally
7245 getUrl : function(appendParams){
7246 var url = this.options.url || this.form.url || this.form.el.dom.action;
7248 var p = this.getParams();
7250 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7256 getMethod : function(){
7257 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7260 getParams : function(){
7261 var bp = this.form.baseParams;
7262 var p = this.options.params;
7264 if(typeof p == "object"){
7265 p = Roo.urlEncode(Roo.applyIf(p, bp));
7266 }else if(typeof p == 'string' && bp){
7267 p += '&' + Roo.urlEncode(bp);
7270 p = Roo.urlEncode(bp);
7275 createCallback : function(){
7277 success: this.success,
7278 failure: this.failure,
7280 timeout: (this.form.timeout*1000),
7281 upload: this.form.fileUpload ? this.success : undefined
7286 Roo.form.Action.Submit = function(form, options){
7287 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7290 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7293 haveProgress : false,
7294 uploadComplete : false,
7296 // uploadProgress indicator.
7297 uploadProgress : function()
7299 if (!this.form.progressUrl) {
7303 if (!this.haveProgress) {
7304 Roo.MessageBox.progress("Uploading", "Uploading");
7306 if (this.uploadComplete) {
7307 Roo.MessageBox.hide();
7311 this.haveProgress = true;
7313 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7315 var c = new Roo.data.Connection();
7317 url : this.form.progressUrl,
7322 success : function(req){
7323 //console.log(data);
7327 rdata = Roo.decode(req.responseText)
7329 Roo.log("Invalid data from server..");
7333 if (!rdata || !rdata.success) {
7335 Roo.MessageBox.alert(Roo.encode(rdata));
7338 var data = rdata.data;
7340 if (this.uploadComplete) {
7341 Roo.MessageBox.hide();
7346 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7347 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7350 this.uploadProgress.defer(2000,this);
7353 failure: function(data) {
7354 Roo.log('progress url failed ');
7365 // run get Values on the form, so it syncs any secondary forms.
7366 this.form.getValues();
7368 var o = this.options;
7369 var method = this.getMethod();
7370 var isPost = method == 'POST';
7371 if(o.clientValidation === false || this.form.isValid()){
7373 if (this.form.progressUrl) {
7374 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7375 (new Date() * 1) + '' + Math.random());
7380 Roo.Ajax.request(Roo.apply(this.createCallback(), {
7381 form:this.form.el.dom,
7382 url:this.getUrl(!isPost),
7384 params:isPost ? this.getParams() : null,
7385 isUpload: this.form.fileUpload
7388 this.uploadProgress();
7390 }else if (o.clientValidation !== false){ // client validation failed
7391 this.failureType = Roo.form.Action.CLIENT_INVALID;
7392 this.form.afterAction(this, false);
7396 success : function(response)
7398 this.uploadComplete= true;
7399 if (this.haveProgress) {
7400 Roo.MessageBox.hide();
7404 var result = this.processResponse(response);
7405 if(result === true || result.success){
7406 this.form.afterAction(this, true);
7410 this.form.markInvalid(result.errors);
7411 this.failureType = Roo.form.Action.SERVER_INVALID;
7413 this.form.afterAction(this, false);
7415 failure : function(response)
7417 this.uploadComplete= true;
7418 if (this.haveProgress) {
7419 Roo.MessageBox.hide();
7422 this.response = response;
7423 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7424 this.form.afterAction(this, false);
7427 handleResponse : function(response){
7428 if(this.form.errorReader){
7429 var rs = this.form.errorReader.read(response);
7432 for(var i = 0, len = rs.records.length; i < len; i++) {
7433 var r = rs.records[i];
7437 if(errors.length < 1){
7441 success : rs.success,
7447 ret = Roo.decode(response.responseText);
7451 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7461 Roo.form.Action.Load = function(form, options){
7462 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7463 this.reader = this.form.reader;
7466 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7471 Roo.Ajax.request(Roo.apply(
7472 this.createCallback(), {
7473 method:this.getMethod(),
7474 url:this.getUrl(false),
7475 params:this.getParams()
7479 success : function(response){
7481 var result = this.processResponse(response);
7482 if(result === true || !result.success || !result.data){
7483 this.failureType = Roo.form.Action.LOAD_FAILURE;
7484 this.form.afterAction(this, false);
7487 this.form.clearInvalid();
7488 this.form.setValues(result.data);
7489 this.form.afterAction(this, true);
7492 handleResponse : function(response){
7493 if(this.form.reader){
7494 var rs = this.form.reader.read(response);
7495 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7497 success : rs.success,
7501 return Roo.decode(response.responseText);
7505 Roo.form.Action.ACTION_TYPES = {
7506 'load' : Roo.form.Action.Load,
7507 'submit' : Roo.form.Action.Submit
7516 * @class Roo.bootstrap.Form
7517 * @extends Roo.bootstrap.Component
7518 * Bootstrap Form class
7519 * @cfg {String} method GET | POST (default POST)
7520 * @cfg {String} labelAlign top | left (default top)
7521 * @cfg {String} align left | right - for navbars
7522 * @cfg {Boolean} loadMask load mask when submit (default true)
7527 * @param {Object} config The config object
7531 Roo.bootstrap.Form = function(config){
7532 Roo.bootstrap.Form.superclass.constructor.call(this, config);
7534 Roo.bootstrap.Form.popover.apply();
7538 * @event clientvalidation
7539 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
7540 * @param {Form} this
7541 * @param {Boolean} valid true if the form has passed client-side validation
7543 clientvalidation: true,
7545 * @event beforeaction
7546 * Fires before any action is performed. Return false to cancel the action.
7547 * @param {Form} this
7548 * @param {Action} action The action to be performed
7552 * @event actionfailed
7553 * Fires when an action fails.
7554 * @param {Form} this
7555 * @param {Action} action The action that failed
7557 actionfailed : true,
7559 * @event actioncomplete
7560 * Fires when an action is completed.
7561 * @param {Form} this
7562 * @param {Action} action The action that completed
7564 actioncomplete : true
7569 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component, {
7572 * @cfg {String} method
7573 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
7578 * The URL to use for form actions if one isn't supplied in the action options.
7581 * @cfg {Boolean} fileUpload
7582 * Set to true if this form is a file upload.
7586 * @cfg {Object} baseParams
7587 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
7591 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
7595 * @cfg {Sting} align (left|right) for navbar forms
7600 activeAction : null,
7603 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
7604 * element by passing it or its id or mask the form itself by passing in true.
7607 waitMsgTarget : false,
7612 * @cfg {Boolean} errorMask (true|false) default false
7617 * @cfg {Number} maskOffset Default 100
7622 * @cfg {Boolean} maskBody
7626 getAutoCreate : function(){
7630 method : this.method || 'POST',
7631 id : this.id || Roo.id(),
7634 if (this.parent().xtype.match(/^Nav/)) {
7635 cfg.cls = 'navbar-form navbar-' + this.align;
7639 if (this.labelAlign == 'left' ) {
7640 cfg.cls += ' form-horizontal';
7646 initEvents : function()
7648 this.el.on('submit', this.onSubmit, this);
7649 // this was added as random key presses on the form where triggering form submit.
7650 this.el.on('keypress', function(e) {
7651 if (e.getCharCode() != 13) {
7654 // we might need to allow it for textareas.. and some other items.
7655 // check e.getTarget().
7657 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
7661 Roo.log("keypress blocked");
7669 onSubmit : function(e){
7674 * Returns true if client-side validation on the form is successful.
7677 isValid : function(){
7678 var items = this.getItems();
7682 items.each(function(f){
7688 if(!target && f.el.isVisible(true)){
7694 if(this.errorMask && !valid){
7695 Roo.bootstrap.Form.popover.mask(this, target);
7702 * Returns true if any fields in this form have changed since their original load.
7705 isDirty : function(){
7707 var items = this.getItems();
7708 items.each(function(f){
7718 * Performs a predefined action (submit or load) or custom actions you define on this form.
7719 * @param {String} actionName The name of the action type
7720 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
7721 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
7722 * accept other config options):
7724 Property Type Description
7725 ---------------- --------------- ----------------------------------------------------------------------------------
7726 url String The url for the action (defaults to the form's url)
7727 method String The form method to use (defaults to the form's method, or POST if not defined)
7728 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
7729 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
7730 validate the form on the client (defaults to false)
7732 * @return {BasicForm} this
7734 doAction : function(action, options){
7735 if(typeof action == 'string'){
7736 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
7738 if(this.fireEvent('beforeaction', this, action) !== false){
7739 this.beforeAction(action);
7740 action.run.defer(100, action);
7746 beforeAction : function(action){
7747 var o = action.options;
7752 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
7754 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7757 // not really supported yet.. ??
7759 //if(this.waitMsgTarget === true){
7760 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7761 //}else if(this.waitMsgTarget){
7762 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
7763 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
7765 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
7771 afterAction : function(action, success){
7772 this.activeAction = null;
7773 var o = action.options;
7775 //if(this.waitMsgTarget === true){
7776 Roo.get(document.body).unmask();
7778 //}else if(this.waitMsgTarget){
7779 // this.waitMsgTarget.unmask();
7781 // Roo.MessageBox.updateProgress(1);
7782 // Roo.MessageBox.hide();
7789 Roo.callback(o.success, o.scope, [this, action]);
7790 this.fireEvent('actioncomplete', this, action);
7794 // failure condition..
7795 // we have a scenario where updates need confirming.
7796 // eg. if a locking scenario exists..
7797 // we look for { errors : { needs_confirm : true }} in the response.
7799 (typeof(action.result) != 'undefined') &&
7800 (typeof(action.result.errors) != 'undefined') &&
7801 (typeof(action.result.errors.needs_confirm) != 'undefined')
7804 Roo.log("not supported yet");
7807 Roo.MessageBox.confirm(
7808 "Change requires confirmation",
7809 action.result.errorMsg,
7814 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
7824 Roo.callback(o.failure, o.scope, [this, action]);
7825 // show an error message if no failed handler is set..
7826 if (!this.hasListener('actionfailed')) {
7827 Roo.log("need to add dialog support");
7829 Roo.MessageBox.alert("Error",
7830 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
7831 action.result.errorMsg :
7832 "Saving Failed, please check your entries or try again"
7837 this.fireEvent('actionfailed', this, action);
7842 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
7843 * @param {String} id The value to search for
7846 findField : function(id){
7847 var items = this.getItems();
7848 var field = items.get(id);
7850 items.each(function(f){
7851 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
7858 return field || null;
7861 * Mark fields in this form invalid in bulk.
7862 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
7863 * @return {BasicForm} this
7865 markInvalid : function(errors){
7866 if(errors instanceof Array){
7867 for(var i = 0, len = errors.length; i < len; i++){
7868 var fieldError = errors[i];
7869 var f = this.findField(fieldError.id);
7871 f.markInvalid(fieldError.msg);
7877 if(typeof errors[id] != 'function' && (field = this.findField(id))){
7878 field.markInvalid(errors[id]);
7882 //Roo.each(this.childForms || [], function (f) {
7883 // f.markInvalid(errors);
7890 * Set values for fields in this form in bulk.
7891 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
7892 * @return {BasicForm} this
7894 setValues : function(values){
7895 if(values instanceof Array){ // array of objects
7896 for(var i = 0, len = values.length; i < len; i++){
7898 var f = this.findField(v.id);
7900 f.setValue(v.value);
7901 if(this.trackResetOnLoad){
7902 f.originalValue = f.getValue();
7906 }else{ // object hash
7909 if(typeof values[id] != 'function' && (field = this.findField(id))){
7911 if (field.setFromData &&
7913 field.displayField &&
7914 // combos' with local stores can
7915 // be queried via setValue()
7916 // to set their value..
7917 (field.store && !field.store.isLocal)
7921 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
7922 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
7923 field.setFromData(sd);
7925 } else if(field.setFromData && (field.store && !field.store.isLocal)) {
7927 field.setFromData(values);
7930 field.setValue(values[id]);
7934 if(this.trackResetOnLoad){
7935 field.originalValue = field.getValue();
7941 //Roo.each(this.childForms || [], function (f) {
7942 // f.setValues(values);
7949 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
7950 * they are returned as an array.
7951 * @param {Boolean} asString
7954 getValues : function(asString){
7955 //if (this.childForms) {
7956 // copy values from the child forms
7957 // Roo.each(this.childForms, function (f) {
7958 // this.setValues(f.getValues());
7964 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
7965 if(asString === true){
7968 return Roo.urlDecode(fs);
7972 * Returns the fields in this form as an object with key/value pairs.
7973 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
7976 getFieldValues : function(with_hidden)
7978 var items = this.getItems();
7980 items.each(function(f){
7986 var v = f.getValue();
7988 if (f.inputType =='radio') {
7989 if (typeof(ret[f.getName()]) == 'undefined') {
7990 ret[f.getName()] = ''; // empty..
7993 if (!f.el.dom.checked) {
8001 if(f.xtype == 'MoneyField'){
8002 ret[f.currencyName] = f.getCurrency();
8005 // not sure if this supported any more..
8006 if ((typeof(v) == 'object') && f.getRawValue) {
8007 v = f.getRawValue() ; // dates..
8009 // combo boxes where name != hiddenName...
8010 if (f.name !== false && f.name != '' && f.name != f.getName()) {
8011 ret[f.name] = f.getRawValue();
8013 ret[f.getName()] = v;
8020 * Clears all invalid messages in this form.
8021 * @return {BasicForm} this
8023 clearInvalid : function(){
8024 var items = this.getItems();
8026 items.each(function(f){
8037 * @return {BasicForm} this
8040 var items = this.getItems();
8041 items.each(function(f){
8045 Roo.each(this.childForms || [], function (f) {
8053 getItems : function()
8055 var r=new Roo.util.MixedCollection(false, function(o){
8056 return o.id || (o.id = Roo.id());
8058 var iter = function(el) {
8065 Roo.each(el.items,function(e) {
8079 Roo.apply(Roo.bootstrap.Form, {
8106 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
8107 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
8108 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
8109 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
8112 this.maskEl.top.enableDisplayMode("block");
8113 this.maskEl.left.enableDisplayMode("block");
8114 this.maskEl.bottom.enableDisplayMode("block");
8115 this.maskEl.right.enableDisplayMode("block");
8117 this.toolTip = new Roo.bootstrap.Tooltip({
8118 cls : 'roo-form-error-popover',
8120 'left' : ['r-l', [-2,0], 'right'],
8121 'right' : ['l-r', [2,0], 'left'],
8122 'bottom' : ['tl-bl', [0,2], 'top'],
8123 'top' : [ 'bl-tl', [0,-2], 'bottom']
8127 this.toolTip.render(Roo.get(document.body));
8129 this.toolTip.el.enableDisplayMode("block");
8131 Roo.get(document.body).on('click', function(){
8135 Roo.get(document.body).on('touchstart', function(){
8139 this.isApplied = true
8142 mask : function(form, target)
8146 this.target = target;
8148 if(!this.form.errorMask || !target.el){
8152 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
8154 Roo.log(scrollable);
8156 var ot = this.target.el.calcOffsetsTo(scrollable);
8158 var scrollTo = ot[1] - this.form.maskOffset;
8160 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
8162 scrollable.scrollTo('top', scrollTo);
8164 var box = this.target.el.getBox();
8166 var zIndex = Roo.bootstrap.Modal.zIndex++;
8169 this.maskEl.top.setStyle('position', 'absolute');
8170 this.maskEl.top.setStyle('z-index', zIndex);
8171 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
8172 this.maskEl.top.setLeft(0);
8173 this.maskEl.top.setTop(0);
8174 this.maskEl.top.show();
8176 this.maskEl.left.setStyle('position', 'absolute');
8177 this.maskEl.left.setStyle('z-index', zIndex);
8178 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
8179 this.maskEl.left.setLeft(0);
8180 this.maskEl.left.setTop(box.y - this.padding);
8181 this.maskEl.left.show();
8183 this.maskEl.bottom.setStyle('position', 'absolute');
8184 this.maskEl.bottom.setStyle('z-index', zIndex);
8185 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
8186 this.maskEl.bottom.setLeft(0);
8187 this.maskEl.bottom.setTop(box.bottom + this.padding);
8188 this.maskEl.bottom.show();
8190 this.maskEl.right.setStyle('position', 'absolute');
8191 this.maskEl.right.setStyle('z-index', zIndex);
8192 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
8193 this.maskEl.right.setLeft(box.right + this.padding);
8194 this.maskEl.right.setTop(box.y - this.padding);
8195 this.maskEl.right.show();
8197 this.toolTip.bindEl = this.target.el;
8199 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
8201 var tip = this.target.blankText;
8203 if(this.target.getValue() !== '' ) {
8205 if (this.target.invalidText.length) {
8206 tip = this.target.invalidText;
8207 } else if (this.target.regexText.length){
8208 tip = this.target.regexText;
8212 this.toolTip.show(tip);
8214 this.intervalID = window.setInterval(function() {
8215 Roo.bootstrap.Form.popover.unmask();
8218 window.onwheel = function(){ return false;};
8220 (function(){ this.isMasked = true; }).defer(500, this);
8226 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
8230 this.maskEl.top.setStyle('position', 'absolute');
8231 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
8232 this.maskEl.top.hide();
8234 this.maskEl.left.setStyle('position', 'absolute');
8235 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
8236 this.maskEl.left.hide();
8238 this.maskEl.bottom.setStyle('position', 'absolute');
8239 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
8240 this.maskEl.bottom.hide();
8242 this.maskEl.right.setStyle('position', 'absolute');
8243 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
8244 this.maskEl.right.hide();
8246 this.toolTip.hide();
8248 this.toolTip.el.hide();
8250 window.onwheel = function(){ return true;};
8252 if(this.intervalID){
8253 window.clearInterval(this.intervalID);
8254 this.intervalID = false;
8257 this.isMasked = false;
8267 * Ext JS Library 1.1.1
8268 * Copyright(c) 2006-2007, Ext JS, LLC.
8270 * Originally Released Under LGPL - original licence link has changed is not relivant.
8273 * <script type="text/javascript">
8276 * @class Roo.form.VTypes
8277 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
8280 Roo.form.VTypes = function(){
8281 // closure these in so they are only created once.
8282 var alpha = /^[a-zA-Z_]+$/;
8283 var alphanum = /^[a-zA-Z0-9_]+$/;
8284 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
8285 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
8287 // All these messages and functions are configurable
8290 * The function used to validate email addresses
8291 * @param {String} value The email address
8293 'email' : function(v){
8294 return email.test(v);
8297 * The error text to display when the email validation function returns false
8300 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
8302 * The keystroke filter mask to be applied on email input
8305 'emailMask' : /[a-z0-9_\.\-@]/i,
8308 * The function used to validate URLs
8309 * @param {String} value The URL
8311 'url' : function(v){
8315 * The error text to display when the url validation function returns false
8318 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
8321 * The function used to validate alpha values
8322 * @param {String} value The value
8324 'alpha' : function(v){
8325 return alpha.test(v);
8328 * The error text to display when the alpha validation function returns false
8331 'alphaText' : 'This field should only contain letters and _',
8333 * The keystroke filter mask to be applied on alpha input
8336 'alphaMask' : /[a-z_]/i,
8339 * The function used to validate alphanumeric values
8340 * @param {String} value The value
8342 'alphanum' : function(v){
8343 return alphanum.test(v);
8346 * The error text to display when the alphanumeric validation function returns false
8349 'alphanumText' : 'This field should only contain letters, numbers and _',
8351 * The keystroke filter mask to be applied on alphanumeric input
8354 'alphanumMask' : /[a-z0-9_]/i
8364 * @class Roo.bootstrap.Input
8365 * @extends Roo.bootstrap.Component
8366 * Bootstrap Input class
8367 * @cfg {Boolean} disabled is it disabled
8368 * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
8369 * @cfg {String} name name of the input
8370 * @cfg {string} fieldLabel - the label associated
8371 * @cfg {string} placeholder - placeholder to put in text.
8372 * @cfg {string} before - input group add on before
8373 * @cfg {string} after - input group add on after
8374 * @cfg {string} size - (lg|sm) or leave empty..
8375 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
8376 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
8377 * @cfg {Number} md colspan out of 12 for computer-sized screens
8378 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
8379 * @cfg {string} value default value of the input
8380 * @cfg {Number} labelWidth set the width of label
8381 * @cfg {Number} labellg set the width of label (1-12)
8382 * @cfg {Number} labelmd set the width of label (1-12)
8383 * @cfg {Number} labelsm set the width of label (1-12)
8384 * @cfg {Number} labelxs set the width of label (1-12)
8385 * @cfg {String} labelAlign (top|left)
8386 * @cfg {Boolean} readOnly Specifies that the field should be read-only
8387 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8388 * @cfg {String} indicatorpos (left|right) default left
8390 * @cfg {String} align (left|center|right) Default left
8391 * @cfg {Boolean} forceFeedback (true|false) Default false
8397 * Create a new Input
8398 * @param {Object} config The config object
8401 Roo.bootstrap.Input = function(config){
8403 Roo.bootstrap.Input.superclass.constructor.call(this, config);
8408 * Fires when this field receives input focus.
8409 * @param {Roo.form.Field} this
8414 * Fires when this field loses input focus.
8415 * @param {Roo.form.Field} this
8420 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8421 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8422 * @param {Roo.form.Field} this
8423 * @param {Roo.EventObject} e The event object
8428 * Fires just before the field blurs if the field value has changed.
8429 * @param {Roo.form.Field} this
8430 * @param {Mixed} newValue The new value
8431 * @param {Mixed} oldValue The original value
8436 * Fires after the field has been marked as invalid.
8437 * @param {Roo.form.Field} this
8438 * @param {String} msg The validation message
8443 * Fires after the field has been validated with no errors.
8444 * @param {Roo.form.Field} this
8449 * Fires after the key up
8450 * @param {Roo.form.Field} this
8451 * @param {Roo.EventObject} e The event Object
8457 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component, {
8459 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8460 automatic validation (defaults to "keyup").
8462 validationEvent : "keyup",
8464 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8466 validateOnBlur : true,
8468 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
8470 validationDelay : 250,
8472 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
8474 focusClass : "x-form-focus", // not needed???
8478 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
8480 invalidClass : "has-warning",
8483 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
8485 validClass : "has-success",
8488 * @cfg {Boolean} hasFeedback (true|false) default true
8493 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8495 invalidFeedbackClass : "glyphicon-warning-sign",
8498 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8500 validFeedbackClass : "glyphicon-ok",
8503 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
8505 selectOnFocus : false,
8508 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
8512 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
8517 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
8519 disableKeyFilter : false,
8522 * @cfg {Boolean} disabled True to disable the field (defaults to false).
8526 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
8530 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
8532 blankText : "Please complete this mandatory field",
8535 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
8539 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
8541 maxLength : Number.MAX_VALUE,
8543 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
8545 minLengthText : "The minimum length for this field is {0}",
8547 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
8549 maxLengthText : "The maximum length for this field is {0}",
8553 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
8554 * If available, this function will be called only after the basic validators all return true, and will be passed the
8555 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
8559 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
8560 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
8561 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
8565 * @cfg {String} regexText -- Depricated - use Invalid Text
8570 * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
8576 autocomplete: false,
8595 formatedValue : false,
8596 forceFeedback : false,
8598 indicatorpos : 'left',
8605 parentLabelAlign : function()
8608 while (parent.parent()) {
8609 parent = parent.parent();
8610 if (typeof(parent.labelAlign) !='undefined') {
8611 return parent.labelAlign;
8618 getAutoCreate : function()
8620 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8626 if(this.inputType != 'hidden'){
8627 cfg.cls = 'form-group' //input-group
8633 type : this.inputType,
8635 cls : 'form-control',
8636 placeholder : this.placeholder || '',
8637 autocomplete : this.autocomplete || 'new-password'
8641 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
8644 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
8645 input.maxLength = this.maxLength;
8648 if (this.disabled) {
8649 input.disabled=true;
8652 if (this.readOnly) {
8653 input.readonly=true;
8657 input.name = this.name;
8661 input.cls += ' input-' + this.size;
8665 ['xs','sm','md','lg'].map(function(size){
8666 if (settings[size]) {
8667 cfg.cls += ' col-' + size + '-' + settings[size];
8671 var inputblock = input;
8675 cls: 'glyphicon form-control-feedback'
8678 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8681 cls : 'has-feedback',
8689 if (this.before || this.after) {
8692 cls : 'input-group',
8696 if (this.before && typeof(this.before) == 'string') {
8698 inputblock.cn.push({
8700 cls : 'roo-input-before input-group-addon',
8704 if (this.before && typeof(this.before) == 'object') {
8705 this.before = Roo.factory(this.before);
8707 inputblock.cn.push({
8709 cls : 'roo-input-before input-group-' +
8710 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8714 inputblock.cn.push(input);
8716 if (this.after && typeof(this.after) == 'string') {
8717 inputblock.cn.push({
8719 cls : 'roo-input-after input-group-addon',
8723 if (this.after && typeof(this.after) == 'object') {
8724 this.after = Roo.factory(this.after);
8726 inputblock.cn.push({
8728 cls : 'roo-input-after input-group-' +
8729 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8733 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8734 inputblock.cls += ' has-feedback';
8735 inputblock.cn.push(feedback);
8739 if (align ==='left' && this.fieldLabel.length) {
8741 cfg.cls += ' roo-form-group-label-left';
8746 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
8747 tooltip : 'This field is required'
8752 cls : 'control-label',
8753 html : this.fieldLabel
8764 var labelCfg = cfg.cn[1];
8765 var contentCfg = cfg.cn[2];
8767 if(this.indicatorpos == 'right'){
8772 cls : 'control-label',
8776 html : this.fieldLabel
8780 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
8781 tooltip : 'This field is required'
8794 labelCfg = cfg.cn[0];
8795 contentCfg = cfg.cn[1];
8799 if(this.labelWidth > 12){
8800 labelCfg.style = "width: " + this.labelWidth + 'px';
8803 if(this.labelWidth < 13 && this.labelmd == 0){
8804 this.labelmd = this.labelWidth;
8807 if(this.labellg > 0){
8808 labelCfg.cls += ' col-lg-' + this.labellg;
8809 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
8812 if(this.labelmd > 0){
8813 labelCfg.cls += ' col-md-' + this.labelmd;
8814 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
8817 if(this.labelsm > 0){
8818 labelCfg.cls += ' col-sm-' + this.labelsm;
8819 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
8822 if(this.labelxs > 0){
8823 labelCfg.cls += ' col-xs-' + this.labelxs;
8824 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
8828 } else if ( this.fieldLabel.length) {
8833 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
8834 tooltip : 'This field is required'
8838 //cls : 'input-group-addon',
8839 html : this.fieldLabel
8847 if(this.indicatorpos == 'right'){
8852 //cls : 'input-group-addon',
8853 html : this.fieldLabel
8858 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
8859 tooltip : 'This field is required'
8879 if (this.parentType === 'Navbar' && this.parent().bar) {
8880 cfg.cls += ' navbar-form';
8883 if (this.parentType === 'NavGroup') {
8884 cfg.cls += ' navbar-form';
8892 * return the real input element.
8894 inputEl: function ()
8896 return this.el.select('input.form-control',true).first();
8899 tooltipEl : function()
8901 return this.inputEl();
8904 indicatorEl : function()
8906 var indicator = this.el.select('i.roo-required-indicator',true).first();
8916 setDisabled : function(v)
8918 var i = this.inputEl().dom;
8920 i.removeAttribute('disabled');
8924 i.setAttribute('disabled','true');
8926 initEvents : function()
8929 this.inputEl().on("keydown" , this.fireKey, this);
8930 this.inputEl().on("focus", this.onFocus, this);
8931 this.inputEl().on("blur", this.onBlur, this);
8933 this.inputEl().relayEvent('keyup', this);
8935 this.indicator = this.indicatorEl();
8938 this.indicator.addClass('invisible');
8942 // reference to original value for reset
8943 this.originalValue = this.getValue();
8944 //Roo.form.TextField.superclass.initEvents.call(this);
8945 if(this.validationEvent == 'keyup'){
8946 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
8947 this.inputEl().on('keyup', this.filterValidation, this);
8949 else if(this.validationEvent !== false){
8950 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
8953 if(this.selectOnFocus){
8954 this.on("focus", this.preFocus, this);
8957 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
8958 this.inputEl().on("keypress", this.filterKeys, this);
8960 this.inputEl().relayEvent('keypress', this);
8963 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
8964 this.el.on("click", this.autoSize, this);
8967 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
8968 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
8971 if (typeof(this.before) == 'object') {
8972 this.before.render(this.el.select('.roo-input-before',true).first());
8974 if (typeof(this.after) == 'object') {
8975 this.after.render(this.el.select('.roo-input-after',true).first());
8980 filterValidation : function(e){
8981 if(!e.isNavKeyPress()){
8982 this.validationTask.delay(this.validationDelay);
8986 * Validates the field value
8987 * @return {Boolean} True if the value is valid, else false
8989 validate : function(){
8990 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
8991 if(this.disabled || this.validateValue(this.getRawValue())){
9002 * Validates a value according to the field's validation rules and marks the field as invalid
9003 * if the validation fails
9004 * @param {Mixed} value The value to validate
9005 * @return {Boolean} True if the value is valid, else false
9007 validateValue : function(value){
9008 if(value.length < 1) { // if it's blank
9009 if(this.allowBlank){
9012 return this.inputEl().hasClass('hide') ? true : false;
9015 if(value.length < this.minLength){
9018 if(value.length > this.maxLength){
9022 var vt = Roo.form.VTypes;
9023 if(!vt[this.vtype](value, this)){
9027 if(typeof this.validator == "function"){
9028 var msg = this.validator(value);
9032 if (typeof(msg) == 'string') {
9033 this.invalidText = msg;
9037 if(this.regex && !this.regex.test(value)){
9047 fireKey : function(e){
9048 //Roo.log('field ' + e.getKey());
9049 if(e.isNavKeyPress()){
9050 this.fireEvent("specialkey", this, e);
9053 focus : function (selectText){
9055 this.inputEl().focus();
9056 if(selectText === true){
9057 this.inputEl().dom.select();
9063 onFocus : function(){
9064 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9065 // this.el.addClass(this.focusClass);
9068 this.hasFocus = true;
9069 this.startValue = this.getValue();
9070 this.fireEvent("focus", this);
9074 beforeBlur : Roo.emptyFn,
9078 onBlur : function(){
9080 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9081 //this.el.removeClass(this.focusClass);
9083 this.hasFocus = false;
9084 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
9087 var v = this.getValue();
9088 if(String(v) !== String(this.startValue)){
9089 this.fireEvent('change', this, v, this.startValue);
9091 this.fireEvent("blur", this);
9095 * Resets the current field value to the originally loaded value and clears any validation messages
9098 this.setValue(this.originalValue);
9102 * Returns the name of the field
9103 * @return {Mixed} name The name field
9105 getName: function(){
9109 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
9110 * @return {Mixed} value The field value
9112 getValue : function(){
9114 var v = this.inputEl().getValue();
9119 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
9120 * @return {Mixed} value The field value
9122 getRawValue : function(){
9123 var v = this.inputEl().getValue();
9129 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
9130 * @param {Mixed} value The value to set
9132 setRawValue : function(v){
9133 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9136 selectText : function(start, end){
9137 var v = this.getRawValue();
9139 start = start === undefined ? 0 : start;
9140 end = end === undefined ? v.length : end;
9141 var d = this.inputEl().dom;
9142 if(d.setSelectionRange){
9143 d.setSelectionRange(start, end);
9144 }else if(d.createTextRange){
9145 var range = d.createTextRange();
9146 range.moveStart("character", start);
9147 range.moveEnd("character", v.length-end);
9154 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
9155 * @param {Mixed} value The value to set
9157 setValue : function(v){
9160 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9166 processValue : function(value){
9167 if(this.stripCharsRe){
9168 var newValue = value.replace(this.stripCharsRe, '');
9169 if(newValue !== value){
9170 this.setRawValue(newValue);
9177 preFocus : function(){
9179 if(this.selectOnFocus){
9180 this.inputEl().dom.select();
9183 filterKeys : function(e){
9185 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
9188 var c = e.getCharCode(), cc = String.fromCharCode(c);
9189 if(Roo.isIE && (e.isSpecialKey() || !cc)){
9192 if(!this.maskRe.test(cc)){
9197 * Clear any invalid styles/messages for this field
9199 clearInvalid : function(){
9201 if(!this.el || this.preventMark){ // not rendered
9206 this.el.removeClass(this.invalidClass);
9208 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9210 var feedback = this.el.select('.form-control-feedback', true).first();
9213 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9218 this.fireEvent('valid', this);
9222 * Mark this field as valid
9224 markValid : function()
9226 if(!this.el || this.preventMark){ // not rendered...
9230 this.el.removeClass([this.invalidClass, this.validClass]);
9232 var feedback = this.el.select('.form-control-feedback', true).first();
9235 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9242 if(this.allowBlank && !this.getRawValue().length){
9247 this.indicator.removeClass('visible');
9248 this.indicator.addClass('invisible');
9251 this.el.addClass(this.validClass);
9253 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9255 var feedback = this.el.select('.form-control-feedback', true).first();
9258 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9259 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9264 this.fireEvent('valid', this);
9268 * Mark this field as invalid
9269 * @param {String} msg The validation message
9271 markInvalid : function(msg)
9273 if(!this.el || this.preventMark){ // not rendered
9277 this.el.removeClass([this.invalidClass, this.validClass]);
9279 var feedback = this.el.select('.form-control-feedback', true).first();
9282 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9289 if(this.allowBlank && !this.getRawValue().length){
9294 this.indicator.removeClass('invisible');
9295 this.indicator.addClass('visible');
9298 this.el.addClass(this.invalidClass);
9300 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9302 var feedback = this.el.select('.form-control-feedback', true).first();
9305 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9307 if(this.getValue().length || this.forceFeedback){
9308 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9315 this.fireEvent('invalid', this, msg);
9318 SafariOnKeyDown : function(event)
9320 // this is a workaround for a password hang bug on chrome/ webkit.
9321 if (this.inputEl().dom.type != 'password') {
9325 var isSelectAll = false;
9327 if(this.inputEl().dom.selectionEnd > 0){
9328 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
9330 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
9331 event.preventDefault();
9336 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
9338 event.preventDefault();
9339 // this is very hacky as keydown always get's upper case.
9341 var cc = String.fromCharCode(event.getCharCode());
9342 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
9346 adjustWidth : function(tag, w){
9347 tag = tag.toLowerCase();
9348 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
9349 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
9353 if(tag == 'textarea'){
9356 }else if(Roo.isOpera){
9360 if(tag == 'textarea'){
9368 setFieldLabel : function(v)
9374 this.fieldLabel = v;
9377 var ar = this.el.select('label > span',true);
9378 if (!ar.elements.length) {
9379 Roo.log("could not find label > span on element");
9383 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9387 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9400 * @class Roo.bootstrap.TextArea
9401 * @extends Roo.bootstrap.Input
9402 * Bootstrap TextArea class
9403 * @cfg {Number} cols Specifies the visible width of a text area
9404 * @cfg {Number} rows Specifies the visible number of lines in a text area
9405 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
9406 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
9407 * @cfg {string} html text
9410 * Create a new TextArea
9411 * @param {Object} config The config object
9414 Roo.bootstrap.TextArea = function(config){
9415 Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
9419 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input, {
9429 getAutoCreate : function(){
9431 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
9437 if(this.inputType != 'hidden'){
9438 cfg.cls = 'form-group' //input-group
9446 value : this.value || '',
9447 html: this.html || '',
9448 cls : 'form-control',
9449 placeholder : this.placeholder || ''
9453 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9454 input.maxLength = this.maxLength;
9458 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
9462 input.cols = this.cols;
9465 if (this.readOnly) {
9466 input.readonly = true;
9470 input.name = this.name;
9474 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
9478 ['xs','sm','md','lg'].map(function(size){
9479 if (settings[size]) {
9480 cfg.cls += ' col-' + size + '-' + settings[size];
9484 var inputblock = input;
9486 if(this.hasFeedback && !this.allowBlank){
9490 cls: 'glyphicon form-control-feedback'
9494 cls : 'has-feedback',
9503 if (this.before || this.after) {
9506 cls : 'input-group',
9510 inputblock.cn.push({
9512 cls : 'input-group-addon',
9517 inputblock.cn.push(input);
9519 if(this.hasFeedback && !this.allowBlank){
9520 inputblock.cls += ' has-feedback';
9521 inputblock.cn.push(feedback);
9525 inputblock.cn.push({
9527 cls : 'input-group-addon',
9534 if (align ==='left' && this.fieldLabel.length) {
9539 cls : 'control-label',
9540 html : this.fieldLabel
9551 if(this.labelWidth > 12){
9552 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
9555 if(this.labelWidth < 13 && this.labelmd == 0){
9556 this.labelmd = this.labelWidth;
9559 if(this.labellg > 0){
9560 cfg.cn[0].cls += ' col-lg-' + this.labellg;
9561 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
9564 if(this.labelmd > 0){
9565 cfg.cn[0].cls += ' col-md-' + this.labelmd;
9566 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
9569 if(this.labelsm > 0){
9570 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
9571 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
9574 if(this.labelxs > 0){
9575 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
9576 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
9579 } else if ( this.fieldLabel.length) {
9584 //cls : 'input-group-addon',
9585 html : this.fieldLabel
9603 if (this.disabled) {
9604 input.disabled=true;
9611 * return the real textarea element.
9613 inputEl: function ()
9615 return this.el.select('textarea.form-control',true).first();
9619 * Clear any invalid styles/messages for this field
9621 clearInvalid : function()
9624 if(!this.el || this.preventMark){ // not rendered
9628 var label = this.el.select('label', true).first();
9629 var icon = this.el.select('i.fa-star', true).first();
9635 this.el.removeClass(this.invalidClass);
9637 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9639 var feedback = this.el.select('.form-control-feedback', true).first();
9642 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9647 this.fireEvent('valid', this);
9651 * Mark this field as valid
9653 markValid : function()
9655 if(!this.el || this.preventMark){ // not rendered
9659 this.el.removeClass([this.invalidClass, this.validClass]);
9661 var feedback = this.el.select('.form-control-feedback', true).first();
9664 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9667 if(this.disabled || this.allowBlank){
9671 var label = this.el.select('label', true).first();
9672 var icon = this.el.select('i.fa-star', true).first();
9678 this.el.addClass(this.validClass);
9680 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9682 var feedback = this.el.select('.form-control-feedback', true).first();
9685 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9686 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9691 this.fireEvent('valid', this);
9695 * Mark this field as invalid
9696 * @param {String} msg The validation message
9698 markInvalid : function(msg)
9700 if(!this.el || this.preventMark){ // not rendered
9704 this.el.removeClass([this.invalidClass, this.validClass]);
9706 var feedback = this.el.select('.form-control-feedback', true).first();
9709 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9712 if(this.disabled || this.allowBlank){
9716 var label = this.el.select('label', true).first();
9717 var icon = this.el.select('i.fa-star', true).first();
9719 if(!this.getValue().length && label && !icon){
9720 this.el.createChild({
9722 cls : 'text-danger fa fa-lg fa-star',
9723 tooltip : 'This field is required',
9724 style : 'margin-right:5px;'
9728 this.el.addClass(this.invalidClass);
9730 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9732 var feedback = this.el.select('.form-control-feedback', true).first();
9735 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9737 if(this.getValue().length || this.forceFeedback){
9738 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9745 this.fireEvent('invalid', this, msg);
9753 * trigger field - base class for combo..
9758 * @class Roo.bootstrap.TriggerField
9759 * @extends Roo.bootstrap.Input
9760 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
9761 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
9762 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
9763 * for which you can provide a custom implementation. For example:
9765 var trigger = new Roo.bootstrap.TriggerField();
9766 trigger.onTriggerClick = myTriggerFn;
9767 trigger.applyTo('my-field');
9770 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
9771 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
9772 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
9773 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
9774 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
9777 * Create a new TriggerField.
9778 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
9779 * to the base TextField)
9781 Roo.bootstrap.TriggerField = function(config){
9782 this.mimicing = false;
9783 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
9786 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
9788 * @cfg {String} triggerClass A CSS class to apply to the trigger
9791 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
9796 * @cfg {Boolean} removable (true|false) special filter default false
9800 /** @cfg {Boolean} grow @hide */
9801 /** @cfg {Number} growMin @hide */
9802 /** @cfg {Number} growMax @hide */
9808 autoSize: Roo.emptyFn,
9815 actionMode : 'wrap',
9820 getAutoCreate : function(){
9822 var align = this.labelAlign || this.parentLabelAlign();
9827 cls: 'form-group' //input-group
9834 type : this.inputType,
9835 cls : 'form-control',
9836 autocomplete: 'new-password',
9837 placeholder : this.placeholder || ''
9841 input.name = this.name;
9844 input.cls += ' input-' + this.size;
9847 if (this.disabled) {
9848 input.disabled=true;
9851 var inputblock = input;
9853 if(this.hasFeedback && !this.allowBlank){
9857 cls: 'glyphicon form-control-feedback'
9860 if(this.removable && !this.editable && !this.tickable){
9862 cls : 'has-feedback',
9868 cls : 'roo-combo-removable-btn close'
9875 cls : 'has-feedback',
9884 if(this.removable && !this.editable && !this.tickable){
9886 cls : 'roo-removable',
9892 cls : 'roo-combo-removable-btn close'
9899 if (this.before || this.after) {
9902 cls : 'input-group',
9906 inputblock.cn.push({
9908 cls : 'input-group-addon',
9913 inputblock.cn.push(input);
9915 if(this.hasFeedback && !this.allowBlank){
9916 inputblock.cls += ' has-feedback';
9917 inputblock.cn.push(feedback);
9921 inputblock.cn.push({
9923 cls : 'input-group-addon',
9936 cls: 'form-hidden-field'
9950 cls: 'form-hidden-field'
9954 cls: 'roo-select2-choices',
9958 cls: 'roo-select2-search-field',
9971 cls: 'roo-select2-container input-group',
9976 // cls: 'typeahead typeahead-long dropdown-menu',
9977 // style: 'display:none'
9982 if(!this.multiple && this.showToggleBtn){
9988 if (this.caret != false) {
9991 cls: 'fa fa-' + this.caret
9998 cls : 'input-group-addon btn dropdown-toggle',
10003 cls: 'combobox-clear',
10017 combobox.cls += ' roo-select2-container-multi';
10020 if (align ==='left' && this.fieldLabel.length) {
10022 cfg.cls += ' roo-form-group-label-left';
10027 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10028 tooltip : 'This field is required'
10033 cls : 'control-label',
10034 html : this.fieldLabel
10046 var labelCfg = cfg.cn[1];
10047 var contentCfg = cfg.cn[2];
10049 if(this.indicatorpos == 'right'){
10054 cls : 'control-label',
10058 html : this.fieldLabel
10062 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10063 tooltip : 'This field is required'
10076 labelCfg = cfg.cn[0];
10077 contentCfg = cfg.cn[1];
10080 if(this.labelWidth > 12){
10081 labelCfg.style = "width: " + this.labelWidth + 'px';
10084 if(this.labelWidth < 13 && this.labelmd == 0){
10085 this.labelmd = this.labelWidth;
10088 if(this.labellg > 0){
10089 labelCfg.cls += ' col-lg-' + this.labellg;
10090 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
10093 if(this.labelmd > 0){
10094 labelCfg.cls += ' col-md-' + this.labelmd;
10095 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
10098 if(this.labelsm > 0){
10099 labelCfg.cls += ' col-sm-' + this.labelsm;
10100 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
10103 if(this.labelxs > 0){
10104 labelCfg.cls += ' col-xs-' + this.labelxs;
10105 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
10108 } else if ( this.fieldLabel.length) {
10109 // Roo.log(" label");
10113 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10114 tooltip : 'This field is required'
10118 //cls : 'input-group-addon',
10119 html : this.fieldLabel
10127 if(this.indicatorpos == 'right'){
10135 html : this.fieldLabel
10139 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10140 tooltip : 'This field is required'
10153 // Roo.log(" no label && no align");
10160 ['xs','sm','md','lg'].map(function(size){
10161 if (settings[size]) {
10162 cfg.cls += ' col-' + size + '-' + settings[size];
10173 onResize : function(w, h){
10174 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
10175 // if(typeof w == 'number'){
10176 // var x = w - this.trigger.getWidth();
10177 // this.inputEl().setWidth(this.adjustWidth('input', x));
10178 // this.trigger.setStyle('left', x+'px');
10183 adjustSize : Roo.BoxComponent.prototype.adjustSize,
10186 getResizeEl : function(){
10187 return this.inputEl();
10191 getPositionEl : function(){
10192 return this.inputEl();
10196 alignErrorIcon : function(){
10197 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
10201 initEvents : function(){
10205 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
10206 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
10207 if(!this.multiple && this.showToggleBtn){
10208 this.trigger = this.el.select('span.dropdown-toggle',true).first();
10209 if(this.hideTrigger){
10210 this.trigger.setDisplayed(false);
10212 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
10216 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
10219 if(this.removable && !this.editable && !this.tickable){
10220 var close = this.closeTriggerEl();
10223 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
10224 close.on('click', this.removeBtnClick, this, close);
10228 //this.trigger.addClassOnOver('x-form-trigger-over');
10229 //this.trigger.addClassOnClick('x-form-trigger-click');
10232 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
10236 closeTriggerEl : function()
10238 var close = this.el.select('.roo-combo-removable-btn', true).first();
10239 return close ? close : false;
10242 removeBtnClick : function(e, h, el)
10244 e.preventDefault();
10246 if(this.fireEvent("remove", this) !== false){
10248 this.fireEvent("afterremove", this)
10252 createList : function()
10254 this.list = Roo.get(document.body).createChild({
10256 cls: 'typeahead typeahead-long dropdown-menu',
10257 style: 'display:none'
10260 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
10265 initTrigger : function(){
10270 onDestroy : function(){
10272 this.trigger.removeAllListeners();
10273 // this.trigger.remove();
10276 // this.wrap.remove();
10278 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
10282 onFocus : function(){
10283 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
10285 if(!this.mimicing){
10286 this.wrap.addClass('x-trigger-wrap-focus');
10287 this.mimicing = true;
10288 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
10289 if(this.monitorTab){
10290 this.el.on("keydown", this.checkTab, this);
10297 checkTab : function(e){
10298 if(e.getKey() == e.TAB){
10299 this.triggerBlur();
10304 onBlur : function(){
10309 mimicBlur : function(e, t){
10311 if(!this.wrap.contains(t) && this.validateBlur()){
10312 this.triggerBlur();
10318 triggerBlur : function(){
10319 this.mimicing = false;
10320 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
10321 if(this.monitorTab){
10322 this.el.un("keydown", this.checkTab, this);
10324 //this.wrap.removeClass('x-trigger-wrap-focus');
10325 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
10329 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
10330 validateBlur : function(e, t){
10335 onDisable : function(){
10336 this.inputEl().dom.disabled = true;
10337 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
10339 // this.wrap.addClass('x-item-disabled');
10344 onEnable : function(){
10345 this.inputEl().dom.disabled = false;
10346 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
10348 // this.el.removeClass('x-item-disabled');
10353 onShow : function(){
10354 var ae = this.getActionEl();
10357 ae.dom.style.display = '';
10358 ae.dom.style.visibility = 'visible';
10364 onHide : function(){
10365 var ae = this.getActionEl();
10366 ae.dom.style.display = 'none';
10370 * The function that should handle the trigger's click event. This method does nothing by default until overridden
10371 * by an implementing function.
10373 * @param {EventObject} e
10375 onTriggerClick : Roo.emptyFn
10379 * Ext JS Library 1.1.1
10380 * Copyright(c) 2006-2007, Ext JS, LLC.
10382 * Originally Released Under LGPL - original licence link has changed is not relivant.
10385 * <script type="text/javascript">
10390 * @class Roo.data.SortTypes
10392 * Defines the default sorting (casting?) comparison functions used when sorting data.
10394 Roo.data.SortTypes = {
10396 * Default sort that does nothing
10397 * @param {Mixed} s The value being converted
10398 * @return {Mixed} The comparison value
10400 none : function(s){
10405 * The regular expression used to strip tags
10409 stripTagsRE : /<\/?[^>]+>/gi,
10412 * Strips all HTML tags to sort on text only
10413 * @param {Mixed} s The value being converted
10414 * @return {String} The comparison value
10416 asText : function(s){
10417 return String(s).replace(this.stripTagsRE, "");
10421 * Strips all HTML tags to sort on text only - Case insensitive
10422 * @param {Mixed} s The value being converted
10423 * @return {String} The comparison value
10425 asUCText : function(s){
10426 return String(s).toUpperCase().replace(this.stripTagsRE, "");
10430 * Case insensitive string
10431 * @param {Mixed} s The value being converted
10432 * @return {String} The comparison value
10434 asUCString : function(s) {
10435 return String(s).toUpperCase();
10440 * @param {Mixed} s The value being converted
10441 * @return {Number} The comparison value
10443 asDate : function(s) {
10447 if(s instanceof Date){
10448 return s.getTime();
10450 return Date.parse(String(s));
10455 * @param {Mixed} s The value being converted
10456 * @return {Float} The comparison value
10458 asFloat : function(s) {
10459 var val = parseFloat(String(s).replace(/,/g, ""));
10468 * @param {Mixed} s The value being converted
10469 * @return {Number} The comparison value
10471 asInt : function(s) {
10472 var val = parseInt(String(s).replace(/,/g, ""));
10480 * Ext JS Library 1.1.1
10481 * Copyright(c) 2006-2007, Ext JS, LLC.
10483 * Originally Released Under LGPL - original licence link has changed is not relivant.
10486 * <script type="text/javascript">
10490 * @class Roo.data.Record
10491 * Instances of this class encapsulate both record <em>definition</em> information, and record
10492 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
10493 * to access Records cached in an {@link Roo.data.Store} object.<br>
10495 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
10496 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
10499 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
10501 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
10502 * {@link #create}. The parameters are the same.
10503 * @param {Array} data An associative Array of data values keyed by the field name.
10504 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
10505 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
10506 * not specified an integer id is generated.
10508 Roo.data.Record = function(data, id){
10509 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
10514 * Generate a constructor for a specific record layout.
10515 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
10516 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
10517 * Each field definition object may contain the following properties: <ul>
10518 * <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,
10519 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
10520 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
10521 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
10522 * is being used, then this is a string containing the javascript expression to reference the data relative to
10523 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
10524 * to the data item relative to the record element. If the mapping expression is the same as the field name,
10525 * this may be omitted.</p></li>
10526 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
10527 * <ul><li>auto (Default, implies no conversion)</li>
10532 * <li>date</li></ul></p></li>
10533 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
10534 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
10535 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
10536 * by the Reader into an object that will be stored in the Record. It is passed the
10537 * following parameters:<ul>
10538 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
10540 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
10542 * <br>usage:<br><pre><code>
10543 var TopicRecord = Roo.data.Record.create(
10544 {name: 'title', mapping: 'topic_title'},
10545 {name: 'author', mapping: 'username'},
10546 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
10547 {name: 'lastPost', mapping: 'post_time', type: 'date'},
10548 {name: 'lastPoster', mapping: 'user2'},
10549 {name: 'excerpt', mapping: 'post_text'}
10552 var myNewRecord = new TopicRecord({
10553 title: 'Do my job please',
10556 lastPost: new Date(),
10557 lastPoster: 'Animal',
10558 excerpt: 'No way dude!'
10560 myStore.add(myNewRecord);
10565 Roo.data.Record.create = function(o){
10566 var f = function(){
10567 f.superclass.constructor.apply(this, arguments);
10569 Roo.extend(f, Roo.data.Record);
10570 var p = f.prototype;
10571 p.fields = new Roo.util.MixedCollection(false, function(field){
10574 for(var i = 0, len = o.length; i < len; i++){
10575 p.fields.add(new Roo.data.Field(o[i]));
10577 f.getField = function(name){
10578 return p.fields.get(name);
10583 Roo.data.Record.AUTO_ID = 1000;
10584 Roo.data.Record.EDIT = 'edit';
10585 Roo.data.Record.REJECT = 'reject';
10586 Roo.data.Record.COMMIT = 'commit';
10588 Roo.data.Record.prototype = {
10590 * Readonly flag - true if this record has been modified.
10599 join : function(store){
10600 this.store = store;
10604 * Set the named field to the specified value.
10605 * @param {String} name The name of the field to set.
10606 * @param {Object} value The value to set the field to.
10608 set : function(name, value){
10609 if(this.data[name] == value){
10613 if(!this.modified){
10614 this.modified = {};
10616 if(typeof this.modified[name] == 'undefined'){
10617 this.modified[name] = this.data[name];
10619 this.data[name] = value;
10620 if(!this.editing && this.store){
10621 this.store.afterEdit(this);
10626 * Get the value of the named field.
10627 * @param {String} name The name of the field to get the value of.
10628 * @return {Object} The value of the field.
10630 get : function(name){
10631 return this.data[name];
10635 beginEdit : function(){
10636 this.editing = true;
10637 this.modified = {};
10641 cancelEdit : function(){
10642 this.editing = false;
10643 delete this.modified;
10647 endEdit : function(){
10648 this.editing = false;
10649 if(this.dirty && this.store){
10650 this.store.afterEdit(this);
10655 * Usually called by the {@link Roo.data.Store} which owns the Record.
10656 * Rejects all changes made to the Record since either creation, or the last commit operation.
10657 * Modified fields are reverted to their original values.
10659 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10660 * of reject operations.
10662 reject : function(){
10663 var m = this.modified;
10665 if(typeof m[n] != "function"){
10666 this.data[n] = m[n];
10669 this.dirty = false;
10670 delete this.modified;
10671 this.editing = false;
10673 this.store.afterReject(this);
10678 * Usually called by the {@link Roo.data.Store} which owns the Record.
10679 * Commits all changes made to the Record since either creation, or the last commit operation.
10681 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10682 * of commit operations.
10684 commit : function(){
10685 this.dirty = false;
10686 delete this.modified;
10687 this.editing = false;
10689 this.store.afterCommit(this);
10694 hasError : function(){
10695 return this.error != null;
10699 clearError : function(){
10704 * Creates a copy of this record.
10705 * @param {String} id (optional) A new record id if you don't want to use this record's id
10708 copy : function(newId) {
10709 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
10713 * Ext JS Library 1.1.1
10714 * Copyright(c) 2006-2007, Ext JS, LLC.
10716 * Originally Released Under LGPL - original licence link has changed is not relivant.
10719 * <script type="text/javascript">
10725 * @class Roo.data.Store
10726 * @extends Roo.util.Observable
10727 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
10728 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
10730 * 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
10731 * has no knowledge of the format of the data returned by the Proxy.<br>
10733 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
10734 * instances from the data object. These records are cached and made available through accessor functions.
10736 * Creates a new Store.
10737 * @param {Object} config A config object containing the objects needed for the Store to access data,
10738 * and read the data into Records.
10740 Roo.data.Store = function(config){
10741 this.data = new Roo.util.MixedCollection(false);
10742 this.data.getKey = function(o){
10745 this.baseParams = {};
10747 this.paramNames = {
10752 "multisort" : "_multisort"
10755 if(config && config.data){
10756 this.inlineData = config.data;
10757 delete config.data;
10760 Roo.apply(this, config);
10762 if(this.reader){ // reader passed
10763 this.reader = Roo.factory(this.reader, Roo.data);
10764 this.reader.xmodule = this.xmodule || false;
10765 if(!this.recordType){
10766 this.recordType = this.reader.recordType;
10768 if(this.reader.onMetaChange){
10769 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
10773 if(this.recordType){
10774 this.fields = this.recordType.prototype.fields;
10776 this.modified = [];
10780 * @event datachanged
10781 * Fires when the data cache has changed, and a widget which is using this Store
10782 * as a Record cache should refresh its view.
10783 * @param {Store} this
10785 datachanged : true,
10787 * @event metachange
10788 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
10789 * @param {Store} this
10790 * @param {Object} meta The JSON metadata
10795 * Fires when Records have been added to the Store
10796 * @param {Store} this
10797 * @param {Roo.data.Record[]} records The array of Records added
10798 * @param {Number} index The index at which the record(s) were added
10803 * Fires when a Record has been removed from the Store
10804 * @param {Store} this
10805 * @param {Roo.data.Record} record The Record that was removed
10806 * @param {Number} index The index at which the record was removed
10811 * Fires when a Record has been updated
10812 * @param {Store} this
10813 * @param {Roo.data.Record} record The Record that was updated
10814 * @param {String} operation The update operation being performed. Value may be one of:
10816 Roo.data.Record.EDIT
10817 Roo.data.Record.REJECT
10818 Roo.data.Record.COMMIT
10824 * Fires when the data cache has been cleared.
10825 * @param {Store} this
10829 * @event beforeload
10830 * Fires before a request is made for a new data object. If the beforeload handler returns false
10831 * the load action will be canceled.
10832 * @param {Store} this
10833 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10837 * @event beforeloadadd
10838 * Fires after a new set of Records has been loaded.
10839 * @param {Store} this
10840 * @param {Roo.data.Record[]} records The Records that were loaded
10841 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10843 beforeloadadd : true,
10846 * Fires after a new set of Records has been loaded, before they are added to the store.
10847 * @param {Store} this
10848 * @param {Roo.data.Record[]} records The Records that were loaded
10849 * @param {Object} options The loading options that were specified (see {@link #load} for details)
10850 * @params {Object} return from reader
10854 * @event loadexception
10855 * Fires if an exception occurs in the Proxy during loading.
10856 * Called with the signature of the Proxy's "loadexception" event.
10857 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
10860 * @param {Object} return from JsonData.reader() - success, totalRecords, records
10861 * @param {Object} load options
10862 * @param {Object} jsonData from your request (normally this contains the Exception)
10864 loadexception : true
10868 this.proxy = Roo.factory(this.proxy, Roo.data);
10869 this.proxy.xmodule = this.xmodule || false;
10870 this.relayEvents(this.proxy, ["loadexception"]);
10872 this.sortToggle = {};
10873 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
10875 Roo.data.Store.superclass.constructor.call(this);
10877 if(this.inlineData){
10878 this.loadData(this.inlineData);
10879 delete this.inlineData;
10883 Roo.extend(Roo.data.Store, Roo.util.Observable, {
10885 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
10886 * without a remote query - used by combo/forms at present.
10890 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
10893 * @cfg {Array} data Inline data to be loaded when the store is initialized.
10896 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
10897 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
10900 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
10901 * on any HTTP request
10904 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
10907 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
10911 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
10912 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
10914 remoteSort : false,
10917 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
10918 * loaded or when a record is removed. (defaults to false).
10920 pruneModifiedRecords : false,
10923 lastOptions : null,
10926 * Add Records to the Store and fires the add event.
10927 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
10929 add : function(records){
10930 records = [].concat(records);
10931 for(var i = 0, len = records.length; i < len; i++){
10932 records[i].join(this);
10934 var index = this.data.length;
10935 this.data.addAll(records);
10936 this.fireEvent("add", this, records, index);
10940 * Remove a Record from the Store and fires the remove event.
10941 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
10943 remove : function(record){
10944 var index = this.data.indexOf(record);
10945 this.data.removeAt(index);
10946 if(this.pruneModifiedRecords){
10947 this.modified.remove(record);
10949 this.fireEvent("remove", this, record, index);
10953 * Remove all Records from the Store and fires the clear event.
10955 removeAll : function(){
10957 if(this.pruneModifiedRecords){
10958 this.modified = [];
10960 this.fireEvent("clear", this);
10964 * Inserts Records to the Store at the given index and fires the add event.
10965 * @param {Number} index The start index at which to insert the passed Records.
10966 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
10968 insert : function(index, records){
10969 records = [].concat(records);
10970 for(var i = 0, len = records.length; i < len; i++){
10971 this.data.insert(index, records[i]);
10972 records[i].join(this);
10974 this.fireEvent("add", this, records, index);
10978 * Get the index within the cache of the passed Record.
10979 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
10980 * @return {Number} The index of the passed Record. Returns -1 if not found.
10982 indexOf : function(record){
10983 return this.data.indexOf(record);
10987 * Get the index within the cache of the Record with the passed id.
10988 * @param {String} id The id of the Record to find.
10989 * @return {Number} The index of the Record. Returns -1 if not found.
10991 indexOfId : function(id){
10992 return this.data.indexOfKey(id);
10996 * Get the Record with the specified id.
10997 * @param {String} id The id of the Record to find.
10998 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
11000 getById : function(id){
11001 return this.data.key(id);
11005 * Get the Record at the specified index.
11006 * @param {Number} index The index of the Record to find.
11007 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
11009 getAt : function(index){
11010 return this.data.itemAt(index);
11014 * Returns a range of Records between specified indices.
11015 * @param {Number} startIndex (optional) The starting index (defaults to 0)
11016 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
11017 * @return {Roo.data.Record[]} An array of Records
11019 getRange : function(start, end){
11020 return this.data.getRange(start, end);
11024 storeOptions : function(o){
11025 o = Roo.apply({}, o);
11028 this.lastOptions = o;
11032 * Loads the Record cache from the configured Proxy using the configured Reader.
11034 * If using remote paging, then the first load call must specify the <em>start</em>
11035 * and <em>limit</em> properties in the options.params property to establish the initial
11036 * position within the dataset, and the number of Records to cache on each read from the Proxy.
11038 * <strong>It is important to note that for remote data sources, loading is asynchronous,
11039 * and this call will return before the new data has been loaded. Perform any post-processing
11040 * in a callback function, or in a "load" event handler.</strong>
11042 * @param {Object} options An object containing properties which control loading options:<ul>
11043 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
11044 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
11045 * passed the following arguments:<ul>
11046 * <li>r : Roo.data.Record[]</li>
11047 * <li>options: Options object from the load call</li>
11048 * <li>success: Boolean success indicator</li></ul></li>
11049 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
11050 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
11053 load : function(options){
11054 options = options || {};
11055 if(this.fireEvent("beforeload", this, options) !== false){
11056 this.storeOptions(options);
11057 var p = Roo.apply(options.params || {}, this.baseParams);
11058 // if meta was not loaded from remote source.. try requesting it.
11059 if (!this.reader.metaFromRemote) {
11060 p._requestMeta = 1;
11062 if(this.sortInfo && this.remoteSort){
11063 var pn = this.paramNames;
11064 p[pn["sort"]] = this.sortInfo.field;
11065 p[pn["dir"]] = this.sortInfo.direction;
11067 if (this.multiSort) {
11068 var pn = this.paramNames;
11069 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
11072 this.proxy.load(p, this.reader, this.loadRecords, this, options);
11077 * Reloads the Record cache from the configured Proxy using the configured Reader and
11078 * the options from the last load operation performed.
11079 * @param {Object} options (optional) An object containing properties which may override the options
11080 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
11081 * the most recently used options are reused).
11083 reload : function(options){
11084 this.load(Roo.applyIf(options||{}, this.lastOptions));
11088 // Called as a callback by the Reader during a load operation.
11089 loadRecords : function(o, options, success){
11090 if(!o || success === false){
11091 if(success !== false){
11092 this.fireEvent("load", this, [], options, o);
11094 if(options.callback){
11095 options.callback.call(options.scope || this, [], options, false);
11099 // if data returned failure - throw an exception.
11100 if (o.success === false) {
11101 // show a message if no listener is registered.
11102 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
11103 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
11105 // loadmask wil be hooked into this..
11106 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
11109 var r = o.records, t = o.totalRecords || r.length;
11111 this.fireEvent("beforeloadadd", this, r, options, o);
11113 if(!options || options.add !== true){
11114 if(this.pruneModifiedRecords){
11115 this.modified = [];
11117 for(var i = 0, len = r.length; i < len; i++){
11121 this.data = this.snapshot;
11122 delete this.snapshot;
11125 this.data.addAll(r);
11126 this.totalLength = t;
11128 this.fireEvent("datachanged", this);
11130 this.totalLength = Math.max(t, this.data.length+r.length);
11134 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
11136 var e = new Roo.data.Record({});
11138 e.set(this.parent.displayField, this.parent.emptyTitle);
11139 e.set(this.parent.valueField, '');
11144 this.fireEvent("load", this, r, options, o);
11145 if(options.callback){
11146 options.callback.call(options.scope || this, r, options, true);
11152 * Loads data from a passed data block. A Reader which understands the format of the data
11153 * must have been configured in the constructor.
11154 * @param {Object} data The data block from which to read the Records. The format of the data expected
11155 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
11156 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
11158 loadData : function(o, append){
11159 var r = this.reader.readRecords(o);
11160 this.loadRecords(r, {add: append}, true);
11164 * Gets the number of cached records.
11166 * <em>If using paging, this may not be the total size of the dataset. If the data object
11167 * used by the Reader contains the dataset size, then the getTotalCount() function returns
11168 * the data set size</em>
11170 getCount : function(){
11171 return this.data.length || 0;
11175 * Gets the total number of records in the dataset as returned by the server.
11177 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
11178 * the dataset size</em>
11180 getTotalCount : function(){
11181 return this.totalLength || 0;
11185 * Returns the sort state of the Store as an object with two properties:
11187 field {String} The name of the field by which the Records are sorted
11188 direction {String} The sort order, "ASC" or "DESC"
11191 getSortState : function(){
11192 return this.sortInfo;
11196 applySort : function(){
11197 if(this.sortInfo && !this.remoteSort){
11198 var s = this.sortInfo, f = s.field;
11199 var st = this.fields.get(f).sortType;
11200 var fn = function(r1, r2){
11201 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
11202 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
11204 this.data.sort(s.direction, fn);
11205 if(this.snapshot && this.snapshot != this.data){
11206 this.snapshot.sort(s.direction, fn);
11212 * Sets the default sort column and order to be used by the next load operation.
11213 * @param {String} fieldName The name of the field to sort by.
11214 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11216 setDefaultSort : function(field, dir){
11217 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
11221 * Sort the Records.
11222 * If remote sorting is used, the sort is performed on the server, and the cache is
11223 * reloaded. If local sorting is used, the cache is sorted internally.
11224 * @param {String} fieldName The name of the field to sort by.
11225 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11227 sort : function(fieldName, dir){
11228 var f = this.fields.get(fieldName);
11230 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
11232 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
11233 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
11238 this.sortToggle[f.name] = dir;
11239 this.sortInfo = {field: f.name, direction: dir};
11240 if(!this.remoteSort){
11242 this.fireEvent("datachanged", this);
11244 this.load(this.lastOptions);
11249 * Calls the specified function for each of the Records in the cache.
11250 * @param {Function} fn The function to call. The Record is passed as the first parameter.
11251 * Returning <em>false</em> aborts and exits the iteration.
11252 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
11254 each : function(fn, scope){
11255 this.data.each(fn, scope);
11259 * Gets all records modified since the last commit. Modified records are persisted across load operations
11260 * (e.g., during paging).
11261 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
11263 getModifiedRecords : function(){
11264 return this.modified;
11268 createFilterFn : function(property, value, anyMatch){
11269 if(!value.exec){ // not a regex
11270 value = String(value);
11271 if(value.length == 0){
11274 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
11276 return function(r){
11277 return value.test(r.data[property]);
11282 * Sums the value of <i>property</i> for each record between start and end and returns the result.
11283 * @param {String} property A field on your records
11284 * @param {Number} start The record index to start at (defaults to 0)
11285 * @param {Number} end The last record index to include (defaults to length - 1)
11286 * @return {Number} The sum
11288 sum : function(property, start, end){
11289 var rs = this.data.items, v = 0;
11290 start = start || 0;
11291 end = (end || end === 0) ? end : rs.length-1;
11293 for(var i = start; i <= end; i++){
11294 v += (rs[i].data[property] || 0);
11300 * Filter the records by a specified property.
11301 * @param {String} field A field on your records
11302 * @param {String/RegExp} value Either a string that the field
11303 * should start with or a RegExp to test against the field
11304 * @param {Boolean} anyMatch True to match any part not just the beginning
11306 filter : function(property, value, anyMatch){
11307 var fn = this.createFilterFn(property, value, anyMatch);
11308 return fn ? this.filterBy(fn) : this.clearFilter();
11312 * Filter by a function. The specified function will be called with each
11313 * record in this data source. If the function returns true the record is included,
11314 * otherwise it is filtered.
11315 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11316 * @param {Object} scope (optional) The scope of the function (defaults to this)
11318 filterBy : function(fn, scope){
11319 this.snapshot = this.snapshot || this.data;
11320 this.data = this.queryBy(fn, scope||this);
11321 this.fireEvent("datachanged", this);
11325 * Query the records by a specified property.
11326 * @param {String} field A field on your records
11327 * @param {String/RegExp} value Either a string that the field
11328 * should start with or a RegExp to test against the field
11329 * @param {Boolean} anyMatch True to match any part not just the beginning
11330 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11332 query : function(property, value, anyMatch){
11333 var fn = this.createFilterFn(property, value, anyMatch);
11334 return fn ? this.queryBy(fn) : this.data.clone();
11338 * Query by a function. The specified function will be called with each
11339 * record in this data source. If the function returns true the record is included
11341 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11342 * @param {Object} scope (optional) The scope of the function (defaults to this)
11343 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11345 queryBy : function(fn, scope){
11346 var data = this.snapshot || this.data;
11347 return data.filterBy(fn, scope||this);
11351 * Collects unique values for a particular dataIndex from this store.
11352 * @param {String} dataIndex The property to collect
11353 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
11354 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
11355 * @return {Array} An array of the unique values
11357 collect : function(dataIndex, allowNull, bypassFilter){
11358 var d = (bypassFilter === true && this.snapshot) ?
11359 this.snapshot.items : this.data.items;
11360 var v, sv, r = [], l = {};
11361 for(var i = 0, len = d.length; i < len; i++){
11362 v = d[i].data[dataIndex];
11364 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
11373 * Revert to a view of the Record cache with no filtering applied.
11374 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
11376 clearFilter : function(suppressEvent){
11377 if(this.snapshot && this.snapshot != this.data){
11378 this.data = this.snapshot;
11379 delete this.snapshot;
11380 if(suppressEvent !== true){
11381 this.fireEvent("datachanged", this);
11387 afterEdit : function(record){
11388 if(this.modified.indexOf(record) == -1){
11389 this.modified.push(record);
11391 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
11395 afterReject : function(record){
11396 this.modified.remove(record);
11397 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
11401 afterCommit : function(record){
11402 this.modified.remove(record);
11403 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
11407 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
11408 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
11410 commitChanges : function(){
11411 var m = this.modified.slice(0);
11412 this.modified = [];
11413 for(var i = 0, len = m.length; i < len; i++){
11419 * Cancel outstanding changes on all changed records.
11421 rejectChanges : function(){
11422 var m = this.modified.slice(0);
11423 this.modified = [];
11424 for(var i = 0, len = m.length; i < len; i++){
11429 onMetaChange : function(meta, rtype, o){
11430 this.recordType = rtype;
11431 this.fields = rtype.prototype.fields;
11432 delete this.snapshot;
11433 this.sortInfo = meta.sortInfo || this.sortInfo;
11434 this.modified = [];
11435 this.fireEvent('metachange', this, this.reader.meta);
11438 moveIndex : function(data, type)
11440 var index = this.indexOf(data);
11442 var newIndex = index + type;
11446 this.insert(newIndex, data);
11451 * Ext JS Library 1.1.1
11452 * Copyright(c) 2006-2007, Ext JS, LLC.
11454 * Originally Released Under LGPL - original licence link has changed is not relivant.
11457 * <script type="text/javascript">
11461 * @class Roo.data.SimpleStore
11462 * @extends Roo.data.Store
11463 * Small helper class to make creating Stores from Array data easier.
11464 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
11465 * @cfg {Array} fields An array of field definition objects, or field name strings.
11466 * @cfg {Array} data The multi-dimensional array of data
11468 * @param {Object} config
11470 Roo.data.SimpleStore = function(config){
11471 Roo.data.SimpleStore.superclass.constructor.call(this, {
11473 reader: new Roo.data.ArrayReader({
11476 Roo.data.Record.create(config.fields)
11478 proxy : new Roo.data.MemoryProxy(config.data)
11482 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
11484 * Ext JS Library 1.1.1
11485 * Copyright(c) 2006-2007, Ext JS, LLC.
11487 * Originally Released Under LGPL - original licence link has changed is not relivant.
11490 * <script type="text/javascript">
11495 * @extends Roo.data.Store
11496 * @class Roo.data.JsonStore
11497 * Small helper class to make creating Stores for JSON data easier. <br/>
11499 var store = new Roo.data.JsonStore({
11500 url: 'get-images.php',
11502 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
11505 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
11506 * JsonReader and HttpProxy (unless inline data is provided).</b>
11507 * @cfg {Array} fields An array of field definition objects, or field name strings.
11509 * @param {Object} config
11511 Roo.data.JsonStore = function(c){
11512 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
11513 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
11514 reader: new Roo.data.JsonReader(c, c.fields)
11517 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
11519 * Ext JS Library 1.1.1
11520 * Copyright(c) 2006-2007, Ext JS, LLC.
11522 * Originally Released Under LGPL - original licence link has changed is not relivant.
11525 * <script type="text/javascript">
11529 Roo.data.Field = function(config){
11530 if(typeof config == "string"){
11531 config = {name: config};
11533 Roo.apply(this, config);
11536 this.type = "auto";
11539 var st = Roo.data.SortTypes;
11540 // named sortTypes are supported, here we look them up
11541 if(typeof this.sortType == "string"){
11542 this.sortType = st[this.sortType];
11545 // set default sortType for strings and dates
11546 if(!this.sortType){
11549 this.sortType = st.asUCString;
11552 this.sortType = st.asDate;
11555 this.sortType = st.none;
11560 var stripRe = /[\$,%]/g;
11562 // prebuilt conversion function for this field, instead of
11563 // switching every time we're reading a value
11565 var cv, dateFormat = this.dateFormat;
11570 cv = function(v){ return v; };
11573 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
11577 return v !== undefined && v !== null && v !== '' ?
11578 parseInt(String(v).replace(stripRe, ""), 10) : '';
11583 return v !== undefined && v !== null && v !== '' ?
11584 parseFloat(String(v).replace(stripRe, ""), 10) : '';
11589 cv = function(v){ return v === true || v === "true" || v == 1; };
11596 if(v instanceof Date){
11600 if(dateFormat == "timestamp"){
11601 return new Date(v*1000);
11603 return Date.parseDate(v, dateFormat);
11605 var parsed = Date.parse(v);
11606 return parsed ? new Date(parsed) : null;
11615 Roo.data.Field.prototype = {
11623 * Ext JS Library 1.1.1
11624 * Copyright(c) 2006-2007, Ext JS, LLC.
11626 * Originally Released Under LGPL - original licence link has changed is not relivant.
11629 * <script type="text/javascript">
11632 // Base class for reading structured data from a data source. This class is intended to be
11633 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
11636 * @class Roo.data.DataReader
11637 * Base class for reading structured data from a data source. This class is intended to be
11638 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
11641 Roo.data.DataReader = function(meta, recordType){
11645 this.recordType = recordType instanceof Array ?
11646 Roo.data.Record.create(recordType) : recordType;
11649 Roo.data.DataReader.prototype = {
11651 * Create an empty record
11652 * @param {Object} data (optional) - overlay some values
11653 * @return {Roo.data.Record} record created.
11655 newRow : function(d) {
11657 this.recordType.prototype.fields.each(function(c) {
11659 case 'int' : da[c.name] = 0; break;
11660 case 'date' : da[c.name] = new Date(); break;
11661 case 'float' : da[c.name] = 0.0; break;
11662 case 'boolean' : da[c.name] = false; break;
11663 default : da[c.name] = ""; break;
11667 return new this.recordType(Roo.apply(da, d));
11672 * Ext JS Library 1.1.1
11673 * Copyright(c) 2006-2007, Ext JS, LLC.
11675 * Originally Released Under LGPL - original licence link has changed is not relivant.
11678 * <script type="text/javascript">
11682 * @class Roo.data.DataProxy
11683 * @extends Roo.data.Observable
11684 * This class is an abstract base class for implementations which provide retrieval of
11685 * unformatted data objects.<br>
11687 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
11688 * (of the appropriate type which knows how to parse the data object) to provide a block of
11689 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
11691 * Custom implementations must implement the load method as described in
11692 * {@link Roo.data.HttpProxy#load}.
11694 Roo.data.DataProxy = function(){
11697 * @event beforeload
11698 * Fires before a network request is made to retrieve a data object.
11699 * @param {Object} This DataProxy object.
11700 * @param {Object} params The params parameter to the load function.
11705 * Fires before the load method's callback is called.
11706 * @param {Object} This DataProxy object.
11707 * @param {Object} o The data object.
11708 * @param {Object} arg The callback argument object passed to the load function.
11712 * @event loadexception
11713 * Fires if an Exception occurs during data retrieval.
11714 * @param {Object} This DataProxy object.
11715 * @param {Object} o The data object.
11716 * @param {Object} arg The callback argument object passed to the load function.
11717 * @param {Object} e The Exception.
11719 loadexception : true
11721 Roo.data.DataProxy.superclass.constructor.call(this);
11724 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
11727 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
11731 * Ext JS Library 1.1.1
11732 * Copyright(c) 2006-2007, Ext JS, LLC.
11734 * Originally Released Under LGPL - original licence link has changed is not relivant.
11737 * <script type="text/javascript">
11740 * @class Roo.data.MemoryProxy
11741 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
11742 * to the Reader when its load method is called.
11744 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
11746 Roo.data.MemoryProxy = function(data){
11750 Roo.data.MemoryProxy.superclass.constructor.call(this);
11754 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
11757 * Load data from the requested source (in this case an in-memory
11758 * data object passed to the constructor), read the data object into
11759 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
11760 * process that block using the passed callback.
11761 * @param {Object} params This parameter is not used by the MemoryProxy class.
11762 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11763 * object into a block of Roo.data.Records.
11764 * @param {Function} callback The function into which to pass the block of Roo.data.records.
11765 * The function must be passed <ul>
11766 * <li>The Record block object</li>
11767 * <li>The "arg" argument from the load function</li>
11768 * <li>A boolean success indicator</li>
11770 * @param {Object} scope The scope in which to call the callback
11771 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11773 load : function(params, reader, callback, scope, arg){
11774 params = params || {};
11777 result = reader.readRecords(this.data);
11779 this.fireEvent("loadexception", this, arg, null, e);
11780 callback.call(scope, null, arg, false);
11783 callback.call(scope, result, arg, true);
11787 update : function(params, records){
11792 * Ext JS Library 1.1.1
11793 * Copyright(c) 2006-2007, Ext JS, LLC.
11795 * Originally Released Under LGPL - original licence link has changed is not relivant.
11798 * <script type="text/javascript">
11801 * @class Roo.data.HttpProxy
11802 * @extends Roo.data.DataProxy
11803 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
11804 * configured to reference a certain URL.<br><br>
11806 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
11807 * from which the running page was served.<br><br>
11809 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
11811 * Be aware that to enable the browser to parse an XML document, the server must set
11812 * the Content-Type header in the HTTP response to "text/xml".
11814 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
11815 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
11816 * will be used to make the request.
11818 Roo.data.HttpProxy = function(conn){
11819 Roo.data.HttpProxy.superclass.constructor.call(this);
11820 // is conn a conn config or a real conn?
11822 this.useAjax = !conn || !conn.events;
11826 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
11827 // thse are take from connection...
11830 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
11833 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
11834 * extra parameters to each request made by this object. (defaults to undefined)
11837 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
11838 * to each request made by this object. (defaults to undefined)
11841 * @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)
11844 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
11847 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
11853 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
11857 * Return the {@link Roo.data.Connection} object being used by this Proxy.
11858 * @return {Connection} The Connection object. This object may be used to subscribe to events on
11859 * a finer-grained basis than the DataProxy events.
11861 getConnection : function(){
11862 return this.useAjax ? Roo.Ajax : this.conn;
11866 * Load data from the configured {@link Roo.data.Connection}, read the data object into
11867 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
11868 * process that block using the passed callback.
11869 * @param {Object} params An object containing properties which are to be used as HTTP parameters
11870 * for the request to the remote server.
11871 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11872 * object into a block of Roo.data.Records.
11873 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
11874 * The function must be passed <ul>
11875 * <li>The Record block object</li>
11876 * <li>The "arg" argument from the load function</li>
11877 * <li>A boolean success indicator</li>
11879 * @param {Object} scope The scope in which to call the callback
11880 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11882 load : function(params, reader, callback, scope, arg){
11883 if(this.fireEvent("beforeload", this, params) !== false){
11885 params : params || {},
11887 callback : callback,
11892 callback : this.loadResponse,
11896 Roo.applyIf(o, this.conn);
11897 if(this.activeRequest){
11898 Roo.Ajax.abort(this.activeRequest);
11900 this.activeRequest = Roo.Ajax.request(o);
11902 this.conn.request(o);
11905 callback.call(scope||this, null, arg, false);
11910 loadResponse : function(o, success, response){
11911 delete this.activeRequest;
11913 this.fireEvent("loadexception", this, o, response);
11914 o.request.callback.call(o.request.scope, null, o.request.arg, false);
11919 result = o.reader.read(response);
11921 this.fireEvent("loadexception", this, o, response, e);
11922 o.request.callback.call(o.request.scope, null, o.request.arg, false);
11926 this.fireEvent("load", this, o, o.request.arg);
11927 o.request.callback.call(o.request.scope, result, o.request.arg, true);
11931 update : function(dataSet){
11936 updateResponse : function(dataSet){
11941 * Ext JS Library 1.1.1
11942 * Copyright(c) 2006-2007, Ext JS, LLC.
11944 * Originally Released Under LGPL - original licence link has changed is not relivant.
11947 * <script type="text/javascript">
11951 * @class Roo.data.ScriptTagProxy
11952 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
11953 * other than the originating domain of the running page.<br><br>
11955 * <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
11956 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
11958 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
11959 * source code that is used as the source inside a <script> tag.<br><br>
11961 * In order for the browser to process the returned data, the server must wrap the data object
11962 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
11963 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
11964 * depending on whether the callback name was passed:
11967 boolean scriptTag = false;
11968 String cb = request.getParameter("callback");
11971 response.setContentType("text/javascript");
11973 response.setContentType("application/x-json");
11975 Writer out = response.getWriter();
11977 out.write(cb + "(");
11979 out.print(dataBlock.toJsonString());
11986 * @param {Object} config A configuration object.
11988 Roo.data.ScriptTagProxy = function(config){
11989 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
11990 Roo.apply(this, config);
11991 this.head = document.getElementsByTagName("head")[0];
11994 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
11996 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
11998 * @cfg {String} url The URL from which to request the data object.
12001 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
12005 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
12006 * the server the name of the callback function set up by the load call to process the returned data object.
12007 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
12008 * javascript output which calls this named function passing the data object as its only parameter.
12010 callbackParam : "callback",
12012 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
12013 * name to the request.
12018 * Load data from the configured URL, read the data object into
12019 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12020 * process that block using the passed callback.
12021 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12022 * for the request to the remote server.
12023 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12024 * object into a block of Roo.data.Records.
12025 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12026 * The function must be passed <ul>
12027 * <li>The Record block object</li>
12028 * <li>The "arg" argument from the load function</li>
12029 * <li>A boolean success indicator</li>
12031 * @param {Object} scope The scope in which to call the callback
12032 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12034 load : function(params, reader, callback, scope, arg){
12035 if(this.fireEvent("beforeload", this, params) !== false){
12037 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
12039 var url = this.url;
12040 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
12042 url += "&_dc=" + (new Date().getTime());
12044 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
12047 cb : "stcCallback"+transId,
12048 scriptId : "stcScript"+transId,
12052 callback : callback,
12058 window[trans.cb] = function(o){
12059 conn.handleResponse(o, trans);
12062 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
12064 if(this.autoAbort !== false){
12068 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
12070 var script = document.createElement("script");
12071 script.setAttribute("src", url);
12072 script.setAttribute("type", "text/javascript");
12073 script.setAttribute("id", trans.scriptId);
12074 this.head.appendChild(script);
12076 this.trans = trans;
12078 callback.call(scope||this, null, arg, false);
12083 isLoading : function(){
12084 return this.trans ? true : false;
12088 * Abort the current server request.
12090 abort : function(){
12091 if(this.isLoading()){
12092 this.destroyTrans(this.trans);
12097 destroyTrans : function(trans, isLoaded){
12098 this.head.removeChild(document.getElementById(trans.scriptId));
12099 clearTimeout(trans.timeoutId);
12101 window[trans.cb] = undefined;
12103 delete window[trans.cb];
12106 // if hasn't been loaded, wait for load to remove it to prevent script error
12107 window[trans.cb] = function(){
12108 window[trans.cb] = undefined;
12110 delete window[trans.cb];
12117 handleResponse : function(o, trans){
12118 this.trans = false;
12119 this.destroyTrans(trans, true);
12122 result = trans.reader.readRecords(o);
12124 this.fireEvent("loadexception", this, o, trans.arg, e);
12125 trans.callback.call(trans.scope||window, null, trans.arg, false);
12128 this.fireEvent("load", this, o, trans.arg);
12129 trans.callback.call(trans.scope||window, result, trans.arg, true);
12133 handleFailure : function(trans){
12134 this.trans = false;
12135 this.destroyTrans(trans, false);
12136 this.fireEvent("loadexception", this, null, trans.arg);
12137 trans.callback.call(trans.scope||window, null, trans.arg, false);
12141 * Ext JS Library 1.1.1
12142 * Copyright(c) 2006-2007, Ext JS, LLC.
12144 * Originally Released Under LGPL - original licence link has changed is not relivant.
12147 * <script type="text/javascript">
12151 * @class Roo.data.JsonReader
12152 * @extends Roo.data.DataReader
12153 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
12154 * based on mappings in a provided Roo.data.Record constructor.
12156 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
12157 * in the reply previously.
12162 var RecordDef = Roo.data.Record.create([
12163 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
12164 {name: 'occupation'} // This field will use "occupation" as the mapping.
12166 var myReader = new Roo.data.JsonReader({
12167 totalProperty: "results", // The property which contains the total dataset size (optional)
12168 root: "rows", // The property which contains an Array of row objects
12169 id: "id" // The property within each row object that provides an ID for the record (optional)
12173 * This would consume a JSON file like this:
12175 { 'results': 2, 'rows': [
12176 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
12177 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
12180 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
12181 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
12182 * paged from the remote server.
12183 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
12184 * @cfg {String} root name of the property which contains the Array of row objects.
12185 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
12186 * @cfg {Array} fields Array of field definition objects
12188 * Create a new JsonReader
12189 * @param {Object} meta Metadata configuration options
12190 * @param {Object} recordType Either an Array of field definition objects,
12191 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
12193 Roo.data.JsonReader = function(meta, recordType){
12196 // set some defaults:
12197 Roo.applyIf(meta, {
12198 totalProperty: 'total',
12199 successProperty : 'success',
12204 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
12206 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
12209 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
12210 * Used by Store query builder to append _requestMeta to params.
12213 metaFromRemote : false,
12215 * This method is only used by a DataProxy which has retrieved data from a remote server.
12216 * @param {Object} response The XHR object which contains the JSON data in its responseText.
12217 * @return {Object} data A data block which is used by an Roo.data.Store object as
12218 * a cache of Roo.data.Records.
12220 read : function(response){
12221 var json = response.responseText;
12223 var o = /* eval:var:o */ eval("("+json+")");
12225 throw {message: "JsonReader.read: Json object not found"};
12231 this.metaFromRemote = true;
12232 this.meta = o.metaData;
12233 this.recordType = Roo.data.Record.create(o.metaData.fields);
12234 this.onMetaChange(this.meta, this.recordType, o);
12236 return this.readRecords(o);
12239 // private function a store will implement
12240 onMetaChange : function(meta, recordType, o){
12247 simpleAccess: function(obj, subsc) {
12254 getJsonAccessor: function(){
12256 return function(expr) {
12258 return(re.test(expr))
12259 ? new Function("obj", "return obj." + expr)
12264 return Roo.emptyFn;
12269 * Create a data block containing Roo.data.Records from an XML document.
12270 * @param {Object} o An object which contains an Array of row objects in the property specified
12271 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
12272 * which contains the total size of the dataset.
12273 * @return {Object} data A data block which is used by an Roo.data.Store object as
12274 * a cache of Roo.data.Records.
12276 readRecords : function(o){
12278 * After any data loads, the raw JSON data is available for further custom processing.
12282 var s = this.meta, Record = this.recordType,
12283 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
12285 // Generate extraction functions for the totalProperty, the root, the id, and for each field
12287 if(s.totalProperty) {
12288 this.getTotal = this.getJsonAccessor(s.totalProperty);
12290 if(s.successProperty) {
12291 this.getSuccess = this.getJsonAccessor(s.successProperty);
12293 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
12295 var g = this.getJsonAccessor(s.id);
12296 this.getId = function(rec) {
12298 return (r === undefined || r === "") ? null : r;
12301 this.getId = function(){return null;};
12304 for(var jj = 0; jj < fl; jj++){
12306 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
12307 this.ef[jj] = this.getJsonAccessor(map);
12311 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
12312 if(s.totalProperty){
12313 var vt = parseInt(this.getTotal(o), 10);
12318 if(s.successProperty){
12319 var vs = this.getSuccess(o);
12320 if(vs === false || vs === 'false'){
12325 for(var i = 0; i < c; i++){
12328 var id = this.getId(n);
12329 for(var j = 0; j < fl; j++){
12331 var v = this.ef[j](n);
12333 Roo.log('missing convert for ' + f.name);
12337 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
12339 var record = new Record(values, id);
12341 records[i] = record;
12347 totalRecords : totalRecords
12352 * Ext JS Library 1.1.1
12353 * Copyright(c) 2006-2007, Ext JS, LLC.
12355 * Originally Released Under LGPL - original licence link has changed is not relivant.
12358 * <script type="text/javascript">
12362 * @class Roo.data.ArrayReader
12363 * @extends Roo.data.DataReader
12364 * Data reader class to create an Array of Roo.data.Record objects from an Array.
12365 * Each element of that Array represents a row of data fields. The
12366 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
12367 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
12371 var RecordDef = Roo.data.Record.create([
12372 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
12373 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
12375 var myReader = new Roo.data.ArrayReader({
12376 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
12380 * This would consume an Array like this:
12382 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
12384 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
12386 * Create a new JsonReader
12387 * @param {Object} meta Metadata configuration options.
12388 * @param {Object} recordType Either an Array of field definition objects
12389 * as specified to {@link Roo.data.Record#create},
12390 * or an {@link Roo.data.Record} object
12391 * created using {@link Roo.data.Record#create}.
12393 Roo.data.ArrayReader = function(meta, recordType){
12394 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
12397 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
12399 * Create a data block containing Roo.data.Records from an XML document.
12400 * @param {Object} o An Array of row objects which represents the dataset.
12401 * @return {Object} data A data block which is used by an Roo.data.Store object as
12402 * a cache of Roo.data.Records.
12404 readRecords : function(o){
12405 var sid = this.meta ? this.meta.id : null;
12406 var recordType = this.recordType, fields = recordType.prototype.fields;
12409 for(var i = 0; i < root.length; i++){
12412 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
12413 for(var j = 0, jlen = fields.length; j < jlen; j++){
12414 var f = fields.items[j];
12415 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
12416 var v = n[k] !== undefined ? n[k] : f.defaultValue;
12418 values[f.name] = v;
12420 var record = new recordType(values, id);
12422 records[records.length] = record;
12426 totalRecords : records.length
12435 * @class Roo.bootstrap.ComboBox
12436 * @extends Roo.bootstrap.TriggerField
12437 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
12438 * @cfg {Boolean} append (true|false) default false
12439 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12440 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
12441 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
12442 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
12443 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
12444 * @cfg {Boolean} animate default true
12445 * @cfg {Boolean} emptyResultText only for touch device
12446 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
12447 * @cfg {String} emptyTitle default ''
12449 * Create a new ComboBox.
12450 * @param {Object} config Configuration options
12452 Roo.bootstrap.ComboBox = function(config){
12453 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
12457 * Fires when the dropdown list is expanded
12458 * @param {Roo.bootstrap.ComboBox} combo This combo box
12463 * Fires when the dropdown list is collapsed
12464 * @param {Roo.bootstrap.ComboBox} combo This combo box
12468 * @event beforeselect
12469 * Fires before a list item is selected. Return false to cancel the selection.
12470 * @param {Roo.bootstrap.ComboBox} combo This combo box
12471 * @param {Roo.data.Record} record The data record returned from the underlying store
12472 * @param {Number} index The index of the selected item in the dropdown list
12474 'beforeselect' : true,
12477 * Fires when a list item is selected
12478 * @param {Roo.bootstrap.ComboBox} combo This combo box
12479 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
12480 * @param {Number} index The index of the selected item in the dropdown list
12484 * @event beforequery
12485 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
12486 * The event object passed has these properties:
12487 * @param {Roo.bootstrap.ComboBox} combo This combo box
12488 * @param {String} query The query
12489 * @param {Boolean} forceAll true to force "all" query
12490 * @param {Boolean} cancel true to cancel the query
12491 * @param {Object} e The query event object
12493 'beforequery': true,
12496 * Fires when the 'add' icon is pressed (add a listener to enable add button)
12497 * @param {Roo.bootstrap.ComboBox} combo This combo box
12502 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
12503 * @param {Roo.bootstrap.ComboBox} combo This combo box
12504 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
12509 * Fires when the remove value from the combobox array
12510 * @param {Roo.bootstrap.ComboBox} combo This combo box
12514 * @event afterremove
12515 * Fires when the remove value from the combobox array
12516 * @param {Roo.bootstrap.ComboBox} combo This combo box
12518 'afterremove' : true,
12520 * @event specialfilter
12521 * Fires when specialfilter
12522 * @param {Roo.bootstrap.ComboBox} combo This combo box
12524 'specialfilter' : true,
12527 * Fires when tick the element
12528 * @param {Roo.bootstrap.ComboBox} combo This combo box
12532 * @event touchviewdisplay
12533 * Fires when touch view require special display (default is using displayField)
12534 * @param {Roo.bootstrap.ComboBox} combo This combo box
12535 * @param {Object} cfg set html .
12537 'touchviewdisplay' : true
12542 this.tickItems = [];
12544 this.selectedIndex = -1;
12545 if(this.mode == 'local'){
12546 if(config.queryDelay === undefined){
12547 this.queryDelay = 10;
12549 if(config.minChars === undefined){
12555 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
12558 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
12559 * rendering into an Roo.Editor, defaults to false)
12562 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
12563 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
12566 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
12569 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
12570 * the dropdown list (defaults to undefined, with no header element)
12574 * @cfg {String/Roo.Template} tpl The template to use to render the output
12578 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
12580 listWidth: undefined,
12582 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
12583 * mode = 'remote' or 'text' if mode = 'local')
12585 displayField: undefined,
12588 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
12589 * mode = 'remote' or 'value' if mode = 'local').
12590 * Note: use of a valueField requires the user make a selection
12591 * in order for a value to be mapped.
12593 valueField: undefined,
12595 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
12600 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
12601 * field's data value (defaults to the underlying DOM element's name)
12603 hiddenName: undefined,
12605 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
12609 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
12611 selectedClass: 'active',
12614 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
12618 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
12619 * anchor positions (defaults to 'tl-bl')
12621 listAlign: 'tl-bl?',
12623 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
12627 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
12628 * query specified by the allQuery config option (defaults to 'query')
12630 triggerAction: 'query',
12632 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
12633 * (defaults to 4, does not apply if editable = false)
12637 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
12638 * delay (typeAheadDelay) if it matches a known value (defaults to false)
12642 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
12643 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
12647 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
12648 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
12652 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
12653 * when editable = true (defaults to false)
12655 selectOnFocus:false,
12657 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
12659 queryParam: 'query',
12661 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
12662 * when mode = 'remote' (defaults to 'Loading...')
12664 loadingText: 'Loading...',
12666 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
12670 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
12674 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
12675 * traditional select (defaults to true)
12679 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
12683 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
12687 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
12688 * listWidth has a higher value)
12692 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
12693 * allow the user to set arbitrary text into the field (defaults to false)
12695 forceSelection:false,
12697 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
12698 * if typeAhead = true (defaults to 250)
12700 typeAheadDelay : 250,
12702 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
12703 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
12705 valueNotFoundText : undefined,
12707 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
12709 blockFocus : false,
12712 * @cfg {Boolean} disableClear Disable showing of clear button.
12714 disableClear : false,
12716 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
12718 alwaysQuery : false,
12721 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
12726 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
12728 invalidClass : "has-warning",
12731 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
12733 validClass : "has-success",
12736 * @cfg {Boolean} specialFilter (true|false) special filter default false
12738 specialFilter : false,
12741 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
12743 mobileTouchView : true,
12746 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
12748 useNativeIOS : false,
12750 ios_options : false,
12762 btnPosition : 'right',
12763 triggerList : true,
12764 showToggleBtn : true,
12766 emptyResultText: 'Empty',
12767 triggerText : 'Select',
12770 // element that contains real text value.. (when hidden is used..)
12772 getAutoCreate : function()
12777 * Render classic select for iso
12780 if(Roo.isIOS && this.useNativeIOS){
12781 cfg = this.getAutoCreateNativeIOS();
12789 if(Roo.isTouch && this.mobileTouchView){
12790 cfg = this.getAutoCreateTouchView();
12797 if(!this.tickable){
12798 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
12803 * ComboBox with tickable selections
12806 var align = this.labelAlign || this.parentLabelAlign();
12809 cls : 'form-group roo-combobox-tickable' //input-group
12812 var btn_text_select = '';
12813 var btn_text_done = '';
12814 var btn_text_cancel = '';
12816 if (this.btn_text_show) {
12817 btn_text_select = 'Select';
12818 btn_text_done = 'Done';
12819 btn_text_cancel = 'Cancel';
12824 cls : 'tickable-buttons',
12829 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
12830 //html : this.triggerText
12831 html: btn_text_select
12837 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
12839 html: btn_text_done
12845 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
12847 html: btn_text_cancel
12853 buttons.cn.unshift({
12855 cls: 'roo-select2-search-field-input'
12861 Roo.each(buttons.cn, function(c){
12863 c.cls += ' btn-' + _this.size;
12866 if (_this.disabled) {
12877 cls: 'form-hidden-field'
12881 cls: 'roo-select2-choices',
12885 cls: 'roo-select2-search-field',
12896 cls: 'roo-select2-container input-group roo-select2-container-multi',
12901 // cls: 'typeahead typeahead-long dropdown-menu',
12902 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
12907 if(this.hasFeedback && !this.allowBlank){
12911 cls: 'glyphicon form-control-feedback'
12914 combobox.cn.push(feedback);
12918 if (align ==='left' && this.fieldLabel.length) {
12920 cfg.cls += ' roo-form-group-label-left';
12925 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
12926 tooltip : 'This field is required'
12931 cls : 'control-label',
12932 html : this.fieldLabel
12944 var labelCfg = cfg.cn[1];
12945 var contentCfg = cfg.cn[2];
12948 if(this.indicatorpos == 'right'){
12954 cls : 'control-label',
12958 html : this.fieldLabel
12962 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
12963 tooltip : 'This field is required'
12978 labelCfg = cfg.cn[0];
12979 contentCfg = cfg.cn[1];
12983 if(this.labelWidth > 12){
12984 labelCfg.style = "width: " + this.labelWidth + 'px';
12987 if(this.labelWidth < 13 && this.labelmd == 0){
12988 this.labelmd = this.labelWidth;
12991 if(this.labellg > 0){
12992 labelCfg.cls += ' col-lg-' + this.labellg;
12993 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
12996 if(this.labelmd > 0){
12997 labelCfg.cls += ' col-md-' + this.labelmd;
12998 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
13001 if(this.labelsm > 0){
13002 labelCfg.cls += ' col-sm-' + this.labelsm;
13003 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
13006 if(this.labelxs > 0){
13007 labelCfg.cls += ' col-xs-' + this.labelxs;
13008 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
13012 } else if ( this.fieldLabel.length) {
13013 // Roo.log(" label");
13017 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13018 tooltip : 'This field is required'
13022 //cls : 'input-group-addon',
13023 html : this.fieldLabel
13028 if(this.indicatorpos == 'right'){
13032 //cls : 'input-group-addon',
13033 html : this.fieldLabel
13037 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13038 tooltip : 'This field is required'
13047 // Roo.log(" no label && no align");
13054 ['xs','sm','md','lg'].map(function(size){
13055 if (settings[size]) {
13056 cfg.cls += ' col-' + size + '-' + settings[size];
13064 _initEventsCalled : false,
13067 initEvents: function()
13069 if (this._initEventsCalled) { // as we call render... prevent looping...
13072 this._initEventsCalled = true;
13075 throw "can not find store for combo";
13078 this.indicator = this.indicatorEl();
13080 this.store = Roo.factory(this.store, Roo.data);
13081 this.store.parent = this;
13083 // if we are building from html. then this element is so complex, that we can not really
13084 // use the rendered HTML.
13085 // so we have to trash and replace the previous code.
13086 if (Roo.XComponent.build_from_html) {
13087 // remove this element....
13088 var e = this.el.dom, k=0;
13089 while (e ) { e = e.previousSibling; ++k;}
13094 this.rendered = false;
13096 this.render(this.parent().getChildContainer(true), k);
13099 if(Roo.isIOS && this.useNativeIOS){
13100 this.initIOSView();
13108 if(Roo.isTouch && this.mobileTouchView){
13109 this.initTouchView();
13114 this.initTickableEvents();
13118 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
13120 if(this.hiddenName){
13122 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13124 this.hiddenField.dom.value =
13125 this.hiddenValue !== undefined ? this.hiddenValue :
13126 this.value !== undefined ? this.value : '';
13128 // prevent input submission
13129 this.el.dom.removeAttribute('name');
13130 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13135 // this.el.dom.setAttribute('autocomplete', 'off');
13138 var cls = 'x-combo-list';
13140 //this.list = new Roo.Layer({
13141 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
13147 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13148 _this.list.setWidth(lw);
13151 this.list.on('mouseover', this.onViewOver, this);
13152 this.list.on('mousemove', this.onViewMove, this);
13153 this.list.on('scroll', this.onViewScroll, this);
13156 this.list.swallowEvent('mousewheel');
13157 this.assetHeight = 0;
13160 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
13161 this.assetHeight += this.header.getHeight();
13164 this.innerList = this.list.createChild({cls:cls+'-inner'});
13165 this.innerList.on('mouseover', this.onViewOver, this);
13166 this.innerList.on('mousemove', this.onViewMove, this);
13167 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13169 if(this.allowBlank && !this.pageSize && !this.disableClear){
13170 this.footer = this.list.createChild({cls:cls+'-ft'});
13171 this.pageTb = new Roo.Toolbar(this.footer);
13175 this.footer = this.list.createChild({cls:cls+'-ft'});
13176 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
13177 {pageSize: this.pageSize});
13181 if (this.pageTb && this.allowBlank && !this.disableClear) {
13183 this.pageTb.add(new Roo.Toolbar.Fill(), {
13184 cls: 'x-btn-icon x-btn-clear',
13186 handler: function()
13189 _this.clearValue();
13190 _this.onSelect(false, -1);
13195 this.assetHeight += this.footer.getHeight();
13200 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
13203 this.view = new Roo.View(this.list, this.tpl, {
13204 singleSelect:true, store: this.store, selectedClass: this.selectedClass
13206 //this.view.wrapEl.setDisplayed(false);
13207 this.view.on('click', this.onViewClick, this);
13210 this.store.on('beforeload', this.onBeforeLoad, this);
13211 this.store.on('load', this.onLoad, this);
13212 this.store.on('loadexception', this.onLoadException, this);
13214 if(this.resizable){
13215 this.resizer = new Roo.Resizable(this.list, {
13216 pinned:true, handles:'se'
13218 this.resizer.on('resize', function(r, w, h){
13219 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
13220 this.listWidth = w;
13221 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
13222 this.restrictHeight();
13224 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
13227 if(!this.editable){
13228 this.editable = true;
13229 this.setEditable(false);
13234 if (typeof(this.events.add.listeners) != 'undefined') {
13236 this.addicon = this.wrap.createChild(
13237 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
13239 this.addicon.on('click', function(e) {
13240 this.fireEvent('add', this);
13243 if (typeof(this.events.edit.listeners) != 'undefined') {
13245 this.editicon = this.wrap.createChild(
13246 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
13247 if (this.addicon) {
13248 this.editicon.setStyle('margin-left', '40px');
13250 this.editicon.on('click', function(e) {
13252 // we fire even if inothing is selected..
13253 this.fireEvent('edit', this, this.lastData );
13259 this.keyNav = new Roo.KeyNav(this.inputEl(), {
13260 "up" : function(e){
13261 this.inKeyMode = true;
13265 "down" : function(e){
13266 if(!this.isExpanded()){
13267 this.onTriggerClick();
13269 this.inKeyMode = true;
13274 "enter" : function(e){
13275 // this.onViewClick();
13279 if(this.fireEvent("specialkey", this, e)){
13280 this.onViewClick(false);
13286 "esc" : function(e){
13290 "tab" : function(e){
13293 if(this.fireEvent("specialkey", this, e)){
13294 this.onViewClick(false);
13302 doRelay : function(foo, bar, hname){
13303 if(hname == 'down' || this.scope.isExpanded()){
13304 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13313 this.queryDelay = Math.max(this.queryDelay || 10,
13314 this.mode == 'local' ? 10 : 250);
13317 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13319 if(this.typeAhead){
13320 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13322 if(this.editable !== false){
13323 this.inputEl().on("keyup", this.onKeyUp, this);
13325 if(this.forceSelection){
13326 this.inputEl().on('blur', this.doForce, this);
13330 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13331 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13335 initTickableEvents: function()
13339 if(this.hiddenName){
13341 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13343 this.hiddenField.dom.value =
13344 this.hiddenValue !== undefined ? this.hiddenValue :
13345 this.value !== undefined ? this.value : '';
13347 // prevent input submission
13348 this.el.dom.removeAttribute('name');
13349 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13354 // this.list = this.el.select('ul.dropdown-menu',true).first();
13356 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13357 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13358 if(this.triggerList){
13359 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
13362 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
13363 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
13365 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
13366 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
13368 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
13369 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
13371 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
13372 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
13373 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
13376 this.cancelBtn.hide();
13381 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13382 _this.list.setWidth(lw);
13385 this.list.on('mouseover', this.onViewOver, this);
13386 this.list.on('mousemove', this.onViewMove, this);
13388 this.list.on('scroll', this.onViewScroll, this);
13391 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>';
13394 this.view = new Roo.View(this.list, this.tpl, {
13395 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
13398 //this.view.wrapEl.setDisplayed(false);
13399 this.view.on('click', this.onViewClick, this);
13403 this.store.on('beforeload', this.onBeforeLoad, this);
13404 this.store.on('load', this.onLoad, this);
13405 this.store.on('loadexception', this.onLoadException, this);
13408 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
13409 "up" : function(e){
13410 this.inKeyMode = true;
13414 "down" : function(e){
13415 this.inKeyMode = true;
13419 "enter" : function(e){
13420 if(this.fireEvent("specialkey", this, e)){
13421 this.onViewClick(false);
13427 "esc" : function(e){
13428 this.onTickableFooterButtonClick(e, false, false);
13431 "tab" : function(e){
13432 this.fireEvent("specialkey", this, e);
13434 this.onTickableFooterButtonClick(e, false, false);
13441 doRelay : function(e, fn, key){
13442 if(this.scope.isExpanded()){
13443 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13452 this.queryDelay = Math.max(this.queryDelay || 10,
13453 this.mode == 'local' ? 10 : 250);
13456 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13458 if(this.typeAhead){
13459 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13462 if(this.editable !== false){
13463 this.tickableInputEl().on("keyup", this.onKeyUp, this);
13466 this.indicator = this.indicatorEl();
13468 if(this.indicator){
13469 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
13470 this.indicator.hide();
13475 onDestroy : function(){
13477 this.view.setStore(null);
13478 this.view.el.removeAllListeners();
13479 this.view.el.remove();
13480 this.view.purgeListeners();
13483 this.list.dom.innerHTML = '';
13487 this.store.un('beforeload', this.onBeforeLoad, this);
13488 this.store.un('load', this.onLoad, this);
13489 this.store.un('loadexception', this.onLoadException, this);
13491 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
13495 fireKey : function(e){
13496 if(e.isNavKeyPress() && !this.list.isVisible()){
13497 this.fireEvent("specialkey", this, e);
13502 onResize: function(w, h){
13503 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
13505 // if(typeof w != 'number'){
13506 // // we do not handle it!?!?
13509 // var tw = this.trigger.getWidth();
13510 // // tw += this.addicon ? this.addicon.getWidth() : 0;
13511 // // tw += this.editicon ? this.editicon.getWidth() : 0;
13513 // this.inputEl().setWidth( this.adjustWidth('input', x));
13515 // //this.trigger.setStyle('left', x+'px');
13517 // if(this.list && this.listWidth === undefined){
13518 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
13519 // this.list.setWidth(lw);
13520 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13528 * Allow or prevent the user from directly editing the field text. If false is passed,
13529 * the user will only be able to select from the items defined in the dropdown list. This method
13530 * is the runtime equivalent of setting the 'editable' config option at config time.
13531 * @param {Boolean} value True to allow the user to directly edit the field text
13533 setEditable : function(value){
13534 if(value == this.editable){
13537 this.editable = value;
13539 this.inputEl().dom.setAttribute('readOnly', true);
13540 this.inputEl().on('mousedown', this.onTriggerClick, this);
13541 this.inputEl().addClass('x-combo-noedit');
13543 this.inputEl().dom.setAttribute('readOnly', false);
13544 this.inputEl().un('mousedown', this.onTriggerClick, this);
13545 this.inputEl().removeClass('x-combo-noedit');
13551 onBeforeLoad : function(combo,opts){
13552 if(!this.hasFocus){
13556 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
13558 this.restrictHeight();
13559 this.selectedIndex = -1;
13563 onLoad : function(){
13565 this.hasQuery = false;
13567 if(!this.hasFocus){
13571 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13572 this.loading.hide();
13575 if(this.store.getCount() > 0){
13578 this.restrictHeight();
13579 if(this.lastQuery == this.allQuery){
13580 if(this.editable && !this.tickable){
13581 this.inputEl().dom.select();
13585 !this.selectByValue(this.value, true) &&
13588 !this.store.lastOptions ||
13589 typeof(this.store.lastOptions.add) == 'undefined' ||
13590 this.store.lastOptions.add != true
13593 this.select(0, true);
13596 if(this.autoFocus){
13599 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
13600 this.taTask.delay(this.typeAheadDelay);
13604 this.onEmptyResults();
13610 onLoadException : function()
13612 this.hasQuery = false;
13614 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13615 this.loading.hide();
13618 if(this.tickable && this.editable){
13623 // only causes errors at present
13624 //Roo.log(this.store.reader.jsonData);
13625 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
13627 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
13633 onTypeAhead : function(){
13634 if(this.store.getCount() > 0){
13635 var r = this.store.getAt(0);
13636 var newValue = r.data[this.displayField];
13637 var len = newValue.length;
13638 var selStart = this.getRawValue().length;
13640 if(selStart != len){
13641 this.setRawValue(newValue);
13642 this.selectText(selStart, newValue.length);
13648 onSelect : function(record, index){
13650 if(this.fireEvent('beforeselect', this, record, index) !== false){
13652 this.setFromData(index > -1 ? record.data : false);
13655 this.fireEvent('select', this, record, index);
13660 * Returns the currently selected field value or empty string if no value is set.
13661 * @return {String} value The selected value
13663 getValue : function()
13665 if(Roo.isIOS && this.useNativeIOS){
13666 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
13670 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
13673 if(this.valueField){
13674 return typeof this.value != 'undefined' ? this.value : '';
13676 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
13680 getRawValue : function()
13682 if(Roo.isIOS && this.useNativeIOS){
13683 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
13686 var v = this.inputEl().getValue();
13692 * Clears any text/value currently set in the field
13694 clearValue : function(){
13696 if(this.hiddenField){
13697 this.hiddenField.dom.value = '';
13700 this.setRawValue('');
13701 this.lastSelectionText = '';
13702 this.lastData = false;
13704 var close = this.closeTriggerEl();
13715 * Sets the specified value into the field. If the value finds a match, the corresponding record text
13716 * will be displayed in the field. If the value does not match the data value of an existing item,
13717 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
13718 * Otherwise the field will be blank (although the value will still be set).
13719 * @param {String} value The value to match
13721 setValue : function(v)
13723 if(Roo.isIOS && this.useNativeIOS){
13724 this.setIOSValue(v);
13734 if(this.valueField){
13735 var r = this.findRecord(this.valueField, v);
13737 text = r.data[this.displayField];
13738 }else if(this.valueNotFoundText !== undefined){
13739 text = this.valueNotFoundText;
13742 this.lastSelectionText = text;
13743 if(this.hiddenField){
13744 this.hiddenField.dom.value = v;
13746 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
13749 var close = this.closeTriggerEl();
13752 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
13758 * @property {Object} the last set data for the element
13763 * Sets the value of the field based on a object which is related to the record format for the store.
13764 * @param {Object} value the value to set as. or false on reset?
13766 setFromData : function(o){
13773 var dv = ''; // display value
13774 var vv = ''; // value value..
13776 if (this.displayField) {
13777 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
13779 // this is an error condition!!!
13780 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
13783 if(this.valueField){
13784 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
13787 var close = this.closeTriggerEl();
13790 if(dv.length || vv * 1 > 0){
13792 this.blockFocus=true;
13798 if(this.hiddenField){
13799 this.hiddenField.dom.value = vv;
13801 this.lastSelectionText = dv;
13802 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
13806 // no hidden field.. - we store the value in 'value', but still display
13807 // display field!!!!
13808 this.lastSelectionText = dv;
13809 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
13816 reset : function(){
13817 // overridden so that last data is reset..
13824 this.setValue(this.originalValue);
13825 //this.clearInvalid();
13826 this.lastData = false;
13828 this.view.clearSelections();
13834 findRecord : function(prop, value){
13836 if(this.store.getCount() > 0){
13837 this.store.each(function(r){
13838 if(r.data[prop] == value){
13848 getName: function()
13850 // returns hidden if it's set..
13851 if (!this.rendered) {return ''};
13852 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
13856 onViewMove : function(e, t){
13857 this.inKeyMode = false;
13861 onViewOver : function(e, t){
13862 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
13865 var item = this.view.findItemFromChild(t);
13868 var index = this.view.indexOf(item);
13869 this.select(index, false);
13874 onViewClick : function(view, doFocus, el, e)
13876 var index = this.view.getSelectedIndexes()[0];
13878 var r = this.store.getAt(index);
13882 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
13889 Roo.each(this.tickItems, function(v,k){
13891 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
13893 _this.tickItems.splice(k, 1);
13895 if(typeof(e) == 'undefined' && view == false){
13896 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
13908 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
13909 this.tickItems.push(r.data);
13912 if(typeof(e) == 'undefined' && view == false){
13913 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
13920 this.onSelect(r, index);
13922 if(doFocus !== false && !this.blockFocus){
13923 this.inputEl().focus();
13928 restrictHeight : function(){
13929 //this.innerList.dom.style.height = '';
13930 //var inner = this.innerList.dom;
13931 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
13932 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
13933 //this.list.beginUpdate();
13934 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
13935 this.list.alignTo(this.inputEl(), this.listAlign);
13936 this.list.alignTo(this.inputEl(), this.listAlign);
13937 //this.list.endUpdate();
13941 onEmptyResults : function(){
13943 if(this.tickable && this.editable){
13944 this.restrictHeight();
13952 * Returns true if the dropdown list is expanded, else false.
13954 isExpanded : function(){
13955 return this.list.isVisible();
13959 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
13960 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
13961 * @param {String} value The data value of the item to select
13962 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
13963 * selected item if it is not currently in view (defaults to true)
13964 * @return {Boolean} True if the value matched an item in the list, else false
13966 selectByValue : function(v, scrollIntoView){
13967 if(v !== undefined && v !== null){
13968 var r = this.findRecord(this.valueField || this.displayField, v);
13970 this.select(this.store.indexOf(r), scrollIntoView);
13978 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
13979 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
13980 * @param {Number} index The zero-based index of the list item to select
13981 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
13982 * selected item if it is not currently in view (defaults to true)
13984 select : function(index, scrollIntoView){
13985 this.selectedIndex = index;
13986 this.view.select(index);
13987 if(scrollIntoView !== false){
13988 var el = this.view.getNode(index);
13990 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
13993 this.list.scrollChildIntoView(el, false);
13999 selectNext : function(){
14000 var ct = this.store.getCount();
14002 if(this.selectedIndex == -1){
14004 }else if(this.selectedIndex < ct-1){
14005 this.select(this.selectedIndex+1);
14011 selectPrev : function(){
14012 var ct = this.store.getCount();
14014 if(this.selectedIndex == -1){
14016 }else if(this.selectedIndex != 0){
14017 this.select(this.selectedIndex-1);
14023 onKeyUp : function(e){
14024 if(this.editable !== false && !e.isSpecialKey()){
14025 this.lastKey = e.getKey();
14026 this.dqTask.delay(this.queryDelay);
14031 validateBlur : function(){
14032 return !this.list || !this.list.isVisible();
14036 initQuery : function(){
14038 var v = this.getRawValue();
14040 if(this.tickable && this.editable){
14041 v = this.tickableInputEl().getValue();
14048 doForce : function(){
14049 if(this.inputEl().dom.value.length > 0){
14050 this.inputEl().dom.value =
14051 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
14057 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
14058 * query allowing the query action to be canceled if needed.
14059 * @param {String} query The SQL query to execute
14060 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
14061 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
14062 * saved in the current store (defaults to false)
14064 doQuery : function(q, forceAll){
14066 if(q === undefined || q === null){
14071 forceAll: forceAll,
14075 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
14080 forceAll = qe.forceAll;
14081 if(forceAll === true || (q.length >= this.minChars)){
14083 this.hasQuery = true;
14085 if(this.lastQuery != q || this.alwaysQuery){
14086 this.lastQuery = q;
14087 if(this.mode == 'local'){
14088 this.selectedIndex = -1;
14090 this.store.clearFilter();
14093 if(this.specialFilter){
14094 this.fireEvent('specialfilter', this);
14099 this.store.filter(this.displayField, q);
14102 this.store.fireEvent("datachanged", this.store);
14109 this.store.baseParams[this.queryParam] = q;
14111 var options = {params : this.getParams(q)};
14114 options.add = true;
14115 options.params.start = this.page * this.pageSize;
14118 this.store.load(options);
14121 * this code will make the page width larger, at the beginning, the list not align correctly,
14122 * we should expand the list on onLoad
14123 * so command out it
14128 this.selectedIndex = -1;
14133 this.loadNext = false;
14137 getParams : function(q){
14139 //p[this.queryParam] = q;
14143 p.limit = this.pageSize;
14149 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
14151 collapse : function(){
14152 if(!this.isExpanded()){
14158 this.hasFocus = false;
14162 this.cancelBtn.hide();
14163 this.trigger.show();
14166 this.tickableInputEl().dom.value = '';
14167 this.tickableInputEl().blur();
14172 Roo.get(document).un('mousedown', this.collapseIf, this);
14173 Roo.get(document).un('mousewheel', this.collapseIf, this);
14174 if (!this.editable) {
14175 Roo.get(document).un('keydown', this.listKeyPress, this);
14177 this.fireEvent('collapse', this);
14183 collapseIf : function(e){
14184 var in_combo = e.within(this.el);
14185 var in_list = e.within(this.list);
14186 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
14188 if (in_combo || in_list || is_list) {
14189 //e.stopPropagation();
14194 this.onTickableFooterButtonClick(e, false, false);
14202 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
14204 expand : function(){
14206 if(this.isExpanded() || !this.hasFocus){
14210 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
14211 this.list.setWidth(lw);
14217 this.restrictHeight();
14221 this.tickItems = Roo.apply([], this.item);
14224 this.cancelBtn.show();
14225 this.trigger.hide();
14228 this.tickableInputEl().focus();
14233 Roo.get(document).on('mousedown', this.collapseIf, this);
14234 Roo.get(document).on('mousewheel', this.collapseIf, this);
14235 if (!this.editable) {
14236 Roo.get(document).on('keydown', this.listKeyPress, this);
14239 this.fireEvent('expand', this);
14243 // Implements the default empty TriggerField.onTriggerClick function
14244 onTriggerClick : function(e)
14246 Roo.log('trigger click');
14248 if(this.disabled || !this.triggerList){
14253 this.loadNext = false;
14255 if(this.isExpanded()){
14257 if (!this.blockFocus) {
14258 this.inputEl().focus();
14262 this.hasFocus = true;
14263 if(this.triggerAction == 'all') {
14264 this.doQuery(this.allQuery, true);
14266 this.doQuery(this.getRawValue());
14268 if (!this.blockFocus) {
14269 this.inputEl().focus();
14274 onTickableTriggerClick : function(e)
14281 this.loadNext = false;
14282 this.hasFocus = true;
14284 if(this.triggerAction == 'all') {
14285 this.doQuery(this.allQuery, true);
14287 this.doQuery(this.getRawValue());
14291 onSearchFieldClick : function(e)
14293 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
14294 this.onTickableFooterButtonClick(e, false, false);
14298 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
14303 this.loadNext = false;
14304 this.hasFocus = true;
14306 if(this.triggerAction == 'all') {
14307 this.doQuery(this.allQuery, true);
14309 this.doQuery(this.getRawValue());
14313 listKeyPress : function(e)
14315 //Roo.log('listkeypress');
14316 // scroll to first matching element based on key pres..
14317 if (e.isSpecialKey()) {
14320 var k = String.fromCharCode(e.getKey()).toUpperCase();
14323 var csel = this.view.getSelectedNodes();
14324 var cselitem = false;
14326 var ix = this.view.indexOf(csel[0]);
14327 cselitem = this.store.getAt(ix);
14328 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
14334 this.store.each(function(v) {
14336 // start at existing selection.
14337 if (cselitem.id == v.id) {
14343 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
14344 match = this.store.indexOf(v);
14350 if (match === false) {
14351 return true; // no more action?
14354 this.view.select(match);
14355 var sn = Roo.get(this.view.getSelectedNodes()[0]);
14356 sn.scrollIntoView(sn.dom.parentNode, false);
14359 onViewScroll : function(e, t){
14361 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){
14365 this.hasQuery = true;
14367 this.loading = this.list.select('.loading', true).first();
14369 if(this.loading === null){
14370 this.list.createChild({
14372 cls: 'loading roo-select2-more-results roo-select2-active',
14373 html: 'Loading more results...'
14376 this.loading = this.list.select('.loading', true).first();
14378 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
14380 this.loading.hide();
14383 this.loading.show();
14388 this.loadNext = true;
14390 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
14395 addItem : function(o)
14397 var dv = ''; // display value
14399 if (this.displayField) {
14400 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14402 // this is an error condition!!!
14403 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14410 var choice = this.choices.createChild({
14412 cls: 'roo-select2-search-choice',
14421 cls: 'roo-select2-search-choice-close fa fa-times',
14426 }, this.searchField);
14428 var close = choice.select('a.roo-select2-search-choice-close', true).first();
14430 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
14438 this.inputEl().dom.value = '';
14443 onRemoveItem : function(e, _self, o)
14445 e.preventDefault();
14447 this.lastItem = Roo.apply([], this.item);
14449 var index = this.item.indexOf(o.data) * 1;
14452 Roo.log('not this item?!');
14456 this.item.splice(index, 1);
14461 this.fireEvent('remove', this, e);
14467 syncValue : function()
14469 if(!this.item.length){
14476 Roo.each(this.item, function(i){
14477 if(_this.valueField){
14478 value.push(i[_this.valueField]);
14485 this.value = value.join(',');
14487 if(this.hiddenField){
14488 this.hiddenField.dom.value = this.value;
14491 this.store.fireEvent("datachanged", this.store);
14496 clearItem : function()
14498 if(!this.multiple){
14504 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
14512 if(this.tickable && !Roo.isTouch){
14513 this.view.refresh();
14517 inputEl: function ()
14519 if(Roo.isIOS && this.useNativeIOS){
14520 return this.el.select('select.roo-ios-select', true).first();
14523 if(Roo.isTouch && this.mobileTouchView){
14524 return this.el.select('input.form-control',true).first();
14528 return this.searchField;
14531 return this.el.select('input.form-control',true).first();
14534 onTickableFooterButtonClick : function(e, btn, el)
14536 e.preventDefault();
14538 this.lastItem = Roo.apply([], this.item);
14540 if(btn && btn.name == 'cancel'){
14541 this.tickItems = Roo.apply([], this.item);
14550 Roo.each(this.tickItems, function(o){
14558 validate : function()
14560 var v = this.getRawValue();
14563 v = this.getValue();
14566 if(this.disabled || this.allowBlank || v.length){
14571 this.markInvalid();
14575 tickableInputEl : function()
14577 if(!this.tickable || !this.editable){
14578 return this.inputEl();
14581 return this.inputEl().select('.roo-select2-search-field-input', true).first();
14585 getAutoCreateTouchView : function()
14590 cls: 'form-group' //input-group
14596 type : this.inputType,
14597 cls : 'form-control x-combo-noedit',
14598 autocomplete: 'new-password',
14599 placeholder : this.placeholder || '',
14604 input.name = this.name;
14608 input.cls += ' input-' + this.size;
14611 if (this.disabled) {
14612 input.disabled = true;
14623 inputblock.cls += ' input-group';
14625 inputblock.cn.unshift({
14627 cls : 'input-group-addon',
14632 if(this.removable && !this.multiple){
14633 inputblock.cls += ' roo-removable';
14635 inputblock.cn.push({
14638 cls : 'roo-combo-removable-btn close'
14642 if(this.hasFeedback && !this.allowBlank){
14644 inputblock.cls += ' has-feedback';
14646 inputblock.cn.push({
14648 cls: 'glyphicon form-control-feedback'
14655 inputblock.cls += (this.before) ? '' : ' input-group';
14657 inputblock.cn.push({
14659 cls : 'input-group-addon',
14670 cls: 'form-hidden-field'
14684 cls: 'form-hidden-field'
14688 cls: 'roo-select2-choices',
14692 cls: 'roo-select2-search-field',
14705 cls: 'roo-select2-container input-group roo-touchview-combobox ',
14711 if(!this.multiple && this.showToggleBtn){
14718 if (this.caret != false) {
14721 cls: 'fa fa-' + this.caret
14728 cls : 'input-group-addon btn dropdown-toggle',
14733 cls: 'combobox-clear',
14747 combobox.cls += ' roo-select2-container-multi';
14750 var align = this.labelAlign || this.parentLabelAlign();
14752 if (align ==='left' && this.fieldLabel.length) {
14757 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
14758 tooltip : 'This field is required'
14762 cls : 'control-label',
14763 html : this.fieldLabel
14774 var labelCfg = cfg.cn[1];
14775 var contentCfg = cfg.cn[2];
14778 if(this.indicatorpos == 'right'){
14783 cls : 'control-label',
14787 html : this.fieldLabel
14791 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
14792 tooltip : 'This field is required'
14805 labelCfg = cfg.cn[0];
14806 contentCfg = cfg.cn[1];
14811 if(this.labelWidth > 12){
14812 labelCfg.style = "width: " + this.labelWidth + 'px';
14815 if(this.labelWidth < 13 && this.labelmd == 0){
14816 this.labelmd = this.labelWidth;
14819 if(this.labellg > 0){
14820 labelCfg.cls += ' col-lg-' + this.labellg;
14821 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
14824 if(this.labelmd > 0){
14825 labelCfg.cls += ' col-md-' + this.labelmd;
14826 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
14829 if(this.labelsm > 0){
14830 labelCfg.cls += ' col-sm-' + this.labelsm;
14831 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
14834 if(this.labelxs > 0){
14835 labelCfg.cls += ' col-xs-' + this.labelxs;
14836 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
14840 } else if ( this.fieldLabel.length) {
14844 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
14845 tooltip : 'This field is required'
14849 cls : 'control-label',
14850 html : this.fieldLabel
14861 if(this.indicatorpos == 'right'){
14865 cls : 'control-label',
14866 html : this.fieldLabel,
14870 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
14871 tooltip : 'This field is required'
14888 var settings = this;
14890 ['xs','sm','md','lg'].map(function(size){
14891 if (settings[size]) {
14892 cfg.cls += ' col-' + size + '-' + settings[size];
14899 initTouchView : function()
14901 this.renderTouchView();
14903 this.touchViewEl.on('scroll', function(){
14904 this.el.dom.scrollTop = 0;
14907 this.originalValue = this.getValue();
14909 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
14911 this.inputEl().on("click", this.showTouchView, this);
14912 if (this.triggerEl) {
14913 this.triggerEl.on("click", this.showTouchView, this);
14917 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
14918 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
14920 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
14922 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
14923 this.store.on('load', this.onTouchViewLoad, this);
14924 this.store.on('loadexception', this.onTouchViewLoadException, this);
14926 if(this.hiddenName){
14928 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
14930 this.hiddenField.dom.value =
14931 this.hiddenValue !== undefined ? this.hiddenValue :
14932 this.value !== undefined ? this.value : '';
14934 this.el.dom.removeAttribute('name');
14935 this.hiddenField.dom.setAttribute('name', this.hiddenName);
14939 this.choices = this.el.select('ul.roo-select2-choices', true).first();
14940 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
14943 if(this.removable && !this.multiple){
14944 var close = this.closeTriggerEl();
14946 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
14947 close.on('click', this.removeBtnClick, this, close);
14951 * fix the bug in Safari iOS8
14953 this.inputEl().on("focus", function(e){
14954 document.activeElement.blur();
14962 renderTouchView : function()
14964 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
14965 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14967 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
14968 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14970 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
14971 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14972 this.touchViewBodyEl.setStyle('overflow', 'auto');
14974 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
14975 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14977 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
14978 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
14982 showTouchView : function()
14988 this.touchViewHeaderEl.hide();
14990 if(this.modalTitle.length){
14991 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
14992 this.touchViewHeaderEl.show();
14995 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
14996 this.touchViewEl.show();
14998 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
15000 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
15001 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15003 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15005 if(this.modalTitle.length){
15006 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15009 this.touchViewBodyEl.setHeight(bodyHeight);
15013 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
15015 this.touchViewEl.addClass('in');
15018 this.doTouchViewQuery();
15022 hideTouchView : function()
15024 this.touchViewEl.removeClass('in');
15028 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
15030 this.touchViewEl.setStyle('display', 'none');
15035 setTouchViewValue : function()
15042 Roo.each(this.tickItems, function(o){
15047 this.hideTouchView();
15050 doTouchViewQuery : function()
15059 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
15063 if(!this.alwaysQuery || this.mode == 'local'){
15064 this.onTouchViewLoad();
15071 onTouchViewBeforeLoad : function(combo,opts)
15077 onTouchViewLoad : function()
15079 if(this.store.getCount() < 1){
15080 this.onTouchViewEmptyResults();
15084 this.clearTouchView();
15086 var rawValue = this.getRawValue();
15088 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
15090 this.tickItems = [];
15092 this.store.data.each(function(d, rowIndex){
15093 var row = this.touchViewListGroup.createChild(template);
15095 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
15096 row.addClass(d.data.cls);
15099 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15102 html : d.data[this.displayField]
15105 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
15106 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
15109 row.removeClass('selected');
15110 if(!this.multiple && this.valueField &&
15111 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
15114 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15115 row.addClass('selected');
15118 if(this.multiple && this.valueField &&
15119 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
15123 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15124 this.tickItems.push(d.data);
15127 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
15131 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
15133 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15135 if(this.modalTitle.length){
15136 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15139 var listHeight = this.touchViewListGroup.getHeight();
15143 if(firstChecked && listHeight > bodyHeight){
15144 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
15149 onTouchViewLoadException : function()
15151 this.hideTouchView();
15154 onTouchViewEmptyResults : function()
15156 this.clearTouchView();
15158 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
15160 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
15164 clearTouchView : function()
15166 this.touchViewListGroup.dom.innerHTML = '';
15169 onTouchViewClick : function(e, el, o)
15171 e.preventDefault();
15174 var rowIndex = o.rowIndex;
15176 var r = this.store.getAt(rowIndex);
15178 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
15180 if(!this.multiple){
15181 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
15182 c.dom.removeAttribute('checked');
15185 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15187 this.setFromData(r.data);
15189 var close = this.closeTriggerEl();
15195 this.hideTouchView();
15197 this.fireEvent('select', this, r, rowIndex);
15202 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
15203 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
15204 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
15208 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15209 this.addItem(r.data);
15210 this.tickItems.push(r.data);
15214 getAutoCreateNativeIOS : function()
15217 cls: 'form-group' //input-group,
15222 cls : 'roo-ios-select'
15226 combobox.name = this.name;
15229 if (this.disabled) {
15230 combobox.disabled = true;
15233 var settings = this;
15235 ['xs','sm','md','lg'].map(function(size){
15236 if (settings[size]) {
15237 cfg.cls += ' col-' + size + '-' + settings[size];
15247 initIOSView : function()
15249 this.store.on('load', this.onIOSViewLoad, this);
15254 onIOSViewLoad : function()
15256 if(this.store.getCount() < 1){
15260 this.clearIOSView();
15262 if(this.allowBlank) {
15264 var default_text = '-- SELECT --';
15266 if(this.placeholder.length){
15267 default_text = this.placeholder;
15270 if(this.emptyTitle.length){
15271 default_text += ' - ' + this.emptyTitle + ' -';
15274 var opt = this.inputEl().createChild({
15277 html : default_text
15281 o[this.valueField] = 0;
15282 o[this.displayField] = default_text;
15284 this.ios_options.push({
15291 this.store.data.each(function(d, rowIndex){
15295 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15296 html = d.data[this.displayField];
15301 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
15302 value = d.data[this.valueField];
15311 if(this.value == d.data[this.valueField]){
15312 option['selected'] = true;
15315 var opt = this.inputEl().createChild(option);
15317 this.ios_options.push({
15324 this.inputEl().on('change', function(){
15325 this.fireEvent('select', this);
15330 clearIOSView: function()
15332 this.inputEl().dom.innerHTML = '';
15334 this.ios_options = [];
15337 setIOSValue: function(v)
15341 if(!this.ios_options){
15345 Roo.each(this.ios_options, function(opts){
15347 opts.el.dom.removeAttribute('selected');
15349 if(opts.data[this.valueField] != v){
15353 opts.el.dom.setAttribute('selected', true);
15359 * @cfg {Boolean} grow
15363 * @cfg {Number} growMin
15367 * @cfg {Number} growMax
15376 Roo.apply(Roo.bootstrap.ComboBox, {
15380 cls: 'modal-header',
15402 cls: 'list-group-item',
15406 cls: 'roo-combobox-list-group-item-value'
15410 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
15424 listItemCheckbox : {
15426 cls: 'list-group-item',
15430 cls: 'roo-combobox-list-group-item-value'
15434 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
15450 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
15455 cls: 'modal-footer',
15463 cls: 'col-xs-6 text-left',
15466 cls: 'btn btn-danger roo-touch-view-cancel',
15472 cls: 'col-xs-6 text-right',
15475 cls: 'btn btn-success roo-touch-view-ok',
15486 Roo.apply(Roo.bootstrap.ComboBox, {
15488 touchViewTemplate : {
15490 cls: 'modal fade roo-combobox-touch-view',
15494 cls: 'modal-dialog',
15495 style : 'position:fixed', // we have to fix position....
15499 cls: 'modal-content',
15501 Roo.bootstrap.ComboBox.header,
15502 Roo.bootstrap.ComboBox.body,
15503 Roo.bootstrap.ComboBox.footer
15512 * Ext JS Library 1.1.1
15513 * Copyright(c) 2006-2007, Ext JS, LLC.
15515 * Originally Released Under LGPL - original licence link has changed is not relivant.
15518 * <script type="text/javascript">
15523 * @extends Roo.util.Observable
15524 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
15525 * This class also supports single and multi selection modes. <br>
15526 * Create a data model bound view:
15528 var store = new Roo.data.Store(...);
15530 var view = new Roo.View({
15532 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
15534 singleSelect: true,
15535 selectedClass: "ydataview-selected",
15539 // listen for node click?
15540 view.on("click", function(vw, index, node, e){
15541 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
15545 dataModel.load("foobar.xml");
15547 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
15549 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
15550 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
15552 * Note: old style constructor is still suported (container, template, config)
15555 * Create a new View
15556 * @param {Object} config The config object
15559 Roo.View = function(config, depreciated_tpl, depreciated_config){
15561 this.parent = false;
15563 if (typeof(depreciated_tpl) == 'undefined') {
15564 // new way.. - universal constructor.
15565 Roo.apply(this, config);
15566 this.el = Roo.get(this.el);
15569 this.el = Roo.get(config);
15570 this.tpl = depreciated_tpl;
15571 Roo.apply(this, depreciated_config);
15573 this.wrapEl = this.el.wrap().wrap();
15574 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
15577 if(typeof(this.tpl) == "string"){
15578 this.tpl = new Roo.Template(this.tpl);
15580 // support xtype ctors..
15581 this.tpl = new Roo.factory(this.tpl, Roo);
15585 this.tpl.compile();
15590 * @event beforeclick
15591 * Fires before a click is processed. Returns false to cancel the default action.
15592 * @param {Roo.View} this
15593 * @param {Number} index The index of the target node
15594 * @param {HTMLElement} node The target node
15595 * @param {Roo.EventObject} e The raw event object
15597 "beforeclick" : true,
15600 * Fires when a template node is clicked.
15601 * @param {Roo.View} this
15602 * @param {Number} index The index of the target node
15603 * @param {HTMLElement} node The target node
15604 * @param {Roo.EventObject} e The raw event object
15609 * Fires when a template node is double clicked.
15610 * @param {Roo.View} this
15611 * @param {Number} index The index of the target node
15612 * @param {HTMLElement} node The target node
15613 * @param {Roo.EventObject} e The raw event object
15617 * @event contextmenu
15618 * Fires when a template node is right clicked.
15619 * @param {Roo.View} this
15620 * @param {Number} index The index of the target node
15621 * @param {HTMLElement} node The target node
15622 * @param {Roo.EventObject} e The raw event object
15624 "contextmenu" : true,
15626 * @event selectionchange
15627 * Fires when the selected nodes change.
15628 * @param {Roo.View} this
15629 * @param {Array} selections Array of the selected nodes
15631 "selectionchange" : true,
15634 * @event beforeselect
15635 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
15636 * @param {Roo.View} this
15637 * @param {HTMLElement} node The node to be selected
15638 * @param {Array} selections Array of currently selected nodes
15640 "beforeselect" : true,
15642 * @event preparedata
15643 * Fires on every row to render, to allow you to change the data.
15644 * @param {Roo.View} this
15645 * @param {Object} data to be rendered (change this)
15647 "preparedata" : true
15655 "click": this.onClick,
15656 "dblclick": this.onDblClick,
15657 "contextmenu": this.onContextMenu,
15661 this.selections = [];
15663 this.cmp = new Roo.CompositeElementLite([]);
15665 this.store = Roo.factory(this.store, Roo.data);
15666 this.setStore(this.store, true);
15669 if ( this.footer && this.footer.xtype) {
15671 var fctr = this.wrapEl.appendChild(document.createElement("div"));
15673 this.footer.dataSource = this.store;
15674 this.footer.container = fctr;
15675 this.footer = Roo.factory(this.footer, Roo);
15676 fctr.insertFirst(this.el);
15678 // this is a bit insane - as the paging toolbar seems to detach the el..
15679 // dom.parentNode.parentNode.parentNode
15680 // they get detached?
15684 Roo.View.superclass.constructor.call(this);
15689 Roo.extend(Roo.View, Roo.util.Observable, {
15692 * @cfg {Roo.data.Store} store Data store to load data from.
15697 * @cfg {String|Roo.Element} el The container element.
15702 * @cfg {String|Roo.Template} tpl The template used by this View
15706 * @cfg {String} dataName the named area of the template to use as the data area
15707 * Works with domtemplates roo-name="name"
15711 * @cfg {String} selectedClass The css class to add to selected nodes
15713 selectedClass : "x-view-selected",
15715 * @cfg {String} emptyText The empty text to show when nothing is loaded.
15720 * @cfg {String} text to display on mask (default Loading)
15724 * @cfg {Boolean} multiSelect Allow multiple selection
15726 multiSelect : false,
15728 * @cfg {Boolean} singleSelect Allow single selection
15730 singleSelect: false,
15733 * @cfg {Boolean} toggleSelect - selecting
15735 toggleSelect : false,
15738 * @cfg {Boolean} tickable - selecting
15743 * Returns the element this view is bound to.
15744 * @return {Roo.Element}
15746 getEl : function(){
15747 return this.wrapEl;
15753 * Refreshes the view. - called by datachanged on the store. - do not call directly.
15755 refresh : function(){
15756 //Roo.log('refresh');
15759 // if we are using something like 'domtemplate', then
15760 // the what gets used is:
15761 // t.applySubtemplate(NAME, data, wrapping data..)
15762 // the outer template then get' applied with
15763 // the store 'extra data'
15764 // and the body get's added to the
15765 // roo-name="data" node?
15766 // <span class='roo-tpl-{name}'></span> ?????
15770 this.clearSelections();
15771 this.el.update("");
15773 var records = this.store.getRange();
15774 if(records.length < 1) {
15776 // is this valid?? = should it render a template??
15778 this.el.update(this.emptyText);
15782 if (this.dataName) {
15783 this.el.update(t.apply(this.store.meta)); //????
15784 el = this.el.child('.roo-tpl-' + this.dataName);
15787 for(var i = 0, len = records.length; i < len; i++){
15788 var data = this.prepareData(records[i].data, i, records[i]);
15789 this.fireEvent("preparedata", this, data, i, records[i]);
15791 var d = Roo.apply({}, data);
15794 Roo.apply(d, {'roo-id' : Roo.id()});
15798 Roo.each(this.parent.item, function(item){
15799 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
15802 Roo.apply(d, {'roo-data-checked' : 'checked'});
15806 html[html.length] = Roo.util.Format.trim(
15808 t.applySubtemplate(this.dataName, d, this.store.meta) :
15815 el.update(html.join(""));
15816 this.nodes = el.dom.childNodes;
15817 this.updateIndexes(0);
15822 * Function to override to reformat the data that is sent to
15823 * the template for each node.
15824 * DEPRICATED - use the preparedata event handler.
15825 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
15826 * a JSON object for an UpdateManager bound view).
15828 prepareData : function(data, index, record)
15830 this.fireEvent("preparedata", this, data, index, record);
15834 onUpdate : function(ds, record){
15835 // Roo.log('on update');
15836 this.clearSelections();
15837 var index = this.store.indexOf(record);
15838 var n = this.nodes[index];
15839 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
15840 n.parentNode.removeChild(n);
15841 this.updateIndexes(index, index);
15847 onAdd : function(ds, records, index)
15849 //Roo.log(['on Add', ds, records, index] );
15850 this.clearSelections();
15851 if(this.nodes.length == 0){
15855 var n = this.nodes[index];
15856 for(var i = 0, len = records.length; i < len; i++){
15857 var d = this.prepareData(records[i].data, i, records[i]);
15859 this.tpl.insertBefore(n, d);
15862 this.tpl.append(this.el, d);
15865 this.updateIndexes(index);
15868 onRemove : function(ds, record, index){
15869 // Roo.log('onRemove');
15870 this.clearSelections();
15871 var el = this.dataName ?
15872 this.el.child('.roo-tpl-' + this.dataName) :
15875 el.dom.removeChild(this.nodes[index]);
15876 this.updateIndexes(index);
15880 * Refresh an individual node.
15881 * @param {Number} index
15883 refreshNode : function(index){
15884 this.onUpdate(this.store, this.store.getAt(index));
15887 updateIndexes : function(startIndex, endIndex){
15888 var ns = this.nodes;
15889 startIndex = startIndex || 0;
15890 endIndex = endIndex || ns.length - 1;
15891 for(var i = startIndex; i <= endIndex; i++){
15892 ns[i].nodeIndex = i;
15897 * Changes the data store this view uses and refresh the view.
15898 * @param {Store} store
15900 setStore : function(store, initial){
15901 if(!initial && this.store){
15902 this.store.un("datachanged", this.refresh);
15903 this.store.un("add", this.onAdd);
15904 this.store.un("remove", this.onRemove);
15905 this.store.un("update", this.onUpdate);
15906 this.store.un("clear", this.refresh);
15907 this.store.un("beforeload", this.onBeforeLoad);
15908 this.store.un("load", this.onLoad);
15909 this.store.un("loadexception", this.onLoad);
15913 store.on("datachanged", this.refresh, this);
15914 store.on("add", this.onAdd, this);
15915 store.on("remove", this.onRemove, this);
15916 store.on("update", this.onUpdate, this);
15917 store.on("clear", this.refresh, this);
15918 store.on("beforeload", this.onBeforeLoad, this);
15919 store.on("load", this.onLoad, this);
15920 store.on("loadexception", this.onLoad, this);
15928 * onbeforeLoad - masks the loading area.
15931 onBeforeLoad : function(store,opts)
15933 //Roo.log('onBeforeLoad');
15935 this.el.update("");
15937 this.el.mask(this.mask ? this.mask : "Loading" );
15939 onLoad : function ()
15946 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
15947 * @param {HTMLElement} node
15948 * @return {HTMLElement} The template node
15950 findItemFromChild : function(node){
15951 var el = this.dataName ?
15952 this.el.child('.roo-tpl-' + this.dataName,true) :
15955 if(!node || node.parentNode == el){
15958 var p = node.parentNode;
15959 while(p && p != el){
15960 if(p.parentNode == el){
15969 onClick : function(e){
15970 var item = this.findItemFromChild(e.getTarget());
15972 var index = this.indexOf(item);
15973 if(this.onItemClick(item, index, e) !== false){
15974 this.fireEvent("click", this, index, item, e);
15977 this.clearSelections();
15982 onContextMenu : function(e){
15983 var item = this.findItemFromChild(e.getTarget());
15985 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
15990 onDblClick : function(e){
15991 var item = this.findItemFromChild(e.getTarget());
15993 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
15997 onItemClick : function(item, index, e)
15999 if(this.fireEvent("beforeclick", this, index, item, e) === false){
16002 if (this.toggleSelect) {
16003 var m = this.isSelected(item) ? 'unselect' : 'select';
16006 _t[m](item, true, false);
16009 if(this.multiSelect || this.singleSelect){
16010 if(this.multiSelect && e.shiftKey && this.lastSelection){
16011 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
16013 this.select(item, this.multiSelect && e.ctrlKey);
16014 this.lastSelection = item;
16017 if(!this.tickable){
16018 e.preventDefault();
16026 * Get the number of selected nodes.
16029 getSelectionCount : function(){
16030 return this.selections.length;
16034 * Get the currently selected nodes.
16035 * @return {Array} An array of HTMLElements
16037 getSelectedNodes : function(){
16038 return this.selections;
16042 * Get the indexes of the selected nodes.
16045 getSelectedIndexes : function(){
16046 var indexes = [], s = this.selections;
16047 for(var i = 0, len = s.length; i < len; i++){
16048 indexes.push(s[i].nodeIndex);
16054 * Clear all selections
16055 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
16057 clearSelections : function(suppressEvent){
16058 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
16059 this.cmp.elements = this.selections;
16060 this.cmp.removeClass(this.selectedClass);
16061 this.selections = [];
16062 if(!suppressEvent){
16063 this.fireEvent("selectionchange", this, this.selections);
16069 * Returns true if the passed node is selected
16070 * @param {HTMLElement/Number} node The node or node index
16071 * @return {Boolean}
16073 isSelected : function(node){
16074 var s = this.selections;
16078 node = this.getNode(node);
16079 return s.indexOf(node) !== -1;
16084 * @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
16085 * @param {Boolean} keepExisting (optional) true to keep existing selections
16086 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16088 select : function(nodeInfo, keepExisting, suppressEvent){
16089 if(nodeInfo instanceof Array){
16091 this.clearSelections(true);
16093 for(var i = 0, len = nodeInfo.length; i < len; i++){
16094 this.select(nodeInfo[i], true, true);
16098 var node = this.getNode(nodeInfo);
16099 if(!node || this.isSelected(node)){
16100 return; // already selected.
16103 this.clearSelections(true);
16106 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
16107 Roo.fly(node).addClass(this.selectedClass);
16108 this.selections.push(node);
16109 if(!suppressEvent){
16110 this.fireEvent("selectionchange", this, this.selections);
16118 * @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
16119 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
16120 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16122 unselect : function(nodeInfo, keepExisting, suppressEvent)
16124 if(nodeInfo instanceof Array){
16125 Roo.each(this.selections, function(s) {
16126 this.unselect(s, nodeInfo);
16130 var node = this.getNode(nodeInfo);
16131 if(!node || !this.isSelected(node)){
16132 //Roo.log("not selected");
16133 return; // not selected.
16137 Roo.each(this.selections, function(s) {
16139 Roo.fly(node).removeClass(this.selectedClass);
16146 this.selections= ns;
16147 this.fireEvent("selectionchange", this, this.selections);
16151 * Gets a template node.
16152 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16153 * @return {HTMLElement} The node or null if it wasn't found
16155 getNode : function(nodeInfo){
16156 if(typeof nodeInfo == "string"){
16157 return document.getElementById(nodeInfo);
16158 }else if(typeof nodeInfo == "number"){
16159 return this.nodes[nodeInfo];
16165 * Gets a range template nodes.
16166 * @param {Number} startIndex
16167 * @param {Number} endIndex
16168 * @return {Array} An array of nodes
16170 getNodes : function(start, end){
16171 var ns = this.nodes;
16172 start = start || 0;
16173 end = typeof end == "undefined" ? ns.length - 1 : end;
16176 for(var i = start; i <= end; i++){
16180 for(var i = start; i >= end; i--){
16188 * Finds the index of the passed node
16189 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16190 * @return {Number} The index of the node or -1
16192 indexOf : function(node){
16193 node = this.getNode(node);
16194 if(typeof node.nodeIndex == "number"){
16195 return node.nodeIndex;
16197 var ns = this.nodes;
16198 for(var i = 0, len = ns.length; i < len; i++){
16209 * based on jquery fullcalendar
16213 Roo.bootstrap = Roo.bootstrap || {};
16215 * @class Roo.bootstrap.Calendar
16216 * @extends Roo.bootstrap.Component
16217 * Bootstrap Calendar class
16218 * @cfg {Boolean} loadMask (true|false) default false
16219 * @cfg {Object} header generate the user specific header of the calendar, default false
16222 * Create a new Container
16223 * @param {Object} config The config object
16228 Roo.bootstrap.Calendar = function(config){
16229 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
16233 * Fires when a date is selected
16234 * @param {DatePicker} this
16235 * @param {Date} date The selected date
16239 * @event monthchange
16240 * Fires when the displayed month changes
16241 * @param {DatePicker} this
16242 * @param {Date} date The selected month
16244 'monthchange': true,
16246 * @event evententer
16247 * Fires when mouse over an event
16248 * @param {Calendar} this
16249 * @param {event} Event
16251 'evententer': true,
16253 * @event eventleave
16254 * Fires when the mouse leaves an
16255 * @param {Calendar} this
16258 'eventleave': true,
16260 * @event eventclick
16261 * Fires when the mouse click an
16262 * @param {Calendar} this
16271 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
16274 * @cfg {Number} startDay
16275 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
16283 getAutoCreate : function(){
16286 var fc_button = function(name, corner, style, content ) {
16287 return Roo.apply({},{
16289 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
16291 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
16294 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
16305 style : 'width:100%',
16312 cls : 'fc-header-left',
16314 fc_button('prev', 'left', 'arrow', '‹' ),
16315 fc_button('next', 'right', 'arrow', '›' ),
16316 { tag: 'span', cls: 'fc-header-space' },
16317 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
16325 cls : 'fc-header-center',
16329 cls: 'fc-header-title',
16332 html : 'month / year'
16340 cls : 'fc-header-right',
16342 /* fc_button('month', 'left', '', 'month' ),
16343 fc_button('week', '', '', 'week' ),
16344 fc_button('day', 'right', '', 'day' )
16356 header = this.header;
16359 var cal_heads = function() {
16361 // fixme - handle this.
16363 for (var i =0; i < Date.dayNames.length; i++) {
16364 var d = Date.dayNames[i];
16367 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
16368 html : d.substring(0,3)
16372 ret[0].cls += ' fc-first';
16373 ret[6].cls += ' fc-last';
16376 var cal_cell = function(n) {
16379 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
16384 cls: 'fc-day-number',
16388 cls: 'fc-day-content',
16392 style: 'position: relative;' // height: 17px;
16404 var cal_rows = function() {
16407 for (var r = 0; r < 6; r++) {
16414 for (var i =0; i < Date.dayNames.length; i++) {
16415 var d = Date.dayNames[i];
16416 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
16419 row.cn[0].cls+=' fc-first';
16420 row.cn[0].cn[0].style = 'min-height:90px';
16421 row.cn[6].cls+=' fc-last';
16425 ret[0].cls += ' fc-first';
16426 ret[4].cls += ' fc-prev-last';
16427 ret[5].cls += ' fc-last';
16434 cls: 'fc-border-separate',
16435 style : 'width:100%',
16443 cls : 'fc-first fc-last',
16461 cls : 'fc-content',
16462 style : "position: relative;",
16465 cls : 'fc-view fc-view-month fc-grid',
16466 style : 'position: relative',
16467 unselectable : 'on',
16470 cls : 'fc-event-container',
16471 style : 'position:absolute;z-index:8;top:0;left:0;'
16489 initEvents : function()
16492 throw "can not find store for calendar";
16498 style: "text-align:center",
16502 style: "background-color:white;width:50%;margin:250 auto",
16506 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
16517 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
16519 var size = this.el.select('.fc-content', true).first().getSize();
16520 this.maskEl.setSize(size.width, size.height);
16521 this.maskEl.enableDisplayMode("block");
16522 if(!this.loadMask){
16523 this.maskEl.hide();
16526 this.store = Roo.factory(this.store, Roo.data);
16527 this.store.on('load', this.onLoad, this);
16528 this.store.on('beforeload', this.onBeforeLoad, this);
16532 this.cells = this.el.select('.fc-day',true);
16533 //Roo.log(this.cells);
16534 this.textNodes = this.el.query('.fc-day-number');
16535 this.cells.addClassOnOver('fc-state-hover');
16537 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
16538 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
16539 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
16540 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
16542 this.on('monthchange', this.onMonthChange, this);
16544 this.update(new Date().clearTime());
16547 resize : function() {
16548 var sz = this.el.getSize();
16550 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
16551 this.el.select('.fc-day-content div',true).setHeight(34);
16556 showPrevMonth : function(e){
16557 this.update(this.activeDate.add("mo", -1));
16559 showToday : function(e){
16560 this.update(new Date().clearTime());
16563 showNextMonth : function(e){
16564 this.update(this.activeDate.add("mo", 1));
16568 showPrevYear : function(){
16569 this.update(this.activeDate.add("y", -1));
16573 showNextYear : function(){
16574 this.update(this.activeDate.add("y", 1));
16579 update : function(date)
16581 var vd = this.activeDate;
16582 this.activeDate = date;
16583 // if(vd && this.el){
16584 // var t = date.getTime();
16585 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
16586 // Roo.log('using add remove');
16588 // this.fireEvent('monthchange', this, date);
16590 // this.cells.removeClass("fc-state-highlight");
16591 // this.cells.each(function(c){
16592 // if(c.dateValue == t){
16593 // c.addClass("fc-state-highlight");
16594 // setTimeout(function(){
16595 // try{c.dom.firstChild.focus();}catch(e){}
16605 var days = date.getDaysInMonth();
16607 var firstOfMonth = date.getFirstDateOfMonth();
16608 var startingPos = firstOfMonth.getDay()-this.startDay;
16610 if(startingPos < this.startDay){
16614 var pm = date.add(Date.MONTH, -1);
16615 var prevStart = pm.getDaysInMonth()-startingPos;
16617 this.cells = this.el.select('.fc-day',true);
16618 this.textNodes = this.el.query('.fc-day-number');
16619 this.cells.addClassOnOver('fc-state-hover');
16621 var cells = this.cells.elements;
16622 var textEls = this.textNodes;
16624 Roo.each(cells, function(cell){
16625 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
16628 days += startingPos;
16630 // convert everything to numbers so it's fast
16631 var day = 86400000;
16632 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
16635 //Roo.log(prevStart);
16637 var today = new Date().clearTime().getTime();
16638 var sel = date.clearTime().getTime();
16639 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
16640 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
16641 var ddMatch = this.disabledDatesRE;
16642 var ddText = this.disabledDatesText;
16643 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
16644 var ddaysText = this.disabledDaysText;
16645 var format = this.format;
16647 var setCellClass = function(cal, cell){
16651 //Roo.log('set Cell Class');
16653 var t = d.getTime();
16657 cell.dateValue = t;
16659 cell.className += " fc-today";
16660 cell.className += " fc-state-highlight";
16661 cell.title = cal.todayText;
16664 // disable highlight in other month..
16665 //cell.className += " fc-state-highlight";
16670 cell.className = " fc-state-disabled";
16671 cell.title = cal.minText;
16675 cell.className = " fc-state-disabled";
16676 cell.title = cal.maxText;
16680 if(ddays.indexOf(d.getDay()) != -1){
16681 cell.title = ddaysText;
16682 cell.className = " fc-state-disabled";
16685 if(ddMatch && format){
16686 var fvalue = d.dateFormat(format);
16687 if(ddMatch.test(fvalue)){
16688 cell.title = ddText.replace("%0", fvalue);
16689 cell.className = " fc-state-disabled";
16693 if (!cell.initialClassName) {
16694 cell.initialClassName = cell.dom.className;
16697 cell.dom.className = cell.initialClassName + ' ' + cell.className;
16702 for(; i < startingPos; i++) {
16703 textEls[i].innerHTML = (++prevStart);
16704 d.setDate(d.getDate()+1);
16706 cells[i].className = "fc-past fc-other-month";
16707 setCellClass(this, cells[i]);
16712 for(; i < days; i++){
16713 intDay = i - startingPos + 1;
16714 textEls[i].innerHTML = (intDay);
16715 d.setDate(d.getDate()+1);
16717 cells[i].className = ''; // "x-date-active";
16718 setCellClass(this, cells[i]);
16722 for(; i < 42; i++) {
16723 textEls[i].innerHTML = (++extraDays);
16724 d.setDate(d.getDate()+1);
16726 cells[i].className = "fc-future fc-other-month";
16727 setCellClass(this, cells[i]);
16730 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
16732 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
16734 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
16735 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
16737 if(totalRows != 6){
16738 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
16739 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
16742 this.fireEvent('monthchange', this, date);
16746 if(!this.internalRender){
16747 var main = this.el.dom.firstChild;
16748 var w = main.offsetWidth;
16749 this.el.setWidth(w + this.el.getBorderWidth("lr"));
16750 Roo.fly(main).setWidth(w);
16751 this.internalRender = true;
16752 // opera does not respect the auto grow header center column
16753 // then, after it gets a width opera refuses to recalculate
16754 // without a second pass
16755 if(Roo.isOpera && !this.secondPass){
16756 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
16757 this.secondPass = true;
16758 this.update.defer(10, this, [date]);
16765 findCell : function(dt) {
16766 dt = dt.clearTime().getTime();
16768 this.cells.each(function(c){
16769 //Roo.log("check " +c.dateValue + '?=' + dt);
16770 if(c.dateValue == dt){
16780 findCells : function(ev) {
16781 var s = ev.start.clone().clearTime().getTime();
16783 var e= ev.end.clone().clearTime().getTime();
16786 this.cells.each(function(c){
16787 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
16789 if(c.dateValue > e){
16792 if(c.dateValue < s){
16801 // findBestRow: function(cells)
16805 // for (var i =0 ; i < cells.length;i++) {
16806 // ret = Math.max(cells[i].rows || 0,ret);
16813 addItem : function(ev)
16815 // look for vertical location slot in
16816 var cells = this.findCells(ev);
16818 // ev.row = this.findBestRow(cells);
16820 // work out the location.
16824 for(var i =0; i < cells.length; i++) {
16826 cells[i].row = cells[0].row;
16829 cells[i].row = cells[i].row + 1;
16839 if (crow.start.getY() == cells[i].getY()) {
16841 crow.end = cells[i];
16858 cells[0].events.push(ev);
16860 this.calevents.push(ev);
16863 clearEvents: function() {
16865 if(!this.calevents){
16869 Roo.each(this.cells.elements, function(c){
16875 Roo.each(this.calevents, function(e) {
16876 Roo.each(e.els, function(el) {
16877 el.un('mouseenter' ,this.onEventEnter, this);
16878 el.un('mouseleave' ,this.onEventLeave, this);
16883 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
16889 renderEvents: function()
16893 this.cells.each(function(c) {
16902 if(c.row != c.events.length){
16903 r = 4 - (4 - (c.row - c.events.length));
16906 c.events = ev.slice(0, r);
16907 c.more = ev.slice(r);
16909 if(c.more.length && c.more.length == 1){
16910 c.events.push(c.more.pop());
16913 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
16917 this.cells.each(function(c) {
16919 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
16922 for (var e = 0; e < c.events.length; e++){
16923 var ev = c.events[e];
16924 var rows = ev.rows;
16926 for(var i = 0; i < rows.length; i++) {
16928 // how many rows should it span..
16931 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
16932 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
16934 unselectable : "on",
16937 cls: 'fc-event-inner',
16941 // cls: 'fc-event-time',
16942 // html : cells.length > 1 ? '' : ev.time
16946 cls: 'fc-event-title',
16947 html : String.format('{0}', ev.title)
16954 cls: 'ui-resizable-handle ui-resizable-e',
16955 html : '  '
16962 cfg.cls += ' fc-event-start';
16964 if ((i+1) == rows.length) {
16965 cfg.cls += ' fc-event-end';
16968 var ctr = _this.el.select('.fc-event-container',true).first();
16969 var cg = ctr.createChild(cfg);
16971 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
16972 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
16974 var r = (c.more.length) ? 1 : 0;
16975 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
16976 cg.setWidth(ebox.right - sbox.x -2);
16978 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
16979 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
16980 cg.on('click', _this.onEventClick, _this, ev);
16991 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
16992 style : 'position: absolute',
16993 unselectable : "on",
16996 cls: 'fc-event-inner',
17000 cls: 'fc-event-title',
17008 cls: 'ui-resizable-handle ui-resizable-e',
17009 html : '  '
17015 var ctr = _this.el.select('.fc-event-container',true).first();
17016 var cg = ctr.createChild(cfg);
17018 var sbox = c.select('.fc-day-content',true).first().getBox();
17019 var ebox = c.select('.fc-day-content',true).first().getBox();
17021 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
17022 cg.setWidth(ebox.right - sbox.x -2);
17024 cg.on('click', _this.onMoreEventClick, _this, c.more);
17034 onEventEnter: function (e, el,event,d) {
17035 this.fireEvent('evententer', this, el, event);
17038 onEventLeave: function (e, el,event,d) {
17039 this.fireEvent('eventleave', this, el, event);
17042 onEventClick: function (e, el,event,d) {
17043 this.fireEvent('eventclick', this, el, event);
17046 onMonthChange: function () {
17050 onMoreEventClick: function(e, el, more)
17054 this.calpopover.placement = 'right';
17055 this.calpopover.setTitle('More');
17057 this.calpopover.setContent('');
17059 var ctr = this.calpopover.el.select('.popover-content', true).first();
17061 Roo.each(more, function(m){
17063 cls : 'fc-event-hori fc-event-draggable',
17066 var cg = ctr.createChild(cfg);
17068 cg.on('click', _this.onEventClick, _this, m);
17071 this.calpopover.show(el);
17076 onLoad: function ()
17078 this.calevents = [];
17081 if(this.store.getCount() > 0){
17082 this.store.data.each(function(d){
17085 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
17086 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
17087 time : d.data.start_time,
17088 title : d.data.title,
17089 description : d.data.description,
17090 venue : d.data.venue
17095 this.renderEvents();
17097 if(this.calevents.length && this.loadMask){
17098 this.maskEl.hide();
17102 onBeforeLoad: function()
17104 this.clearEvents();
17106 this.maskEl.show();
17120 * @class Roo.bootstrap.Popover
17121 * @extends Roo.bootstrap.Component
17122 * Bootstrap Popover class
17123 * @cfg {String} html contents of the popover (or false to use children..)
17124 * @cfg {String} title of popover (or false to hide)
17125 * @cfg {String} placement how it is placed
17126 * @cfg {String} trigger click || hover (or false to trigger manually)
17127 * @cfg {String} over what (parent or false to trigger manually.)
17128 * @cfg {Number} delay - delay before showing
17131 * Create a new Popover
17132 * @param {Object} config The config object
17135 Roo.bootstrap.Popover = function(config){
17136 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
17142 * After the popover show
17144 * @param {Roo.bootstrap.Popover} this
17149 * After the popover hide
17151 * @param {Roo.bootstrap.Popover} this
17157 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
17159 title: 'Fill in a title',
17162 placement : 'right',
17163 trigger : 'hover', // hover
17169 can_build_overlaid : false,
17171 getChildContainer : function()
17173 return this.el.select('.popover-content',true).first();
17176 getAutoCreate : function(){
17179 cls : 'popover roo-dynamic',
17180 style: 'display:block',
17186 cls : 'popover-inner',
17190 cls: 'popover-title',
17194 cls : 'popover-content',
17205 setTitle: function(str)
17208 this.el.select('.popover-title',true).first().dom.innerHTML = str;
17210 setContent: function(str)
17213 this.el.select('.popover-content',true).first().dom.innerHTML = str;
17215 // as it get's added to the bottom of the page.
17216 onRender : function(ct, position)
17218 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
17220 var cfg = Roo.apply({}, this.getAutoCreate());
17224 cfg.cls += ' ' + this.cls;
17227 cfg.style = this.style;
17229 //Roo.log("adding to ");
17230 this.el = Roo.get(document.body).createChild(cfg, position);
17231 // Roo.log(this.el);
17236 initEvents : function()
17238 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
17239 this.el.enableDisplayMode('block');
17241 if (this.over === false) {
17244 if (this.triggers === false) {
17247 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17248 var triggers = this.trigger ? this.trigger.split(' ') : [];
17249 Roo.each(triggers, function(trigger) {
17251 if (trigger == 'click') {
17252 on_el.on('click', this.toggle, this);
17253 } else if (trigger != 'manual') {
17254 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
17255 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
17257 on_el.on(eventIn ,this.enter, this);
17258 on_el.on(eventOut, this.leave, this);
17269 toggle : function () {
17270 this.hoverState == 'in' ? this.leave() : this.enter();
17273 enter : function () {
17275 clearTimeout(this.timeout);
17277 this.hoverState = 'in';
17279 if (!this.delay || !this.delay.show) {
17284 this.timeout = setTimeout(function () {
17285 if (_t.hoverState == 'in') {
17288 }, this.delay.show)
17291 leave : function() {
17292 clearTimeout(this.timeout);
17294 this.hoverState = 'out';
17296 if (!this.delay || !this.delay.hide) {
17301 this.timeout = setTimeout(function () {
17302 if (_t.hoverState == 'out') {
17305 }, this.delay.hide)
17308 show : function (on_el)
17311 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17315 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
17316 if (this.html !== false) {
17317 this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
17319 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
17320 if (!this.title.length) {
17321 this.el.select('.popover-title',true).hide();
17324 var placement = typeof this.placement == 'function' ?
17325 this.placement.call(this, this.el, on_el) :
17328 var autoToken = /\s?auto?\s?/i;
17329 var autoPlace = autoToken.test(placement);
17331 placement = placement.replace(autoToken, '') || 'top';
17335 //this.el.setXY([0,0]);
17337 this.el.dom.style.display='block';
17338 this.el.addClass(placement);
17340 //this.el.appendTo(on_el);
17342 var p = this.getPosition();
17343 var box = this.el.getBox();
17348 var align = Roo.bootstrap.Popover.alignment[placement];
17351 this.el.alignTo(on_el, align[0],align[1]);
17352 //var arrow = this.el.select('.arrow',true).first();
17353 //arrow.set(align[2],
17355 this.el.addClass('in');
17358 if (this.el.hasClass('fade')) {
17362 this.hoverState = 'in';
17364 this.fireEvent('show', this);
17369 this.el.setXY([0,0]);
17370 this.el.removeClass('in');
17372 this.hoverState = null;
17374 this.fireEvent('hide', this);
17379 Roo.bootstrap.Popover.alignment = {
17380 'left' : ['r-l', [-10,0], 'right'],
17381 'right' : ['l-r', [10,0], 'left'],
17382 'bottom' : ['t-b', [0,10], 'top'],
17383 'top' : [ 'b-t', [0,-10], 'bottom']
17394 * @class Roo.bootstrap.Progress
17395 * @extends Roo.bootstrap.Component
17396 * Bootstrap Progress class
17397 * @cfg {Boolean} striped striped of the progress bar
17398 * @cfg {Boolean} active animated of the progress bar
17402 * Create a new Progress
17403 * @param {Object} config The config object
17406 Roo.bootstrap.Progress = function(config){
17407 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
17410 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
17415 getAutoCreate : function(){
17423 cfg.cls += ' progress-striped';
17427 cfg.cls += ' active';
17446 * @class Roo.bootstrap.ProgressBar
17447 * @extends Roo.bootstrap.Component
17448 * Bootstrap ProgressBar class
17449 * @cfg {Number} aria_valuenow aria-value now
17450 * @cfg {Number} aria_valuemin aria-value min
17451 * @cfg {Number} aria_valuemax aria-value max
17452 * @cfg {String} label label for the progress bar
17453 * @cfg {String} panel (success | info | warning | danger )
17454 * @cfg {String} role role of the progress bar
17455 * @cfg {String} sr_only text
17459 * Create a new ProgressBar
17460 * @param {Object} config The config object
17463 Roo.bootstrap.ProgressBar = function(config){
17464 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
17467 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
17471 aria_valuemax : 100,
17477 getAutoCreate : function()
17482 cls: 'progress-bar',
17483 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
17495 cfg.role = this.role;
17498 if(this.aria_valuenow){
17499 cfg['aria-valuenow'] = this.aria_valuenow;
17502 if(this.aria_valuemin){
17503 cfg['aria-valuemin'] = this.aria_valuemin;
17506 if(this.aria_valuemax){
17507 cfg['aria-valuemax'] = this.aria_valuemax;
17510 if(this.label && !this.sr_only){
17511 cfg.html = this.label;
17515 cfg.cls += ' progress-bar-' + this.panel;
17521 update : function(aria_valuenow)
17523 this.aria_valuenow = aria_valuenow;
17525 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
17540 * @class Roo.bootstrap.TabGroup
17541 * @extends Roo.bootstrap.Column
17542 * Bootstrap Column class
17543 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
17544 * @cfg {Boolean} carousel true to make the group behave like a carousel
17545 * @cfg {Boolean} bullets show bullets for the panels
17546 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
17547 * @cfg {Number} timer auto slide timer .. default 0 millisecond
17548 * @cfg {Boolean} showarrow (true|false) show arrow default true
17551 * Create a new TabGroup
17552 * @param {Object} config The config object
17555 Roo.bootstrap.TabGroup = function(config){
17556 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
17558 this.navId = Roo.id();
17561 Roo.bootstrap.TabGroup.register(this);
17565 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
17568 transition : false,
17573 slideOnTouch : false,
17576 getAutoCreate : function()
17578 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
17580 cfg.cls += ' tab-content';
17582 if (this.carousel) {
17583 cfg.cls += ' carousel slide';
17586 cls : 'carousel-inner',
17590 if(this.bullets && !Roo.isTouch){
17593 cls : 'carousel-bullets',
17597 if(this.bullets_cls){
17598 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
17605 cfg.cn[0].cn.push(bullets);
17608 if(this.showarrow){
17609 cfg.cn[0].cn.push({
17611 class : 'carousel-arrow',
17615 class : 'carousel-prev',
17619 class : 'fa fa-chevron-left'
17625 class : 'carousel-next',
17629 class : 'fa fa-chevron-right'
17642 initEvents: function()
17644 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
17645 // this.el.on("touchstart", this.onTouchStart, this);
17648 if(this.autoslide){
17651 this.slideFn = window.setInterval(function() {
17652 _this.showPanelNext();
17656 if(this.showarrow){
17657 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
17658 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
17664 // onTouchStart : function(e, el, o)
17666 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
17670 // this.showPanelNext();
17674 getChildContainer : function()
17676 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
17680 * register a Navigation item
17681 * @param {Roo.bootstrap.NavItem} the navitem to add
17683 register : function(item)
17685 this.tabs.push( item);
17686 item.navId = this.navId; // not really needed..
17691 getActivePanel : function()
17694 Roo.each(this.tabs, function(t) {
17704 getPanelByName : function(n)
17707 Roo.each(this.tabs, function(t) {
17708 if (t.tabId == n) {
17716 indexOfPanel : function(p)
17719 Roo.each(this.tabs, function(t,i) {
17720 if (t.tabId == p.tabId) {
17729 * show a specific panel
17730 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
17731 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
17733 showPanel : function (pan)
17735 if(this.transition || typeof(pan) == 'undefined'){
17736 Roo.log("waiting for the transitionend");
17740 if (typeof(pan) == 'number') {
17741 pan = this.tabs[pan];
17744 if (typeof(pan) == 'string') {
17745 pan = this.getPanelByName(pan);
17748 var cur = this.getActivePanel();
17751 Roo.log('pan or acitve pan is undefined');
17755 if (pan.tabId == this.getActivePanel().tabId) {
17759 if (false === cur.fireEvent('beforedeactivate')) {
17763 if(this.bullets > 0 && !Roo.isTouch){
17764 this.setActiveBullet(this.indexOfPanel(pan));
17767 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
17769 this.transition = true;
17770 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
17771 var lr = dir == 'next' ? 'left' : 'right';
17772 pan.el.addClass(dir); // or prev
17773 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
17774 cur.el.addClass(lr); // or right
17775 pan.el.addClass(lr);
17778 cur.el.on('transitionend', function() {
17779 Roo.log("trans end?");
17781 pan.el.removeClass([lr,dir]);
17782 pan.setActive(true);
17784 cur.el.removeClass([lr]);
17785 cur.setActive(false);
17787 _this.transition = false;
17789 }, this, { single: true } );
17794 cur.setActive(false);
17795 pan.setActive(true);
17800 showPanelNext : function()
17802 var i = this.indexOfPanel(this.getActivePanel());
17804 if (i >= this.tabs.length - 1 && !this.autoslide) {
17808 if (i >= this.tabs.length - 1 && this.autoslide) {
17812 this.showPanel(this.tabs[i+1]);
17815 showPanelPrev : function()
17817 var i = this.indexOfPanel(this.getActivePanel());
17819 if (i < 1 && !this.autoslide) {
17823 if (i < 1 && this.autoslide) {
17824 i = this.tabs.length;
17827 this.showPanel(this.tabs[i-1]);
17831 addBullet: function()
17833 if(!this.bullets || Roo.isTouch){
17836 var ctr = this.el.select('.carousel-bullets',true).first();
17837 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
17838 var bullet = ctr.createChild({
17839 cls : 'bullet bullet-' + i
17840 },ctr.dom.lastChild);
17845 bullet.on('click', (function(e, el, o, ii, t){
17847 e.preventDefault();
17849 this.showPanel(ii);
17851 if(this.autoslide && this.slideFn){
17852 clearInterval(this.slideFn);
17853 this.slideFn = window.setInterval(function() {
17854 _this.showPanelNext();
17858 }).createDelegate(this, [i, bullet], true));
17863 setActiveBullet : function(i)
17869 Roo.each(this.el.select('.bullet', true).elements, function(el){
17870 el.removeClass('selected');
17873 var bullet = this.el.select('.bullet-' + i, true).first();
17879 bullet.addClass('selected');
17890 Roo.apply(Roo.bootstrap.TabGroup, {
17894 * register a Navigation Group
17895 * @param {Roo.bootstrap.NavGroup} the navgroup to add
17897 register : function(navgrp)
17899 this.groups[navgrp.navId] = navgrp;
17903 * fetch a Navigation Group based on the navigation ID
17904 * if one does not exist , it will get created.
17905 * @param {string} the navgroup to add
17906 * @returns {Roo.bootstrap.NavGroup} the navgroup
17908 get: function(navId) {
17909 if (typeof(this.groups[navId]) == 'undefined') {
17910 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
17912 return this.groups[navId] ;
17927 * @class Roo.bootstrap.TabPanel
17928 * @extends Roo.bootstrap.Component
17929 * Bootstrap TabPanel class
17930 * @cfg {Boolean} active panel active
17931 * @cfg {String} html panel content
17932 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
17933 * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
17934 * @cfg {String} href click to link..
17938 * Create a new TabPanel
17939 * @param {Object} config The config object
17942 Roo.bootstrap.TabPanel = function(config){
17943 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
17947 * Fires when the active status changes
17948 * @param {Roo.bootstrap.TabPanel} this
17949 * @param {Boolean} state the new state
17954 * @event beforedeactivate
17955 * Fires before a tab is de-activated - can be used to do validation on a form.
17956 * @param {Roo.bootstrap.TabPanel} this
17957 * @return {Boolean} false if there is an error
17960 'beforedeactivate': true
17963 this.tabId = this.tabId || Roo.id();
17967 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
17975 getAutoCreate : function(){
17978 // item is needed for carousel - not sure if it has any effect otherwise
17979 cls: 'tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
17980 html: this.html || ''
17984 cfg.cls += ' active';
17988 cfg.tabId = this.tabId;
17995 initEvents: function()
17997 var p = this.parent();
17999 this.navId = this.navId || p.navId;
18001 if (typeof(this.navId) != 'undefined') {
18002 // not really needed.. but just in case.. parent should be a NavGroup.
18003 var tg = Roo.bootstrap.TabGroup.get(this.navId);
18007 var i = tg.tabs.length - 1;
18009 if(this.active && tg.bullets > 0 && i < tg.bullets){
18010 tg.setActiveBullet(i);
18014 this.el.on('click', this.onClick, this);
18017 this.el.on("touchstart", this.onTouchStart, this);
18018 this.el.on("touchmove", this.onTouchMove, this);
18019 this.el.on("touchend", this.onTouchEnd, this);
18024 onRender : function(ct, position)
18026 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
18029 setActive : function(state)
18031 Roo.log("panel - set active " + this.tabId + "=" + state);
18033 this.active = state;
18035 this.el.removeClass('active');
18037 } else if (!this.el.hasClass('active')) {
18038 this.el.addClass('active');
18041 this.fireEvent('changed', this, state);
18044 onClick : function(e)
18046 e.preventDefault();
18048 if(!this.href.length){
18052 window.location.href = this.href;
18061 onTouchStart : function(e)
18063 this.swiping = false;
18065 this.startX = e.browserEvent.touches[0].clientX;
18066 this.startY = e.browserEvent.touches[0].clientY;
18069 onTouchMove : function(e)
18071 this.swiping = true;
18073 this.endX = e.browserEvent.touches[0].clientX;
18074 this.endY = e.browserEvent.touches[0].clientY;
18077 onTouchEnd : function(e)
18084 var tabGroup = this.parent();
18086 if(this.endX > this.startX){ // swiping right
18087 tabGroup.showPanelPrev();
18091 if(this.startX > this.endX){ // swiping left
18092 tabGroup.showPanelNext();
18111 * @class Roo.bootstrap.DateField
18112 * @extends Roo.bootstrap.Input
18113 * Bootstrap DateField class
18114 * @cfg {Number} weekStart default 0
18115 * @cfg {String} viewMode default empty, (months|years)
18116 * @cfg {String} minViewMode default empty, (months|years)
18117 * @cfg {Number} startDate default -Infinity
18118 * @cfg {Number} endDate default Infinity
18119 * @cfg {Boolean} todayHighlight default false
18120 * @cfg {Boolean} todayBtn default false
18121 * @cfg {Boolean} calendarWeeks default false
18122 * @cfg {Object} daysOfWeekDisabled default empty
18123 * @cfg {Boolean} singleMode default false (true | false)
18125 * @cfg {Boolean} keyboardNavigation default true
18126 * @cfg {String} language default en
18129 * Create a new DateField
18130 * @param {Object} config The config object
18133 Roo.bootstrap.DateField = function(config){
18134 Roo.bootstrap.DateField.superclass.constructor.call(this, config);
18138 * Fires when this field show.
18139 * @param {Roo.bootstrap.DateField} this
18140 * @param {Mixed} date The date value
18145 * Fires when this field hide.
18146 * @param {Roo.bootstrap.DateField} this
18147 * @param {Mixed} date The date value
18152 * Fires when select a date.
18153 * @param {Roo.bootstrap.DateField} this
18154 * @param {Mixed} date The date value
18158 * @event beforeselect
18159 * Fires when before select a date.
18160 * @param {Roo.bootstrap.DateField} this
18161 * @param {Mixed} date The date value
18163 beforeselect : true
18167 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, {
18170 * @cfg {String} format
18171 * The default date format string which can be overriden for localization support. The format must be
18172 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18176 * @cfg {String} altFormats
18177 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18178 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18180 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
18188 todayHighlight : false,
18194 keyboardNavigation: true,
18196 calendarWeeks: false,
18198 startDate: -Infinity,
18202 daysOfWeekDisabled: [],
18206 singleMode : false,
18208 UTCDate: function()
18210 return new Date(Date.UTC.apply(Date, arguments));
18213 UTCToday: function()
18215 var today = new Date();
18216 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
18219 getDate: function() {
18220 var d = this.getUTCDate();
18221 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
18224 getUTCDate: function() {
18228 setDate: function(d) {
18229 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
18232 setUTCDate: function(d) {
18234 this.setValue(this.formatDate(this.date));
18237 onRender: function(ct, position)
18240 Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
18242 this.language = this.language || 'en';
18243 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
18244 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
18246 this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
18247 this.format = this.format || 'm/d/y';
18248 this.isInline = false;
18249 this.isInput = true;
18250 this.component = this.el.select('.add-on', true).first() || false;
18251 this.component = (this.component && this.component.length === 0) ? false : this.component;
18252 this.hasInput = this.component && this.inputEl().length;
18254 if (typeof(this.minViewMode === 'string')) {
18255 switch (this.minViewMode) {
18257 this.minViewMode = 1;
18260 this.minViewMode = 2;
18263 this.minViewMode = 0;
18268 if (typeof(this.viewMode === 'string')) {
18269 switch (this.viewMode) {
18282 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
18284 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
18286 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18288 this.picker().on('mousedown', this.onMousedown, this);
18289 this.picker().on('click', this.onClick, this);
18291 this.picker().addClass('datepicker-dropdown');
18293 this.startViewMode = this.viewMode;
18295 if(this.singleMode){
18296 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
18297 v.setVisibilityMode(Roo.Element.DISPLAY);
18301 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18302 v.setStyle('width', '189px');
18306 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
18307 if(!this.calendarWeeks){
18312 v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18313 v.attr('colspan', function(i, val){
18314 return parseInt(val) + 1;
18319 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
18321 this.setStartDate(this.startDate);
18322 this.setEndDate(this.endDate);
18324 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
18331 if(this.isInline) {
18336 picker : function()
18338 return this.pickerEl;
18339 // return this.el.select('.datepicker', true).first();
18342 fillDow: function()
18344 var dowCnt = this.weekStart;
18353 if(this.calendarWeeks){
18361 while (dowCnt < this.weekStart + 7) {
18365 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
18369 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
18372 fillMonths: function()
18375 var months = this.picker().select('>.datepicker-months td', true).first();
18377 months.dom.innerHTML = '';
18383 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
18386 months.createChild(month);
18393 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;
18395 if (this.date < this.startDate) {
18396 this.viewDate = new Date(this.startDate);
18397 } else if (this.date > this.endDate) {
18398 this.viewDate = new Date(this.endDate);
18400 this.viewDate = new Date(this.date);
18408 var d = new Date(this.viewDate),
18409 year = d.getUTCFullYear(),
18410 month = d.getUTCMonth(),
18411 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
18412 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
18413 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
18414 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
18415 currentDate = this.date && this.date.valueOf(),
18416 today = this.UTCToday();
18418 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
18420 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18422 // this.picker.select('>tfoot th.today').
18423 // .text(dates[this.language].today)
18424 // .toggle(this.todayBtn !== false);
18426 this.updateNavArrows();
18429 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
18431 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
18433 prevMonth.setUTCDate(day);
18435 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
18437 var nextMonth = new Date(prevMonth);
18439 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
18441 nextMonth = nextMonth.valueOf();
18443 var fillMonths = false;
18445 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
18447 while(prevMonth.valueOf() < nextMonth) {
18450 if (prevMonth.getUTCDay() === this.weekStart) {
18452 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
18460 if(this.calendarWeeks){
18461 // ISO 8601: First week contains first thursday.
18462 // ISO also states week starts on Monday, but we can be more abstract here.
18464 // Start of current week: based on weekstart/current date
18465 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
18466 // Thursday of this week
18467 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
18468 // First Thursday of year, year from thursday
18469 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
18470 // Calendar week: ms between thursdays, div ms per day, div 7 days
18471 calWeek = (th - yth) / 864e5 / 7 + 1;
18473 fillMonths.cn.push({
18481 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
18483 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
18486 if (this.todayHighlight &&
18487 prevMonth.getUTCFullYear() == today.getFullYear() &&
18488 prevMonth.getUTCMonth() == today.getMonth() &&
18489 prevMonth.getUTCDate() == today.getDate()) {
18490 clsName += ' today';
18493 if (currentDate && prevMonth.valueOf() === currentDate) {
18494 clsName += ' active';
18497 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
18498 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
18499 clsName += ' disabled';
18502 fillMonths.cn.push({
18504 cls: 'day ' + clsName,
18505 html: prevMonth.getDate()
18508 prevMonth.setDate(prevMonth.getDate()+1);
18511 var currentYear = this.date && this.date.getUTCFullYear();
18512 var currentMonth = this.date && this.date.getUTCMonth();
18514 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
18516 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
18517 v.removeClass('active');
18519 if(currentYear === year && k === currentMonth){
18520 v.addClass('active');
18523 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
18524 v.addClass('disabled');
18530 year = parseInt(year/10, 10) * 10;
18532 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
18534 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
18537 for (var i = -1; i < 11; i++) {
18538 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
18540 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
18548 showMode: function(dir)
18551 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
18554 Roo.each(this.picker().select('>div',true).elements, function(v){
18555 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18558 this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
18563 if(this.isInline) {
18567 this.picker().removeClass(['bottom', 'top']);
18569 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
18571 * place to the top of element!
18575 this.picker().addClass('top');
18576 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
18581 this.picker().addClass('bottom');
18583 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
18586 parseDate : function(value)
18588 if(!value || value instanceof Date){
18591 var v = Date.parseDate(value, this.format);
18592 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
18593 v = Date.parseDate(value, 'Y-m-d');
18595 if(!v && this.altFormats){
18596 if(!this.altFormatsArray){
18597 this.altFormatsArray = this.altFormats.split("|");
18599 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18600 v = Date.parseDate(value, this.altFormatsArray[i]);
18606 formatDate : function(date, fmt)
18608 return (!date || !(date instanceof Date)) ?
18609 date : date.dateFormat(fmt || this.format);
18612 onFocus : function()
18614 Roo.bootstrap.DateField.superclass.onFocus.call(this);
18618 onBlur : function()
18620 Roo.bootstrap.DateField.superclass.onBlur.call(this);
18622 var d = this.inputEl().getValue();
18631 this.picker().show();
18635 this.fireEvent('show', this, this.date);
18640 if(this.isInline) {
18643 this.picker().hide();
18644 this.viewMode = this.startViewMode;
18647 this.fireEvent('hide', this, this.date);
18651 onMousedown: function(e)
18653 e.stopPropagation();
18654 e.preventDefault();
18659 Roo.bootstrap.DateField.superclass.keyup.call(this);
18663 setValue: function(v)
18665 if(this.fireEvent('beforeselect', this, v) !== false){
18666 var d = new Date(this.parseDate(v) ).clearTime();
18668 if(isNaN(d.getTime())){
18669 this.date = this.viewDate = '';
18670 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
18674 v = this.formatDate(d);
18676 Roo.bootstrap.DateField.superclass.setValue.call(this, v);
18678 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
18682 this.fireEvent('select', this, this.date);
18686 getValue: function()
18688 return this.formatDate(this.date);
18691 fireKey: function(e)
18693 if (!this.picker().isVisible()){
18694 if (e.keyCode == 27) { // allow escape to hide and re-show picker
18700 var dateChanged = false,
18702 newDate, newViewDate;
18707 e.preventDefault();
18711 if (!this.keyboardNavigation) {
18714 dir = e.keyCode == 37 ? -1 : 1;
18717 newDate = this.moveYear(this.date, dir);
18718 newViewDate = this.moveYear(this.viewDate, dir);
18719 } else if (e.shiftKey){
18720 newDate = this.moveMonth(this.date, dir);
18721 newViewDate = this.moveMonth(this.viewDate, dir);
18723 newDate = new Date(this.date);
18724 newDate.setUTCDate(this.date.getUTCDate() + dir);
18725 newViewDate = new Date(this.viewDate);
18726 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
18728 if (this.dateWithinRange(newDate)){
18729 this.date = newDate;
18730 this.viewDate = newViewDate;
18731 this.setValue(this.formatDate(this.date));
18733 e.preventDefault();
18734 dateChanged = true;
18739 if (!this.keyboardNavigation) {
18742 dir = e.keyCode == 38 ? -1 : 1;
18744 newDate = this.moveYear(this.date, dir);
18745 newViewDate = this.moveYear(this.viewDate, dir);
18746 } else if (e.shiftKey){
18747 newDate = this.moveMonth(this.date, dir);
18748 newViewDate = this.moveMonth(this.viewDate, dir);
18750 newDate = new Date(this.date);
18751 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
18752 newViewDate = new Date(this.viewDate);
18753 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
18755 if (this.dateWithinRange(newDate)){
18756 this.date = newDate;
18757 this.viewDate = newViewDate;
18758 this.setValue(this.formatDate(this.date));
18760 e.preventDefault();
18761 dateChanged = true;
18765 this.setValue(this.formatDate(this.date));
18767 e.preventDefault();
18770 this.setValue(this.formatDate(this.date));
18784 onClick: function(e)
18786 e.stopPropagation();
18787 e.preventDefault();
18789 var target = e.getTarget();
18791 if(target.nodeName.toLowerCase() === 'i'){
18792 target = Roo.get(target).dom.parentNode;
18795 var nodeName = target.nodeName;
18796 var className = target.className;
18797 var html = target.innerHTML;
18798 //Roo.log(nodeName);
18800 switch(nodeName.toLowerCase()) {
18802 switch(className) {
18808 var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
18809 switch(this.viewMode){
18811 this.viewDate = this.moveMonth(this.viewDate, dir);
18815 this.viewDate = this.moveYear(this.viewDate, dir);
18821 var date = new Date();
18822 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
18824 this.setValue(this.formatDate(this.date));
18831 if (className.indexOf('disabled') < 0) {
18832 this.viewDate.setUTCDate(1);
18833 if (className.indexOf('month') > -1) {
18834 this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
18836 var year = parseInt(html, 10) || 0;
18837 this.viewDate.setUTCFullYear(year);
18841 if(this.singleMode){
18842 this.setValue(this.formatDate(this.viewDate));
18853 //Roo.log(className);
18854 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
18855 var day = parseInt(html, 10) || 1;
18856 var year = this.viewDate.getUTCFullYear(),
18857 month = this.viewDate.getUTCMonth();
18859 if (className.indexOf('old') > -1) {
18866 } else if (className.indexOf('new') > -1) {
18874 //Roo.log([year,month,day]);
18875 this.date = this.UTCDate(year, month, day,0,0,0,0);
18876 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
18878 //Roo.log(this.formatDate(this.date));
18879 this.setValue(this.formatDate(this.date));
18886 setStartDate: function(startDate)
18888 this.startDate = startDate || -Infinity;
18889 if (this.startDate !== -Infinity) {
18890 this.startDate = this.parseDate(this.startDate);
18893 this.updateNavArrows();
18896 setEndDate: function(endDate)
18898 this.endDate = endDate || Infinity;
18899 if (this.endDate !== Infinity) {
18900 this.endDate = this.parseDate(this.endDate);
18903 this.updateNavArrows();
18906 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
18908 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
18909 if (typeof(this.daysOfWeekDisabled) !== 'object') {
18910 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
18912 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
18913 return parseInt(d, 10);
18916 this.updateNavArrows();
18919 updateNavArrows: function()
18921 if(this.singleMode){
18925 var d = new Date(this.viewDate),
18926 year = d.getUTCFullYear(),
18927 month = d.getUTCMonth();
18929 Roo.each(this.picker().select('.prev', true).elements, function(v){
18931 switch (this.viewMode) {
18934 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
18940 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
18947 Roo.each(this.picker().select('.next', true).elements, function(v){
18949 switch (this.viewMode) {
18952 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
18958 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
18966 moveMonth: function(date, dir)
18971 var new_date = new Date(date.valueOf()),
18972 day = new_date.getUTCDate(),
18973 month = new_date.getUTCMonth(),
18974 mag = Math.abs(dir),
18976 dir = dir > 0 ? 1 : -1;
18979 // If going back one month, make sure month is not current month
18980 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
18982 return new_date.getUTCMonth() == month;
18984 // If going forward one month, make sure month is as expected
18985 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
18987 return new_date.getUTCMonth() != new_month;
18989 new_month = month + dir;
18990 new_date.setUTCMonth(new_month);
18991 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
18992 if (new_month < 0 || new_month > 11) {
18993 new_month = (new_month + 12) % 12;
18996 // For magnitudes >1, move one month at a time...
18997 for (var i=0; i<mag; i++) {
18998 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
18999 new_date = this.moveMonth(new_date, dir);
19001 // ...then reset the day, keeping it in the new month
19002 new_month = new_date.getUTCMonth();
19003 new_date.setUTCDate(day);
19005 return new_month != new_date.getUTCMonth();
19008 // Common date-resetting loop -- if date is beyond end of month, make it
19011 new_date.setUTCDate(--day);
19012 new_date.setUTCMonth(new_month);
19017 moveYear: function(date, dir)
19019 return this.moveMonth(date, dir*12);
19022 dateWithinRange: function(date)
19024 return date >= this.startDate && date <= this.endDate;
19030 this.picker().remove();
19033 validateValue : function(value)
19035 if(value.length < 1) {
19036 if(this.allowBlank){
19042 if(value.length < this.minLength){
19045 if(value.length > this.maxLength){
19049 var vt = Roo.form.VTypes;
19050 if(!vt[this.vtype](value, this)){
19054 if(typeof this.validator == "function"){
19055 var msg = this.validator(value);
19061 if(this.regex && !this.regex.test(value)){
19065 if(typeof(this.parseDate(value)) == 'undefined'){
19069 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
19073 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
19083 Roo.apply(Roo.bootstrap.DateField, {
19094 html: '<i class="fa fa-arrow-left"/>'
19104 html: '<i class="fa fa-arrow-right"/>'
19146 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
19147 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
19148 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
19149 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19150 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
19163 navFnc: 'FullYear',
19168 navFnc: 'FullYear',
19173 Roo.apply(Roo.bootstrap.DateField, {
19177 cls: 'datepicker dropdown-menu roo-dynamic',
19181 cls: 'datepicker-days',
19185 cls: 'table-condensed',
19187 Roo.bootstrap.DateField.head,
19191 Roo.bootstrap.DateField.footer
19198 cls: 'datepicker-months',
19202 cls: 'table-condensed',
19204 Roo.bootstrap.DateField.head,
19205 Roo.bootstrap.DateField.content,
19206 Roo.bootstrap.DateField.footer
19213 cls: 'datepicker-years',
19217 cls: 'table-condensed',
19219 Roo.bootstrap.DateField.head,
19220 Roo.bootstrap.DateField.content,
19221 Roo.bootstrap.DateField.footer
19240 * @class Roo.bootstrap.TimeField
19241 * @extends Roo.bootstrap.Input
19242 * Bootstrap DateField class
19246 * Create a new TimeField
19247 * @param {Object} config The config object
19250 Roo.bootstrap.TimeField = function(config){
19251 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
19255 * Fires when this field show.
19256 * @param {Roo.bootstrap.DateField} thisthis
19257 * @param {Mixed} date The date value
19262 * Fires when this field hide.
19263 * @param {Roo.bootstrap.DateField} this
19264 * @param {Mixed} date The date value
19269 * Fires when select a date.
19270 * @param {Roo.bootstrap.DateField} this
19271 * @param {Mixed} date The date value
19277 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
19280 * @cfg {String} format
19281 * The default time format string which can be overriden for localization support. The format must be
19282 * valid according to {@link Date#parseDate} (defaults to 'H:i').
19286 onRender: function(ct, position)
19289 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
19291 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
19293 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19295 this.pop = this.picker().select('>.datepicker-time',true).first();
19296 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19298 this.picker().on('mousedown', this.onMousedown, this);
19299 this.picker().on('click', this.onClick, this);
19301 this.picker().addClass('datepicker-dropdown');
19306 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
19307 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
19308 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
19309 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
19310 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
19311 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
19315 fireKey: function(e){
19316 if (!this.picker().isVisible()){
19317 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19323 e.preventDefault();
19331 this.onTogglePeriod();
19334 this.onIncrementMinutes();
19337 this.onDecrementMinutes();
19346 onClick: function(e) {
19347 e.stopPropagation();
19348 e.preventDefault();
19351 picker : function()
19353 return this.el.select('.datepicker', true).first();
19356 fillTime: function()
19358 var time = this.pop.select('tbody', true).first();
19360 time.dom.innerHTML = '';
19375 cls: 'hours-up glyphicon glyphicon-chevron-up'
19395 cls: 'minutes-up glyphicon glyphicon-chevron-up'
19416 cls: 'timepicker-hour',
19431 cls: 'timepicker-minute',
19446 cls: 'btn btn-primary period',
19468 cls: 'hours-down glyphicon glyphicon-chevron-down'
19488 cls: 'minutes-down glyphicon glyphicon-chevron-down'
19506 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
19513 var hours = this.time.getHours();
19514 var minutes = this.time.getMinutes();
19527 hours = hours - 12;
19531 hours = '0' + hours;
19535 minutes = '0' + minutes;
19538 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
19539 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
19540 this.pop.select('button', true).first().dom.innerHTML = period;
19546 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
19548 var cls = ['bottom'];
19550 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
19557 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
19562 this.picker().addClass(cls.join('-'));
19566 Roo.each(cls, function(c){
19568 _this.picker().setTop(_this.inputEl().getHeight());
19572 _this.picker().setTop(0 - _this.picker().getHeight());
19577 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
19581 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
19588 onFocus : function()
19590 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
19594 onBlur : function()
19596 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
19602 this.picker().show();
19607 this.fireEvent('show', this, this.date);
19612 this.picker().hide();
19615 this.fireEvent('hide', this, this.date);
19618 setTime : function()
19621 this.setValue(this.time.format(this.format));
19623 this.fireEvent('select', this, this.date);
19628 onMousedown: function(e){
19629 e.stopPropagation();
19630 e.preventDefault();
19633 onIncrementHours: function()
19635 Roo.log('onIncrementHours');
19636 this.time = this.time.add(Date.HOUR, 1);
19641 onDecrementHours: function()
19643 Roo.log('onDecrementHours');
19644 this.time = this.time.add(Date.HOUR, -1);
19648 onIncrementMinutes: function()
19650 Roo.log('onIncrementMinutes');
19651 this.time = this.time.add(Date.MINUTE, 1);
19655 onDecrementMinutes: function()
19657 Roo.log('onDecrementMinutes');
19658 this.time = this.time.add(Date.MINUTE, -1);
19662 onTogglePeriod: function()
19664 Roo.log('onTogglePeriod');
19665 this.time = this.time.add(Date.HOUR, 12);
19672 Roo.apply(Roo.bootstrap.TimeField, {
19702 cls: 'btn btn-info ok',
19714 Roo.apply(Roo.bootstrap.TimeField, {
19718 cls: 'datepicker dropdown-menu',
19722 cls: 'datepicker-time',
19726 cls: 'table-condensed',
19728 Roo.bootstrap.TimeField.content,
19729 Roo.bootstrap.TimeField.footer
19748 * @class Roo.bootstrap.MonthField
19749 * @extends Roo.bootstrap.Input
19750 * Bootstrap MonthField class
19752 * @cfg {String} language default en
19755 * Create a new MonthField
19756 * @param {Object} config The config object
19759 Roo.bootstrap.MonthField = function(config){
19760 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
19765 * Fires when this field show.
19766 * @param {Roo.bootstrap.MonthField} this
19767 * @param {Mixed} date The date value
19772 * Fires when this field hide.
19773 * @param {Roo.bootstrap.MonthField} this
19774 * @param {Mixed} date The date value
19779 * Fires when select a date.
19780 * @param {Roo.bootstrap.MonthField} this
19781 * @param {String} oldvalue The old value
19782 * @param {String} newvalue The new value
19788 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
19790 onRender: function(ct, position)
19793 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
19795 this.language = this.language || 'en';
19796 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
19797 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
19799 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
19800 this.isInline = false;
19801 this.isInput = true;
19802 this.component = this.el.select('.add-on', true).first() || false;
19803 this.component = (this.component && this.component.length === 0) ? false : this.component;
19804 this.hasInput = this.component && this.inputEL().length;
19806 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
19808 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19810 this.picker().on('mousedown', this.onMousedown, this);
19811 this.picker().on('click', this.onClick, this);
19813 this.picker().addClass('datepicker-dropdown');
19815 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
19816 v.setStyle('width', '189px');
19823 if(this.isInline) {
19829 setValue: function(v, suppressEvent)
19831 var o = this.getValue();
19833 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
19837 if(suppressEvent !== true){
19838 this.fireEvent('select', this, o, v);
19843 getValue: function()
19848 onClick: function(e)
19850 e.stopPropagation();
19851 e.preventDefault();
19853 var target = e.getTarget();
19855 if(target.nodeName.toLowerCase() === 'i'){
19856 target = Roo.get(target).dom.parentNode;
19859 var nodeName = target.nodeName;
19860 var className = target.className;
19861 var html = target.innerHTML;
19863 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
19867 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
19869 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
19875 picker : function()
19877 return this.pickerEl;
19880 fillMonths: function()
19883 var months = this.picker().select('>.datepicker-months td', true).first();
19885 months.dom.innerHTML = '';
19891 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
19894 months.createChild(month);
19903 if(typeof(this.vIndex) == 'undefined' && this.value.length){
19904 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
19907 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
19908 e.removeClass('active');
19910 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
19911 e.addClass('active');
19918 if(this.isInline) {
19922 this.picker().removeClass(['bottom', 'top']);
19924 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
19926 * place to the top of element!
19930 this.picker().addClass('top');
19931 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
19936 this.picker().addClass('bottom');
19938 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
19941 onFocus : function()
19943 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
19947 onBlur : function()
19949 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
19951 var d = this.inputEl().getValue();
19960 this.picker().show();
19961 this.picker().select('>.datepicker-months', true).first().show();
19965 this.fireEvent('show', this, this.date);
19970 if(this.isInline) {
19973 this.picker().hide();
19974 this.fireEvent('hide', this, this.date);
19978 onMousedown: function(e)
19980 e.stopPropagation();
19981 e.preventDefault();
19986 Roo.bootstrap.MonthField.superclass.keyup.call(this);
19990 fireKey: function(e)
19992 if (!this.picker().isVisible()){
19993 if (e.keyCode == 27) {// allow escape to hide and re-show picker
20004 e.preventDefault();
20008 dir = e.keyCode == 37 ? -1 : 1;
20010 this.vIndex = this.vIndex + dir;
20012 if(this.vIndex < 0){
20016 if(this.vIndex > 11){
20020 if(isNaN(this.vIndex)){
20024 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20030 dir = e.keyCode == 38 ? -1 : 1;
20032 this.vIndex = this.vIndex + dir * 4;
20034 if(this.vIndex < 0){
20038 if(this.vIndex > 11){
20042 if(isNaN(this.vIndex)){
20046 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20051 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20052 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20056 e.preventDefault();
20059 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20060 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20076 this.picker().remove();
20081 Roo.apply(Roo.bootstrap.MonthField, {
20100 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
20101 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
20106 Roo.apply(Roo.bootstrap.MonthField, {
20110 cls: 'datepicker dropdown-menu roo-dynamic',
20114 cls: 'datepicker-months',
20118 cls: 'table-condensed',
20120 Roo.bootstrap.DateField.content
20140 * @class Roo.bootstrap.CheckBox
20141 * @extends Roo.bootstrap.Input
20142 * Bootstrap CheckBox class
20144 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20145 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
20146 * @cfg {String} boxLabel The text that appears beside the checkbox
20147 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
20148 * @cfg {Boolean} checked initnal the element
20149 * @cfg {Boolean} inline inline the element (default false)
20150 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
20151 * @cfg {String} tooltip label tooltip
20154 * Create a new CheckBox
20155 * @param {Object} config The config object
20158 Roo.bootstrap.CheckBox = function(config){
20159 Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
20164 * Fires when the element is checked or unchecked.
20165 * @param {Roo.bootstrap.CheckBox} this This input
20166 * @param {Boolean} checked The new checked value
20171 * Fires when the element is click.
20172 * @param {Roo.bootstrap.CheckBox} this This input
20179 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input, {
20181 inputType: 'checkbox',
20190 getAutoCreate : function()
20192 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
20198 cfg.cls = 'form-group ' + this.inputType; //input-group
20201 cfg.cls += ' ' + this.inputType + '-inline';
20207 type : this.inputType,
20208 value : this.inputValue,
20209 cls : 'roo-' + this.inputType, //'form-box',
20210 placeholder : this.placeholder || ''
20214 if(this.inputType != 'radio'){
20218 cls : 'roo-hidden-value',
20219 value : this.checked ? this.inputValue : this.valueOff
20224 if (this.weight) { // Validity check?
20225 cfg.cls += " " + this.inputType + "-" + this.weight;
20228 if (this.disabled) {
20229 input.disabled=true;
20233 input.checked = this.checked;
20238 input.name = this.name;
20240 if(this.inputType != 'radio'){
20241 hidden.name = this.name;
20242 input.name = '_hidden_' + this.name;
20247 input.cls += ' input-' + this.size;
20252 ['xs','sm','md','lg'].map(function(size){
20253 if (settings[size]) {
20254 cfg.cls += ' col-' + size + '-' + settings[size];
20258 var inputblock = input;
20260 if (this.before || this.after) {
20263 cls : 'input-group',
20268 inputblock.cn.push({
20270 cls : 'input-group-addon',
20275 inputblock.cn.push(input);
20277 if(this.inputType != 'radio'){
20278 inputblock.cn.push(hidden);
20282 inputblock.cn.push({
20284 cls : 'input-group-addon',
20291 if (align ==='left' && this.fieldLabel.length) {
20292 // Roo.log("left and has label");
20297 cls : 'control-label',
20298 html : this.fieldLabel
20308 if(this.labelWidth > 12){
20309 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
20312 if(this.labelWidth < 13 && this.labelmd == 0){
20313 this.labelmd = this.labelWidth;
20316 if(this.labellg > 0){
20317 cfg.cn[0].cls += ' col-lg-' + this.labellg;
20318 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
20321 if(this.labelmd > 0){
20322 cfg.cn[0].cls += ' col-md-' + this.labelmd;
20323 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
20326 if(this.labelsm > 0){
20327 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
20328 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
20331 if(this.labelxs > 0){
20332 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
20333 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
20336 } else if ( this.fieldLabel.length) {
20337 // Roo.log(" label");
20341 tag: this.boxLabel ? 'span' : 'label',
20343 cls: 'control-label box-input-label',
20344 //cls : 'input-group-addon',
20345 html : this.fieldLabel
20354 // Roo.log(" no label && no align");
20355 cfg.cn = [ inputblock ] ;
20361 var boxLabelCfg = {
20363 //'for': id, // box label is handled by onclick - so no for...
20365 html: this.boxLabel
20369 boxLabelCfg.tooltip = this.tooltip;
20372 cfg.cn.push(boxLabelCfg);
20375 if(this.inputType != 'radio'){
20376 cfg.cn.push(hidden);
20384 * return the real input element.
20386 inputEl: function ()
20388 return this.el.select('input.roo-' + this.inputType,true).first();
20390 hiddenEl: function ()
20392 return this.el.select('input.roo-hidden-value',true).first();
20395 labelEl: function()
20397 return this.el.select('label.control-label',true).first();
20399 /* depricated... */
20403 return this.labelEl();
20406 boxLabelEl: function()
20408 return this.el.select('label.box-label',true).first();
20411 initEvents : function()
20413 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
20415 this.inputEl().on('click', this.onClick, this);
20417 if (this.boxLabel) {
20418 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
20421 this.startValue = this.getValue();
20424 Roo.bootstrap.CheckBox.register(this);
20428 onClick : function(e)
20430 if(this.fireEvent('click', this, e) !== false){
20431 this.setChecked(!this.checked);
20436 setChecked : function(state,suppressEvent)
20438 this.startValue = this.getValue();
20440 if(this.inputType == 'radio'){
20442 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20443 e.dom.checked = false;
20446 this.inputEl().dom.checked = true;
20448 this.inputEl().dom.value = this.inputValue;
20450 if(suppressEvent !== true){
20451 this.fireEvent('check', this, true);
20459 this.checked = state;
20461 this.inputEl().dom.checked = state;
20464 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
20466 if(suppressEvent !== true){
20467 this.fireEvent('check', this, state);
20473 getValue : function()
20475 if(this.inputType == 'radio'){
20476 return this.getGroupValue();
20479 return this.hiddenEl().dom.value;
20483 getGroupValue : function()
20485 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
20489 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
20492 setValue : function(v,suppressEvent)
20494 if(this.inputType == 'radio'){
20495 this.setGroupValue(v, suppressEvent);
20499 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
20504 setGroupValue : function(v, suppressEvent)
20506 this.startValue = this.getValue();
20508 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20509 e.dom.checked = false;
20511 if(e.dom.value == v){
20512 e.dom.checked = true;
20516 if(suppressEvent !== true){
20517 this.fireEvent('check', this, true);
20525 validate : function()
20529 (this.inputType == 'radio' && this.validateRadio()) ||
20530 (this.inputType == 'checkbox' && this.validateCheckbox())
20536 this.markInvalid();
20540 validateRadio : function()
20542 if(this.allowBlank){
20548 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20549 if(!e.dom.checked){
20561 validateCheckbox : function()
20564 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
20565 //return (this.getValue() == this.inputValue) ? true : false;
20568 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20576 for(var i in group){
20577 if(group[i].el.isVisible(true)){
20585 for(var i in group){
20590 r = (group[i].getValue() == group[i].inputValue) ? true : false;
20597 * Mark this field as valid
20599 markValid : function()
20603 this.fireEvent('valid', this);
20605 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20608 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
20615 if(this.inputType == 'radio'){
20616 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20617 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
20618 e.findParent('.form-group', false, true).addClass(_this.validClass);
20625 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20626 this.el.findParent('.form-group', false, true).addClass(this.validClass);
20630 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20636 for(var i in group){
20637 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20638 group[i].el.findParent('.form-group', false, true).addClass(this.validClass);
20643 * Mark this field as invalid
20644 * @param {String} msg The validation message
20646 markInvalid : function(msg)
20648 if(this.allowBlank){
20654 this.fireEvent('invalid', this, msg);
20656 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20659 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
20663 label.markInvalid();
20666 if(this.inputType == 'radio'){
20667 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20668 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
20669 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
20676 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20677 this.el.findParent('.form-group', false, true).addClass(this.invalidClass);
20681 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20687 for(var i in group){
20688 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20689 group[i].el.findParent('.form-group', false, true).addClass(this.invalidClass);
20694 clearInvalid : function()
20696 Roo.bootstrap.Input.prototype.clearInvalid.call(this);
20698 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20700 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20702 if (label && label.iconEl) {
20703 label.iconEl.removeClass(label.validClass);
20704 label.iconEl.removeClass(label.invalidClass);
20708 disable : function()
20710 if(this.inputType != 'radio'){
20711 Roo.bootstrap.CheckBox.superclass.disable.call(this);
20718 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20719 _this.getActionEl().addClass(this.disabledClass);
20720 e.dom.disabled = true;
20724 this.disabled = true;
20725 this.fireEvent("disable", this);
20729 enable : function()
20731 if(this.inputType != 'radio'){
20732 Roo.bootstrap.CheckBox.superclass.enable.call(this);
20739 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20740 _this.getActionEl().removeClass(this.disabledClass);
20741 e.dom.disabled = false;
20745 this.disabled = false;
20746 this.fireEvent("enable", this);
20752 Roo.apply(Roo.bootstrap.CheckBox, {
20757 * register a CheckBox Group
20758 * @param {Roo.bootstrap.CheckBox} the CheckBox to add
20760 register : function(checkbox)
20762 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
20763 this.groups[checkbox.groupId] = {};
20766 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
20770 this.groups[checkbox.groupId][checkbox.name] = checkbox;
20774 * fetch a CheckBox Group based on the group ID
20775 * @param {string} the group ID
20776 * @returns {Roo.bootstrap.CheckBox} the CheckBox group
20778 get: function(groupId) {
20779 if (typeof(this.groups[groupId]) == 'undefined') {
20783 return this.groups[groupId] ;
20796 * @class Roo.bootstrap.Radio
20797 * @extends Roo.bootstrap.Component
20798 * Bootstrap Radio class
20799 * @cfg {String} boxLabel - the label associated
20800 * @cfg {String} value - the value of radio
20803 * Create a new Radio
20804 * @param {Object} config The config object
20806 Roo.bootstrap.Radio = function(config){
20807 Roo.bootstrap.Radio.superclass.constructor.call(this, config);
20811 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.Component, {
20817 getAutoCreate : function()
20821 cls : 'form-group radio',
20826 html : this.boxLabel
20834 initEvents : function()
20836 this.parent().register(this);
20838 this.el.on('click', this.onClick, this);
20842 onClick : function()
20844 this.setChecked(true);
20847 setChecked : function(state, suppressEvent)
20849 this.parent().setValue(this.value, suppressEvent);
20853 setBoxLabel : function(v)
20858 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
20873 * @class Roo.bootstrap.SecurePass
20874 * @extends Roo.bootstrap.Input
20875 * Bootstrap SecurePass class
20879 * Create a new SecurePass
20880 * @param {Object} config The config object
20883 Roo.bootstrap.SecurePass = function (config) {
20884 // these go here, so the translation tool can replace them..
20886 PwdEmpty: "Please type a password, and then retype it to confirm.",
20887 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
20888 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
20889 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
20890 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
20891 FNInPwd: "Your password can't contain your first name. Please type a different password.",
20892 LNInPwd: "Your password can't contain your last name. Please type a different password.",
20893 TooWeak: "Your password is Too Weak."
20895 this.meterLabel = "Password strength:";
20896 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
20897 this.meterClass = [
20898 "roo-password-meter-tooweak",
20899 "roo-password-meter-weak",
20900 "roo-password-meter-medium",
20901 "roo-password-meter-strong",
20902 "roo-password-meter-grey"
20907 Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
20910 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
20912 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
20914 * PwdEmpty: "Please type a password, and then retype it to confirm.",
20915 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
20916 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
20917 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
20918 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
20919 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
20920 * LNInPwd: "Your password can't contain your last name. Please type a different password."
20930 * @cfg {String/Object} Label for the strength meter (defaults to
20931 * 'Password strength:')
20936 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
20937 * ['Weak', 'Medium', 'Strong'])
20940 pwdStrengths: false,
20953 initEvents: function ()
20955 Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
20957 if (this.el.is('input[type=password]') && Roo.isSafari) {
20958 this.el.on('keydown', this.SafariOnKeyDown, this);
20961 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
20964 onRender: function (ct, position)
20966 Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
20967 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
20968 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
20970 this.trigger.createChild({
20975 cls: 'roo-password-meter-grey col-xs-12',
20978 //width: this.meterWidth + 'px'
20982 cls: 'roo-password-meter-text'
20988 if (this.hideTrigger) {
20989 this.trigger.setDisplayed(false);
20991 this.setSize(this.width || '', this.height || '');
20994 onDestroy: function ()
20996 if (this.trigger) {
20997 this.trigger.removeAllListeners();
20998 this.trigger.remove();
21001 this.wrap.remove();
21003 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
21006 checkStrength: function ()
21008 var pwd = this.inputEl().getValue();
21009 if (pwd == this._lastPwd) {
21014 if (this.ClientSideStrongPassword(pwd)) {
21016 } else if (this.ClientSideMediumPassword(pwd)) {
21018 } else if (this.ClientSideWeakPassword(pwd)) {
21024 Roo.log('strength1: ' + strength);
21026 //var pm = this.trigger.child('div/div/div').dom;
21027 var pm = this.trigger.child('div/div');
21028 pm.removeClass(this.meterClass);
21029 pm.addClass(this.meterClass[strength]);
21032 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21034 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21036 this._lastPwd = pwd;
21040 Roo.bootstrap.SecurePass.superclass.reset.call(this);
21042 this._lastPwd = '';
21044 var pm = this.trigger.child('div/div');
21045 pm.removeClass(this.meterClass);
21046 pm.addClass('roo-password-meter-grey');
21049 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21052 this.inputEl().dom.type='password';
21055 validateValue: function (value)
21058 if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
21061 if (value.length == 0) {
21062 if (this.allowBlank) {
21063 this.clearInvalid();
21067 this.markInvalid(this.errors.PwdEmpty);
21068 this.errorMsg = this.errors.PwdEmpty;
21076 if ('[\x21-\x7e]*'.match(value)) {
21077 this.markInvalid(this.errors.PwdBadChar);
21078 this.errorMsg = this.errors.PwdBadChar;
21081 if (value.length < 6) {
21082 this.markInvalid(this.errors.PwdShort);
21083 this.errorMsg = this.errors.PwdShort;
21086 if (value.length > 16) {
21087 this.markInvalid(this.errors.PwdLong);
21088 this.errorMsg = this.errors.PwdLong;
21092 if (this.ClientSideStrongPassword(value)) {
21094 } else if (this.ClientSideMediumPassword(value)) {
21096 } else if (this.ClientSideWeakPassword(value)) {
21103 if (strength < 2) {
21104 //this.markInvalid(this.errors.TooWeak);
21105 this.errorMsg = this.errors.TooWeak;
21110 console.log('strength2: ' + strength);
21112 //var pm = this.trigger.child('div/div/div').dom;
21114 var pm = this.trigger.child('div/div');
21115 pm.removeClass(this.meterClass);
21116 pm.addClass(this.meterClass[strength]);
21118 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21120 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21122 this.errorMsg = '';
21126 CharacterSetChecks: function (type)
21129 this.fResult = false;
21132 isctype: function (character, type)
21135 case this.kCapitalLetter:
21136 if (character >= 'A' && character <= 'Z') {
21141 case this.kSmallLetter:
21142 if (character >= 'a' && character <= 'z') {
21148 if (character >= '0' && character <= '9') {
21153 case this.kPunctuation:
21154 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
21165 IsLongEnough: function (pwd, size)
21167 return !(pwd == null || isNaN(size) || pwd.length < size);
21170 SpansEnoughCharacterSets: function (word, nb)
21172 if (!this.IsLongEnough(word, nb))
21177 var characterSetChecks = new Array(
21178 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
21179 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
21182 for (var index = 0; index < word.length; ++index) {
21183 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21184 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
21185 characterSetChecks[nCharSet].fResult = true;
21192 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21193 if (characterSetChecks[nCharSet].fResult) {
21198 if (nCharSets < nb) {
21204 ClientSideStrongPassword: function (pwd)
21206 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
21209 ClientSideMediumPassword: function (pwd)
21211 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
21214 ClientSideWeakPassword: function (pwd)
21216 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
21219 })//<script type="text/javascript">
21222 * Based Ext JS Library 1.1.1
21223 * Copyright(c) 2006-2007, Ext JS, LLC.
21229 * @class Roo.HtmlEditorCore
21230 * @extends Roo.Component
21231 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
21233 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
21236 Roo.HtmlEditorCore = function(config){
21239 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
21244 * @event initialize
21245 * Fires when the editor is fully initialized (including the iframe)
21246 * @param {Roo.HtmlEditorCore} this
21251 * Fires when the editor is first receives the focus. Any insertion must wait
21252 * until after this event.
21253 * @param {Roo.HtmlEditorCore} this
21257 * @event beforesync
21258 * Fires before the textarea is updated with content from the editor iframe. Return false
21259 * to cancel the sync.
21260 * @param {Roo.HtmlEditorCore} this
21261 * @param {String} html
21265 * @event beforepush
21266 * Fires before the iframe editor is updated with content from the textarea. Return false
21267 * to cancel the push.
21268 * @param {Roo.HtmlEditorCore} this
21269 * @param {String} html
21274 * Fires when the textarea is updated with content from the editor iframe.
21275 * @param {Roo.HtmlEditorCore} this
21276 * @param {String} html
21281 * Fires when the iframe editor is updated with content from the textarea.
21282 * @param {Roo.HtmlEditorCore} this
21283 * @param {String} html
21288 * @event editorevent
21289 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21290 * @param {Roo.HtmlEditorCore} this
21296 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
21298 // defaults : white / black...
21299 this.applyBlacklists();
21306 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
21310 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
21316 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
21321 * @cfg {Number} height (in pixels)
21325 * @cfg {Number} width (in pixels)
21330 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21333 stylesheets: false,
21338 // private properties
21339 validationEvent : false,
21341 initialized : false,
21343 sourceEditMode : false,
21344 onFocus : Roo.emptyFn,
21346 hideMode:'offsets',
21350 // blacklist + whitelisted elements..
21357 * Protected method that will not generally be called directly. It
21358 * is called when the editor initializes the iframe with HTML contents. Override this method if you
21359 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
21361 getDocMarkup : function(){
21365 // inherit styels from page...??
21366 if (this.stylesheets === false) {
21368 Roo.get(document.head).select('style').each(function(node) {
21369 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21372 Roo.get(document.head).select('link').each(function(node) {
21373 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21376 } else if (!this.stylesheets.length) {
21378 st = '<style type="text/css">' +
21379 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21382 st = '<style type="text/css">' +
21387 st += '<style type="text/css">' +
21388 'IMG { cursor: pointer } ' +
21391 var cls = 'roo-htmleditor-body';
21393 if(this.bodyCls.length){
21394 cls += ' ' + this.bodyCls;
21397 return '<html><head>' + st +
21398 //<style type="text/css">' +
21399 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21401 ' </head><body class="' + cls + '"></body></html>';
21405 onRender : function(ct, position)
21408 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
21409 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
21412 this.el.dom.style.border = '0 none';
21413 this.el.dom.setAttribute('tabIndex', -1);
21414 this.el.addClass('x-hidden hide');
21418 if(Roo.isIE){ // fix IE 1px bogus margin
21419 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
21423 this.frameId = Roo.id();
21427 var iframe = this.owner.wrap.createChild({
21429 cls: 'form-control', // bootstrap..
21431 name: this.frameId,
21432 frameBorder : 'no',
21433 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
21438 this.iframe = iframe.dom;
21440 this.assignDocWin();
21442 this.doc.designMode = 'on';
21445 this.doc.write(this.getDocMarkup());
21449 var task = { // must defer to wait for browser to be ready
21451 //console.log("run task?" + this.doc.readyState);
21452 this.assignDocWin();
21453 if(this.doc.body || this.doc.readyState == 'complete'){
21455 this.doc.designMode="on";
21459 Roo.TaskMgr.stop(task);
21460 this.initEditor.defer(10, this);
21467 Roo.TaskMgr.start(task);
21472 onResize : function(w, h)
21474 Roo.log('resize: ' +w + ',' + h );
21475 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
21479 if(typeof w == 'number'){
21481 this.iframe.style.width = w + 'px';
21483 if(typeof h == 'number'){
21485 this.iframe.style.height = h + 'px';
21487 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
21494 * Toggles the editor between standard and source edit mode.
21495 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21497 toggleSourceEdit : function(sourceEditMode){
21499 this.sourceEditMode = sourceEditMode === true;
21501 if(this.sourceEditMode){
21503 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
21506 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
21507 //this.iframe.className = '';
21510 //this.setSize(this.owner.wrap.getSize());
21511 //this.fireEvent('editmodechange', this, this.sourceEditMode);
21518 * Protected method that will not generally be called directly. If you need/want
21519 * custom HTML cleanup, this is the method you should override.
21520 * @param {String} html The HTML to be cleaned
21521 * return {String} The cleaned HTML
21523 cleanHtml : function(html){
21524 html = String(html);
21525 if(html.length > 5){
21526 if(Roo.isSafari){ // strip safari nonsense
21527 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
21530 if(html == ' '){
21537 * HTML Editor -> Textarea
21538 * Protected method that will not generally be called directly. Syncs the contents
21539 * of the editor iframe with the textarea.
21541 syncValue : function(){
21542 if(this.initialized){
21543 var bd = (this.doc.body || this.doc.documentElement);
21544 //this.cleanUpPaste(); -- this is done else where and causes havoc..
21545 var html = bd.innerHTML;
21547 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
21548 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
21550 html = '<div style="'+m[0]+'">' + html + '</div>';
21553 html = this.cleanHtml(html);
21554 // fix up the special chars.. normaly like back quotes in word...
21555 // however we do not want to do this with chinese..
21556 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
21557 var cc = b.charCodeAt();
21559 (cc >= 0x4E00 && cc < 0xA000 ) ||
21560 (cc >= 0x3400 && cc < 0x4E00 ) ||
21561 (cc >= 0xf900 && cc < 0xfb00 )
21567 if(this.owner.fireEvent('beforesync', this, html) !== false){
21568 this.el.dom.value = html;
21569 this.owner.fireEvent('sync', this, html);
21575 * Protected method that will not generally be called directly. Pushes the value of the textarea
21576 * into the iframe editor.
21578 pushValue : function(){
21579 if(this.initialized){
21580 var v = this.el.dom.value.trim();
21582 // if(v.length < 1){
21586 if(this.owner.fireEvent('beforepush', this, v) !== false){
21587 var d = (this.doc.body || this.doc.documentElement);
21589 this.cleanUpPaste();
21590 this.el.dom.value = d.innerHTML;
21591 this.owner.fireEvent('push', this, v);
21597 deferFocus : function(){
21598 this.focus.defer(10, this);
21602 focus : function(){
21603 if(this.win && !this.sourceEditMode){
21610 assignDocWin: function()
21612 var iframe = this.iframe;
21615 this.doc = iframe.contentWindow.document;
21616 this.win = iframe.contentWindow;
21618 // if (!Roo.get(this.frameId)) {
21621 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21622 // this.win = Roo.get(this.frameId).dom.contentWindow;
21624 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
21628 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21629 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
21634 initEditor : function(){
21635 //console.log("INIT EDITOR");
21636 this.assignDocWin();
21640 this.doc.designMode="on";
21642 this.doc.write(this.getDocMarkup());
21645 var dbody = (this.doc.body || this.doc.documentElement);
21646 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
21647 // this copies styles from the containing element into thsi one..
21648 // not sure why we need all of this..
21649 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
21651 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
21652 //ss['background-attachment'] = 'fixed'; // w3c
21653 dbody.bgProperties = 'fixed'; // ie
21654 //Roo.DomHelper.applyStyles(dbody, ss);
21655 Roo.EventManager.on(this.doc, {
21656 //'mousedown': this.onEditorEvent,
21657 'mouseup': this.onEditorEvent,
21658 'dblclick': this.onEditorEvent,
21659 'click': this.onEditorEvent,
21660 'keyup': this.onEditorEvent,
21665 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
21667 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
21668 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
21670 this.initialized = true;
21672 this.owner.fireEvent('initialize', this);
21677 onDestroy : function(){
21683 //for (var i =0; i < this.toolbars.length;i++) {
21684 // // fixme - ask toolbars for heights?
21685 // this.toolbars[i].onDestroy();
21688 //this.wrap.dom.innerHTML = '';
21689 //this.wrap.remove();
21694 onFirstFocus : function(){
21696 this.assignDocWin();
21699 this.activated = true;
21702 if(Roo.isGecko){ // prevent silly gecko errors
21704 var s = this.win.getSelection();
21705 if(!s.focusNode || s.focusNode.nodeType != 3){
21706 var r = s.getRangeAt(0);
21707 r.selectNodeContents((this.doc.body || this.doc.documentElement));
21712 this.execCmd('useCSS', true);
21713 this.execCmd('styleWithCSS', false);
21716 this.owner.fireEvent('activate', this);
21720 adjustFont: function(btn){
21721 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
21722 //if(Roo.isSafari){ // safari
21725 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
21726 if(Roo.isSafari){ // safari
21727 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
21728 v = (v < 10) ? 10 : v;
21729 v = (v > 48) ? 48 : v;
21730 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
21735 v = Math.max(1, v+adjust);
21737 this.execCmd('FontSize', v );
21740 onEditorEvent : function(e)
21742 this.owner.fireEvent('editorevent', this, e);
21743 // this.updateToolbar();
21744 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
21747 insertTag : function(tg)
21749 // could be a bit smarter... -> wrap the current selected tRoo..
21750 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
21752 range = this.createRange(this.getSelection());
21753 var wrappingNode = this.doc.createElement(tg.toLowerCase());
21754 wrappingNode.appendChild(range.extractContents());
21755 range.insertNode(wrappingNode);
21762 this.execCmd("formatblock", tg);
21766 insertText : function(txt)
21770 var range = this.createRange();
21771 range.deleteContents();
21772 //alert(Sender.getAttribute('label'));
21774 range.insertNode(this.doc.createTextNode(txt));
21780 * Executes a Midas editor command on the editor document and performs necessary focus and
21781 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
21782 * @param {String} cmd The Midas command
21783 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21785 relayCmd : function(cmd, value){
21787 this.execCmd(cmd, value);
21788 this.owner.fireEvent('editorevent', this);
21789 //this.updateToolbar();
21790 this.owner.deferFocus();
21794 * Executes a Midas editor command directly on the editor document.
21795 * For visual commands, you should use {@link #relayCmd} instead.
21796 * <b>This should only be called after the editor is initialized.</b>
21797 * @param {String} cmd The Midas command
21798 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
21800 execCmd : function(cmd, value){
21801 this.doc.execCommand(cmd, false, value === undefined ? null : value);
21808 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
21810 * @param {String} text | dom node..
21812 insertAtCursor : function(text)
21815 if(!this.activated){
21821 var r = this.doc.selection.createRange();
21832 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
21836 // from jquery ui (MIT licenced)
21838 var win = this.win;
21840 if (win.getSelection && win.getSelection().getRangeAt) {
21841 range = win.getSelection().getRangeAt(0);
21842 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
21843 range.insertNode(node);
21844 } else if (win.document.selection && win.document.selection.createRange) {
21845 // no firefox support
21846 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21847 win.document.selection.createRange().pasteHTML(txt);
21849 // no firefox support
21850 var txt = typeof(text) == 'string' ? text : text.outerHTML;
21851 this.execCmd('InsertHTML', txt);
21860 mozKeyPress : function(e){
21862 var c = e.getCharCode(), cmd;
21865 c = String.fromCharCode(c).toLowerCase();
21879 this.cleanUpPaste.defer(100, this);
21887 e.preventDefault();
21895 fixKeys : function(){ // load time branching for fastest keydown performance
21897 return function(e){
21898 var k = e.getKey(), r;
21901 r = this.doc.selection.createRange();
21904 r.pasteHTML('    ');
21911 r = this.doc.selection.createRange();
21913 var target = r.parentElement();
21914 if(!target || target.tagName.toLowerCase() != 'li'){
21916 r.pasteHTML('<br />');
21922 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21923 this.cleanUpPaste.defer(100, this);
21929 }else if(Roo.isOpera){
21930 return function(e){
21931 var k = e.getKey();
21935 this.execCmd('InsertHTML','    ');
21938 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21939 this.cleanUpPaste.defer(100, this);
21944 }else if(Roo.isSafari){
21945 return function(e){
21946 var k = e.getKey();
21950 this.execCmd('InsertText','\t');
21954 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
21955 this.cleanUpPaste.defer(100, this);
21963 getAllAncestors: function()
21965 var p = this.getSelectedNode();
21968 a.push(p); // push blank onto stack..
21969 p = this.getParentElement();
21973 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
21977 a.push(this.doc.body);
21981 lastSelNode : false,
21984 getSelection : function()
21986 this.assignDocWin();
21987 return Roo.isIE ? this.doc.selection : this.win.getSelection();
21990 getSelectedNode: function()
21992 // this may only work on Gecko!!!
21994 // should we cache this!!!!
21999 var range = this.createRange(this.getSelection()).cloneRange();
22002 var parent = range.parentElement();
22004 var testRange = range.duplicate();
22005 testRange.moveToElementText(parent);
22006 if (testRange.inRange(range)) {
22009 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
22012 parent = parent.parentElement;
22017 // is ancestor a text element.
22018 var ac = range.commonAncestorContainer;
22019 if (ac.nodeType == 3) {
22020 ac = ac.parentNode;
22023 var ar = ac.childNodes;
22026 var other_nodes = [];
22027 var has_other_nodes = false;
22028 for (var i=0;i<ar.length;i++) {
22029 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
22032 // fullly contained node.
22034 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
22039 // probably selected..
22040 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
22041 other_nodes.push(ar[i]);
22045 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
22050 has_other_nodes = true;
22052 if (!nodes.length && other_nodes.length) {
22053 nodes= other_nodes;
22055 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
22061 createRange: function(sel)
22063 // this has strange effects when using with
22064 // top toolbar - not sure if it's a great idea.
22065 //this.editor.contentWindow.focus();
22066 if (typeof sel != "undefined") {
22068 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
22070 return this.doc.createRange();
22073 return this.doc.createRange();
22076 getParentElement: function()
22079 this.assignDocWin();
22080 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
22082 var range = this.createRange(sel);
22085 var p = range.commonAncestorContainer;
22086 while (p.nodeType == 3) { // text node
22097 * Range intersection.. the hard stuff...
22101 * [ -- selected range --- ]
22105 * if end is before start or hits it. fail.
22106 * if start is after end or hits it fail.
22108 * if either hits (but other is outside. - then it's not
22114 // @see http://www.thismuchiknow.co.uk/?p=64.
22115 rangeIntersectsNode : function(range, node)
22117 var nodeRange = node.ownerDocument.createRange();
22119 nodeRange.selectNode(node);
22121 nodeRange.selectNodeContents(node);
22124 var rangeStartRange = range.cloneRange();
22125 rangeStartRange.collapse(true);
22127 var rangeEndRange = range.cloneRange();
22128 rangeEndRange.collapse(false);
22130 var nodeStartRange = nodeRange.cloneRange();
22131 nodeStartRange.collapse(true);
22133 var nodeEndRange = nodeRange.cloneRange();
22134 nodeEndRange.collapse(false);
22136 return rangeStartRange.compareBoundaryPoints(
22137 Range.START_TO_START, nodeEndRange) == -1 &&
22138 rangeEndRange.compareBoundaryPoints(
22139 Range.START_TO_START, nodeStartRange) == 1;
22143 rangeCompareNode : function(range, node)
22145 var nodeRange = node.ownerDocument.createRange();
22147 nodeRange.selectNode(node);
22149 nodeRange.selectNodeContents(node);
22153 range.collapse(true);
22155 nodeRange.collapse(true);
22157 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
22158 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
22160 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
22162 var nodeIsBefore = ss == 1;
22163 var nodeIsAfter = ee == -1;
22165 if (nodeIsBefore && nodeIsAfter) {
22168 if (!nodeIsBefore && nodeIsAfter) {
22169 return 1; //right trailed.
22172 if (nodeIsBefore && !nodeIsAfter) {
22173 return 2; // left trailed.
22179 // private? - in a new class?
22180 cleanUpPaste : function()
22182 // cleans up the whole document..
22183 Roo.log('cleanuppaste');
22185 this.cleanUpChildren(this.doc.body);
22186 var clean = this.cleanWordChars(this.doc.body.innerHTML);
22187 if (clean != this.doc.body.innerHTML) {
22188 this.doc.body.innerHTML = clean;
22193 cleanWordChars : function(input) {// change the chars to hex code
22194 var he = Roo.HtmlEditorCore;
22196 var output = input;
22197 Roo.each(he.swapCodes, function(sw) {
22198 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
22200 output = output.replace(swapper, sw[1]);
22207 cleanUpChildren : function (n)
22209 if (!n.childNodes.length) {
22212 for (var i = n.childNodes.length-1; i > -1 ; i--) {
22213 this.cleanUpChild(n.childNodes[i]);
22220 cleanUpChild : function (node)
22223 //console.log(node);
22224 if (node.nodeName == "#text") {
22225 // clean up silly Windows -- stuff?
22228 if (node.nodeName == "#comment") {
22229 node.parentNode.removeChild(node);
22230 // clean up silly Windows -- stuff?
22233 var lcname = node.tagName.toLowerCase();
22234 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
22235 // whitelist of tags..
22237 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
22239 node.parentNode.removeChild(node);
22244 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
22246 // remove <a name=....> as rendering on yahoo mailer is borked with this.
22247 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
22249 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
22250 // remove_keep_children = true;
22253 if (remove_keep_children) {
22254 this.cleanUpChildren(node);
22255 // inserts everything just before this node...
22256 while (node.childNodes.length) {
22257 var cn = node.childNodes[0];
22258 node.removeChild(cn);
22259 node.parentNode.insertBefore(cn, node);
22261 node.parentNode.removeChild(node);
22265 if (!node.attributes || !node.attributes.length) {
22266 this.cleanUpChildren(node);
22270 function cleanAttr(n,v)
22273 if (v.match(/^\./) || v.match(/^\//)) {
22276 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) {
22279 if (v.match(/^#/)) {
22282 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
22283 node.removeAttribute(n);
22287 var cwhite = this.cwhite;
22288 var cblack = this.cblack;
22290 function cleanStyle(n,v)
22292 if (v.match(/expression/)) { //XSS?? should we even bother..
22293 node.removeAttribute(n);
22297 var parts = v.split(/;/);
22300 Roo.each(parts, function(p) {
22301 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
22305 var l = p.split(':').shift().replace(/\s+/g,'');
22306 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
22308 if ( cwhite.length && cblack.indexOf(l) > -1) {
22309 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22310 //node.removeAttribute(n);
22314 // only allow 'c whitelisted system attributes'
22315 if ( cwhite.length && cwhite.indexOf(l) < 0) {
22316 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22317 //node.removeAttribute(n);
22327 if (clean.length) {
22328 node.setAttribute(n, clean.join(';'));
22330 node.removeAttribute(n);
22336 for (var i = node.attributes.length-1; i > -1 ; i--) {
22337 var a = node.attributes[i];
22340 if (a.name.toLowerCase().substr(0,2)=='on') {
22341 node.removeAttribute(a.name);
22344 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
22345 node.removeAttribute(a.name);
22348 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
22349 cleanAttr(a.name,a.value); // fixme..
22352 if (a.name == 'style') {
22353 cleanStyle(a.name,a.value);
22356 /// clean up MS crap..
22357 // tecnically this should be a list of valid class'es..
22360 if (a.name == 'class') {
22361 if (a.value.match(/^Mso/)) {
22362 node.className = '';
22365 if (a.value.match(/^body$/)) {
22366 node.className = '';
22377 this.cleanUpChildren(node);
22383 * Clean up MS wordisms...
22385 cleanWord : function(node)
22390 this.cleanWord(this.doc.body);
22393 if (node.nodeName == "#text") {
22394 // clean up silly Windows -- stuff?
22397 if (node.nodeName == "#comment") {
22398 node.parentNode.removeChild(node);
22399 // clean up silly Windows -- stuff?
22403 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
22404 node.parentNode.removeChild(node);
22408 // remove - but keep children..
22409 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
22410 while (node.childNodes.length) {
22411 var cn = node.childNodes[0];
22412 node.removeChild(cn);
22413 node.parentNode.insertBefore(cn, node);
22415 node.parentNode.removeChild(node);
22416 this.iterateChildren(node, this.cleanWord);
22420 if (node.className.length) {
22422 var cn = node.className.split(/\W+/);
22424 Roo.each(cn, function(cls) {
22425 if (cls.match(/Mso[a-zA-Z]+/)) {
22430 node.className = cna.length ? cna.join(' ') : '';
22432 node.removeAttribute("class");
22436 if (node.hasAttribute("lang")) {
22437 node.removeAttribute("lang");
22440 if (node.hasAttribute("style")) {
22442 var styles = node.getAttribute("style").split(";");
22444 Roo.each(styles, function(s) {
22445 if (!s.match(/:/)) {
22448 var kv = s.split(":");
22449 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
22452 // what ever is left... we allow.
22455 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22456 if (!nstyle.length) {
22457 node.removeAttribute('style');
22460 this.iterateChildren(node, this.cleanWord);
22466 * iterateChildren of a Node, calling fn each time, using this as the scole..
22467 * @param {DomNode} node node to iterate children of.
22468 * @param {Function} fn method of this class to call on each item.
22470 iterateChildren : function(node, fn)
22472 if (!node.childNodes.length) {
22475 for (var i = node.childNodes.length-1; i > -1 ; i--) {
22476 fn.call(this, node.childNodes[i])
22482 * cleanTableWidths.
22484 * Quite often pasting from word etc.. results in tables with column and widths.
22485 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
22488 cleanTableWidths : function(node)
22493 this.cleanTableWidths(this.doc.body);
22498 if (node.nodeName == "#text" || node.nodeName == "#comment") {
22501 Roo.log(node.tagName);
22502 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
22503 this.iterateChildren(node, this.cleanTableWidths);
22506 if (node.hasAttribute('width')) {
22507 node.removeAttribute('width');
22511 if (node.hasAttribute("style")) {
22514 var styles = node.getAttribute("style").split(";");
22516 Roo.each(styles, function(s) {
22517 if (!s.match(/:/)) {
22520 var kv = s.split(":");
22521 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
22524 // what ever is left... we allow.
22527 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22528 if (!nstyle.length) {
22529 node.removeAttribute('style');
22533 this.iterateChildren(node, this.cleanTableWidths);
22541 domToHTML : function(currentElement, depth, nopadtext) {
22543 depth = depth || 0;
22544 nopadtext = nopadtext || false;
22546 if (!currentElement) {
22547 return this.domToHTML(this.doc.body);
22550 //Roo.log(currentElement);
22552 var allText = false;
22553 var nodeName = currentElement.nodeName;
22554 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
22556 if (nodeName == '#text') {
22558 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
22563 if (nodeName != 'BODY') {
22566 // Prints the node tagName, such as <A>, <IMG>, etc
22569 for(i = 0; i < currentElement.attributes.length;i++) {
22571 var aname = currentElement.attributes.item(i).name;
22572 if (!currentElement.attributes.item(i).value.length) {
22575 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
22578 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
22587 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
22590 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
22595 // Traverse the tree
22597 var currentElementChild = currentElement.childNodes.item(i);
22598 var allText = true;
22599 var innerHTML = '';
22601 while (currentElementChild) {
22602 // Formatting code (indent the tree so it looks nice on the screen)
22603 var nopad = nopadtext;
22604 if (lastnode == 'SPAN') {
22608 if (currentElementChild.nodeName == '#text') {
22609 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
22610 toadd = nopadtext ? toadd : toadd.trim();
22611 if (!nopad && toadd.length > 80) {
22612 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
22614 innerHTML += toadd;
22617 currentElementChild = currentElement.childNodes.item(i);
22623 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
22625 // Recursively traverse the tree structure of the child node
22626 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
22627 lastnode = currentElementChild.nodeName;
22629 currentElementChild=currentElement.childNodes.item(i);
22635 // The remaining code is mostly for formatting the tree
22636 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
22641 ret+= "</"+tagName+">";
22647 applyBlacklists : function()
22649 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
22650 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
22654 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
22655 if (b.indexOf(tag) > -1) {
22658 this.white.push(tag);
22662 Roo.each(w, function(tag) {
22663 if (b.indexOf(tag) > -1) {
22666 if (this.white.indexOf(tag) > -1) {
22669 this.white.push(tag);
22674 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
22675 if (w.indexOf(tag) > -1) {
22678 this.black.push(tag);
22682 Roo.each(b, function(tag) {
22683 if (w.indexOf(tag) > -1) {
22686 if (this.black.indexOf(tag) > -1) {
22689 this.black.push(tag);
22694 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
22695 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
22699 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
22700 if (b.indexOf(tag) > -1) {
22703 this.cwhite.push(tag);
22707 Roo.each(w, function(tag) {
22708 if (b.indexOf(tag) > -1) {
22711 if (this.cwhite.indexOf(tag) > -1) {
22714 this.cwhite.push(tag);
22719 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
22720 if (w.indexOf(tag) > -1) {
22723 this.cblack.push(tag);
22727 Roo.each(b, function(tag) {
22728 if (w.indexOf(tag) > -1) {
22731 if (this.cblack.indexOf(tag) > -1) {
22734 this.cblack.push(tag);
22739 setStylesheets : function(stylesheets)
22741 if(typeof(stylesheets) == 'string'){
22742 Roo.get(this.iframe.contentDocument.head).createChild({
22744 rel : 'stylesheet',
22753 Roo.each(stylesheets, function(s) {
22758 Roo.get(_this.iframe.contentDocument.head).createChild({
22760 rel : 'stylesheet',
22769 removeStylesheets : function()
22773 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
22778 setStyle : function(style)
22780 Roo.get(this.iframe.contentDocument.head).createChild({
22789 // hide stuff that is not compatible
22803 * @event specialkey
22807 * @cfg {String} fieldClass @hide
22810 * @cfg {String} focusClass @hide
22813 * @cfg {String} autoCreate @hide
22816 * @cfg {String} inputType @hide
22819 * @cfg {String} invalidClass @hide
22822 * @cfg {String} invalidText @hide
22825 * @cfg {String} msgFx @hide
22828 * @cfg {String} validateOnBlur @hide
22832 Roo.HtmlEditorCore.white = [
22833 'area', 'br', 'img', 'input', 'hr', 'wbr',
22835 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
22836 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
22837 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
22838 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
22839 'table', 'ul', 'xmp',
22841 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
22844 'dir', 'menu', 'ol', 'ul', 'dl',
22850 Roo.HtmlEditorCore.black = [
22851 // 'embed', 'object', // enable - backend responsiblity to clean thiese
22853 'base', 'basefont', 'bgsound', 'blink', 'body',
22854 'frame', 'frameset', 'head', 'html', 'ilayer',
22855 'iframe', 'layer', 'link', 'meta', 'object',
22856 'script', 'style' ,'title', 'xml' // clean later..
22858 Roo.HtmlEditorCore.clean = [
22859 'script', 'style', 'title', 'xml'
22861 Roo.HtmlEditorCore.remove = [
22866 Roo.HtmlEditorCore.ablack = [
22870 Roo.HtmlEditorCore.aclean = [
22871 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
22875 Roo.HtmlEditorCore.pwhite= [
22876 'http', 'https', 'mailto'
22879 // white listed style attributes.
22880 Roo.HtmlEditorCore.cwhite= [
22881 // 'text-align', /// default is to allow most things..
22887 // black listed style attributes.
22888 Roo.HtmlEditorCore.cblack= [
22889 // 'font-size' -- this can be set by the project
22893 Roo.HtmlEditorCore.swapCodes =[
22912 * @class Roo.bootstrap.HtmlEditor
22913 * @extends Roo.bootstrap.TextArea
22914 * Bootstrap HtmlEditor class
22917 * Create a new HtmlEditor
22918 * @param {Object} config The config object
22921 Roo.bootstrap.HtmlEditor = function(config){
22922 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
22923 if (!this.toolbars) {
22924 this.toolbars = [];
22927 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
22930 * @event initialize
22931 * Fires when the editor is fully initialized (including the iframe)
22932 * @param {HtmlEditor} this
22937 * Fires when the editor is first receives the focus. Any insertion must wait
22938 * until after this event.
22939 * @param {HtmlEditor} this
22943 * @event beforesync
22944 * Fires before the textarea is updated with content from the editor iframe. Return false
22945 * to cancel the sync.
22946 * @param {HtmlEditor} this
22947 * @param {String} html
22951 * @event beforepush
22952 * Fires before the iframe editor is updated with content from the textarea. Return false
22953 * to cancel the push.
22954 * @param {HtmlEditor} this
22955 * @param {String} html
22960 * Fires when the textarea is updated with content from the editor iframe.
22961 * @param {HtmlEditor} this
22962 * @param {String} html
22967 * Fires when the iframe editor is updated with content from the textarea.
22968 * @param {HtmlEditor} this
22969 * @param {String} html
22973 * @event editmodechange
22974 * Fires when the editor switches edit modes
22975 * @param {HtmlEditor} this
22976 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
22978 editmodechange: true,
22980 * @event editorevent
22981 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
22982 * @param {HtmlEditor} this
22986 * @event firstfocus
22987 * Fires when on first focus - needed by toolbars..
22988 * @param {HtmlEditor} this
22993 * Auto save the htmlEditor value as a file into Events
22994 * @param {HtmlEditor} this
22998 * @event savedpreview
22999 * preview the saved version of htmlEditor
23000 * @param {HtmlEditor} this
23007 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
23011 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
23016 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
23021 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
23026 * @cfg {Number} height (in pixels)
23030 * @cfg {Number} width (in pixels)
23035 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
23038 stylesheets: false,
23043 // private properties
23044 validationEvent : false,
23046 initialized : false,
23049 onFocus : Roo.emptyFn,
23051 hideMode:'offsets',
23053 tbContainer : false,
23057 toolbarContainer :function() {
23058 return this.wrap.select('.x-html-editor-tb',true).first();
23062 * Protected method that will not generally be called directly. It
23063 * is called when the editor creates its toolbar. Override this method if you need to
23064 * add custom toolbar buttons.
23065 * @param {HtmlEditor} editor
23067 createToolbar : function(){
23068 Roo.log('renewing');
23069 Roo.log("create toolbars");
23071 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
23072 this.toolbars[0].render(this.toolbarContainer());
23076 // if (!editor.toolbars || !editor.toolbars.length) {
23077 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
23080 // for (var i =0 ; i < editor.toolbars.length;i++) {
23081 // editor.toolbars[i] = Roo.factory(
23082 // typeof(editor.toolbars[i]) == 'string' ?
23083 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
23084 // Roo.bootstrap.HtmlEditor);
23085 // editor.toolbars[i].init(editor);
23091 onRender : function(ct, position)
23093 // Roo.log("Call onRender: " + this.xtype);
23095 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
23097 this.wrap = this.inputEl().wrap({
23098 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
23101 this.editorcore.onRender(ct, position);
23103 if (this.resizable) {
23104 this.resizeEl = new Roo.Resizable(this.wrap, {
23108 minHeight : this.height,
23109 height: this.height,
23110 handles : this.resizable,
23113 resize : function(r, w, h) {
23114 _t.onResize(w,h); // -something
23120 this.createToolbar(this);
23123 if(!this.width && this.resizable){
23124 this.setSize(this.wrap.getSize());
23126 if (this.resizeEl) {
23127 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
23128 // should trigger onReize..
23134 onResize : function(w, h)
23136 Roo.log('resize: ' +w + ',' + h );
23137 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
23141 if(this.inputEl() ){
23142 if(typeof w == 'number'){
23143 var aw = w - this.wrap.getFrameWidth('lr');
23144 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
23147 if(typeof h == 'number'){
23148 var tbh = -11; // fixme it needs to tool bar size!
23149 for (var i =0; i < this.toolbars.length;i++) {
23150 // fixme - ask toolbars for heights?
23151 tbh += this.toolbars[i].el.getHeight();
23152 //if (this.toolbars[i].footer) {
23153 // tbh += this.toolbars[i].footer.el.getHeight();
23161 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23162 ah -= 5; // knock a few pixes off for look..
23163 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
23167 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23168 this.editorcore.onResize(ew,eh);
23173 * Toggles the editor between standard and source edit mode.
23174 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23176 toggleSourceEdit : function(sourceEditMode)
23178 this.editorcore.toggleSourceEdit(sourceEditMode);
23180 if(this.editorcore.sourceEditMode){
23181 Roo.log('editor - showing textarea');
23184 // Roo.log(this.syncValue());
23186 this.inputEl().removeClass(['hide', 'x-hidden']);
23187 this.inputEl().dom.removeAttribute('tabIndex');
23188 this.inputEl().focus();
23190 Roo.log('editor - hiding textarea');
23192 // Roo.log(this.pushValue());
23195 this.inputEl().addClass(['hide', 'x-hidden']);
23196 this.inputEl().dom.setAttribute('tabIndex', -1);
23197 //this.deferFocus();
23200 if(this.resizable){
23201 this.setSize(this.wrap.getSize());
23204 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23207 // private (for BoxComponent)
23208 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23210 // private (for BoxComponent)
23211 getResizeEl : function(){
23215 // private (for BoxComponent)
23216 getPositionEl : function(){
23221 initEvents : function(){
23222 this.originalValue = this.getValue();
23226 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23229 // markInvalid : Roo.emptyFn,
23231 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23234 // clearInvalid : Roo.emptyFn,
23236 setValue : function(v){
23237 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
23238 this.editorcore.pushValue();
23243 deferFocus : function(){
23244 this.focus.defer(10, this);
23248 focus : function(){
23249 this.editorcore.focus();
23255 onDestroy : function(){
23261 for (var i =0; i < this.toolbars.length;i++) {
23262 // fixme - ask toolbars for heights?
23263 this.toolbars[i].onDestroy();
23266 this.wrap.dom.innerHTML = '';
23267 this.wrap.remove();
23272 onFirstFocus : function(){
23273 //Roo.log("onFirstFocus");
23274 this.editorcore.onFirstFocus();
23275 for (var i =0; i < this.toolbars.length;i++) {
23276 this.toolbars[i].onFirstFocus();
23282 syncValue : function()
23284 this.editorcore.syncValue();
23287 pushValue : function()
23289 this.editorcore.pushValue();
23293 // hide stuff that is not compatible
23307 * @event specialkey
23311 * @cfg {String} fieldClass @hide
23314 * @cfg {String} focusClass @hide
23317 * @cfg {String} autoCreate @hide
23320 * @cfg {String} inputType @hide
23323 * @cfg {String} invalidClass @hide
23326 * @cfg {String} invalidText @hide
23329 * @cfg {String} msgFx @hide
23332 * @cfg {String} validateOnBlur @hide
23341 Roo.namespace('Roo.bootstrap.htmleditor');
23343 * @class Roo.bootstrap.HtmlEditorToolbar1
23348 new Roo.bootstrap.HtmlEditor({
23351 new Roo.bootstrap.HtmlEditorToolbar1({
23352 disable : { fonts: 1 , format: 1, ..., ... , ...],
23358 * @cfg {Object} disable List of elements to disable..
23359 * @cfg {Array} btns List of additional buttons.
23363 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
23366 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
23369 Roo.apply(this, config);
23371 // default disabled, based on 'good practice'..
23372 this.disable = this.disable || {};
23373 Roo.applyIf(this.disable, {
23376 specialElements : true
23378 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
23380 this.editor = config.editor;
23381 this.editorcore = config.editor.editorcore;
23383 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
23385 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23386 // dont call parent... till later.
23388 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
23393 editorcore : false,
23398 "h1","h2","h3","h4","h5","h6",
23400 "abbr", "acronym", "address", "cite", "samp", "var",
23404 onRender : function(ct, position)
23406 // Roo.log("Call onRender: " + this.xtype);
23408 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
23410 this.el.dom.style.marginBottom = '0';
23412 var editorcore = this.editorcore;
23413 var editor= this.editor;
23416 var btn = function(id,cmd , toggle, handler, html){
23418 var event = toggle ? 'toggle' : 'click';
23423 xns: Roo.bootstrap,
23426 enableToggle:toggle !== false,
23428 pressed : toggle ? false : null,
23431 a.listeners[toggle ? 'toggle' : 'click'] = function() {
23432 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
23438 // var cb_box = function...
23443 xns: Roo.bootstrap,
23444 glyphicon : 'font',
23448 xns: Roo.bootstrap,
23452 Roo.each(this.formats, function(f) {
23453 style.menu.items.push({
23455 xns: Roo.bootstrap,
23456 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
23461 editorcore.insertTag(this.tagname);
23468 children.push(style);
23470 btn('bold',false,true);
23471 btn('italic',false,true);
23472 btn('align-left', 'justifyleft',true);
23473 btn('align-center', 'justifycenter',true);
23474 btn('align-right' , 'justifyright',true);
23475 btn('link', false, false, function(btn) {
23476 //Roo.log("create link?");
23477 var url = prompt(this.createLinkText, this.defaultLinkValue);
23478 if(url && url != 'http:/'+'/'){
23479 this.editorcore.relayCmd('createlink', url);
23482 btn('list','insertunorderedlist',true);
23483 btn('pencil', false,true, function(btn){
23485 this.toggleSourceEdit(btn.pressed);
23488 if (this.editor.btns.length > 0) {
23489 for (var i = 0; i<this.editor.btns.length; i++) {
23490 children.push(this.editor.btns[i]);
23498 xns: Roo.bootstrap,
23503 xns: Roo.bootstrap,
23508 cog.menu.items.push({
23510 xns: Roo.bootstrap,
23511 html : Clean styles,
23516 editorcore.insertTag(this.tagname);
23525 this.xtype = 'NavSimplebar';
23527 for(var i=0;i< children.length;i++) {
23529 this.buttons.add(this.addxtypeChild(children[i]));
23533 editor.on('editorevent', this.updateToolbar, this);
23535 onBtnClick : function(id)
23537 this.editorcore.relayCmd(id);
23538 this.editorcore.focus();
23542 * Protected method that will not generally be called directly. It triggers
23543 * a toolbar update by reading the markup state of the current selection in the editor.
23545 updateToolbar: function(){
23547 if(!this.editorcore.activated){
23548 this.editor.onFirstFocus(); // is this neeed?
23552 var btns = this.buttons;
23553 var doc = this.editorcore.doc;
23554 btns.get('bold').setActive(doc.queryCommandState('bold'));
23555 btns.get('italic').setActive(doc.queryCommandState('italic'));
23556 //btns.get('underline').setActive(doc.queryCommandState('underline'));
23558 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
23559 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
23560 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
23562 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
23563 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
23566 var ans = this.editorcore.getAllAncestors();
23567 if (this.formatCombo) {
23570 var store = this.formatCombo.store;
23571 this.formatCombo.setValue("");
23572 for (var i =0; i < ans.length;i++) {
23573 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
23575 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
23583 // hides menus... - so this cant be on a menu...
23584 Roo.bootstrap.MenuMgr.hideAll();
23586 Roo.bootstrap.MenuMgr.hideAll();
23587 //this.editorsyncValue();
23589 onFirstFocus: function() {
23590 this.buttons.each(function(item){
23594 toggleSourceEdit : function(sourceEditMode){
23597 if(sourceEditMode){
23598 Roo.log("disabling buttons");
23599 this.buttons.each( function(item){
23600 if(item.cmd != 'pencil'){
23606 Roo.log("enabling buttons");
23607 if(this.editorcore.initialized){
23608 this.buttons.each( function(item){
23614 Roo.log("calling toggole on editor");
23615 // tell the editor that it's been pressed..
23616 this.editor.toggleSourceEdit(sourceEditMode);
23626 * @class Roo.bootstrap.Table.AbstractSelectionModel
23627 * @extends Roo.util.Observable
23628 * Abstract base class for grid SelectionModels. It provides the interface that should be
23629 * implemented by descendant classes. This class should not be directly instantiated.
23632 Roo.bootstrap.Table.AbstractSelectionModel = function(){
23633 this.locked = false;
23634 Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
23638 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable, {
23639 /** @ignore Called by the grid automatically. Do not call directly. */
23640 init : function(grid){
23646 * Locks the selections.
23649 this.locked = true;
23653 * Unlocks the selections.
23655 unlock : function(){
23656 this.locked = false;
23660 * Returns true if the selections are locked.
23661 * @return {Boolean}
23663 isLocked : function(){
23664 return this.locked;
23668 * @extends Roo.bootstrap.Table.AbstractSelectionModel
23669 * @class Roo.bootstrap.Table.RowSelectionModel
23670 * The default SelectionModel used by {@link Roo.bootstrap.Table}.
23671 * It supports multiple selections and keyboard selection/navigation.
23673 * @param {Object} config
23676 Roo.bootstrap.Table.RowSelectionModel = function(config){
23677 Roo.apply(this, config);
23678 this.selections = new Roo.util.MixedCollection(false, function(o){
23683 this.lastActive = false;
23687 * @event selectionchange
23688 * Fires when the selection changes
23689 * @param {SelectionModel} this
23691 "selectionchange" : true,
23693 * @event afterselectionchange
23694 * Fires after the selection changes (eg. by key press or clicking)
23695 * @param {SelectionModel} this
23697 "afterselectionchange" : true,
23699 * @event beforerowselect
23700 * Fires when a row is selected being selected, return false to cancel.
23701 * @param {SelectionModel} this
23702 * @param {Number} rowIndex The selected index
23703 * @param {Boolean} keepExisting False if other selections will be cleared
23705 "beforerowselect" : true,
23708 * Fires when a row is selected.
23709 * @param {SelectionModel} this
23710 * @param {Number} rowIndex The selected index
23711 * @param {Roo.data.Record} r The record
23713 "rowselect" : true,
23715 * @event rowdeselect
23716 * Fires when a row is deselected.
23717 * @param {SelectionModel} this
23718 * @param {Number} rowIndex The selected index
23720 "rowdeselect" : true
23722 Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
23723 this.locked = false;
23726 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel, {
23728 * @cfg {Boolean} singleSelect
23729 * True to allow selection of only one row at a time (defaults to false)
23731 singleSelect : false,
23734 initEvents : function()
23737 //if(!this.grid.enableDragDrop && !this.grid.enableDrag){
23738 // this.growclickrid.on("mousedown", this.handleMouseDown, this);
23739 //}else{ // allow click to work like normal
23740 // this.grid.on("rowclick", this.handleDragableRowClick, this);
23742 //this.grid.on("rowdblclick", this.handleMouseDBClick, this);
23743 this.grid.on("rowclick", this.handleMouseDown, this);
23745 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
23746 "up" : function(e){
23748 this.selectPrevious(e.shiftKey);
23749 }else if(this.last !== false && this.lastActive !== false){
23750 var last = this.last;
23751 this.selectRange(this.last, this.lastActive-1);
23752 this.grid.getView().focusRow(this.lastActive);
23753 if(last !== false){
23757 this.selectFirstRow();
23759 this.fireEvent("afterselectionchange", this);
23761 "down" : function(e){
23763 this.selectNext(e.shiftKey);
23764 }else if(this.last !== false && this.lastActive !== false){
23765 var last = this.last;
23766 this.selectRange(this.last, this.lastActive+1);
23767 this.grid.getView().focusRow(this.lastActive);
23768 if(last !== false){
23772 this.selectFirstRow();
23774 this.fireEvent("afterselectionchange", this);
23778 this.grid.store.on('load', function(){
23779 this.selections.clear();
23782 var view = this.grid.view;
23783 view.on("refresh", this.onRefresh, this);
23784 view.on("rowupdated", this.onRowUpdated, this);
23785 view.on("rowremoved", this.onRemove, this);
23790 onRefresh : function()
23792 var ds = this.grid.store, i, v = this.grid.view;
23793 var s = this.selections;
23794 s.each(function(r){
23795 if((i = ds.indexOfId(r.id)) != -1){
23804 onRemove : function(v, index, r){
23805 this.selections.remove(r);
23809 onRowUpdated : function(v, index, r){
23810 if(this.isSelected(r)){
23811 v.onRowSelect(index);
23817 * @param {Array} records The records to select
23818 * @param {Boolean} keepExisting (optional) True to keep existing selections
23820 selectRecords : function(records, keepExisting)
23823 this.clearSelections();
23825 var ds = this.grid.store;
23826 for(var i = 0, len = records.length; i < len; i++){
23827 this.selectRow(ds.indexOf(records[i]), true);
23832 * Gets the number of selected rows.
23835 getCount : function(){
23836 return this.selections.length;
23840 * Selects the first row in the grid.
23842 selectFirstRow : function(){
23847 * Select the last row.
23848 * @param {Boolean} keepExisting (optional) True to keep existing selections
23850 selectLastRow : function(keepExisting){
23851 //this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
23852 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
23856 * Selects the row immediately following the last selected row.
23857 * @param {Boolean} keepExisting (optional) True to keep existing selections
23859 selectNext : function(keepExisting)
23861 if(this.last !== false && (this.last+1) < this.grid.store.getCount()){
23862 this.selectRow(this.last+1, keepExisting);
23863 this.grid.getView().focusRow(this.last);
23868 * Selects the row that precedes the last selected row.
23869 * @param {Boolean} keepExisting (optional) True to keep existing selections
23871 selectPrevious : function(keepExisting){
23873 this.selectRow(this.last-1, keepExisting);
23874 this.grid.getView().focusRow(this.last);
23879 * Returns the selected records
23880 * @return {Array} Array of selected records
23882 getSelections : function(){
23883 return [].concat(this.selections.items);
23887 * Returns the first selected record.
23890 getSelected : function(){
23891 return this.selections.itemAt(0);
23896 * Clears all selections.
23898 clearSelections : function(fast)
23904 var ds = this.grid.store;
23905 var s = this.selections;
23906 s.each(function(r){
23907 this.deselectRow(ds.indexOfId(r.id));
23911 this.selections.clear();
23918 * Selects all rows.
23920 selectAll : function(){
23924 this.selections.clear();
23925 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
23926 this.selectRow(i, true);
23931 * Returns True if there is a selection.
23932 * @return {Boolean}
23934 hasSelection : function(){
23935 return this.selections.length > 0;
23939 * Returns True if the specified row is selected.
23940 * @param {Number/Record} record The record or index of the record to check
23941 * @return {Boolean}
23943 isSelected : function(index){
23944 var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
23945 return (r && this.selections.key(r.id) ? true : false);
23949 * Returns True if the specified record id is selected.
23950 * @param {String} id The id of record to check
23951 * @return {Boolean}
23953 isIdSelected : function(id){
23954 return (this.selections.key(id) ? true : false);
23959 handleMouseDBClick : function(e, t){
23963 handleMouseDown : function(e, t)
23965 var rowIndex = this.grid.headerShow ? t.dom.rowIndex - 1 : t.dom.rowIndex ; // first row is header???
23966 if(this.isLocked() || rowIndex < 0 ){
23969 if(e.shiftKey && this.last !== false){
23970 var last = this.last;
23971 this.selectRange(last, rowIndex, e.ctrlKey);
23972 this.last = last; // reset the last
23976 var isSelected = this.isSelected(rowIndex);
23977 //Roo.log("select row:" + rowIndex);
23979 this.deselectRow(rowIndex);
23981 this.selectRow(rowIndex, true);
23985 if(e.button !== 0 && isSelected){
23986 alert('rowIndex 2: ' + rowIndex);
23987 view.focusRow(rowIndex);
23988 }else if(e.ctrlKey && isSelected){
23989 this.deselectRow(rowIndex);
23990 }else if(!isSelected){
23991 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
23992 view.focusRow(rowIndex);
23996 this.fireEvent("afterselectionchange", this);
23999 handleDragableRowClick : function(grid, rowIndex, e)
24001 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
24002 this.selectRow(rowIndex, false);
24003 grid.view.focusRow(rowIndex);
24004 this.fireEvent("afterselectionchange", this);
24009 * Selects multiple rows.
24010 * @param {Array} rows Array of the indexes of the row to select
24011 * @param {Boolean} keepExisting (optional) True to keep existing selections
24013 selectRows : function(rows, keepExisting){
24015 this.clearSelections();
24017 for(var i = 0, len = rows.length; i < len; i++){
24018 this.selectRow(rows[i], true);
24023 * Selects a range of rows. All rows in between startRow and endRow are also selected.
24024 * @param {Number} startRow The index of the first row in the range
24025 * @param {Number} endRow The index of the last row in the range
24026 * @param {Boolean} keepExisting (optional) True to retain existing selections
24028 selectRange : function(startRow, endRow, keepExisting){
24033 this.clearSelections();
24035 if(startRow <= endRow){
24036 for(var i = startRow; i <= endRow; i++){
24037 this.selectRow(i, true);
24040 for(var i = startRow; i >= endRow; i--){
24041 this.selectRow(i, true);
24047 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
24048 * @param {Number} startRow The index of the first row in the range
24049 * @param {Number} endRow The index of the last row in the range
24051 deselectRange : function(startRow, endRow, preventViewNotify){
24055 for(var i = startRow; i <= endRow; i++){
24056 this.deselectRow(i, preventViewNotify);
24062 * @param {Number} row The index of the row to select
24063 * @param {Boolean} keepExisting (optional) True to keep existing selections
24065 selectRow : function(index, keepExisting, preventViewNotify)
24067 if(this.locked || (index < 0 || index > this.grid.store.getCount())) {
24070 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
24071 if(!keepExisting || this.singleSelect){
24072 this.clearSelections();
24075 var r = this.grid.store.getAt(index);
24076 //console.log('selectRow - record id :' + r.id);
24078 this.selections.add(r);
24079 this.last = this.lastActive = index;
24080 if(!preventViewNotify){
24081 var proxy = new Roo.Element(
24082 this.grid.getRowDom(index)
24084 proxy.addClass('bg-info info');
24086 this.fireEvent("rowselect", this, index, r);
24087 this.fireEvent("selectionchange", this);
24093 * @param {Number} row The index of the row to deselect
24095 deselectRow : function(index, preventViewNotify)
24100 if(this.last == index){
24103 if(this.lastActive == index){
24104 this.lastActive = false;
24107 var r = this.grid.store.getAt(index);
24112 this.selections.remove(r);
24113 //.console.log('deselectRow - record id :' + r.id);
24114 if(!preventViewNotify){
24116 var proxy = new Roo.Element(
24117 this.grid.getRowDom(index)
24119 proxy.removeClass('bg-info info');
24121 this.fireEvent("rowdeselect", this, index);
24122 this.fireEvent("selectionchange", this);
24126 restoreLast : function(){
24128 this.last = this._last;
24133 acceptsNav : function(row, col, cm){
24134 return !cm.isHidden(col) && cm.isCellEditable(col, row);
24138 onEditorKey : function(field, e){
24139 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
24144 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
24146 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
24148 }else if(k == e.ENTER && !e.ctrlKey){
24152 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
24154 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
24156 }else if(k == e.ESC){
24160 g.startEditing(newCell[0], newCell[1]);
24166 * Ext JS Library 1.1.1
24167 * Copyright(c) 2006-2007, Ext JS, LLC.
24169 * Originally Released Under LGPL - original licence link has changed is not relivant.
24172 * <script type="text/javascript">
24176 * @class Roo.bootstrap.PagingToolbar
24177 * @extends Roo.bootstrap.NavSimplebar
24178 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
24180 * Create a new PagingToolbar
24181 * @param {Object} config The config object
24182 * @param {Roo.data.Store} store
24184 Roo.bootstrap.PagingToolbar = function(config)
24186 // old args format still supported... - xtype is prefered..
24187 // created from xtype...
24189 this.ds = config.dataSource;
24191 if (config.store && !this.ds) {
24192 this.store= Roo.factory(config.store, Roo.data);
24193 this.ds = this.store;
24194 this.ds.xmodule = this.xmodule || false;
24197 this.toolbarItems = [];
24198 if (config.items) {
24199 this.toolbarItems = config.items;
24202 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
24207 this.bind(this.ds);
24210 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
24214 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
24216 * @cfg {Roo.data.Store} dataSource
24217 * The underlying data store providing the paged data
24220 * @cfg {String/HTMLElement/Element} container
24221 * container The id or element that will contain the toolbar
24224 * @cfg {Boolean} displayInfo
24225 * True to display the displayMsg (defaults to false)
24228 * @cfg {Number} pageSize
24229 * The number of records to display per page (defaults to 20)
24233 * @cfg {String} displayMsg
24234 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
24236 displayMsg : 'Displaying {0} - {1} of {2}',
24238 * @cfg {String} emptyMsg
24239 * The message to display when no records are found (defaults to "No data to display")
24241 emptyMsg : 'No data to display',
24243 * Customizable piece of the default paging text (defaults to "Page")
24246 beforePageText : "Page",
24248 * Customizable piece of the default paging text (defaults to "of %0")
24251 afterPageText : "of {0}",
24253 * Customizable piece of the default paging text (defaults to "First Page")
24256 firstText : "First Page",
24258 * Customizable piece of the default paging text (defaults to "Previous Page")
24261 prevText : "Previous Page",
24263 * Customizable piece of the default paging text (defaults to "Next Page")
24266 nextText : "Next Page",
24268 * Customizable piece of the default paging text (defaults to "Last Page")
24271 lastText : "Last Page",
24273 * Customizable piece of the default paging text (defaults to "Refresh")
24276 refreshText : "Refresh",
24280 onRender : function(ct, position)
24282 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
24283 this.navgroup.parentId = this.id;
24284 this.navgroup.onRender(this.el, null);
24285 // add the buttons to the navgroup
24287 if(this.displayInfo){
24288 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
24289 this.displayEl = this.el.select('.x-paging-info', true).first();
24290 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
24291 // this.displayEl = navel.el.select('span',true).first();
24297 Roo.each(_this.buttons, function(e){ // this might need to use render????
24298 Roo.factory(e).onRender(_this.el, null);
24302 Roo.each(_this.toolbarItems, function(e) {
24303 _this.navgroup.addItem(e);
24307 this.first = this.navgroup.addItem({
24308 tooltip: this.firstText,
24310 icon : 'fa fa-backward',
24312 preventDefault: true,
24313 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
24316 this.prev = this.navgroup.addItem({
24317 tooltip: this.prevText,
24319 icon : 'fa fa-step-backward',
24321 preventDefault: true,
24322 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
24324 //this.addSeparator();
24327 var field = this.navgroup.addItem( {
24329 cls : 'x-paging-position',
24331 html : this.beforePageText +
24332 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
24333 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
24336 this.field = field.el.select('input', true).first();
24337 this.field.on("keydown", this.onPagingKeydown, this);
24338 this.field.on("focus", function(){this.dom.select();});
24341 this.afterTextEl = field.el.select('.x-paging-after',true).first();
24342 //this.field.setHeight(18);
24343 //this.addSeparator();
24344 this.next = this.navgroup.addItem({
24345 tooltip: this.nextText,
24347 html : ' <i class="fa fa-step-forward">',
24349 preventDefault: true,
24350 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
24352 this.last = this.navgroup.addItem({
24353 tooltip: this.lastText,
24354 icon : 'fa fa-forward',
24357 preventDefault: true,
24358 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
24360 //this.addSeparator();
24361 this.loading = this.navgroup.addItem({
24362 tooltip: this.refreshText,
24363 icon: 'fa fa-refresh',
24364 preventDefault: true,
24365 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
24371 updateInfo : function(){
24372 if(this.displayEl){
24373 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
24374 var msg = count == 0 ?
24378 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
24380 this.displayEl.update(msg);
24385 onLoad : function(ds, r, o)
24387 this.cursor = o.params ? o.params.start : 0;
24388 var d = this.getPageData(),
24393 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
24394 this.field.dom.value = ap;
24395 this.first.setDisabled(ap == 1);
24396 this.prev.setDisabled(ap == 1);
24397 this.next.setDisabled(ap == ps);
24398 this.last.setDisabled(ap == ps);
24399 this.loading.enable();
24404 getPageData : function(){
24405 var total = this.ds.getTotalCount();
24408 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
24409 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
24414 onLoadError : function(){
24415 this.loading.enable();
24419 onPagingKeydown : function(e){
24420 var k = e.getKey();
24421 var d = this.getPageData();
24423 var v = this.field.dom.value, pageNum;
24424 if(!v || isNaN(pageNum = parseInt(v, 10))){
24425 this.field.dom.value = d.activePage;
24428 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
24429 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24432 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))
24434 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
24435 this.field.dom.value = pageNum;
24436 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
24439 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
24441 var v = this.field.dom.value, pageNum;
24442 var increment = (e.shiftKey) ? 10 : 1;
24443 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
24446 if(!v || isNaN(pageNum = parseInt(v, 10))) {
24447 this.field.dom.value = d.activePage;
24450 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
24452 this.field.dom.value = parseInt(v, 10) + increment;
24453 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
24454 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24461 beforeLoad : function(){
24463 this.loading.disable();
24468 onClick : function(which){
24477 ds.load({params:{start: 0, limit: this.pageSize}});
24480 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
24483 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
24486 var total = ds.getTotalCount();
24487 var extra = total % this.pageSize;
24488 var lastStart = extra ? (total - extra) : total-this.pageSize;
24489 ds.load({params:{start: lastStart, limit: this.pageSize}});
24492 ds.load({params:{start: this.cursor, limit: this.pageSize}});
24498 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
24499 * @param {Roo.data.Store} store The data store to unbind
24501 unbind : function(ds){
24502 ds.un("beforeload", this.beforeLoad, this);
24503 ds.un("load", this.onLoad, this);
24504 ds.un("loadexception", this.onLoadError, this);
24505 ds.un("remove", this.updateInfo, this);
24506 ds.un("add", this.updateInfo, this);
24507 this.ds = undefined;
24511 * Binds the paging toolbar to the specified {@link Roo.data.Store}
24512 * @param {Roo.data.Store} store The data store to bind
24514 bind : function(ds){
24515 ds.on("beforeload", this.beforeLoad, this);
24516 ds.on("load", this.onLoad, this);
24517 ds.on("loadexception", this.onLoadError, this);
24518 ds.on("remove", this.updateInfo, this);
24519 ds.on("add", this.updateInfo, this);
24530 * @class Roo.bootstrap.MessageBar
24531 * @extends Roo.bootstrap.Component
24532 * Bootstrap MessageBar class
24533 * @cfg {String} html contents of the MessageBar
24534 * @cfg {String} weight (info | success | warning | danger) default info
24535 * @cfg {String} beforeClass insert the bar before the given class
24536 * @cfg {Boolean} closable (true | false) default false
24537 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
24540 * Create a new Element
24541 * @param {Object} config The config object
24544 Roo.bootstrap.MessageBar = function(config){
24545 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
24548 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
24554 beforeClass: 'bootstrap-sticky-wrap',
24556 getAutoCreate : function(){
24560 cls: 'alert alert-dismissable alert-' + this.weight,
24565 html: this.html || ''
24571 cfg.cls += ' alert-messages-fixed';
24585 onRender : function(ct, position)
24587 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
24590 var cfg = Roo.apply({}, this.getAutoCreate());
24594 cfg.cls += ' ' + this.cls;
24597 cfg.style = this.style;
24599 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
24601 this.el.setVisibilityMode(Roo.Element.DISPLAY);
24604 this.el.select('>button.close').on('click', this.hide, this);
24610 if (!this.rendered) {
24616 this.fireEvent('show', this);
24622 if (!this.rendered) {
24628 this.fireEvent('hide', this);
24631 update : function()
24633 // var e = this.el.dom.firstChild;
24635 // if(this.closable){
24636 // e = e.nextSibling;
24639 // e.data = this.html || '';
24641 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
24657 * @class Roo.bootstrap.Graph
24658 * @extends Roo.bootstrap.Component
24659 * Bootstrap Graph class
24663 @cfg {String} graphtype bar | vbar | pie
24664 @cfg {number} g_x coodinator | centre x (pie)
24665 @cfg {number} g_y coodinator | centre y (pie)
24666 @cfg {number} g_r radius (pie)
24667 @cfg {number} g_height height of the chart (respected by all elements in the set)
24668 @cfg {number} g_width width of the chart (respected by all elements in the set)
24669 @cfg {Object} title The title of the chart
24672 -opts (object) options for the chart
24674 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
24675 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
24677 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.
24678 o stacked (boolean) whether or not to tread values as in a stacked bar chart
24680 o stretch (boolean)
24682 -opts (object) options for the pie
24685 o startAngle (number)
24686 o endAngle (number)
24690 * Create a new Input
24691 * @param {Object} config The config object
24694 Roo.bootstrap.Graph = function(config){
24695 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
24701 * The img click event for the img.
24702 * @param {Roo.EventObject} e
24708 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
24719 //g_colors: this.colors,
24726 getAutoCreate : function(){
24737 onRender : function(ct,position){
24740 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
24742 if (typeof(Raphael) == 'undefined') {
24743 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
24747 this.raphael = Raphael(this.el.dom);
24749 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
24750 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
24751 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
24752 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
24754 r.text(160, 10, "Single Series Chart").attr(txtattr);
24755 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
24756 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
24757 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
24759 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
24760 r.barchart(330, 10, 300, 220, data1);
24761 r.barchart(10, 250, 300, 220, data2, {stacked: true});
24762 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
24765 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
24766 // r.barchart(30, 30, 560, 250, xdata, {
24767 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
24768 // axis : "0 0 1 1",
24769 // axisxlabels : xdata
24770 // //yvalues : cols,
24773 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
24775 // this.load(null,xdata,{
24776 // axis : "0 0 1 1",
24777 // axisxlabels : xdata
24782 load : function(graphtype,xdata,opts)
24784 this.raphael.clear();
24786 graphtype = this.graphtype;
24791 var r = this.raphael,
24792 fin = function () {
24793 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
24795 fout = function () {
24796 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
24798 pfin = function() {
24799 this.sector.stop();
24800 this.sector.scale(1.1, 1.1, this.cx, this.cy);
24803 this.label[0].stop();
24804 this.label[0].attr({ r: 7.5 });
24805 this.label[1].attr({ "font-weight": 800 });
24808 pfout = function() {
24809 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
24812 this.label[0].animate({ r: 5 }, 500, "bounce");
24813 this.label[1].attr({ "font-weight": 400 });
24819 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
24822 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
24825 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
24826 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
24828 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
24835 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
24840 setTitle: function(o)
24845 initEvents: function() {
24848 this.el.on('click', this.onClick, this);
24852 onClick : function(e)
24854 Roo.log('img onclick');
24855 this.fireEvent('click', this, e);
24867 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
24870 * @class Roo.bootstrap.dash.NumberBox
24871 * @extends Roo.bootstrap.Component
24872 * Bootstrap NumberBox class
24873 * @cfg {String} headline Box headline
24874 * @cfg {String} content Box content
24875 * @cfg {String} icon Box icon
24876 * @cfg {String} footer Footer text
24877 * @cfg {String} fhref Footer href
24880 * Create a new NumberBox
24881 * @param {Object} config The config object
24885 Roo.bootstrap.dash.NumberBox = function(config){
24886 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
24890 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
24899 getAutoCreate : function(){
24903 cls : 'small-box ',
24911 cls : 'roo-headline',
24912 html : this.headline
24916 cls : 'roo-content',
24917 html : this.content
24931 cls : 'ion ' + this.icon
24940 cls : 'small-box-footer',
24941 href : this.fhref || '#',
24945 cfg.cn.push(footer);
24952 onRender : function(ct,position){
24953 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
24960 setHeadline: function (value)
24962 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
24965 setFooter: function (value, href)
24967 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
24970 this.el.select('a.small-box-footer',true).first().attr('href', href);
24975 setContent: function (value)
24977 this.el.select('.roo-content',true).first().dom.innerHTML = value;
24980 initEvents: function()
24994 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
24997 * @class Roo.bootstrap.dash.TabBox
24998 * @extends Roo.bootstrap.Component
24999 * Bootstrap TabBox class
25000 * @cfg {String} title Title of the TabBox
25001 * @cfg {String} icon Icon of the TabBox
25002 * @cfg {Boolean} showtabs (true|false) show the tabs default true
25003 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
25006 * Create a new TabBox
25007 * @param {Object} config The config object
25011 Roo.bootstrap.dash.TabBox = function(config){
25012 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
25017 * When a pane is added
25018 * @param {Roo.bootstrap.dash.TabPane} pane
25022 * @event activatepane
25023 * When a pane is activated
25024 * @param {Roo.bootstrap.dash.TabPane} pane
25026 "activatepane" : true
25034 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
25039 tabScrollable : false,
25041 getChildContainer : function()
25043 return this.el.select('.tab-content', true).first();
25046 getAutoCreate : function(){
25050 cls: 'pull-left header',
25058 cls: 'fa ' + this.icon
25064 cls: 'nav nav-tabs pull-right',
25070 if(this.tabScrollable){
25077 cls: 'nav nav-tabs pull-right',
25088 cls: 'nav-tabs-custom',
25093 cls: 'tab-content no-padding',
25101 initEvents : function()
25103 //Roo.log('add add pane handler');
25104 this.on('addpane', this.onAddPane, this);
25107 * Updates the box title
25108 * @param {String} html to set the title to.
25110 setTitle : function(value)
25112 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
25114 onAddPane : function(pane)
25116 this.panes.push(pane);
25117 //Roo.log('addpane');
25119 // tabs are rendere left to right..
25120 if(!this.showtabs){
25124 var ctr = this.el.select('.nav-tabs', true).first();
25127 var existing = ctr.select('.nav-tab',true);
25128 var qty = existing.getCount();;
25131 var tab = ctr.createChild({
25133 cls : 'nav-tab' + (qty ? '' : ' active'),
25141 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
25144 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
25146 pane.el.addClass('active');
25151 onTabClick : function(ev,un,ob,pane)
25153 //Roo.log('tab - prev default');
25154 ev.preventDefault();
25157 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
25158 pane.tab.addClass('active');
25159 //Roo.log(pane.title);
25160 this.getChildContainer().select('.tab-pane',true).removeClass('active');
25161 // technically we should have a deactivate event.. but maybe add later.
25162 // and it should not de-activate the selected tab...
25163 this.fireEvent('activatepane', pane);
25164 pane.el.addClass('active');
25165 pane.fireEvent('activate');
25170 getActivePane : function()
25173 Roo.each(this.panes, function(p) {
25174 if(p.el.hasClass('active')){
25195 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25197 * @class Roo.bootstrap.TabPane
25198 * @extends Roo.bootstrap.Component
25199 * Bootstrap TabPane class
25200 * @cfg {Boolean} active (false | true) Default false
25201 * @cfg {String} title title of panel
25205 * Create a new TabPane
25206 * @param {Object} config The config object
25209 Roo.bootstrap.dash.TabPane = function(config){
25210 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
25216 * When a pane is activated
25217 * @param {Roo.bootstrap.dash.TabPane} pane
25224 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
25229 // the tabBox that this is attached to.
25232 getAutoCreate : function()
25240 cfg.cls += ' active';
25245 initEvents : function()
25247 //Roo.log('trigger add pane handler');
25248 this.parent().fireEvent('addpane', this)
25252 * Updates the tab title
25253 * @param {String} html to set the title to.
25255 setTitle: function(str)
25261 this.tab.select('a', true).first().dom.innerHTML = str;
25278 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25281 * @class Roo.bootstrap.menu.Menu
25282 * @extends Roo.bootstrap.Component
25283 * Bootstrap Menu class - container for Menu
25284 * @cfg {String} html Text of the menu
25285 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
25286 * @cfg {String} icon Font awesome icon
25287 * @cfg {String} pos Menu align to (top | bottom) default bottom
25291 * Create a new Menu
25292 * @param {Object} config The config object
25296 Roo.bootstrap.menu.Menu = function(config){
25297 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
25301 * @event beforeshow
25302 * Fires before this menu is displayed
25303 * @param {Roo.bootstrap.menu.Menu} this
25307 * @event beforehide
25308 * Fires before this menu is hidden
25309 * @param {Roo.bootstrap.menu.Menu} this
25314 * Fires after this menu is displayed
25315 * @param {Roo.bootstrap.menu.Menu} this
25320 * Fires after this menu is hidden
25321 * @param {Roo.bootstrap.menu.Menu} this
25326 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
25327 * @param {Roo.bootstrap.menu.Menu} this
25328 * @param {Roo.EventObject} e
25335 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
25339 weight : 'default',
25344 getChildContainer : function() {
25345 if(this.isSubMenu){
25349 return this.el.select('ul.dropdown-menu', true).first();
25352 getAutoCreate : function()
25357 cls : 'roo-menu-text',
25365 cls : 'fa ' + this.icon
25376 cls : 'dropdown-button btn btn-' + this.weight,
25381 cls : 'dropdown-toggle btn btn-' + this.weight,
25391 cls : 'dropdown-menu'
25397 if(this.pos == 'top'){
25398 cfg.cls += ' dropup';
25401 if(this.isSubMenu){
25404 cls : 'dropdown-menu'
25411 onRender : function(ct, position)
25413 this.isSubMenu = ct.hasClass('dropdown-submenu');
25415 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
25418 initEvents : function()
25420 if(this.isSubMenu){
25424 this.hidden = true;
25426 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
25427 this.triggerEl.on('click', this.onTriggerPress, this);
25429 this.buttonEl = this.el.select('button.dropdown-button', true).first();
25430 this.buttonEl.on('click', this.onClick, this);
25436 if(this.isSubMenu){
25440 return this.el.select('ul.dropdown-menu', true).first();
25443 onClick : function(e)
25445 this.fireEvent("click", this, e);
25448 onTriggerPress : function(e)
25450 if (this.isVisible()) {
25457 isVisible : function(){
25458 return !this.hidden;
25463 this.fireEvent("beforeshow", this);
25465 this.hidden = false;
25466 this.el.addClass('open');
25468 Roo.get(document).on("mouseup", this.onMouseUp, this);
25470 this.fireEvent("show", this);
25477 this.fireEvent("beforehide", this);
25479 this.hidden = true;
25480 this.el.removeClass('open');
25482 Roo.get(document).un("mouseup", this.onMouseUp);
25484 this.fireEvent("hide", this);
25487 onMouseUp : function()
25501 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25504 * @class Roo.bootstrap.menu.Item
25505 * @extends Roo.bootstrap.Component
25506 * Bootstrap MenuItem class
25507 * @cfg {Boolean} submenu (true | false) default false
25508 * @cfg {String} html text of the item
25509 * @cfg {String} href the link
25510 * @cfg {Boolean} disable (true | false) default false
25511 * @cfg {Boolean} preventDefault (true | false) default true
25512 * @cfg {String} icon Font awesome icon
25513 * @cfg {String} pos Submenu align to (left | right) default right
25517 * Create a new Item
25518 * @param {Object} config The config object
25522 Roo.bootstrap.menu.Item = function(config){
25523 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
25527 * Fires when the mouse is hovering over this menu
25528 * @param {Roo.bootstrap.menu.Item} this
25529 * @param {Roo.EventObject} e
25534 * Fires when the mouse exits this menu
25535 * @param {Roo.bootstrap.menu.Item} this
25536 * @param {Roo.EventObject} e
25542 * The raw click event for the entire grid.
25543 * @param {Roo.EventObject} e
25549 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
25554 preventDefault: true,
25559 getAutoCreate : function()
25564 cls : 'roo-menu-item-text',
25572 cls : 'fa ' + this.icon
25581 href : this.href || '#',
25588 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
25592 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
25594 if(this.pos == 'left'){
25595 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
25602 initEvents : function()
25604 this.el.on('mouseover', this.onMouseOver, this);
25605 this.el.on('mouseout', this.onMouseOut, this);
25607 this.el.select('a', true).first().on('click', this.onClick, this);
25611 onClick : function(e)
25613 if(this.preventDefault){
25614 e.preventDefault();
25617 this.fireEvent("click", this, e);
25620 onMouseOver : function(e)
25622 if(this.submenu && this.pos == 'left'){
25623 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
25626 this.fireEvent("mouseover", this, e);
25629 onMouseOut : function(e)
25631 this.fireEvent("mouseout", this, e);
25643 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25646 * @class Roo.bootstrap.menu.Separator
25647 * @extends Roo.bootstrap.Component
25648 * Bootstrap Separator class
25651 * Create a new Separator
25652 * @param {Object} config The config object
25656 Roo.bootstrap.menu.Separator = function(config){
25657 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
25660 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
25662 getAutoCreate : function(){
25683 * @class Roo.bootstrap.Tooltip
25684 * Bootstrap Tooltip class
25685 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
25686 * to determine which dom element triggers the tooltip.
25688 * It needs to add support for additional attributes like tooltip-position
25691 * Create a new Toolti
25692 * @param {Object} config The config object
25695 Roo.bootstrap.Tooltip = function(config){
25696 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
25698 this.alignment = Roo.bootstrap.Tooltip.alignment;
25700 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
25701 this.alignment = config.alignment;
25706 Roo.apply(Roo.bootstrap.Tooltip, {
25708 * @function init initialize tooltip monitoring.
25712 currentTip : false,
25713 currentRegion : false,
25719 Roo.get(document).on('mouseover', this.enter ,this);
25720 Roo.get(document).on('mouseout', this.leave, this);
25723 this.currentTip = new Roo.bootstrap.Tooltip();
25726 enter : function(ev)
25728 var dom = ev.getTarget();
25730 //Roo.log(['enter',dom]);
25731 var el = Roo.fly(dom);
25732 if (this.currentEl) {
25734 //Roo.log(this.currentEl);
25735 //Roo.log(this.currentEl.contains(dom));
25736 if (this.currentEl == el) {
25739 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
25745 if (this.currentTip.el) {
25746 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
25750 if(!el || el.dom == document){
25756 // you can not look for children, as if el is the body.. then everythign is the child..
25757 if (!el.attr('tooltip')) { //
25758 if (!el.select("[tooltip]").elements.length) {
25761 // is the mouse over this child...?
25762 bindEl = el.select("[tooltip]").first();
25763 var xy = ev.getXY();
25764 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
25765 //Roo.log("not in region.");
25768 //Roo.log("child element over..");
25771 this.currentEl = bindEl;
25772 this.currentTip.bind(bindEl);
25773 this.currentRegion = Roo.lib.Region.getRegion(dom);
25774 this.currentTip.enter();
25777 leave : function(ev)
25779 var dom = ev.getTarget();
25780 //Roo.log(['leave',dom]);
25781 if (!this.currentEl) {
25786 if (dom != this.currentEl.dom) {
25789 var xy = ev.getXY();
25790 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
25793 // only activate leave if mouse cursor is outside... bounding box..
25798 if (this.currentTip) {
25799 this.currentTip.leave();
25801 //Roo.log('clear currentEl');
25802 this.currentEl = false;
25807 'left' : ['r-l', [-2,0], 'right'],
25808 'right' : ['l-r', [2,0], 'left'],
25809 'bottom' : ['t-b', [0,2], 'top'],
25810 'top' : [ 'b-t', [0,-2], 'bottom']
25816 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
25821 delay : null, // can be { show : 300 , hide: 500}
25825 hoverState : null, //???
25827 placement : 'bottom',
25831 getAutoCreate : function(){
25838 cls : 'tooltip-arrow'
25841 cls : 'tooltip-inner'
25848 bind : function(el)
25854 enter : function () {
25856 if (this.timeout != null) {
25857 clearTimeout(this.timeout);
25860 this.hoverState = 'in';
25861 //Roo.log("enter - show");
25862 if (!this.delay || !this.delay.show) {
25867 this.timeout = setTimeout(function () {
25868 if (_t.hoverState == 'in') {
25871 }, this.delay.show);
25875 clearTimeout(this.timeout);
25877 this.hoverState = 'out';
25878 if (!this.delay || !this.delay.hide) {
25884 this.timeout = setTimeout(function () {
25885 //Roo.log("leave - timeout");
25887 if (_t.hoverState == 'out') {
25889 Roo.bootstrap.Tooltip.currentEl = false;
25894 show : function (msg)
25897 this.render(document.body);
25900 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
25902 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
25904 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
25906 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
25908 var placement = typeof this.placement == 'function' ?
25909 this.placement.call(this, this.el, on_el) :
25912 var autoToken = /\s?auto?\s?/i;
25913 var autoPlace = autoToken.test(placement);
25915 placement = placement.replace(autoToken, '') || 'top';
25919 //this.el.setXY([0,0]);
25921 //this.el.dom.style.display='block';
25923 //this.el.appendTo(on_el);
25925 var p = this.getPosition();
25926 var box = this.el.getBox();
25932 var align = this.alignment[placement];
25934 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
25936 if(placement == 'top' || placement == 'bottom'){
25938 placement = 'right';
25941 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
25942 placement = 'left';
25945 var scroll = Roo.select('body', true).first().getScroll();
25947 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
25953 this.el.alignTo(this.bindEl, align[0],align[1]);
25954 //var arrow = this.el.select('.arrow',true).first();
25955 //arrow.set(align[2],
25957 this.el.addClass(placement);
25959 this.el.addClass('in fade');
25961 this.hoverState = null;
25963 if (this.el.hasClass('fade')) {
25974 //this.el.setXY([0,0]);
25975 this.el.removeClass('in');
25991 * @class Roo.bootstrap.LocationPicker
25992 * @extends Roo.bootstrap.Component
25993 * Bootstrap LocationPicker class
25994 * @cfg {Number} latitude Position when init default 0
25995 * @cfg {Number} longitude Position when init default 0
25996 * @cfg {Number} zoom default 15
25997 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
25998 * @cfg {Boolean} mapTypeControl default false
25999 * @cfg {Boolean} disableDoubleClickZoom default false
26000 * @cfg {Boolean} scrollwheel default true
26001 * @cfg {Boolean} streetViewControl default false
26002 * @cfg {Number} radius default 0
26003 * @cfg {String} locationName
26004 * @cfg {Boolean} draggable default true
26005 * @cfg {Boolean} enableAutocomplete default false
26006 * @cfg {Boolean} enableReverseGeocode default true
26007 * @cfg {String} markerTitle
26010 * Create a new LocationPicker
26011 * @param {Object} config The config object
26015 Roo.bootstrap.LocationPicker = function(config){
26017 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
26022 * Fires when the picker initialized.
26023 * @param {Roo.bootstrap.LocationPicker} this
26024 * @param {Google Location} location
26028 * @event positionchanged
26029 * Fires when the picker position changed.
26030 * @param {Roo.bootstrap.LocationPicker} this
26031 * @param {Google Location} location
26033 positionchanged : true,
26036 * Fires when the map resize.
26037 * @param {Roo.bootstrap.LocationPicker} this
26042 * Fires when the map show.
26043 * @param {Roo.bootstrap.LocationPicker} this
26048 * Fires when the map hide.
26049 * @param {Roo.bootstrap.LocationPicker} this
26054 * Fires when click the map.
26055 * @param {Roo.bootstrap.LocationPicker} this
26056 * @param {Map event} e
26060 * @event mapRightClick
26061 * Fires when right click the map.
26062 * @param {Roo.bootstrap.LocationPicker} this
26063 * @param {Map event} e
26065 mapRightClick : true,
26067 * @event markerClick
26068 * Fires when click the marker.
26069 * @param {Roo.bootstrap.LocationPicker} this
26070 * @param {Map event} e
26072 markerClick : true,
26074 * @event markerRightClick
26075 * Fires when right click the marker.
26076 * @param {Roo.bootstrap.LocationPicker} this
26077 * @param {Map event} e
26079 markerRightClick : true,
26081 * @event OverlayViewDraw
26082 * Fires when OverlayView Draw
26083 * @param {Roo.bootstrap.LocationPicker} this
26085 OverlayViewDraw : true,
26087 * @event OverlayViewOnAdd
26088 * Fires when OverlayView Draw
26089 * @param {Roo.bootstrap.LocationPicker} this
26091 OverlayViewOnAdd : true,
26093 * @event OverlayViewOnRemove
26094 * Fires when OverlayView Draw
26095 * @param {Roo.bootstrap.LocationPicker} this
26097 OverlayViewOnRemove : true,
26099 * @event OverlayViewShow
26100 * Fires when OverlayView Draw
26101 * @param {Roo.bootstrap.LocationPicker} this
26102 * @param {Pixel} cpx
26104 OverlayViewShow : true,
26106 * @event OverlayViewHide
26107 * Fires when OverlayView Draw
26108 * @param {Roo.bootstrap.LocationPicker} this
26110 OverlayViewHide : true,
26112 * @event loadexception
26113 * Fires when load google lib failed.
26114 * @param {Roo.bootstrap.LocationPicker} this
26116 loadexception : true
26121 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
26123 gMapContext: false,
26129 mapTypeControl: false,
26130 disableDoubleClickZoom: false,
26132 streetViewControl: false,
26136 enableAutocomplete: false,
26137 enableReverseGeocode: true,
26140 getAutoCreate: function()
26145 cls: 'roo-location-picker'
26151 initEvents: function(ct, position)
26153 if(!this.el.getWidth() || this.isApplied()){
26157 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26162 initial: function()
26164 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
26165 this.fireEvent('loadexception', this);
26169 if(!this.mapTypeId){
26170 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
26173 this.gMapContext = this.GMapContext();
26175 this.initOverlayView();
26177 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
26181 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
26182 _this.setPosition(_this.gMapContext.marker.position);
26185 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
26186 _this.fireEvent('mapClick', this, event);
26190 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
26191 _this.fireEvent('mapRightClick', this, event);
26195 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
26196 _this.fireEvent('markerClick', this, event);
26200 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
26201 _this.fireEvent('markerRightClick', this, event);
26205 this.setPosition(this.gMapContext.location);
26207 this.fireEvent('initial', this, this.gMapContext.location);
26210 initOverlayView: function()
26214 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
26218 _this.fireEvent('OverlayViewDraw', _this);
26223 _this.fireEvent('OverlayViewOnAdd', _this);
26226 onRemove: function()
26228 _this.fireEvent('OverlayViewOnRemove', _this);
26231 show: function(cpx)
26233 _this.fireEvent('OverlayViewShow', _this, cpx);
26238 _this.fireEvent('OverlayViewHide', _this);
26244 fromLatLngToContainerPixel: function(event)
26246 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
26249 isApplied: function()
26251 return this.getGmapContext() == false ? false : true;
26254 getGmapContext: function()
26256 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
26259 GMapContext: function()
26261 var position = new google.maps.LatLng(this.latitude, this.longitude);
26263 var _map = new google.maps.Map(this.el.dom, {
26266 mapTypeId: this.mapTypeId,
26267 mapTypeControl: this.mapTypeControl,
26268 disableDoubleClickZoom: this.disableDoubleClickZoom,
26269 scrollwheel: this.scrollwheel,
26270 streetViewControl: this.streetViewControl,
26271 locationName: this.locationName,
26272 draggable: this.draggable,
26273 enableAutocomplete: this.enableAutocomplete,
26274 enableReverseGeocode: this.enableReverseGeocode
26277 var _marker = new google.maps.Marker({
26278 position: position,
26280 title: this.markerTitle,
26281 draggable: this.draggable
26288 location: position,
26289 radius: this.radius,
26290 locationName: this.locationName,
26291 addressComponents: {
26292 formatted_address: null,
26293 addressLine1: null,
26294 addressLine2: null,
26296 streetNumber: null,
26300 stateOrProvince: null
26303 domContainer: this.el.dom,
26304 geodecoder: new google.maps.Geocoder()
26308 drawCircle: function(center, radius, options)
26310 if (this.gMapContext.circle != null) {
26311 this.gMapContext.circle.setMap(null);
26315 options = Roo.apply({}, options, {
26316 strokeColor: "#0000FF",
26317 strokeOpacity: .35,
26319 fillColor: "#0000FF",
26323 options.map = this.gMapContext.map;
26324 options.radius = radius;
26325 options.center = center;
26326 this.gMapContext.circle = new google.maps.Circle(options);
26327 return this.gMapContext.circle;
26333 setPosition: function(location)
26335 this.gMapContext.location = location;
26336 this.gMapContext.marker.setPosition(location);
26337 this.gMapContext.map.panTo(location);
26338 this.drawCircle(location, this.gMapContext.radius, {});
26342 if (this.gMapContext.settings.enableReverseGeocode) {
26343 this.gMapContext.geodecoder.geocode({
26344 latLng: this.gMapContext.location
26345 }, function(results, status) {
26347 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
26348 _this.gMapContext.locationName = results[0].formatted_address;
26349 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
26351 _this.fireEvent('positionchanged', this, location);
26358 this.fireEvent('positionchanged', this, location);
26363 google.maps.event.trigger(this.gMapContext.map, "resize");
26365 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
26367 this.fireEvent('resize', this);
26370 setPositionByLatLng: function(latitude, longitude)
26372 this.setPosition(new google.maps.LatLng(latitude, longitude));
26375 getCurrentPosition: function()
26378 latitude: this.gMapContext.location.lat(),
26379 longitude: this.gMapContext.location.lng()
26383 getAddressName: function()
26385 return this.gMapContext.locationName;
26388 getAddressComponents: function()
26390 return this.gMapContext.addressComponents;
26393 address_component_from_google_geocode: function(address_components)
26397 for (var i = 0; i < address_components.length; i++) {
26398 var component = address_components[i];
26399 if (component.types.indexOf("postal_code") >= 0) {
26400 result.postalCode = component.short_name;
26401 } else if (component.types.indexOf("street_number") >= 0) {
26402 result.streetNumber = component.short_name;
26403 } else if (component.types.indexOf("route") >= 0) {
26404 result.streetName = component.short_name;
26405 } else if (component.types.indexOf("neighborhood") >= 0) {
26406 result.city = component.short_name;
26407 } else if (component.types.indexOf("locality") >= 0) {
26408 result.city = component.short_name;
26409 } else if (component.types.indexOf("sublocality") >= 0) {
26410 result.district = component.short_name;
26411 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
26412 result.stateOrProvince = component.short_name;
26413 } else if (component.types.indexOf("country") >= 0) {
26414 result.country = component.short_name;
26418 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
26419 result.addressLine2 = "";
26423 setZoomLevel: function(zoom)
26425 this.gMapContext.map.setZoom(zoom);
26438 this.fireEvent('show', this);
26449 this.fireEvent('hide', this);
26454 Roo.apply(Roo.bootstrap.LocationPicker, {
26456 OverlayView : function(map, options)
26458 options = options || {};
26472 * @class Roo.bootstrap.Alert
26473 * @extends Roo.bootstrap.Component
26474 * Bootstrap Alert class
26475 * @cfg {String} title The title of alert
26476 * @cfg {String} html The content of alert
26477 * @cfg {String} weight ( success | info | warning | danger )
26478 * @cfg {String} faicon font-awesomeicon
26481 * Create a new alert
26482 * @param {Object} config The config object
26486 Roo.bootstrap.Alert = function(config){
26487 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
26491 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
26498 getAutoCreate : function()
26507 cls : 'roo-alert-icon'
26512 cls : 'roo-alert-title',
26517 cls : 'roo-alert-text',
26524 cfg.cn[0].cls += ' fa ' + this.faicon;
26528 cfg.cls += ' alert-' + this.weight;
26534 initEvents: function()
26536 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26539 setTitle : function(str)
26541 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
26544 setText : function(str)
26546 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
26549 setWeight : function(weight)
26552 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
26555 this.weight = weight;
26557 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
26560 setIcon : function(icon)
26563 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
26566 this.faicon = icon;
26568 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
26589 * @class Roo.bootstrap.UploadCropbox
26590 * @extends Roo.bootstrap.Component
26591 * Bootstrap UploadCropbox class
26592 * @cfg {String} emptyText show when image has been loaded
26593 * @cfg {String} rotateNotify show when image too small to rotate
26594 * @cfg {Number} errorTimeout default 3000
26595 * @cfg {Number} minWidth default 300
26596 * @cfg {Number} minHeight default 300
26597 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
26598 * @cfg {Boolean} isDocument (true|false) default false
26599 * @cfg {String} url action url
26600 * @cfg {String} paramName default 'imageUpload'
26601 * @cfg {String} method default POST
26602 * @cfg {Boolean} loadMask (true|false) default true
26603 * @cfg {Boolean} loadingText default 'Loading...'
26606 * Create a new UploadCropbox
26607 * @param {Object} config The config object
26610 Roo.bootstrap.UploadCropbox = function(config){
26611 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
26615 * @event beforeselectfile
26616 * Fire before select file
26617 * @param {Roo.bootstrap.UploadCropbox} this
26619 "beforeselectfile" : true,
26622 * Fire after initEvent
26623 * @param {Roo.bootstrap.UploadCropbox} this
26628 * Fire after initEvent
26629 * @param {Roo.bootstrap.UploadCropbox} this
26630 * @param {String} data
26635 * Fire when preparing the file data
26636 * @param {Roo.bootstrap.UploadCropbox} this
26637 * @param {Object} file
26642 * Fire when get exception
26643 * @param {Roo.bootstrap.UploadCropbox} this
26644 * @param {XMLHttpRequest} xhr
26646 "exception" : true,
26648 * @event beforeloadcanvas
26649 * Fire before load the canvas
26650 * @param {Roo.bootstrap.UploadCropbox} this
26651 * @param {String} src
26653 "beforeloadcanvas" : true,
26656 * Fire when trash image
26657 * @param {Roo.bootstrap.UploadCropbox} this
26662 * Fire when download the image
26663 * @param {Roo.bootstrap.UploadCropbox} this
26667 * @event footerbuttonclick
26668 * Fire when footerbuttonclick
26669 * @param {Roo.bootstrap.UploadCropbox} this
26670 * @param {String} type
26672 "footerbuttonclick" : true,
26676 * @param {Roo.bootstrap.UploadCropbox} this
26681 * Fire when rotate the image
26682 * @param {Roo.bootstrap.UploadCropbox} this
26683 * @param {String} pos
26688 * Fire when inspect the file
26689 * @param {Roo.bootstrap.UploadCropbox} this
26690 * @param {Object} file
26695 * Fire when xhr upload the file
26696 * @param {Roo.bootstrap.UploadCropbox} this
26697 * @param {Object} data
26702 * Fire when arrange the file data
26703 * @param {Roo.bootstrap.UploadCropbox} this
26704 * @param {Object} formData
26709 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
26712 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
26714 emptyText : 'Click to upload image',
26715 rotateNotify : 'Image is too small to rotate',
26716 errorTimeout : 3000,
26730 cropType : 'image/jpeg',
26732 canvasLoaded : false,
26733 isDocument : false,
26735 paramName : 'imageUpload',
26737 loadingText : 'Loading...',
26740 getAutoCreate : function()
26744 cls : 'roo-upload-cropbox',
26748 cls : 'roo-upload-cropbox-selector',
26753 cls : 'roo-upload-cropbox-body',
26754 style : 'cursor:pointer',
26758 cls : 'roo-upload-cropbox-preview'
26762 cls : 'roo-upload-cropbox-thumb'
26766 cls : 'roo-upload-cropbox-empty-notify',
26767 html : this.emptyText
26771 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
26772 html : this.rotateNotify
26778 cls : 'roo-upload-cropbox-footer',
26781 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
26791 onRender : function(ct, position)
26793 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
26795 if (this.buttons.length) {
26797 Roo.each(this.buttons, function(bb) {
26799 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
26801 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
26807 this.maskEl = this.el;
26811 initEvents : function()
26813 this.urlAPI = (window.createObjectURL && window) ||
26814 (window.URL && URL.revokeObjectURL && URL) ||
26815 (window.webkitURL && webkitURL);
26817 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
26818 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26820 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
26821 this.selectorEl.hide();
26823 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
26824 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26826 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
26827 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26828 this.thumbEl.hide();
26830 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
26831 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26833 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
26834 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26835 this.errorEl.hide();
26837 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
26838 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
26839 this.footerEl.hide();
26841 this.setThumbBoxSize();
26847 this.fireEvent('initial', this);
26854 window.addEventListener("resize", function() { _this.resize(); } );
26856 this.bodyEl.on('click', this.beforeSelectFile, this);
26859 this.bodyEl.on('touchstart', this.onTouchStart, this);
26860 this.bodyEl.on('touchmove', this.onTouchMove, this);
26861 this.bodyEl.on('touchend', this.onTouchEnd, this);
26865 this.bodyEl.on('mousedown', this.onMouseDown, this);
26866 this.bodyEl.on('mousemove', this.onMouseMove, this);
26867 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
26868 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
26869 Roo.get(document).on('mouseup', this.onMouseUp, this);
26872 this.selectorEl.on('change', this.onFileSelected, this);
26878 this.baseScale = 1;
26880 this.baseRotate = 1;
26881 this.dragable = false;
26882 this.pinching = false;
26885 this.cropData = false;
26886 this.notifyEl.dom.innerHTML = this.emptyText;
26888 this.selectorEl.dom.value = '';
26892 resize : function()
26894 if(this.fireEvent('resize', this) != false){
26895 this.setThumbBoxPosition();
26896 this.setCanvasPosition();
26900 onFooterButtonClick : function(e, el, o, type)
26903 case 'rotate-left' :
26904 this.onRotateLeft(e);
26906 case 'rotate-right' :
26907 this.onRotateRight(e);
26910 this.beforeSelectFile(e);
26925 this.fireEvent('footerbuttonclick', this, type);
26928 beforeSelectFile : function(e)
26930 e.preventDefault();
26932 if(this.fireEvent('beforeselectfile', this) != false){
26933 this.selectorEl.dom.click();
26937 onFileSelected : function(e)
26939 e.preventDefault();
26941 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
26945 var file = this.selectorEl.dom.files[0];
26947 if(this.fireEvent('inspect', this, file) != false){
26948 this.prepare(file);
26953 trash : function(e)
26955 this.fireEvent('trash', this);
26958 download : function(e)
26960 this.fireEvent('download', this);
26963 loadCanvas : function(src)
26965 if(this.fireEvent('beforeloadcanvas', this, src) != false){
26969 this.imageEl = document.createElement('img');
26973 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
26975 this.imageEl.src = src;
26979 onLoadCanvas : function()
26981 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
26982 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
26984 this.bodyEl.un('click', this.beforeSelectFile, this);
26986 this.notifyEl.hide();
26987 this.thumbEl.show();
26988 this.footerEl.show();
26990 this.baseRotateLevel();
26992 if(this.isDocument){
26993 this.setThumbBoxSize();
26996 this.setThumbBoxPosition();
26998 this.baseScaleLevel();
27004 this.canvasLoaded = true;
27007 this.maskEl.unmask();
27012 setCanvasPosition : function()
27014 if(!this.canvasEl){
27018 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
27019 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
27021 this.previewEl.setLeft(pw);
27022 this.previewEl.setTop(ph);
27026 onMouseDown : function(e)
27030 this.dragable = true;
27031 this.pinching = false;
27033 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
27034 this.dragable = false;
27038 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27039 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27043 onMouseMove : function(e)
27047 if(!this.canvasLoaded){
27051 if (!this.dragable){
27055 var minX = Math.ceil(this.thumbEl.getLeft(true));
27056 var minY = Math.ceil(this.thumbEl.getTop(true));
27058 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
27059 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
27061 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27062 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27064 x = x - this.mouseX;
27065 y = y - this.mouseY;
27067 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
27068 var bgY = Math.ceil(y + this.previewEl.getTop(true));
27070 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
27071 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
27073 this.previewEl.setLeft(bgX);
27074 this.previewEl.setTop(bgY);
27076 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27077 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27080 onMouseUp : function(e)
27084 this.dragable = false;
27087 onMouseWheel : function(e)
27091 this.startScale = this.scale;
27093 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
27095 if(!this.zoomable()){
27096 this.scale = this.startScale;
27105 zoomable : function()
27107 var minScale = this.thumbEl.getWidth() / this.minWidth;
27109 if(this.minWidth < this.minHeight){
27110 minScale = this.thumbEl.getHeight() / this.minHeight;
27113 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
27114 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
27118 (this.rotate == 0 || this.rotate == 180) &&
27120 width > this.imageEl.OriginWidth ||
27121 height > this.imageEl.OriginHeight ||
27122 (width < this.minWidth && height < this.minHeight)
27130 (this.rotate == 90 || this.rotate == 270) &&
27132 width > this.imageEl.OriginWidth ||
27133 height > this.imageEl.OriginHeight ||
27134 (width < this.minHeight && height < this.minWidth)
27141 !this.isDocument &&
27142 (this.rotate == 0 || this.rotate == 180) &&
27144 width < this.minWidth ||
27145 width > this.imageEl.OriginWidth ||
27146 height < this.minHeight ||
27147 height > this.imageEl.OriginHeight
27154 !this.isDocument &&
27155 (this.rotate == 90 || this.rotate == 270) &&
27157 width < this.minHeight ||
27158 width > this.imageEl.OriginWidth ||
27159 height < this.minWidth ||
27160 height > this.imageEl.OriginHeight
27170 onRotateLeft : function(e)
27172 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27174 var minScale = this.thumbEl.getWidth() / this.minWidth;
27176 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27177 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27179 this.startScale = this.scale;
27181 while (this.getScaleLevel() < minScale){
27183 this.scale = this.scale + 1;
27185 if(!this.zoomable()){
27190 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27191 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27196 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27203 this.scale = this.startScale;
27205 this.onRotateFail();
27210 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27212 if(this.isDocument){
27213 this.setThumbBoxSize();
27214 this.setThumbBoxPosition();
27215 this.setCanvasPosition();
27220 this.fireEvent('rotate', this, 'left');
27224 onRotateRight : function(e)
27226 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27228 var minScale = this.thumbEl.getWidth() / this.minWidth;
27230 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27231 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27233 this.startScale = this.scale;
27235 while (this.getScaleLevel() < minScale){
27237 this.scale = this.scale + 1;
27239 if(!this.zoomable()){
27244 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27245 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27250 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27257 this.scale = this.startScale;
27259 this.onRotateFail();
27264 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27266 if(this.isDocument){
27267 this.setThumbBoxSize();
27268 this.setThumbBoxPosition();
27269 this.setCanvasPosition();
27274 this.fireEvent('rotate', this, 'right');
27277 onRotateFail : function()
27279 this.errorEl.show(true);
27283 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
27288 this.previewEl.dom.innerHTML = '';
27290 var canvasEl = document.createElement("canvas");
27292 var contextEl = canvasEl.getContext("2d");
27294 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27295 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27296 var center = this.imageEl.OriginWidth / 2;
27298 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
27299 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27300 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27301 center = this.imageEl.OriginHeight / 2;
27304 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
27306 contextEl.translate(center, center);
27307 contextEl.rotate(this.rotate * Math.PI / 180);
27309 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27311 this.canvasEl = document.createElement("canvas");
27313 this.contextEl = this.canvasEl.getContext("2d");
27315 switch (this.rotate) {
27318 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27319 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27321 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27326 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27327 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27329 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27330 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);
27334 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27339 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27340 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27342 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27343 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);
27347 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);
27352 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27353 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27355 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27356 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27360 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);
27367 this.previewEl.appendChild(this.canvasEl);
27369 this.setCanvasPosition();
27374 if(!this.canvasLoaded){
27378 var imageCanvas = document.createElement("canvas");
27380 var imageContext = imageCanvas.getContext("2d");
27382 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27383 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27385 var center = imageCanvas.width / 2;
27387 imageContext.translate(center, center);
27389 imageContext.rotate(this.rotate * Math.PI / 180);
27391 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27393 var canvas = document.createElement("canvas");
27395 var context = canvas.getContext("2d");
27397 canvas.width = this.minWidth;
27398 canvas.height = this.minHeight;
27400 switch (this.rotate) {
27403 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27404 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27406 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27407 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27409 var targetWidth = this.minWidth - 2 * x;
27410 var targetHeight = this.minHeight - 2 * y;
27414 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27415 scale = targetWidth / width;
27418 if(x > 0 && y == 0){
27419 scale = targetHeight / height;
27422 if(x > 0 && y > 0){
27423 scale = targetWidth / width;
27425 if(width < height){
27426 scale = targetHeight / height;
27430 context.scale(scale, scale);
27432 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27433 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27435 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27436 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27438 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27443 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27444 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27446 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27447 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27449 var targetWidth = this.minWidth - 2 * x;
27450 var targetHeight = this.minHeight - 2 * y;
27454 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27455 scale = targetWidth / width;
27458 if(x > 0 && y == 0){
27459 scale = targetHeight / height;
27462 if(x > 0 && y > 0){
27463 scale = targetWidth / width;
27465 if(width < height){
27466 scale = targetHeight / height;
27470 context.scale(scale, scale);
27472 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27473 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27475 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27476 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27478 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27480 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27485 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27486 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27488 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27489 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27491 var targetWidth = this.minWidth - 2 * x;
27492 var targetHeight = this.minHeight - 2 * y;
27496 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27497 scale = targetWidth / width;
27500 if(x > 0 && y == 0){
27501 scale = targetHeight / height;
27504 if(x > 0 && y > 0){
27505 scale = targetWidth / width;
27507 if(width < height){
27508 scale = targetHeight / height;
27512 context.scale(scale, scale);
27514 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27515 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27517 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27518 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27520 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27521 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27523 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27528 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27529 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27531 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27532 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27534 var targetWidth = this.minWidth - 2 * x;
27535 var targetHeight = this.minHeight - 2 * y;
27539 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27540 scale = targetWidth / width;
27543 if(x > 0 && y == 0){
27544 scale = targetHeight / height;
27547 if(x > 0 && y > 0){
27548 scale = targetWidth / width;
27550 if(width < height){
27551 scale = targetHeight / height;
27555 context.scale(scale, scale);
27557 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27558 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27560 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27561 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27563 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27565 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27572 this.cropData = canvas.toDataURL(this.cropType);
27574 if(this.fireEvent('crop', this, this.cropData) !== false){
27575 this.process(this.file, this.cropData);
27582 setThumbBoxSize : function()
27586 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
27587 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
27588 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
27590 this.minWidth = width;
27591 this.minHeight = height;
27593 if(this.rotate == 90 || this.rotate == 270){
27594 this.minWidth = height;
27595 this.minHeight = width;
27600 width = Math.ceil(this.minWidth * height / this.minHeight);
27602 if(this.minWidth > this.minHeight){
27604 height = Math.ceil(this.minHeight * width / this.minWidth);
27607 this.thumbEl.setStyle({
27608 width : width + 'px',
27609 height : height + 'px'
27616 setThumbBoxPosition : function()
27618 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
27619 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
27621 this.thumbEl.setLeft(x);
27622 this.thumbEl.setTop(y);
27626 baseRotateLevel : function()
27628 this.baseRotate = 1;
27631 typeof(this.exif) != 'undefined' &&
27632 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
27633 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
27635 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
27638 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
27642 baseScaleLevel : function()
27646 if(this.isDocument){
27648 if(this.baseRotate == 6 || this.baseRotate == 8){
27650 height = this.thumbEl.getHeight();
27651 this.baseScale = height / this.imageEl.OriginWidth;
27653 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
27654 width = this.thumbEl.getWidth();
27655 this.baseScale = width / this.imageEl.OriginHeight;
27661 height = this.thumbEl.getHeight();
27662 this.baseScale = height / this.imageEl.OriginHeight;
27664 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
27665 width = this.thumbEl.getWidth();
27666 this.baseScale = width / this.imageEl.OriginWidth;
27672 if(this.baseRotate == 6 || this.baseRotate == 8){
27674 width = this.thumbEl.getHeight();
27675 this.baseScale = width / this.imageEl.OriginHeight;
27677 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
27678 height = this.thumbEl.getWidth();
27679 this.baseScale = height / this.imageEl.OriginHeight;
27682 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27683 height = this.thumbEl.getWidth();
27684 this.baseScale = height / this.imageEl.OriginHeight;
27686 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
27687 width = this.thumbEl.getHeight();
27688 this.baseScale = width / this.imageEl.OriginWidth;
27695 width = this.thumbEl.getWidth();
27696 this.baseScale = width / this.imageEl.OriginWidth;
27698 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
27699 height = this.thumbEl.getHeight();
27700 this.baseScale = height / this.imageEl.OriginHeight;
27703 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27705 height = this.thumbEl.getHeight();
27706 this.baseScale = height / this.imageEl.OriginHeight;
27708 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
27709 width = this.thumbEl.getWidth();
27710 this.baseScale = width / this.imageEl.OriginWidth;
27718 getScaleLevel : function()
27720 return this.baseScale * Math.pow(1.1, this.scale);
27723 onTouchStart : function(e)
27725 if(!this.canvasLoaded){
27726 this.beforeSelectFile(e);
27730 var touches = e.browserEvent.touches;
27736 if(touches.length == 1){
27737 this.onMouseDown(e);
27741 if(touches.length != 2){
27747 for(var i = 0, finger; finger = touches[i]; i++){
27748 coords.push(finger.pageX, finger.pageY);
27751 var x = Math.pow(coords[0] - coords[2], 2);
27752 var y = Math.pow(coords[1] - coords[3], 2);
27754 this.startDistance = Math.sqrt(x + y);
27756 this.startScale = this.scale;
27758 this.pinching = true;
27759 this.dragable = false;
27763 onTouchMove : function(e)
27765 if(!this.pinching && !this.dragable){
27769 var touches = e.browserEvent.touches;
27776 this.onMouseMove(e);
27782 for(var i = 0, finger; finger = touches[i]; i++){
27783 coords.push(finger.pageX, finger.pageY);
27786 var x = Math.pow(coords[0] - coords[2], 2);
27787 var y = Math.pow(coords[1] - coords[3], 2);
27789 this.endDistance = Math.sqrt(x + y);
27791 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
27793 if(!this.zoomable()){
27794 this.scale = this.startScale;
27802 onTouchEnd : function(e)
27804 this.pinching = false;
27805 this.dragable = false;
27809 process : function(file, crop)
27812 this.maskEl.mask(this.loadingText);
27815 this.xhr = new XMLHttpRequest();
27817 file.xhr = this.xhr;
27819 this.xhr.open(this.method, this.url, true);
27822 "Accept": "application/json",
27823 "Cache-Control": "no-cache",
27824 "X-Requested-With": "XMLHttpRequest"
27827 for (var headerName in headers) {
27828 var headerValue = headers[headerName];
27830 this.xhr.setRequestHeader(headerName, headerValue);
27836 this.xhr.onload = function()
27838 _this.xhrOnLoad(_this.xhr);
27841 this.xhr.onerror = function()
27843 _this.xhrOnError(_this.xhr);
27846 var formData = new FormData();
27848 formData.append('returnHTML', 'NO');
27851 formData.append('crop', crop);
27854 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
27855 formData.append(this.paramName, file, file.name);
27858 if(typeof(file.filename) != 'undefined'){
27859 formData.append('filename', file.filename);
27862 if(typeof(file.mimetype) != 'undefined'){
27863 formData.append('mimetype', file.mimetype);
27866 if(this.fireEvent('arrange', this, formData) != false){
27867 this.xhr.send(formData);
27871 xhrOnLoad : function(xhr)
27874 this.maskEl.unmask();
27877 if (xhr.readyState !== 4) {
27878 this.fireEvent('exception', this, xhr);
27882 var response = Roo.decode(xhr.responseText);
27884 if(!response.success){
27885 this.fireEvent('exception', this, xhr);
27889 var response = Roo.decode(xhr.responseText);
27891 this.fireEvent('upload', this, response);
27895 xhrOnError : function()
27898 this.maskEl.unmask();
27901 Roo.log('xhr on error');
27903 var response = Roo.decode(xhr.responseText);
27909 prepare : function(file)
27912 this.maskEl.mask(this.loadingText);
27918 if(typeof(file) === 'string'){
27919 this.loadCanvas(file);
27923 if(!file || !this.urlAPI){
27928 this.cropType = file.type;
27932 if(this.fireEvent('prepare', this, this.file) != false){
27934 var reader = new FileReader();
27936 reader.onload = function (e) {
27937 if (e.target.error) {
27938 Roo.log(e.target.error);
27942 var buffer = e.target.result,
27943 dataView = new DataView(buffer),
27945 maxOffset = dataView.byteLength - 4,
27949 if (dataView.getUint16(0) === 0xffd8) {
27950 while (offset < maxOffset) {
27951 markerBytes = dataView.getUint16(offset);
27953 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
27954 markerLength = dataView.getUint16(offset + 2) + 2;
27955 if (offset + markerLength > dataView.byteLength) {
27956 Roo.log('Invalid meta data: Invalid segment size.');
27960 if(markerBytes == 0xffe1){
27961 _this.parseExifData(
27968 offset += markerLength;
27978 var url = _this.urlAPI.createObjectURL(_this.file);
27980 _this.loadCanvas(url);
27985 reader.readAsArrayBuffer(this.file);
27991 parseExifData : function(dataView, offset, length)
27993 var tiffOffset = offset + 10,
27997 if (dataView.getUint32(offset + 4) !== 0x45786966) {
27998 // No Exif data, might be XMP data instead
28002 // Check for the ASCII code for "Exif" (0x45786966):
28003 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28004 // No Exif data, might be XMP data instead
28007 if (tiffOffset + 8 > dataView.byteLength) {
28008 Roo.log('Invalid Exif data: Invalid segment size.');
28011 // Check for the two null bytes:
28012 if (dataView.getUint16(offset + 8) !== 0x0000) {
28013 Roo.log('Invalid Exif data: Missing byte alignment offset.');
28016 // Check the byte alignment:
28017 switch (dataView.getUint16(tiffOffset)) {
28019 littleEndian = true;
28022 littleEndian = false;
28025 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
28028 // Check for the TIFF tag marker (0x002A):
28029 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
28030 Roo.log('Invalid Exif data: Missing TIFF marker.');
28033 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
28034 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
28036 this.parseExifTags(
28039 tiffOffset + dirOffset,
28044 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
28049 if (dirOffset + 6 > dataView.byteLength) {
28050 Roo.log('Invalid Exif data: Invalid directory offset.');
28053 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
28054 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
28055 if (dirEndOffset + 4 > dataView.byteLength) {
28056 Roo.log('Invalid Exif data: Invalid directory size.');
28059 for (i = 0; i < tagsNumber; i += 1) {
28063 dirOffset + 2 + 12 * i, // tag offset
28067 // Return the offset to the next directory:
28068 return dataView.getUint32(dirEndOffset, littleEndian);
28071 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
28073 var tag = dataView.getUint16(offset, littleEndian);
28075 this.exif[tag] = this.getExifValue(
28079 dataView.getUint16(offset + 2, littleEndian), // tag type
28080 dataView.getUint32(offset + 4, littleEndian), // tag length
28085 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
28087 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
28096 Roo.log('Invalid Exif data: Invalid tag type.');
28100 tagSize = tagType.size * length;
28101 // Determine if the value is contained in the dataOffset bytes,
28102 // or if the value at the dataOffset is a pointer to the actual data:
28103 dataOffset = tagSize > 4 ?
28104 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
28105 if (dataOffset + tagSize > dataView.byteLength) {
28106 Roo.log('Invalid Exif data: Invalid data offset.');
28109 if (length === 1) {
28110 return tagType.getValue(dataView, dataOffset, littleEndian);
28113 for (i = 0; i < length; i += 1) {
28114 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
28117 if (tagType.ascii) {
28119 // Concatenate the chars:
28120 for (i = 0; i < values.length; i += 1) {
28122 // Ignore the terminating NULL byte(s):
28123 if (c === '\u0000') {
28135 Roo.apply(Roo.bootstrap.UploadCropbox, {
28137 'Orientation': 0x0112
28141 1: 0, //'top-left',
28143 3: 180, //'bottom-right',
28144 // 4: 'bottom-left',
28146 6: 90, //'right-top',
28147 // 7: 'right-bottom',
28148 8: 270 //'left-bottom'
28152 // byte, 8-bit unsigned int:
28154 getValue: function (dataView, dataOffset) {
28155 return dataView.getUint8(dataOffset);
28159 // ascii, 8-bit byte:
28161 getValue: function (dataView, dataOffset) {
28162 return String.fromCharCode(dataView.getUint8(dataOffset));
28167 // short, 16 bit int:
28169 getValue: function (dataView, dataOffset, littleEndian) {
28170 return dataView.getUint16(dataOffset, littleEndian);
28174 // long, 32 bit int:
28176 getValue: function (dataView, dataOffset, littleEndian) {
28177 return dataView.getUint32(dataOffset, littleEndian);
28181 // rational = two long values, first is numerator, second is denominator:
28183 getValue: function (dataView, dataOffset, littleEndian) {
28184 return dataView.getUint32(dataOffset, littleEndian) /
28185 dataView.getUint32(dataOffset + 4, littleEndian);
28189 // slong, 32 bit signed int:
28191 getValue: function (dataView, dataOffset, littleEndian) {
28192 return dataView.getInt32(dataOffset, littleEndian);
28196 // srational, two slongs, first is numerator, second is denominator:
28198 getValue: function (dataView, dataOffset, littleEndian) {
28199 return dataView.getInt32(dataOffset, littleEndian) /
28200 dataView.getInt32(dataOffset + 4, littleEndian);
28210 cls : 'btn-group roo-upload-cropbox-rotate-left',
28211 action : 'rotate-left',
28215 cls : 'btn btn-default',
28216 html : '<i class="fa fa-undo"></i>'
28222 cls : 'btn-group roo-upload-cropbox-picture',
28223 action : 'picture',
28227 cls : 'btn btn-default',
28228 html : '<i class="fa fa-picture-o"></i>'
28234 cls : 'btn-group roo-upload-cropbox-rotate-right',
28235 action : 'rotate-right',
28239 cls : 'btn btn-default',
28240 html : '<i class="fa fa-repeat"></i>'
28248 cls : 'btn-group roo-upload-cropbox-rotate-left',
28249 action : 'rotate-left',
28253 cls : 'btn btn-default',
28254 html : '<i class="fa fa-undo"></i>'
28260 cls : 'btn-group roo-upload-cropbox-download',
28261 action : 'download',
28265 cls : 'btn btn-default',
28266 html : '<i class="fa fa-download"></i>'
28272 cls : 'btn-group roo-upload-cropbox-crop',
28277 cls : 'btn btn-default',
28278 html : '<i class="fa fa-crop"></i>'
28284 cls : 'btn-group roo-upload-cropbox-trash',
28289 cls : 'btn btn-default',
28290 html : '<i class="fa fa-trash"></i>'
28296 cls : 'btn-group roo-upload-cropbox-rotate-right',
28297 action : 'rotate-right',
28301 cls : 'btn btn-default',
28302 html : '<i class="fa fa-repeat"></i>'
28310 cls : 'btn-group roo-upload-cropbox-rotate-left',
28311 action : 'rotate-left',
28315 cls : 'btn btn-default',
28316 html : '<i class="fa fa-undo"></i>'
28322 cls : 'btn-group roo-upload-cropbox-rotate-right',
28323 action : 'rotate-right',
28327 cls : 'btn btn-default',
28328 html : '<i class="fa fa-repeat"></i>'
28341 * @class Roo.bootstrap.DocumentManager
28342 * @extends Roo.bootstrap.Component
28343 * Bootstrap DocumentManager class
28344 * @cfg {String} paramName default 'imageUpload'
28345 * @cfg {String} toolTipName default 'filename'
28346 * @cfg {String} method default POST
28347 * @cfg {String} url action url
28348 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
28349 * @cfg {Boolean} multiple multiple upload default true
28350 * @cfg {Number} thumbSize default 300
28351 * @cfg {String} fieldLabel
28352 * @cfg {Number} labelWidth default 4
28353 * @cfg {String} labelAlign (left|top) default left
28354 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
28355 * @cfg {Number} labellg set the width of label (1-12)
28356 * @cfg {Number} labelmd set the width of label (1-12)
28357 * @cfg {Number} labelsm set the width of label (1-12)
28358 * @cfg {Number} labelxs set the width of label (1-12)
28361 * Create a new DocumentManager
28362 * @param {Object} config The config object
28365 Roo.bootstrap.DocumentManager = function(config){
28366 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
28369 this.delegates = [];
28374 * Fire when initial the DocumentManager
28375 * @param {Roo.bootstrap.DocumentManager} this
28380 * inspect selected file
28381 * @param {Roo.bootstrap.DocumentManager} this
28382 * @param {File} file
28387 * Fire when xhr load exception
28388 * @param {Roo.bootstrap.DocumentManager} this
28389 * @param {XMLHttpRequest} xhr
28391 "exception" : true,
28393 * @event afterupload
28394 * Fire when xhr load exception
28395 * @param {Roo.bootstrap.DocumentManager} this
28396 * @param {XMLHttpRequest} xhr
28398 "afterupload" : true,
28401 * prepare the form data
28402 * @param {Roo.bootstrap.DocumentManager} this
28403 * @param {Object} formData
28408 * Fire when remove the file
28409 * @param {Roo.bootstrap.DocumentManager} this
28410 * @param {Object} file
28415 * Fire after refresh the file
28416 * @param {Roo.bootstrap.DocumentManager} this
28421 * Fire after click the image
28422 * @param {Roo.bootstrap.DocumentManager} this
28423 * @param {Object} file
28428 * Fire when upload a image and editable set to true
28429 * @param {Roo.bootstrap.DocumentManager} this
28430 * @param {Object} file
28434 * @event beforeselectfile
28435 * Fire before select file
28436 * @param {Roo.bootstrap.DocumentManager} this
28438 "beforeselectfile" : true,
28441 * Fire before process file
28442 * @param {Roo.bootstrap.DocumentManager} this
28443 * @param {Object} file
28447 * @event previewrendered
28448 * Fire when preview rendered
28449 * @param {Roo.bootstrap.DocumentManager} this
28450 * @param {Object} file
28452 "previewrendered" : true
28457 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
28466 paramName : 'imageUpload',
28467 toolTipName : 'filename',
28470 labelAlign : 'left',
28480 getAutoCreate : function()
28482 var managerWidget = {
28484 cls : 'roo-document-manager',
28488 cls : 'roo-document-manager-selector',
28493 cls : 'roo-document-manager-uploader',
28497 cls : 'roo-document-manager-upload-btn',
28498 html : '<i class="fa fa-plus"></i>'
28509 cls : 'column col-md-12',
28514 if(this.fieldLabel.length){
28519 cls : 'column col-md-12',
28520 html : this.fieldLabel
28524 cls : 'column col-md-12',
28529 if(this.labelAlign == 'left'){
28534 html : this.fieldLabel
28543 if(this.labelWidth > 12){
28544 content[0].style = "width: " + this.labelWidth + 'px';
28547 if(this.labelWidth < 13 && this.labelmd == 0){
28548 this.labelmd = this.labelWidth;
28551 if(this.labellg > 0){
28552 content[0].cls += ' col-lg-' + this.labellg;
28553 content[1].cls += ' col-lg-' + (12 - this.labellg);
28556 if(this.labelmd > 0){
28557 content[0].cls += ' col-md-' + this.labelmd;
28558 content[1].cls += ' col-md-' + (12 - this.labelmd);
28561 if(this.labelsm > 0){
28562 content[0].cls += ' col-sm-' + this.labelsm;
28563 content[1].cls += ' col-sm-' + (12 - this.labelsm);
28566 if(this.labelxs > 0){
28567 content[0].cls += ' col-xs-' + this.labelxs;
28568 content[1].cls += ' col-xs-' + (12 - this.labelxs);
28576 cls : 'row clearfix',
28584 initEvents : function()
28586 this.managerEl = this.el.select('.roo-document-manager', true).first();
28587 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28589 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
28590 this.selectorEl.hide();
28593 this.selectorEl.attr('multiple', 'multiple');
28596 this.selectorEl.on('change', this.onFileSelected, this);
28598 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
28599 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28601 this.uploader.on('click', this.onUploaderClick, this);
28603 this.renderProgressDialog();
28607 window.addEventListener("resize", function() { _this.refresh(); } );
28609 this.fireEvent('initial', this);
28612 renderProgressDialog : function()
28616 this.progressDialog = new Roo.bootstrap.Modal({
28617 cls : 'roo-document-manager-progress-dialog',
28618 allow_close : false,
28628 btnclick : function() {
28629 _this.uploadCancel();
28635 this.progressDialog.render(Roo.get(document.body));
28637 this.progress = new Roo.bootstrap.Progress({
28638 cls : 'roo-document-manager-progress',
28643 this.progress.render(this.progressDialog.getChildContainer());
28645 this.progressBar = new Roo.bootstrap.ProgressBar({
28646 cls : 'roo-document-manager-progress-bar',
28649 aria_valuemax : 12,
28653 this.progressBar.render(this.progress.getChildContainer());
28656 onUploaderClick : function(e)
28658 e.preventDefault();
28660 if(this.fireEvent('beforeselectfile', this) != false){
28661 this.selectorEl.dom.click();
28666 onFileSelected : function(e)
28668 e.preventDefault();
28670 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
28674 Roo.each(this.selectorEl.dom.files, function(file){
28675 if(this.fireEvent('inspect', this, file) != false){
28676 this.files.push(file);
28686 this.selectorEl.dom.value = '';
28688 if(!this.files || !this.files.length){
28692 if(this.boxes > 0 && this.files.length > this.boxes){
28693 this.files = this.files.slice(0, this.boxes);
28696 this.uploader.show();
28698 if(this.boxes > 0 && this.files.length > this.boxes - 1){
28699 this.uploader.hide();
28708 Roo.each(this.files, function(file){
28710 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
28711 var f = this.renderPreview(file);
28716 if(file.type.indexOf('image') != -1){
28717 this.delegates.push(
28719 _this.process(file);
28720 }).createDelegate(this)
28728 _this.process(file);
28729 }).createDelegate(this)
28734 this.files = files;
28736 this.delegates = this.delegates.concat(docs);
28738 if(!this.delegates.length){
28743 this.progressBar.aria_valuemax = this.delegates.length;
28750 arrange : function()
28752 if(!this.delegates.length){
28753 this.progressDialog.hide();
28758 var delegate = this.delegates.shift();
28760 this.progressDialog.show();
28762 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
28764 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
28769 refresh : function()
28771 this.uploader.show();
28773 if(this.boxes > 0 && this.files.length > this.boxes - 1){
28774 this.uploader.hide();
28777 Roo.isTouch ? this.closable(false) : this.closable(true);
28779 this.fireEvent('refresh', this);
28782 onRemove : function(e, el, o)
28784 e.preventDefault();
28786 this.fireEvent('remove', this, o);
28790 remove : function(o)
28794 Roo.each(this.files, function(file){
28795 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
28804 this.files = files;
28811 Roo.each(this.files, function(file){
28816 file.target.remove();
28825 onClick : function(e, el, o)
28827 e.preventDefault();
28829 this.fireEvent('click', this, o);
28833 closable : function(closable)
28835 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
28837 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28849 xhrOnLoad : function(xhr)
28851 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
28855 if (xhr.readyState !== 4) {
28857 this.fireEvent('exception', this, xhr);
28861 var response = Roo.decode(xhr.responseText);
28863 if(!response.success){
28865 this.fireEvent('exception', this, xhr);
28869 var file = this.renderPreview(response.data);
28871 this.files.push(file);
28875 this.fireEvent('afterupload', this, xhr);
28879 xhrOnError : function(xhr)
28881 Roo.log('xhr on error');
28883 var response = Roo.decode(xhr.responseText);
28890 process : function(file)
28892 if(this.fireEvent('process', this, file) !== false){
28893 if(this.editable && file.type.indexOf('image') != -1){
28894 this.fireEvent('edit', this, file);
28898 this.uploadStart(file, false);
28905 uploadStart : function(file, crop)
28907 this.xhr = new XMLHttpRequest();
28909 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
28914 file.xhr = this.xhr;
28916 this.managerEl.createChild({
28918 cls : 'roo-document-manager-loading',
28922 tooltip : file.name,
28923 cls : 'roo-document-manager-thumb',
28924 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
28930 this.xhr.open(this.method, this.url, true);
28933 "Accept": "application/json",
28934 "Cache-Control": "no-cache",
28935 "X-Requested-With": "XMLHttpRequest"
28938 for (var headerName in headers) {
28939 var headerValue = headers[headerName];
28941 this.xhr.setRequestHeader(headerName, headerValue);
28947 this.xhr.onload = function()
28949 _this.xhrOnLoad(_this.xhr);
28952 this.xhr.onerror = function()
28954 _this.xhrOnError(_this.xhr);
28957 var formData = new FormData();
28959 formData.append('returnHTML', 'NO');
28962 formData.append('crop', crop);
28965 formData.append(this.paramName, file, file.name);
28972 if(this.fireEvent('prepare', this, formData, options) != false){
28974 if(options.manually){
28978 this.xhr.send(formData);
28982 this.uploadCancel();
28985 uploadCancel : function()
28991 this.delegates = [];
28993 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29000 renderPreview : function(file)
29002 if(typeof(file.target) != 'undefined' && file.target){
29006 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
29008 var previewEl = this.managerEl.createChild({
29010 cls : 'roo-document-manager-preview',
29014 tooltip : file[this.toolTipName],
29015 cls : 'roo-document-manager-thumb',
29016 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
29021 html : '<i class="fa fa-times-circle"></i>'
29026 var close = previewEl.select('button.close', true).first();
29028 close.on('click', this.onRemove, this, file);
29030 file.target = previewEl;
29032 var image = previewEl.select('img', true).first();
29036 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
29038 image.on('click', this.onClick, this, file);
29040 this.fireEvent('previewrendered', this, file);
29046 onPreviewLoad : function(file, image)
29048 if(typeof(file.target) == 'undefined' || !file.target){
29052 var width = image.dom.naturalWidth || image.dom.width;
29053 var height = image.dom.naturalHeight || image.dom.height;
29055 if(width > height){
29056 file.target.addClass('wide');
29060 file.target.addClass('tall');
29065 uploadFromSource : function(file, crop)
29067 this.xhr = new XMLHttpRequest();
29069 this.managerEl.createChild({
29071 cls : 'roo-document-manager-loading',
29075 tooltip : file.name,
29076 cls : 'roo-document-manager-thumb',
29077 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29083 this.xhr.open(this.method, this.url, true);
29086 "Accept": "application/json",
29087 "Cache-Control": "no-cache",
29088 "X-Requested-With": "XMLHttpRequest"
29091 for (var headerName in headers) {
29092 var headerValue = headers[headerName];
29094 this.xhr.setRequestHeader(headerName, headerValue);
29100 this.xhr.onload = function()
29102 _this.xhrOnLoad(_this.xhr);
29105 this.xhr.onerror = function()
29107 _this.xhrOnError(_this.xhr);
29110 var formData = new FormData();
29112 formData.append('returnHTML', 'NO');
29114 formData.append('crop', crop);
29116 if(typeof(file.filename) != 'undefined'){
29117 formData.append('filename', file.filename);
29120 if(typeof(file.mimetype) != 'undefined'){
29121 formData.append('mimetype', file.mimetype);
29126 if(this.fireEvent('prepare', this, formData) != false){
29127 this.xhr.send(formData);
29137 * @class Roo.bootstrap.DocumentViewer
29138 * @extends Roo.bootstrap.Component
29139 * Bootstrap DocumentViewer class
29140 * @cfg {Boolean} showDownload (true|false) show download button (default true)
29141 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
29144 * Create a new DocumentViewer
29145 * @param {Object} config The config object
29148 Roo.bootstrap.DocumentViewer = function(config){
29149 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
29154 * Fire after initEvent
29155 * @param {Roo.bootstrap.DocumentViewer} this
29161 * @param {Roo.bootstrap.DocumentViewer} this
29166 * Fire after download button
29167 * @param {Roo.bootstrap.DocumentViewer} this
29172 * Fire after trash button
29173 * @param {Roo.bootstrap.DocumentViewer} this
29180 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
29182 showDownload : true,
29186 getAutoCreate : function()
29190 cls : 'roo-document-viewer',
29194 cls : 'roo-document-viewer-body',
29198 cls : 'roo-document-viewer-thumb',
29202 cls : 'roo-document-viewer-image'
29210 cls : 'roo-document-viewer-footer',
29213 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
29217 cls : 'btn-group roo-document-viewer-download',
29221 cls : 'btn btn-default',
29222 html : '<i class="fa fa-download"></i>'
29228 cls : 'btn-group roo-document-viewer-trash',
29232 cls : 'btn btn-default',
29233 html : '<i class="fa fa-trash"></i>'
29246 initEvents : function()
29248 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
29249 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
29251 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
29252 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
29254 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
29255 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
29257 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
29258 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
29260 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
29261 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
29263 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
29264 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
29266 this.bodyEl.on('click', this.onClick, this);
29267 this.downloadBtn.on('click', this.onDownload, this);
29268 this.trashBtn.on('click', this.onTrash, this);
29270 this.downloadBtn.hide();
29271 this.trashBtn.hide();
29273 if(this.showDownload){
29274 this.downloadBtn.show();
29277 if(this.showTrash){
29278 this.trashBtn.show();
29281 if(!this.showDownload && !this.showTrash) {
29282 this.footerEl.hide();
29287 initial : function()
29289 this.fireEvent('initial', this);
29293 onClick : function(e)
29295 e.preventDefault();
29297 this.fireEvent('click', this);
29300 onDownload : function(e)
29302 e.preventDefault();
29304 this.fireEvent('download', this);
29307 onTrash : function(e)
29309 e.preventDefault();
29311 this.fireEvent('trash', this);
29323 * @class Roo.bootstrap.NavProgressBar
29324 * @extends Roo.bootstrap.Component
29325 * Bootstrap NavProgressBar class
29328 * Create a new nav progress bar
29329 * @param {Object} config The config object
29332 Roo.bootstrap.NavProgressBar = function(config){
29333 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
29335 this.bullets = this.bullets || [];
29337 // Roo.bootstrap.NavProgressBar.register(this);
29341 * Fires when the active item changes
29342 * @param {Roo.bootstrap.NavProgressBar} this
29343 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
29344 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
29351 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
29356 getAutoCreate : function()
29358 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
29362 cls : 'roo-navigation-bar-group',
29366 cls : 'roo-navigation-top-bar'
29370 cls : 'roo-navigation-bullets-bar',
29374 cls : 'roo-navigation-bar'
29381 cls : 'roo-navigation-bottom-bar'
29391 initEvents: function()
29396 onRender : function(ct, position)
29398 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
29400 if(this.bullets.length){
29401 Roo.each(this.bullets, function(b){
29410 addItem : function(cfg)
29412 var item = new Roo.bootstrap.NavProgressItem(cfg);
29414 item.parentId = this.id;
29415 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
29418 var top = new Roo.bootstrap.Element({
29420 cls : 'roo-navigation-bar-text'
29423 var bottom = new Roo.bootstrap.Element({
29425 cls : 'roo-navigation-bar-text'
29428 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
29429 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
29431 var topText = new Roo.bootstrap.Element({
29433 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
29436 var bottomText = new Roo.bootstrap.Element({
29438 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
29441 topText.onRender(top.el, null);
29442 bottomText.onRender(bottom.el, null);
29445 item.bottomEl = bottom;
29448 this.barItems.push(item);
29453 getActive : function()
29455 var active = false;
29457 Roo.each(this.barItems, function(v){
29459 if (!v.isActive()) {
29471 setActiveItem : function(item)
29475 Roo.each(this.barItems, function(v){
29476 if (v.rid == item.rid) {
29480 if (v.isActive()) {
29481 v.setActive(false);
29486 item.setActive(true);
29488 this.fireEvent('changed', this, item, prev);
29491 getBarItem: function(rid)
29495 Roo.each(this.barItems, function(e) {
29496 if (e.rid != rid) {
29507 indexOfItem : function(item)
29511 Roo.each(this.barItems, function(v, i){
29513 if (v.rid != item.rid) {
29524 setActiveNext : function()
29526 var i = this.indexOfItem(this.getActive());
29528 if (i > this.barItems.length) {
29532 this.setActiveItem(this.barItems[i+1]);
29535 setActivePrev : function()
29537 var i = this.indexOfItem(this.getActive());
29543 this.setActiveItem(this.barItems[i-1]);
29546 format : function()
29548 if(!this.barItems.length){
29552 var width = 100 / this.barItems.length;
29554 Roo.each(this.barItems, function(i){
29555 i.el.setStyle('width', width + '%');
29556 i.topEl.el.setStyle('width', width + '%');
29557 i.bottomEl.el.setStyle('width', width + '%');
29566 * Nav Progress Item
29571 * @class Roo.bootstrap.NavProgressItem
29572 * @extends Roo.bootstrap.Component
29573 * Bootstrap NavProgressItem class
29574 * @cfg {String} rid the reference id
29575 * @cfg {Boolean} active (true|false) Is item active default false
29576 * @cfg {Boolean} disabled (true|false) Is item active default false
29577 * @cfg {String} html
29578 * @cfg {String} position (top|bottom) text position default bottom
29579 * @cfg {String} icon show icon instead of number
29582 * Create a new NavProgressItem
29583 * @param {Object} config The config object
29585 Roo.bootstrap.NavProgressItem = function(config){
29586 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
29591 * The raw click event for the entire grid.
29592 * @param {Roo.bootstrap.NavProgressItem} this
29593 * @param {Roo.EventObject} e
29600 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
29606 position : 'bottom',
29609 getAutoCreate : function()
29611 var iconCls = 'roo-navigation-bar-item-icon';
29613 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
29617 cls: 'roo-navigation-bar-item',
29627 cfg.cls += ' active';
29630 cfg.cls += ' disabled';
29636 disable : function()
29638 this.setDisabled(true);
29641 enable : function()
29643 this.setDisabled(false);
29646 initEvents: function()
29648 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
29650 this.iconEl.on('click', this.onClick, this);
29653 onClick : function(e)
29655 e.preventDefault();
29661 if(this.fireEvent('click', this, e) === false){
29665 this.parent().setActiveItem(this);
29668 isActive: function ()
29670 return this.active;
29673 setActive : function(state)
29675 if(this.active == state){
29679 this.active = state;
29682 this.el.addClass('active');
29686 this.el.removeClass('active');
29691 setDisabled : function(state)
29693 if(this.disabled == state){
29697 this.disabled = state;
29700 this.el.addClass('disabled');
29704 this.el.removeClass('disabled');
29707 tooltipEl : function()
29709 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
29722 * @class Roo.bootstrap.FieldLabel
29723 * @extends Roo.bootstrap.Component
29724 * Bootstrap FieldLabel class
29725 * @cfg {String} html contents of the element
29726 * @cfg {String} tag tag of the element default label
29727 * @cfg {String} cls class of the element
29728 * @cfg {String} target label target
29729 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
29730 * @cfg {String} invalidClass default "text-warning"
29731 * @cfg {String} validClass default "text-success"
29732 * @cfg {String} iconTooltip default "This field is required"
29733 * @cfg {String} indicatorpos (left|right) default left
29736 * Create a new FieldLabel
29737 * @param {Object} config The config object
29740 Roo.bootstrap.FieldLabel = function(config){
29741 Roo.bootstrap.Element.superclass.constructor.call(this, config);
29746 * Fires after the field has been marked as invalid.
29747 * @param {Roo.form.FieldLabel} this
29748 * @param {String} msg The validation message
29753 * Fires after the field has been validated with no errors.
29754 * @param {Roo.form.FieldLabel} this
29760 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
29767 invalidClass : 'has-warning',
29768 validClass : 'has-success',
29769 iconTooltip : 'This field is required',
29770 indicatorpos : 'left',
29772 getAutoCreate : function(){
29776 cls : 'roo-bootstrap-field-label ' + this.cls,
29781 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
29782 tooltip : this.iconTooltip
29791 if(this.indicatorpos == 'right'){
29794 cls : 'roo-bootstrap-field-label ' + this.cls,
29803 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
29804 tooltip : this.iconTooltip
29813 initEvents: function()
29815 Roo.bootstrap.Element.superclass.initEvents.call(this);
29817 this.indicator = this.indicatorEl();
29819 if(this.indicator){
29820 this.indicator.removeClass('visible');
29821 this.indicator.addClass('invisible');
29824 Roo.bootstrap.FieldLabel.register(this);
29827 indicatorEl : function()
29829 var indicator = this.el.select('i.roo-required-indicator',true).first();
29840 * Mark this field as valid
29842 markValid : function()
29844 if(this.indicator){
29845 this.indicator.removeClass('visible');
29846 this.indicator.addClass('invisible');
29849 this.el.removeClass(this.invalidClass);
29851 this.el.addClass(this.validClass);
29853 this.fireEvent('valid', this);
29857 * Mark this field as invalid
29858 * @param {String} msg The validation message
29860 markInvalid : function(msg)
29862 if(this.indicator){
29863 this.indicator.removeClass('invisible');
29864 this.indicator.addClass('visible');
29867 this.el.removeClass(this.validClass);
29869 this.el.addClass(this.invalidClass);
29871 this.fireEvent('invalid', this, msg);
29877 Roo.apply(Roo.bootstrap.FieldLabel, {
29882 * register a FieldLabel Group
29883 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
29885 register : function(label)
29887 if(this.groups.hasOwnProperty(label.target)){
29891 this.groups[label.target] = label;
29895 * fetch a FieldLabel Group based on the target
29896 * @param {string} target
29897 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
29899 get: function(target) {
29900 if (typeof(this.groups[target]) == 'undefined') {
29904 return this.groups[target] ;
29913 * page DateSplitField.
29919 * @class Roo.bootstrap.DateSplitField
29920 * @extends Roo.bootstrap.Component
29921 * Bootstrap DateSplitField class
29922 * @cfg {string} fieldLabel - the label associated
29923 * @cfg {Number} labelWidth set the width of label (0-12)
29924 * @cfg {String} labelAlign (top|left)
29925 * @cfg {Boolean} dayAllowBlank (true|false) default false
29926 * @cfg {Boolean} monthAllowBlank (true|false) default false
29927 * @cfg {Boolean} yearAllowBlank (true|false) default false
29928 * @cfg {string} dayPlaceholder
29929 * @cfg {string} monthPlaceholder
29930 * @cfg {string} yearPlaceholder
29931 * @cfg {string} dayFormat default 'd'
29932 * @cfg {string} monthFormat default 'm'
29933 * @cfg {string} yearFormat default 'Y'
29934 * @cfg {Number} labellg set the width of label (1-12)
29935 * @cfg {Number} labelmd set the width of label (1-12)
29936 * @cfg {Number} labelsm set the width of label (1-12)
29937 * @cfg {Number} labelxs set the width of label (1-12)
29941 * Create a new DateSplitField
29942 * @param {Object} config The config object
29945 Roo.bootstrap.DateSplitField = function(config){
29946 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
29952 * getting the data of years
29953 * @param {Roo.bootstrap.DateSplitField} this
29954 * @param {Object} years
29959 * getting the data of days
29960 * @param {Roo.bootstrap.DateSplitField} this
29961 * @param {Object} days
29966 * Fires after the field has been marked as invalid.
29967 * @param {Roo.form.Field} this
29968 * @param {String} msg The validation message
29973 * Fires after the field has been validated with no errors.
29974 * @param {Roo.form.Field} this
29980 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
29983 labelAlign : 'top',
29985 dayAllowBlank : false,
29986 monthAllowBlank : false,
29987 yearAllowBlank : false,
29988 dayPlaceholder : '',
29989 monthPlaceholder : '',
29990 yearPlaceholder : '',
29994 isFormField : true,
30000 getAutoCreate : function()
30004 cls : 'row roo-date-split-field-group',
30009 cls : 'form-hidden-field roo-date-split-field-group-value',
30015 var labelCls = 'col-md-12';
30016 var contentCls = 'col-md-4';
30018 if(this.fieldLabel){
30022 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
30026 html : this.fieldLabel
30031 if(this.labelAlign == 'left'){
30033 if(this.labelWidth > 12){
30034 label.style = "width: " + this.labelWidth + 'px';
30037 if(this.labelWidth < 13 && this.labelmd == 0){
30038 this.labelmd = this.labelWidth;
30041 if(this.labellg > 0){
30042 labelCls = ' col-lg-' + this.labellg;
30043 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
30046 if(this.labelmd > 0){
30047 labelCls = ' col-md-' + this.labelmd;
30048 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
30051 if(this.labelsm > 0){
30052 labelCls = ' col-sm-' + this.labelsm;
30053 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
30056 if(this.labelxs > 0){
30057 labelCls = ' col-xs-' + this.labelxs;
30058 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
30062 label.cls += ' ' + labelCls;
30064 cfg.cn.push(label);
30067 Roo.each(['day', 'month', 'year'], function(t){
30070 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
30077 inputEl: function ()
30079 return this.el.select('.roo-date-split-field-group-value', true).first();
30082 onRender : function(ct, position)
30086 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
30088 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
30090 this.dayField = new Roo.bootstrap.ComboBox({
30091 allowBlank : this.dayAllowBlank,
30092 alwaysQuery : true,
30093 displayField : 'value',
30096 forceSelection : true,
30098 placeholder : this.dayPlaceholder,
30099 selectOnFocus : true,
30100 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30101 triggerAction : 'all',
30103 valueField : 'value',
30104 store : new Roo.data.SimpleStore({
30105 data : (function() {
30107 _this.fireEvent('days', _this, days);
30110 fields : [ 'value' ]
30113 select : function (_self, record, index)
30115 _this.setValue(_this.getValue());
30120 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
30122 this.monthField = new Roo.bootstrap.MonthField({
30123 after : '<i class=\"fa fa-calendar\"></i>',
30124 allowBlank : this.monthAllowBlank,
30125 placeholder : this.monthPlaceholder,
30128 render : function (_self)
30130 this.el.select('span.input-group-addon', true).first().on('click', function(e){
30131 e.preventDefault();
30135 select : function (_self, oldvalue, newvalue)
30137 _this.setValue(_this.getValue());
30142 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
30144 this.yearField = new Roo.bootstrap.ComboBox({
30145 allowBlank : this.yearAllowBlank,
30146 alwaysQuery : true,
30147 displayField : 'value',
30150 forceSelection : true,
30152 placeholder : this.yearPlaceholder,
30153 selectOnFocus : true,
30154 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30155 triggerAction : 'all',
30157 valueField : 'value',
30158 store : new Roo.data.SimpleStore({
30159 data : (function() {
30161 _this.fireEvent('years', _this, years);
30164 fields : [ 'value' ]
30167 select : function (_self, record, index)
30169 _this.setValue(_this.getValue());
30174 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
30177 setValue : function(v, format)
30179 this.inputEl.dom.value = v;
30181 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
30183 var d = Date.parseDate(v, f);
30190 this.setDay(d.format(this.dayFormat));
30191 this.setMonth(d.format(this.monthFormat));
30192 this.setYear(d.format(this.yearFormat));
30199 setDay : function(v)
30201 this.dayField.setValue(v);
30202 this.inputEl.dom.value = this.getValue();
30207 setMonth : function(v)
30209 this.monthField.setValue(v, true);
30210 this.inputEl.dom.value = this.getValue();
30215 setYear : function(v)
30217 this.yearField.setValue(v);
30218 this.inputEl.dom.value = this.getValue();
30223 getDay : function()
30225 return this.dayField.getValue();
30228 getMonth : function()
30230 return this.monthField.getValue();
30233 getYear : function()
30235 return this.yearField.getValue();
30238 getValue : function()
30240 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
30242 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
30252 this.inputEl.dom.value = '';
30257 validate : function()
30259 var d = this.dayField.validate();
30260 var m = this.monthField.validate();
30261 var y = this.yearField.validate();
30266 (!this.dayAllowBlank && !d) ||
30267 (!this.monthAllowBlank && !m) ||
30268 (!this.yearAllowBlank && !y)
30273 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
30282 this.markInvalid();
30287 markValid : function()
30290 var label = this.el.select('label', true).first();
30291 var icon = this.el.select('i.fa-star', true).first();
30297 this.fireEvent('valid', this);
30301 * Mark this field as invalid
30302 * @param {String} msg The validation message
30304 markInvalid : function(msg)
30307 var label = this.el.select('label', true).first();
30308 var icon = this.el.select('i.fa-star', true).first();
30310 if(label && !icon){
30311 this.el.select('.roo-date-split-field-label', true).createChild({
30313 cls : 'text-danger fa fa-lg fa-star',
30314 tooltip : 'This field is required',
30315 style : 'margin-right:5px;'
30319 this.fireEvent('invalid', this, msg);
30322 clearInvalid : function()
30324 var label = this.el.select('label', true).first();
30325 var icon = this.el.select('i.fa-star', true).first();
30331 this.fireEvent('valid', this);
30334 getName: function()
30344 * http://masonry.desandro.com
30346 * The idea is to render all the bricks based on vertical width...
30348 * The original code extends 'outlayer' - we might need to use that....
30354 * @class Roo.bootstrap.LayoutMasonry
30355 * @extends Roo.bootstrap.Component
30356 * Bootstrap Layout Masonry class
30359 * Create a new Element
30360 * @param {Object} config The config object
30363 Roo.bootstrap.LayoutMasonry = function(config){
30365 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
30369 Roo.bootstrap.LayoutMasonry.register(this);
30375 * Fire after layout the items
30376 * @param {Roo.bootstrap.LayoutMasonry} this
30377 * @param {Roo.EventObject} e
30384 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
30387 * @cfg {Boolean} isLayoutInstant = no animation?
30389 isLayoutInstant : false, // needed?
30392 * @cfg {Number} boxWidth width of the columns
30397 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
30402 * @cfg {Number} padWidth padding below box..
30407 * @cfg {Number} gutter gutter width..
30412 * @cfg {Number} maxCols maximum number of columns
30418 * @cfg {Boolean} isAutoInitial defalut true
30420 isAutoInitial : true,
30425 * @cfg {Boolean} isHorizontal defalut false
30427 isHorizontal : false,
30429 currentSize : null,
30435 bricks: null, //CompositeElement
30439 _isLayoutInited : false,
30441 // isAlternative : false, // only use for vertical layout...
30444 * @cfg {Number} alternativePadWidth padding below box..
30446 alternativePadWidth : 50,
30448 selectedBrick : [],
30450 getAutoCreate : function(){
30452 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
30456 cls: 'blog-masonary-wrapper ' + this.cls,
30458 cls : 'mas-boxes masonary'
30465 getChildContainer: function( )
30467 if (this.boxesEl) {
30468 return this.boxesEl;
30471 this.boxesEl = this.el.select('.mas-boxes').first();
30473 return this.boxesEl;
30477 initEvents : function()
30481 if(this.isAutoInitial){
30482 Roo.log('hook children rendered');
30483 this.on('childrenrendered', function() {
30484 Roo.log('children rendered');
30490 initial : function()
30492 this.selectedBrick = [];
30494 this.currentSize = this.el.getBox(true);
30496 Roo.EventManager.onWindowResize(this.resize, this);
30498 if(!this.isAutoInitial){
30506 //this.layout.defer(500,this);
30510 resize : function()
30512 var cs = this.el.getBox(true);
30515 this.currentSize.width == cs.width &&
30516 this.currentSize.x == cs.x &&
30517 this.currentSize.height == cs.height &&
30518 this.currentSize.y == cs.y
30520 Roo.log("no change in with or X or Y");
30524 this.currentSize = cs;
30530 layout : function()
30532 this._resetLayout();
30534 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
30536 this.layoutItems( isInstant );
30538 this._isLayoutInited = true;
30540 this.fireEvent('layout', this);
30544 _resetLayout : function()
30546 if(this.isHorizontal){
30547 this.horizontalMeasureColumns();
30551 this.verticalMeasureColumns();
30555 verticalMeasureColumns : function()
30557 this.getContainerWidth();
30559 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30560 // this.colWidth = Math.floor(this.containerWidth * 0.8);
30564 var boxWidth = this.boxWidth + this.padWidth;
30566 if(this.containerWidth < this.boxWidth){
30567 boxWidth = this.containerWidth
30570 var containerWidth = this.containerWidth;
30572 var cols = Math.floor(containerWidth / boxWidth);
30574 this.cols = Math.max( cols, 1 );
30576 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
30578 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
30580 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
30582 this.colWidth = boxWidth + avail - this.padWidth;
30584 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
30585 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
30588 horizontalMeasureColumns : function()
30590 this.getContainerWidth();
30592 var boxWidth = this.boxWidth;
30594 if(this.containerWidth < boxWidth){
30595 boxWidth = this.containerWidth;
30598 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
30600 this.el.setHeight(boxWidth);
30604 getContainerWidth : function()
30606 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
30609 layoutItems : function( isInstant )
30611 Roo.log(this.bricks);
30613 var items = Roo.apply([], this.bricks);
30615 if(this.isHorizontal){
30616 this._horizontalLayoutItems( items , isInstant );
30620 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30621 // this._verticalAlternativeLayoutItems( items , isInstant );
30625 this._verticalLayoutItems( items , isInstant );
30629 _verticalLayoutItems : function ( items , isInstant)
30631 if ( !items || !items.length ) {
30636 ['xs', 'xs', 'xs', 'tall'],
30637 ['xs', 'xs', 'tall'],
30638 ['xs', 'xs', 'sm'],
30639 ['xs', 'xs', 'xs'],
30645 ['sm', 'xs', 'xs'],
30649 ['tall', 'xs', 'xs', 'xs'],
30650 ['tall', 'xs', 'xs'],
30662 Roo.each(items, function(item, k){
30664 switch (item.size) {
30665 // these layouts take up a full box,
30676 boxes.push([item]);
30699 var filterPattern = function(box, length)
30707 var pattern = box.slice(0, length);
30711 Roo.each(pattern, function(i){
30712 format.push(i.size);
30715 Roo.each(standard, function(s){
30717 if(String(s) != String(format)){
30726 if(!match && length == 1){
30731 filterPattern(box, length - 1);
30735 queue.push(pattern);
30737 box = box.slice(length, box.length);
30739 filterPattern(box, 4);
30745 Roo.each(boxes, function(box, k){
30751 if(box.length == 1){
30756 filterPattern(box, 4);
30760 this._processVerticalLayoutQueue( queue, isInstant );
30764 // _verticalAlternativeLayoutItems : function( items , isInstant )
30766 // if ( !items || !items.length ) {
30770 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
30774 _horizontalLayoutItems : function ( items , isInstant)
30776 if ( !items || !items.length || items.length < 3) {
30782 var eItems = items.slice(0, 3);
30784 items = items.slice(3, items.length);
30787 ['xs', 'xs', 'xs', 'wide'],
30788 ['xs', 'xs', 'wide'],
30789 ['xs', 'xs', 'sm'],
30790 ['xs', 'xs', 'xs'],
30796 ['sm', 'xs', 'xs'],
30800 ['wide', 'xs', 'xs', 'xs'],
30801 ['wide', 'xs', 'xs'],
30814 Roo.each(items, function(item, k){
30816 switch (item.size) {
30827 boxes.push([item]);
30851 var filterPattern = function(box, length)
30859 var pattern = box.slice(0, length);
30863 Roo.each(pattern, function(i){
30864 format.push(i.size);
30867 Roo.each(standard, function(s){
30869 if(String(s) != String(format)){
30878 if(!match && length == 1){
30883 filterPattern(box, length - 1);
30887 queue.push(pattern);
30889 box = box.slice(length, box.length);
30891 filterPattern(box, 4);
30897 Roo.each(boxes, function(box, k){
30903 if(box.length == 1){
30908 filterPattern(box, 4);
30915 var pos = this.el.getBox(true);
30919 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
30921 var hit_end = false;
30923 Roo.each(queue, function(box){
30927 Roo.each(box, function(b){
30929 b.el.setVisibilityMode(Roo.Element.DISPLAY);
30939 Roo.each(box, function(b){
30941 b.el.setVisibilityMode(Roo.Element.DISPLAY);
30944 mx = Math.max(mx, b.x);
30948 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
30952 Roo.each(box, function(b){
30954 b.el.setVisibilityMode(Roo.Element.DISPLAY);
30968 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
30971 /** Sets position of item in DOM
30972 * @param {Element} item
30973 * @param {Number} x - horizontal position
30974 * @param {Number} y - vertical position
30975 * @param {Boolean} isInstant - disables transitions
30977 _processVerticalLayoutQueue : function( queue, isInstant )
30979 var pos = this.el.getBox(true);
30984 for (var i = 0; i < this.cols; i++){
30988 Roo.each(queue, function(box, k){
30990 var col = k % this.cols;
30992 Roo.each(box, function(b,kk){
30994 b.el.position('absolute');
30996 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
30997 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
30999 if(b.size == 'md-left' || b.size == 'md-right'){
31000 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31001 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31004 b.el.setWidth(width);
31005 b.el.setHeight(height);
31007 b.el.select('iframe',true).setSize(width,height);
31011 for (var i = 0; i < this.cols; i++){
31013 if(maxY[i] < maxY[col]){
31018 col = Math.min(col, i);
31022 x = pos.x + col * (this.colWidth + this.padWidth);
31026 var positions = [];
31028 switch (box.length){
31030 positions = this.getVerticalOneBoxColPositions(x, y, box);
31033 positions = this.getVerticalTwoBoxColPositions(x, y, box);
31036 positions = this.getVerticalThreeBoxColPositions(x, y, box);
31039 positions = this.getVerticalFourBoxColPositions(x, y, box);
31045 Roo.each(box, function(b,kk){
31047 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31049 var sz = b.el.getSize();
31051 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
31059 for (var i = 0; i < this.cols; i++){
31060 mY = Math.max(mY, maxY[i]);
31063 this.el.setHeight(mY - pos.y);
31067 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
31069 // var pos = this.el.getBox(true);
31072 // var maxX = pos.right;
31074 // var maxHeight = 0;
31076 // Roo.each(items, function(item, k){
31080 // item.el.position('absolute');
31082 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
31084 // item.el.setWidth(width);
31086 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
31088 // item.el.setHeight(height);
31091 // item.el.setXY([x, y], isInstant ? false : true);
31093 // item.el.setXY([maxX - width, y], isInstant ? false : true);
31096 // y = y + height + this.alternativePadWidth;
31098 // maxHeight = maxHeight + height + this.alternativePadWidth;
31102 // this.el.setHeight(maxHeight);
31106 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
31108 var pos = this.el.getBox(true);
31113 var maxX = pos.right;
31115 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
31117 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31119 Roo.each(queue, function(box, k){
31121 Roo.each(box, function(b, kk){
31123 b.el.position('absolute');
31125 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31126 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31128 if(b.size == 'md-left' || b.size == 'md-right'){
31129 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31130 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31133 b.el.setWidth(width);
31134 b.el.setHeight(height);
31142 var positions = [];
31144 switch (box.length){
31146 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
31149 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
31152 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
31155 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
31161 Roo.each(box, function(b,kk){
31163 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31165 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
31173 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
31175 Roo.each(eItems, function(b,k){
31177 b.size = (k == 0) ? 'sm' : 'xs';
31178 b.x = (k == 0) ? 2 : 1;
31179 b.y = (k == 0) ? 2 : 1;
31181 b.el.position('absolute');
31183 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31185 b.el.setWidth(width);
31187 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31189 b.el.setHeight(height);
31193 var positions = [];
31196 x : maxX - this.unitWidth * 2 - this.gutter,
31201 x : maxX - this.unitWidth,
31202 y : minY + (this.unitWidth + this.gutter) * 2
31206 x : maxX - this.unitWidth * 3 - this.gutter * 2,
31210 Roo.each(eItems, function(b,k){
31212 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
31218 getVerticalOneBoxColPositions : function(x, y, box)
31222 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
31224 if(box[0].size == 'md-left'){
31228 if(box[0].size == 'md-right'){
31233 x : x + (this.unitWidth + this.gutter) * rand,
31240 getVerticalTwoBoxColPositions : function(x, y, box)
31244 if(box[0].size == 'xs'){
31248 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
31252 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
31266 x : x + (this.unitWidth + this.gutter) * 2,
31267 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
31274 getVerticalThreeBoxColPositions : function(x, y, box)
31278 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31286 x : x + (this.unitWidth + this.gutter) * 1,
31291 x : x + (this.unitWidth + this.gutter) * 2,
31299 if(box[0].size == 'xs' && box[1].size == 'xs'){
31308 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
31312 x : x + (this.unitWidth + this.gutter) * 1,
31326 x : x + (this.unitWidth + this.gutter) * 2,
31331 x : x + (this.unitWidth + this.gutter) * 2,
31332 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
31339 getVerticalFourBoxColPositions : function(x, y, box)
31343 if(box[0].size == 'xs'){
31352 y : y + (this.unitHeight + this.gutter) * 1
31357 y : y + (this.unitHeight + this.gutter) * 2
31361 x : x + (this.unitWidth + this.gutter) * 1,
31375 x : x + (this.unitWidth + this.gutter) * 2,
31380 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
31381 y : y + (this.unitHeight + this.gutter) * 1
31385 x : x + (this.unitWidth + this.gutter) * 2,
31386 y : y + (this.unitWidth + this.gutter) * 2
31393 getHorizontalOneBoxColPositions : function(maxX, minY, box)
31397 if(box[0].size == 'md-left'){
31399 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31406 if(box[0].size == 'md-right'){
31408 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31409 y : minY + (this.unitWidth + this.gutter) * 1
31415 var rand = Math.floor(Math.random() * (4 - box[0].y));
31418 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31419 y : minY + (this.unitWidth + this.gutter) * rand
31426 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
31430 if(box[0].size == 'xs'){
31433 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31438 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31439 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
31447 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31452 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31453 y : minY + (this.unitWidth + this.gutter) * 2
31460 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
31464 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31467 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31472 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31473 y : minY + (this.unitWidth + this.gutter) * 1
31477 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31478 y : minY + (this.unitWidth + this.gutter) * 2
31485 if(box[0].size == 'xs' && box[1].size == 'xs'){
31488 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31493 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31498 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31499 y : minY + (this.unitWidth + this.gutter) * 1
31507 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31512 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31513 y : minY + (this.unitWidth + this.gutter) * 2
31517 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31518 y : minY + (this.unitWidth + this.gutter) * 2
31525 getHorizontalFourBoxColPositions : function(maxX, minY, box)
31529 if(box[0].size == 'xs'){
31532 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31537 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31542 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),
31547 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
31548 y : minY + (this.unitWidth + this.gutter) * 1
31556 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31561 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31562 y : minY + (this.unitWidth + this.gutter) * 2
31566 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31567 y : minY + (this.unitWidth + this.gutter) * 2
31571 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),
31572 y : minY + (this.unitWidth + this.gutter) * 2
31580 * remove a Masonry Brick
31581 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
31583 removeBrick : function(brick_id)
31589 for (var i = 0; i<this.bricks.length; i++) {
31590 if (this.bricks[i].id == brick_id) {
31591 this.bricks.splice(i,1);
31592 this.el.dom.removeChild(Roo.get(brick_id).dom);
31599 * adds a Masonry Brick
31600 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31602 addBrick : function(cfg)
31604 var cn = new Roo.bootstrap.MasonryBrick(cfg);
31605 //this.register(cn);
31606 cn.parentId = this.id;
31607 cn.onRender(this.el, null);
31612 * register a Masonry Brick
31613 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31616 register : function(brick)
31618 this.bricks.push(brick);
31619 brick.masonryId = this.id;
31623 * clear all the Masonry Brick
31625 clearAll : function()
31628 //this.getChildContainer().dom.innerHTML = "";
31629 this.el.dom.innerHTML = '';
31632 getSelected : function()
31634 if (!this.selectedBrick) {
31638 return this.selectedBrick;
31642 Roo.apply(Roo.bootstrap.LayoutMasonry, {
31646 * register a Masonry Layout
31647 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
31650 register : function(layout)
31652 this.groups[layout.id] = layout;
31655 * fetch a Masonry Layout based on the masonry layout ID
31656 * @param {string} the masonry layout to add
31657 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
31660 get: function(layout_id) {
31661 if (typeof(this.groups[layout_id]) == 'undefined') {
31664 return this.groups[layout_id] ;
31676 * http://masonry.desandro.com
31678 * The idea is to render all the bricks based on vertical width...
31680 * The original code extends 'outlayer' - we might need to use that....
31686 * @class Roo.bootstrap.LayoutMasonryAuto
31687 * @extends Roo.bootstrap.Component
31688 * Bootstrap Layout Masonry class
31691 * Create a new Element
31692 * @param {Object} config The config object
31695 Roo.bootstrap.LayoutMasonryAuto = function(config){
31696 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
31699 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
31702 * @cfg {Boolean} isFitWidth - resize the width..
31704 isFitWidth : false, // options..
31706 * @cfg {Boolean} isOriginLeft = left align?
31708 isOriginLeft : true,
31710 * @cfg {Boolean} isOriginTop = top align?
31712 isOriginTop : false,
31714 * @cfg {Boolean} isLayoutInstant = no animation?
31716 isLayoutInstant : false, // needed?
31718 * @cfg {Boolean} isResizingContainer = not sure if this is used..
31720 isResizingContainer : true,
31722 * @cfg {Number} columnWidth width of the columns
31728 * @cfg {Number} maxCols maximum number of columns
31733 * @cfg {Number} padHeight padding below box..
31739 * @cfg {Boolean} isAutoInitial defalut true
31742 isAutoInitial : true,
31748 initialColumnWidth : 0,
31749 currentSize : null,
31751 colYs : null, // array.
31758 bricks: null, //CompositeElement
31759 cols : 0, // array?
31760 // element : null, // wrapped now this.el
31761 _isLayoutInited : null,
31764 getAutoCreate : function(){
31768 cls: 'blog-masonary-wrapper ' + this.cls,
31770 cls : 'mas-boxes masonary'
31777 getChildContainer: function( )
31779 if (this.boxesEl) {
31780 return this.boxesEl;
31783 this.boxesEl = this.el.select('.mas-boxes').first();
31785 return this.boxesEl;
31789 initEvents : function()
31793 if(this.isAutoInitial){
31794 Roo.log('hook children rendered');
31795 this.on('childrenrendered', function() {
31796 Roo.log('children rendered');
31803 initial : function()
31805 this.reloadItems();
31807 this.currentSize = this.el.getBox(true);
31809 /// was window resize... - let's see if this works..
31810 Roo.EventManager.onWindowResize(this.resize, this);
31812 if(!this.isAutoInitial){
31817 this.layout.defer(500,this);
31820 reloadItems: function()
31822 this.bricks = this.el.select('.masonry-brick', true);
31824 this.bricks.each(function(b) {
31825 //Roo.log(b.getSize());
31826 if (!b.attr('originalwidth')) {
31827 b.attr('originalwidth', b.getSize().width);
31832 Roo.log(this.bricks.elements.length);
31835 resize : function()
31838 var cs = this.el.getBox(true);
31840 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
31841 Roo.log("no change in with or X");
31844 this.currentSize = cs;
31848 layout : function()
31851 this._resetLayout();
31852 //this._manageStamps();
31854 // don't animate first layout
31855 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
31856 this.layoutItems( isInstant );
31858 // flag for initalized
31859 this._isLayoutInited = true;
31862 layoutItems : function( isInstant )
31864 //var items = this._getItemsForLayout( this.items );
31865 // original code supports filtering layout items.. we just ignore it..
31867 this._layoutItems( this.bricks , isInstant );
31869 this._postLayout();
31871 _layoutItems : function ( items , isInstant)
31873 //this.fireEvent( 'layout', this, items );
31876 if ( !items || !items.elements.length ) {
31877 // no items, emit event with empty array
31882 items.each(function(item) {
31883 Roo.log("layout item");
31885 // get x/y object from method
31886 var position = this._getItemLayoutPosition( item );
31888 position.item = item;
31889 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
31890 queue.push( position );
31893 this._processLayoutQueue( queue );
31895 /** Sets position of item in DOM
31896 * @param {Element} item
31897 * @param {Number} x - horizontal position
31898 * @param {Number} y - vertical position
31899 * @param {Boolean} isInstant - disables transitions
31901 _processLayoutQueue : function( queue )
31903 for ( var i=0, len = queue.length; i < len; i++ ) {
31904 var obj = queue[i];
31905 obj.item.position('absolute');
31906 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
31912 * Any logic you want to do after each layout,
31913 * i.e. size the container
31915 _postLayout : function()
31917 this.resizeContainer();
31920 resizeContainer : function()
31922 if ( !this.isResizingContainer ) {
31925 var size = this._getContainerSize();
31927 this.el.setSize(size.width,size.height);
31928 this.boxesEl.setSize(size.width,size.height);
31934 _resetLayout : function()
31936 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
31937 this.colWidth = this.el.getWidth();
31938 //this.gutter = this.el.getWidth();
31940 this.measureColumns();
31946 this.colYs.push( 0 );
31952 measureColumns : function()
31954 this.getContainerWidth();
31955 // if columnWidth is 0, default to outerWidth of first item
31956 if ( !this.columnWidth ) {
31957 var firstItem = this.bricks.first();
31958 Roo.log(firstItem);
31959 this.columnWidth = this.containerWidth;
31960 if (firstItem && firstItem.attr('originalwidth') ) {
31961 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
31963 // columnWidth fall back to item of first element
31964 Roo.log("set column width?");
31965 this.initialColumnWidth = this.columnWidth ;
31967 // if first elem has no width, default to size of container
31972 if (this.initialColumnWidth) {
31973 this.columnWidth = this.initialColumnWidth;
31978 // column width is fixed at the top - however if container width get's smaller we should
31981 // this bit calcs how man columns..
31983 var columnWidth = this.columnWidth += this.gutter;
31985 // calculate columns
31986 var containerWidth = this.containerWidth + this.gutter;
31988 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
31989 // fix rounding errors, typically with gutters
31990 var excess = columnWidth - containerWidth % columnWidth;
31993 // if overshoot is less than a pixel, round up, otherwise floor it
31994 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
31995 cols = Math[ mathMethod ]( cols );
31996 this.cols = Math.max( cols, 1 );
31997 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
31999 // padding positioning..
32000 var totalColWidth = this.cols * this.columnWidth;
32001 var padavail = this.containerWidth - totalColWidth;
32002 // so for 2 columns - we need 3 'pads'
32004 var padNeeded = (1+this.cols) * this.padWidth;
32006 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
32008 this.columnWidth += padExtra
32009 //this.padWidth = Math.floor(padavail / ( this.cols));
32011 // adjust colum width so that padding is fixed??
32013 // we have 3 columns ... total = width * 3
32014 // we have X left over... that should be used by
32016 //if (this.expandC) {
32024 getContainerWidth : function()
32026 /* // container is parent if fit width
32027 var container = this.isFitWidth ? this.element.parentNode : this.element;
32028 // check that this.size and size are there
32029 // IE8 triggers resize on body size change, so they might not be
32031 var size = getSize( container ); //FIXME
32032 this.containerWidth = size && size.innerWidth; //FIXME
32035 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
32039 _getItemLayoutPosition : function( item ) // what is item?
32041 // we resize the item to our columnWidth..
32043 item.setWidth(this.columnWidth);
32044 item.autoBoxAdjust = false;
32046 var sz = item.getSize();
32048 // how many columns does this brick span
32049 var remainder = this.containerWidth % this.columnWidth;
32051 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
32052 // round if off by 1 pixel, otherwise use ceil
32053 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
32054 colSpan = Math.min( colSpan, this.cols );
32056 // normally this should be '1' as we dont' currently allow multi width columns..
32058 var colGroup = this._getColGroup( colSpan );
32059 // get the minimum Y value from the columns
32060 var minimumY = Math.min.apply( Math, colGroup );
32061 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32063 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
32065 // position the brick
32067 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
32068 y: this.currentSize.y + minimumY + this.padHeight
32072 // apply setHeight to necessary columns
32073 var setHeight = minimumY + sz.height + this.padHeight;
32074 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32076 var setSpan = this.cols + 1 - colGroup.length;
32077 for ( var i = 0; i < setSpan; i++ ) {
32078 this.colYs[ shortColIndex + i ] = setHeight ;
32085 * @param {Number} colSpan - number of columns the element spans
32086 * @returns {Array} colGroup
32088 _getColGroup : function( colSpan )
32090 if ( colSpan < 2 ) {
32091 // if brick spans only one column, use all the column Ys
32096 // how many different places could this brick fit horizontally
32097 var groupCount = this.cols + 1 - colSpan;
32098 // for each group potential horizontal position
32099 for ( var i = 0; i < groupCount; i++ ) {
32100 // make an array of colY values for that one group
32101 var groupColYs = this.colYs.slice( i, i + colSpan );
32102 // and get the max value of the array
32103 colGroup[i] = Math.max.apply( Math, groupColYs );
32108 _manageStamp : function( stamp )
32110 var stampSize = stamp.getSize();
32111 var offset = stamp.getBox();
32112 // get the columns that this stamp affects
32113 var firstX = this.isOriginLeft ? offset.x : offset.right;
32114 var lastX = firstX + stampSize.width;
32115 var firstCol = Math.floor( firstX / this.columnWidth );
32116 firstCol = Math.max( 0, firstCol );
32118 var lastCol = Math.floor( lastX / this.columnWidth );
32119 // lastCol should not go over if multiple of columnWidth #425
32120 lastCol -= lastX % this.columnWidth ? 0 : 1;
32121 lastCol = Math.min( this.cols - 1, lastCol );
32123 // set colYs to bottom of the stamp
32124 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
32127 for ( var i = firstCol; i <= lastCol; i++ ) {
32128 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
32133 _getContainerSize : function()
32135 this.maxY = Math.max.apply( Math, this.colYs );
32140 if ( this.isFitWidth ) {
32141 size.width = this._getContainerFitWidth();
32147 _getContainerFitWidth : function()
32149 var unusedCols = 0;
32150 // count unused columns
32153 if ( this.colYs[i] !== 0 ) {
32158 // fit container to columns that have been used
32159 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
32162 needsResizeLayout : function()
32164 var previousWidth = this.containerWidth;
32165 this.getContainerWidth();
32166 return previousWidth !== this.containerWidth;
32181 * @class Roo.bootstrap.MasonryBrick
32182 * @extends Roo.bootstrap.Component
32183 * Bootstrap MasonryBrick class
32186 * Create a new MasonryBrick
32187 * @param {Object} config The config object
32190 Roo.bootstrap.MasonryBrick = function(config){
32192 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
32194 Roo.bootstrap.MasonryBrick.register(this);
32200 * When a MasonryBrick is clcik
32201 * @param {Roo.bootstrap.MasonryBrick} this
32202 * @param {Roo.EventObject} e
32208 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
32211 * @cfg {String} title
32215 * @cfg {String} html
32219 * @cfg {String} bgimage
32223 * @cfg {String} videourl
32227 * @cfg {String} cls
32231 * @cfg {String} href
32235 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
32240 * @cfg {String} placetitle (center|bottom)
32245 * @cfg {Boolean} isFitContainer defalut true
32247 isFitContainer : true,
32250 * @cfg {Boolean} preventDefault defalut false
32252 preventDefault : false,
32255 * @cfg {Boolean} inverse defalut false
32257 maskInverse : false,
32259 getAutoCreate : function()
32261 if(!this.isFitContainer){
32262 return this.getSplitAutoCreate();
32265 var cls = 'masonry-brick masonry-brick-full';
32267 if(this.href.length){
32268 cls += ' masonry-brick-link';
32271 if(this.bgimage.length){
32272 cls += ' masonry-brick-image';
32275 if(this.maskInverse){
32276 cls += ' mask-inverse';
32279 if(!this.html.length && !this.maskInverse && !this.videourl.length){
32280 cls += ' enable-mask';
32284 cls += ' masonry-' + this.size + '-brick';
32287 if(this.placetitle.length){
32289 switch (this.placetitle) {
32291 cls += ' masonry-center-title';
32294 cls += ' masonry-bottom-title';
32301 if(!this.html.length && !this.bgimage.length){
32302 cls += ' masonry-center-title';
32305 if(!this.html.length && this.bgimage.length){
32306 cls += ' masonry-bottom-title';
32311 cls += ' ' + this.cls;
32315 tag: (this.href.length) ? 'a' : 'div',
32320 cls: 'masonry-brick-mask'
32324 cls: 'masonry-brick-paragraph',
32330 if(this.href.length){
32331 cfg.href = this.href;
32334 var cn = cfg.cn[1].cn;
32336 if(this.title.length){
32339 cls: 'masonry-brick-title',
32344 if(this.html.length){
32347 cls: 'masonry-brick-text',
32352 if (!this.title.length && !this.html.length) {
32353 cfg.cn[1].cls += ' hide';
32356 if(this.bgimage.length){
32359 cls: 'masonry-brick-image-view',
32364 if(this.videourl.length){
32365 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32366 // youtube support only?
32369 cls: 'masonry-brick-image-view',
32372 allowfullscreen : true
32380 getSplitAutoCreate : function()
32382 var cls = 'masonry-brick masonry-brick-split';
32384 if(this.href.length){
32385 cls += ' masonry-brick-link';
32388 if(this.bgimage.length){
32389 cls += ' masonry-brick-image';
32393 cls += ' masonry-' + this.size + '-brick';
32396 switch (this.placetitle) {
32398 cls += ' masonry-center-title';
32401 cls += ' masonry-bottom-title';
32404 if(!this.bgimage.length){
32405 cls += ' masonry-center-title';
32408 if(this.bgimage.length){
32409 cls += ' masonry-bottom-title';
32415 cls += ' ' + this.cls;
32419 tag: (this.href.length) ? 'a' : 'div',
32424 cls: 'masonry-brick-split-head',
32428 cls: 'masonry-brick-paragraph',
32435 cls: 'masonry-brick-split-body',
32441 if(this.href.length){
32442 cfg.href = this.href;
32445 if(this.title.length){
32446 cfg.cn[0].cn[0].cn.push({
32448 cls: 'masonry-brick-title',
32453 if(this.html.length){
32454 cfg.cn[1].cn.push({
32456 cls: 'masonry-brick-text',
32461 if(this.bgimage.length){
32462 cfg.cn[0].cn.push({
32464 cls: 'masonry-brick-image-view',
32469 if(this.videourl.length){
32470 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32471 // youtube support only?
32472 cfg.cn[0].cn.cn.push({
32474 cls: 'masonry-brick-image-view',
32477 allowfullscreen : true
32484 initEvents: function()
32486 switch (this.size) {
32519 this.el.on('touchstart', this.onTouchStart, this);
32520 this.el.on('touchmove', this.onTouchMove, this);
32521 this.el.on('touchend', this.onTouchEnd, this);
32522 this.el.on('contextmenu', this.onContextMenu, this);
32524 this.el.on('mouseenter' ,this.enter, this);
32525 this.el.on('mouseleave', this.leave, this);
32526 this.el.on('click', this.onClick, this);
32529 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
32530 this.parent().bricks.push(this);
32535 onClick: function(e, el)
32537 var time = this.endTimer - this.startTimer;
32538 // Roo.log(e.preventDefault());
32541 e.preventDefault();
32546 if(!this.preventDefault){
32550 e.preventDefault();
32552 if (this.activcClass != '') {
32553 this.selectBrick();
32556 this.fireEvent('click', this);
32559 enter: function(e, el)
32561 e.preventDefault();
32563 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32567 if(this.bgimage.length && this.html.length){
32568 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32572 leave: function(e, el)
32574 e.preventDefault();
32576 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32580 if(this.bgimage.length && this.html.length){
32581 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
32585 onTouchStart: function(e, el)
32587 // e.preventDefault();
32589 this.touchmoved = false;
32591 if(!this.isFitContainer){
32595 if(!this.bgimage.length || !this.html.length){
32599 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32601 this.timer = new Date().getTime();
32605 onTouchMove: function(e, el)
32607 this.touchmoved = true;
32610 onContextMenu : function(e,el)
32612 e.preventDefault();
32613 e.stopPropagation();
32617 onTouchEnd: function(e, el)
32619 // e.preventDefault();
32621 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
32628 if(!this.bgimage.length || !this.html.length){
32630 if(this.href.length){
32631 window.location.href = this.href;
32637 if(!this.isFitContainer){
32641 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
32643 window.location.href = this.href;
32646 //selection on single brick only
32647 selectBrick : function() {
32649 if (!this.parentId) {
32653 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
32654 var index = m.selectedBrick.indexOf(this.id);
32657 m.selectedBrick.splice(index,1);
32658 this.el.removeClass(this.activeClass);
32662 for(var i = 0; i < m.selectedBrick.length; i++) {
32663 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
32664 b.el.removeClass(b.activeClass);
32667 m.selectedBrick = [];
32669 m.selectedBrick.push(this.id);
32670 this.el.addClass(this.activeClass);
32676 Roo.apply(Roo.bootstrap.MasonryBrick, {
32679 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
32681 * register a Masonry Brick
32682 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32685 register : function(brick)
32687 //this.groups[brick.id] = brick;
32688 this.groups.add(brick.id, brick);
32691 * fetch a masonry brick based on the masonry brick ID
32692 * @param {string} the masonry brick to add
32693 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
32696 get: function(brick_id)
32698 // if (typeof(this.groups[brick_id]) == 'undefined') {
32701 // return this.groups[brick_id] ;
32703 if(this.groups.key(brick_id)) {
32704 return this.groups.key(brick_id);
32722 * @class Roo.bootstrap.Brick
32723 * @extends Roo.bootstrap.Component
32724 * Bootstrap Brick class
32727 * Create a new Brick
32728 * @param {Object} config The config object
32731 Roo.bootstrap.Brick = function(config){
32732 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
32738 * When a Brick is click
32739 * @param {Roo.bootstrap.Brick} this
32740 * @param {Roo.EventObject} e
32746 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
32749 * @cfg {String} title
32753 * @cfg {String} html
32757 * @cfg {String} bgimage
32761 * @cfg {String} cls
32765 * @cfg {String} href
32769 * @cfg {String} video
32773 * @cfg {Boolean} square
32777 getAutoCreate : function()
32779 var cls = 'roo-brick';
32781 if(this.href.length){
32782 cls += ' roo-brick-link';
32785 if(this.bgimage.length){
32786 cls += ' roo-brick-image';
32789 if(!this.html.length && !this.bgimage.length){
32790 cls += ' roo-brick-center-title';
32793 if(!this.html.length && this.bgimage.length){
32794 cls += ' roo-brick-bottom-title';
32798 cls += ' ' + this.cls;
32802 tag: (this.href.length) ? 'a' : 'div',
32807 cls: 'roo-brick-paragraph',
32813 if(this.href.length){
32814 cfg.href = this.href;
32817 var cn = cfg.cn[0].cn;
32819 if(this.title.length){
32822 cls: 'roo-brick-title',
32827 if(this.html.length){
32830 cls: 'roo-brick-text',
32837 if(this.bgimage.length){
32840 cls: 'roo-brick-image-view',
32848 initEvents: function()
32850 if(this.title.length || this.html.length){
32851 this.el.on('mouseenter' ,this.enter, this);
32852 this.el.on('mouseleave', this.leave, this);
32855 Roo.EventManager.onWindowResize(this.resize, this);
32857 if(this.bgimage.length){
32858 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
32859 this.imageEl.on('load', this.onImageLoad, this);
32866 onImageLoad : function()
32871 resize : function()
32873 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
32875 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
32877 if(this.bgimage.length){
32878 var image = this.el.select('.roo-brick-image-view', true).first();
32880 image.setWidth(paragraph.getWidth());
32883 image.setHeight(paragraph.getWidth());
32886 this.el.setHeight(image.getHeight());
32887 paragraph.setHeight(image.getHeight());
32893 enter: function(e, el)
32895 e.preventDefault();
32897 if(this.bgimage.length){
32898 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
32899 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
32903 leave: function(e, el)
32905 e.preventDefault();
32907 if(this.bgimage.length){
32908 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
32909 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
32925 * @class Roo.bootstrap.NumberField
32926 * @extends Roo.bootstrap.Input
32927 * Bootstrap NumberField class
32933 * Create a new NumberField
32934 * @param {Object} config The config object
32937 Roo.bootstrap.NumberField = function(config){
32938 Roo.bootstrap.NumberField.superclass.constructor.call(this, config);
32941 Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
32944 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
32946 allowDecimals : true,
32948 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
32950 decimalSeparator : ".",
32952 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
32954 decimalPrecision : 2,
32956 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
32958 allowNegative : true,
32960 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
32962 minValue : Number.NEGATIVE_INFINITY,
32964 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
32966 maxValue : Number.MAX_VALUE,
32968 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
32970 minText : "The minimum value for this field is {0}",
32972 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
32974 maxText : "The maximum value for this field is {0}",
32976 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
32977 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
32979 nanText : "{0} is not a valid number",
32981 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
32986 initEvents : function()
32988 Roo.bootstrap.NumberField.superclass.initEvents.call(this);
32990 var allowed = "0123456789";
32992 if(this.allowDecimals){
32993 allowed += this.decimalSeparator;
32996 if(this.allowNegative){
33000 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
33002 var keyPress = function(e){
33004 var k = e.getKey();
33006 var c = e.getCharCode();
33009 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
33010 allowed.indexOf(String.fromCharCode(c)) === -1
33016 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
33020 if(allowed.indexOf(String.fromCharCode(c)) === -1){
33025 this.el.on("keypress", keyPress, this);
33028 validateValue : function(value)
33031 if(!Roo.bootstrap.NumberField.superclass.validateValue.call(this, value)){
33035 var num = this.parseValue(value);
33038 this.markInvalid(String.format(this.nanText, value));
33042 if(num < this.minValue){
33043 this.markInvalid(String.format(this.minText, this.minValue));
33047 if(num > this.maxValue){
33048 this.markInvalid(String.format(this.maxText, this.maxValue));
33055 getValue : function()
33057 return this.fixPrecision(this.parseValue(Roo.bootstrap.NumberField.superclass.getValue.call(this)));
33060 parseValue : function(value)
33062 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
33063 return isNaN(value) ? '' : value;
33066 fixPrecision : function(value)
33068 var nan = isNaN(value);
33070 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
33071 return nan ? '' : value;
33073 return parseFloat(value).toFixed(this.decimalPrecision);
33076 setValue : function(v)
33078 v = this.fixPrecision(v);
33079 Roo.bootstrap.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
33082 decimalPrecisionFcn : function(v)
33084 return Math.floor(v);
33087 beforeBlur : function()
33093 var v = this.parseValue(this.getRawValue());
33108 * @class Roo.bootstrap.DocumentSlider
33109 * @extends Roo.bootstrap.Component
33110 * Bootstrap DocumentSlider class
33113 * Create a new DocumentViewer
33114 * @param {Object} config The config object
33117 Roo.bootstrap.DocumentSlider = function(config){
33118 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
33125 * Fire after initEvent
33126 * @param {Roo.bootstrap.DocumentSlider} this
33131 * Fire after update
33132 * @param {Roo.bootstrap.DocumentSlider} this
33138 * @param {Roo.bootstrap.DocumentSlider} this
33144 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
33150 getAutoCreate : function()
33154 cls : 'roo-document-slider',
33158 cls : 'roo-document-slider-header',
33162 cls : 'roo-document-slider-header-title'
33168 cls : 'roo-document-slider-body',
33172 cls : 'roo-document-slider-prev',
33176 cls : 'fa fa-chevron-left'
33182 cls : 'roo-document-slider-thumb',
33186 cls : 'roo-document-slider-image'
33192 cls : 'roo-document-slider-next',
33196 cls : 'fa fa-chevron-right'
33208 initEvents : function()
33210 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
33211 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
33213 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
33214 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
33216 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
33217 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
33219 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
33220 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
33222 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
33223 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
33225 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
33226 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33228 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
33229 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33231 this.thumbEl.on('click', this.onClick, this);
33233 this.prevIndicator.on('click', this.prev, this);
33235 this.nextIndicator.on('click', this.next, this);
33239 initial : function()
33241 if(this.files.length){
33242 this.indicator = 1;
33246 this.fireEvent('initial', this);
33249 update : function()
33251 this.imageEl.attr('src', this.files[this.indicator - 1]);
33253 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
33255 this.prevIndicator.show();
33257 if(this.indicator == 1){
33258 this.prevIndicator.hide();
33261 this.nextIndicator.show();
33263 if(this.indicator == this.files.length){
33264 this.nextIndicator.hide();
33267 this.thumbEl.scrollTo('top');
33269 this.fireEvent('update', this);
33272 onClick : function(e)
33274 e.preventDefault();
33276 this.fireEvent('click', this);
33281 e.preventDefault();
33283 this.indicator = Math.max(1, this.indicator - 1);
33290 e.preventDefault();
33292 this.indicator = Math.min(this.files.length, this.indicator + 1);
33306 * @class Roo.bootstrap.RadioSet
33307 * @extends Roo.bootstrap.Input
33308 * Bootstrap RadioSet class
33309 * @cfg {String} indicatorpos (left|right) default left
33310 * @cfg {Boolean} inline (true|false) inline the element (default true)
33311 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
33313 * Create a new RadioSet
33314 * @param {Object} config The config object
33317 Roo.bootstrap.RadioSet = function(config){
33319 Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
33323 Roo.bootstrap.RadioSet.register(this);
33328 * Fires when the element is checked or unchecked.
33329 * @param {Roo.bootstrap.RadioSet} this This radio
33330 * @param {Roo.bootstrap.Radio} item The checked item
33337 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
33345 indicatorpos : 'left',
33347 getAutoCreate : function()
33351 cls : 'roo-radio-set-label',
33355 html : this.fieldLabel
33360 if(this.indicatorpos == 'left'){
33363 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
33364 tooltip : 'This field is required'
33369 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
33370 tooltip : 'This field is required'
33376 cls : 'roo-radio-set-items'
33379 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
33381 if (align === 'left' && this.fieldLabel.length) {
33384 cls : "roo-radio-set-right",
33390 if(this.labelWidth > 12){
33391 label.style = "width: " + this.labelWidth + 'px';
33394 if(this.labelWidth < 13 && this.labelmd == 0){
33395 this.labelmd = this.labelWidth;
33398 if(this.labellg > 0){
33399 label.cls += ' col-lg-' + this.labellg;
33400 items.cls += ' col-lg-' + (12 - this.labellg);
33403 if(this.labelmd > 0){
33404 label.cls += ' col-md-' + this.labelmd;
33405 items.cls += ' col-md-' + (12 - this.labelmd);
33408 if(this.labelsm > 0){
33409 label.cls += ' col-sm-' + this.labelsm;
33410 items.cls += ' col-sm-' + (12 - this.labelsm);
33413 if(this.labelxs > 0){
33414 label.cls += ' col-xs-' + this.labelxs;
33415 items.cls += ' col-xs-' + (12 - this.labelxs);
33421 cls : 'roo-radio-set',
33425 cls : 'roo-radio-set-input',
33428 value : this.value ? this.value : ''
33435 if(this.weight.length){
33436 cfg.cls += ' roo-radio-' + this.weight;
33440 cfg.cls += ' roo-radio-set-inline';
33444 ['xs','sm','md','lg'].map(function(size){
33445 if (settings[size]) {
33446 cfg.cls += ' col-' + size + '-' + settings[size];
33454 initEvents : function()
33456 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
33457 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
33459 if(!this.fieldLabel.length){
33460 this.labelEl.hide();
33463 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
33464 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
33466 this.indicatorEl().addClass('invisible');
33468 this.originalValue = this.getValue();
33472 inputEl: function ()
33474 return this.el.select('.roo-radio-set-input', true).first();
33477 getChildContainer : function()
33479 return this.itemsEl;
33482 register : function(item)
33484 this.radioes.push(item);
33488 validate : function()
33492 Roo.each(this.radioes, function(i){
33501 if(this.allowBlank) {
33505 if(this.disabled || valid){
33510 this.markInvalid();
33515 markValid : function()
33517 if(this.labelEl.isVisible(true)){
33518 this.indicatorEl().removeClass('visible');
33519 this.indicatorEl().addClass('invisible');
33522 this.el.removeClass([this.invalidClass, this.validClass]);
33523 this.el.addClass(this.validClass);
33525 this.fireEvent('valid', this);
33528 markInvalid : function(msg)
33530 if(this.allowBlank || this.disabled){
33534 if(this.labelEl.isVisible(true)){
33535 this.indicatorEl().removeClass('invisible');
33536 this.indicatorEl().addClass('visible');
33539 this.el.removeClass([this.invalidClass, this.validClass]);
33540 this.el.addClass(this.invalidClass);
33542 this.fireEvent('invalid', this, msg);
33546 setValue : function(v, suppressEvent)
33548 if(this.value === v){
33555 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
33558 Roo.each(this.radioes, function(i){
33561 i.el.removeClass('checked');
33563 if(i.value === v || i.value.toString() === v.toString()){
33565 i.el.addClass('checked');
33567 if(suppressEvent !== true){
33568 this.fireEvent('check', this, i);
33577 clearInvalid : function(){
33579 if(!this.el || this.preventMark){
33583 this.el.removeClass([this.invalidClass]);
33585 this.fireEvent('valid', this);
33590 Roo.apply(Roo.bootstrap.RadioSet, {
33594 register : function(set)
33596 this.groups[set.name] = set;
33599 get: function(name)
33601 if (typeof(this.groups[name]) == 'undefined') {
33605 return this.groups[name] ;
33611 * Ext JS Library 1.1.1
33612 * Copyright(c) 2006-2007, Ext JS, LLC.
33614 * Originally Released Under LGPL - original licence link has changed is not relivant.
33617 * <script type="text/javascript">
33622 * @class Roo.bootstrap.SplitBar
33623 * @extends Roo.util.Observable
33624 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
33628 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
33629 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
33630 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
33631 split.minSize = 100;
33632 split.maxSize = 600;
33633 split.animate = true;
33634 split.on('moved', splitterMoved);
33637 * Create a new SplitBar
33638 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
33639 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
33640 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
33641 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
33642 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
33643 position of the SplitBar).
33645 Roo.bootstrap.SplitBar = function(cfg){
33650 // dragElement : elm
33651 // resizingElement: el,
33653 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
33654 // placement : Roo.bootstrap.SplitBar.LEFT ,
33655 // existingProxy ???
33658 this.el = Roo.get(cfg.dragElement, true);
33659 this.el.dom.unselectable = "on";
33661 this.resizingEl = Roo.get(cfg.resizingElement, true);
33665 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
33666 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
33669 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
33672 * The minimum size of the resizing element. (Defaults to 0)
33678 * The maximum size of the resizing element. (Defaults to 2000)
33681 this.maxSize = 2000;
33684 * Whether to animate the transition to the new size
33687 this.animate = false;
33690 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
33693 this.useShim = false;
33698 if(!cfg.existingProxy){
33700 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
33702 this.proxy = Roo.get(cfg.existingProxy).dom;
33705 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
33708 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
33711 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
33714 this.dragSpecs = {};
33717 * @private The adapter to use to positon and resize elements
33719 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
33720 this.adapter.init(this);
33722 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33724 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
33725 this.el.addClass("roo-splitbar-h");
33728 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
33729 this.el.addClass("roo-splitbar-v");
33735 * Fires when the splitter is moved (alias for {@link #event-moved})
33736 * @param {Roo.bootstrap.SplitBar} this
33737 * @param {Number} newSize the new width or height
33742 * Fires when the splitter is moved
33743 * @param {Roo.bootstrap.SplitBar} this
33744 * @param {Number} newSize the new width or height
33748 * @event beforeresize
33749 * Fires before the splitter is dragged
33750 * @param {Roo.bootstrap.SplitBar} this
33752 "beforeresize" : true,
33754 "beforeapply" : true
33757 Roo.util.Observable.call(this);
33760 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
33761 onStartProxyDrag : function(x, y){
33762 this.fireEvent("beforeresize", this);
33764 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
33766 o.enableDisplayMode("block");
33767 // all splitbars share the same overlay
33768 Roo.bootstrap.SplitBar.prototype.overlay = o;
33770 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
33771 this.overlay.show();
33772 Roo.get(this.proxy).setDisplayed("block");
33773 var size = this.adapter.getElementSize(this);
33774 this.activeMinSize = this.getMinimumSize();;
33775 this.activeMaxSize = this.getMaximumSize();;
33776 var c1 = size - this.activeMinSize;
33777 var c2 = Math.max(this.activeMaxSize - size, 0);
33778 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33779 this.dd.resetConstraints();
33780 this.dd.setXConstraint(
33781 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
33782 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
33784 this.dd.setYConstraint(0, 0);
33786 this.dd.resetConstraints();
33787 this.dd.setXConstraint(0, 0);
33788 this.dd.setYConstraint(
33789 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
33790 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
33793 this.dragSpecs.startSize = size;
33794 this.dragSpecs.startPoint = [x, y];
33795 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
33799 * @private Called after the drag operation by the DDProxy
33801 onEndProxyDrag : function(e){
33802 Roo.get(this.proxy).setDisplayed(false);
33803 var endPoint = Roo.lib.Event.getXY(e);
33805 this.overlay.hide();
33808 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33809 newSize = this.dragSpecs.startSize +
33810 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
33811 endPoint[0] - this.dragSpecs.startPoint[0] :
33812 this.dragSpecs.startPoint[0] - endPoint[0]
33815 newSize = this.dragSpecs.startSize +
33816 (this.placement == Roo.bootstrap.SplitBar.TOP ?
33817 endPoint[1] - this.dragSpecs.startPoint[1] :
33818 this.dragSpecs.startPoint[1] - endPoint[1]
33821 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
33822 if(newSize != this.dragSpecs.startSize){
33823 if(this.fireEvent('beforeapply', this, newSize) !== false){
33824 this.adapter.setElementSize(this, newSize);
33825 this.fireEvent("moved", this, newSize);
33826 this.fireEvent("resize", this, newSize);
33832 * Get the adapter this SplitBar uses
33833 * @return The adapter object
33835 getAdapter : function(){
33836 return this.adapter;
33840 * Set the adapter this SplitBar uses
33841 * @param {Object} adapter A SplitBar adapter object
33843 setAdapter : function(adapter){
33844 this.adapter = adapter;
33845 this.adapter.init(this);
33849 * Gets the minimum size for the resizing element
33850 * @return {Number} The minimum size
33852 getMinimumSize : function(){
33853 return this.minSize;
33857 * Sets the minimum size for the resizing element
33858 * @param {Number} minSize The minimum size
33860 setMinimumSize : function(minSize){
33861 this.minSize = minSize;
33865 * Gets the maximum size for the resizing element
33866 * @return {Number} The maximum size
33868 getMaximumSize : function(){
33869 return this.maxSize;
33873 * Sets the maximum size for the resizing element
33874 * @param {Number} maxSize The maximum size
33876 setMaximumSize : function(maxSize){
33877 this.maxSize = maxSize;
33881 * Sets the initialize size for the resizing element
33882 * @param {Number} size The initial size
33884 setCurrentSize : function(size){
33885 var oldAnimate = this.animate;
33886 this.animate = false;
33887 this.adapter.setElementSize(this, size);
33888 this.animate = oldAnimate;
33892 * Destroy this splitbar.
33893 * @param {Boolean} removeEl True to remove the element
33895 destroy : function(removeEl){
33897 this.shim.remove();
33900 this.proxy.parentNode.removeChild(this.proxy);
33908 * @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.
33910 Roo.bootstrap.SplitBar.createProxy = function(dir){
33911 var proxy = new Roo.Element(document.createElement("div"));
33912 proxy.unselectable();
33913 var cls = 'roo-splitbar-proxy';
33914 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
33915 document.body.appendChild(proxy.dom);
33920 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
33921 * Default Adapter. It assumes the splitter and resizing element are not positioned
33922 * elements and only gets/sets the width of the element. Generally used for table based layouts.
33924 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
33927 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
33928 // do nothing for now
33929 init : function(s){
33933 * Called before drag operations to get the current size of the resizing element.
33934 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
33936 getElementSize : function(s){
33937 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33938 return s.resizingEl.getWidth();
33940 return s.resizingEl.getHeight();
33945 * Called after drag operations to set the size of the resizing element.
33946 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
33947 * @param {Number} newSize The new size to set
33948 * @param {Function} onComplete A function to be invoked when resizing is complete
33950 setElementSize : function(s, newSize, onComplete){
33951 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
33953 s.resizingEl.setWidth(newSize);
33955 onComplete(s, newSize);
33958 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
33963 s.resizingEl.setHeight(newSize);
33965 onComplete(s, newSize);
33968 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
33975 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
33976 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
33977 * Adapter that moves the splitter element to align with the resized sizing element.
33978 * Used with an absolute positioned SplitBar.
33979 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
33980 * document.body, make sure you assign an id to the body element.
33982 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
33983 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
33984 this.container = Roo.get(container);
33987 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
33988 init : function(s){
33989 this.basic.init(s);
33992 getElementSize : function(s){
33993 return this.basic.getElementSize(s);
33996 setElementSize : function(s, newSize, onComplete){
33997 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
34000 moveSplitter : function(s){
34001 var yes = Roo.bootstrap.SplitBar;
34002 switch(s.placement){
34004 s.el.setX(s.resizingEl.getRight());
34007 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
34010 s.el.setY(s.resizingEl.getBottom());
34013 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
34020 * Orientation constant - Create a vertical SplitBar
34024 Roo.bootstrap.SplitBar.VERTICAL = 1;
34027 * Orientation constant - Create a horizontal SplitBar
34031 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
34034 * Placement constant - The resizing element is to the left of the splitter element
34038 Roo.bootstrap.SplitBar.LEFT = 1;
34041 * Placement constant - The resizing element is to the right of the splitter element
34045 Roo.bootstrap.SplitBar.RIGHT = 2;
34048 * Placement constant - The resizing element is positioned above the splitter element
34052 Roo.bootstrap.SplitBar.TOP = 3;
34055 * Placement constant - The resizing element is positioned under splitter element
34059 Roo.bootstrap.SplitBar.BOTTOM = 4;
34060 Roo.namespace("Roo.bootstrap.layout");/*
34062 * Ext JS Library 1.1.1
34063 * Copyright(c) 2006-2007, Ext JS, LLC.
34065 * Originally Released Under LGPL - original licence link has changed is not relivant.
34068 * <script type="text/javascript">
34072 * @class Roo.bootstrap.layout.Manager
34073 * @extends Roo.bootstrap.Component
34074 * Base class for layout managers.
34076 Roo.bootstrap.layout.Manager = function(config)
34078 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
34084 /** false to disable window resize monitoring @type Boolean */
34085 this.monitorWindowResize = true;
34090 * Fires when a layout is performed.
34091 * @param {Roo.LayoutManager} this
34095 * @event regionresized
34096 * Fires when the user resizes a region.
34097 * @param {Roo.LayoutRegion} region The resized region
34098 * @param {Number} newSize The new size (width for east/west, height for north/south)
34100 "regionresized" : true,
34102 * @event regioncollapsed
34103 * Fires when a region is collapsed.
34104 * @param {Roo.LayoutRegion} region The collapsed region
34106 "regioncollapsed" : true,
34108 * @event regionexpanded
34109 * Fires when a region is expanded.
34110 * @param {Roo.LayoutRegion} region The expanded region
34112 "regionexpanded" : true
34114 this.updating = false;
34117 this.el = Roo.get(config.el);
34123 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
34128 monitorWindowResize : true,
34134 onRender : function(ct, position)
34137 this.el = Roo.get(ct);
34140 //this.fireEvent('render',this);
34144 initEvents: function()
34148 // ie scrollbar fix
34149 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
34150 document.body.scroll = "no";
34151 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
34152 this.el.position('relative');
34154 this.id = this.el.id;
34155 this.el.addClass("roo-layout-container");
34156 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34157 if(this.el.dom != document.body ) {
34158 this.el.on('resize', this.layout,this);
34159 this.el.on('show', this.layout,this);
34165 * Returns true if this layout is currently being updated
34166 * @return {Boolean}
34168 isUpdating : function(){
34169 return this.updating;
34173 * Suspend the LayoutManager from doing auto-layouts while
34174 * making multiple add or remove calls
34176 beginUpdate : function(){
34177 this.updating = true;
34181 * Restore auto-layouts and optionally disable the manager from performing a layout
34182 * @param {Boolean} noLayout true to disable a layout update
34184 endUpdate : function(noLayout){
34185 this.updating = false;
34191 layout: function(){
34195 onRegionResized : function(region, newSize){
34196 this.fireEvent("regionresized", region, newSize);
34200 onRegionCollapsed : function(region){
34201 this.fireEvent("regioncollapsed", region);
34204 onRegionExpanded : function(region){
34205 this.fireEvent("regionexpanded", region);
34209 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
34210 * performs box-model adjustments.
34211 * @return {Object} The size as an object {width: (the width), height: (the height)}
34213 getViewSize : function()
34216 if(this.el.dom != document.body){
34217 size = this.el.getSize();
34219 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
34221 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
34222 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34227 * Returns the Element this layout is bound to.
34228 * @return {Roo.Element}
34230 getEl : function(){
34235 * Returns the specified region.
34236 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
34237 * @return {Roo.LayoutRegion}
34239 getRegion : function(target){
34240 return this.regions[target.toLowerCase()];
34243 onWindowResize : function(){
34244 if(this.monitorWindowResize){
34251 * Ext JS Library 1.1.1
34252 * Copyright(c) 2006-2007, Ext JS, LLC.
34254 * Originally Released Under LGPL - original licence link has changed is not relivant.
34257 * <script type="text/javascript">
34260 * @class Roo.bootstrap.layout.Border
34261 * @extends Roo.bootstrap.layout.Manager
34262 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
34263 * please see: examples/bootstrap/nested.html<br><br>
34265 <b>The container the layout is rendered into can be either the body element or any other element.
34266 If it is not the body element, the container needs to either be an absolute positioned element,
34267 or you will need to add "position:relative" to the css of the container. You will also need to specify
34268 the container size if it is not the body element.</b>
34271 * Create a new Border
34272 * @param {Object} config Configuration options
34274 Roo.bootstrap.layout.Border = function(config){
34275 config = config || {};
34276 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
34280 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34281 if(config[region]){
34282 config[region].region = region;
34283 this.addRegion(config[region]);
34289 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
34291 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
34293 * Creates and adds a new region if it doesn't already exist.
34294 * @param {String} target The target region key (north, south, east, west or center).
34295 * @param {Object} config The regions config object
34296 * @return {BorderLayoutRegion} The new region
34298 addRegion : function(config)
34300 if(!this.regions[config.region]){
34301 var r = this.factory(config);
34302 this.bindRegion(r);
34304 return this.regions[config.region];
34308 bindRegion : function(r){
34309 this.regions[r.config.region] = r;
34311 r.on("visibilitychange", this.layout, this);
34312 r.on("paneladded", this.layout, this);
34313 r.on("panelremoved", this.layout, this);
34314 r.on("invalidated", this.layout, this);
34315 r.on("resized", this.onRegionResized, this);
34316 r.on("collapsed", this.onRegionCollapsed, this);
34317 r.on("expanded", this.onRegionExpanded, this);
34321 * Performs a layout update.
34323 layout : function()
34325 if(this.updating) {
34329 // render all the rebions if they have not been done alreayd?
34330 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34331 if(this.regions[region] && !this.regions[region].bodyEl){
34332 this.regions[region].onRender(this.el)
34336 var size = this.getViewSize();
34337 var w = size.width;
34338 var h = size.height;
34343 //var x = 0, y = 0;
34345 var rs = this.regions;
34346 var north = rs["north"];
34347 var south = rs["south"];
34348 var west = rs["west"];
34349 var east = rs["east"];
34350 var center = rs["center"];
34351 //if(this.hideOnLayout){ // not supported anymore
34352 //c.el.setStyle("display", "none");
34354 if(north && north.isVisible()){
34355 var b = north.getBox();
34356 var m = north.getMargins();
34357 b.width = w - (m.left+m.right);
34360 centerY = b.height + b.y + m.bottom;
34361 centerH -= centerY;
34362 north.updateBox(this.safeBox(b));
34364 if(south && south.isVisible()){
34365 var b = south.getBox();
34366 var m = south.getMargins();
34367 b.width = w - (m.left+m.right);
34369 var totalHeight = (b.height + m.top + m.bottom);
34370 b.y = h - totalHeight + m.top;
34371 centerH -= totalHeight;
34372 south.updateBox(this.safeBox(b));
34374 if(west && west.isVisible()){
34375 var b = west.getBox();
34376 var m = west.getMargins();
34377 b.height = centerH - (m.top+m.bottom);
34379 b.y = centerY + m.top;
34380 var totalWidth = (b.width + m.left + m.right);
34381 centerX += totalWidth;
34382 centerW -= totalWidth;
34383 west.updateBox(this.safeBox(b));
34385 if(east && east.isVisible()){
34386 var b = east.getBox();
34387 var m = east.getMargins();
34388 b.height = centerH - (m.top+m.bottom);
34389 var totalWidth = (b.width + m.left + m.right);
34390 b.x = w - totalWidth + m.left;
34391 b.y = centerY + m.top;
34392 centerW -= totalWidth;
34393 east.updateBox(this.safeBox(b));
34396 var m = center.getMargins();
34398 x: centerX + m.left,
34399 y: centerY + m.top,
34400 width: centerW - (m.left+m.right),
34401 height: centerH - (m.top+m.bottom)
34403 //if(this.hideOnLayout){
34404 //center.el.setStyle("display", "block");
34406 center.updateBox(this.safeBox(centerBox));
34409 this.fireEvent("layout", this);
34413 safeBox : function(box){
34414 box.width = Math.max(0, box.width);
34415 box.height = Math.max(0, box.height);
34420 * Adds a ContentPanel (or subclass) to this layout.
34421 * @param {String} target The target region key (north, south, east, west or center).
34422 * @param {Roo.ContentPanel} panel The panel to add
34423 * @return {Roo.ContentPanel} The added panel
34425 add : function(target, panel){
34427 target = target.toLowerCase();
34428 return this.regions[target].add(panel);
34432 * Remove a ContentPanel (or subclass) to this layout.
34433 * @param {String} target The target region key (north, south, east, west or center).
34434 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
34435 * @return {Roo.ContentPanel} The removed panel
34437 remove : function(target, panel){
34438 target = target.toLowerCase();
34439 return this.regions[target].remove(panel);
34443 * Searches all regions for a panel with the specified id
34444 * @param {String} panelId
34445 * @return {Roo.ContentPanel} The panel or null if it wasn't found
34447 findPanel : function(panelId){
34448 var rs = this.regions;
34449 for(var target in rs){
34450 if(typeof rs[target] != "function"){
34451 var p = rs[target].getPanel(panelId);
34461 * Searches all regions for a panel with the specified id and activates (shows) it.
34462 * @param {String/ContentPanel} panelId The panels id or the panel itself
34463 * @return {Roo.ContentPanel} The shown panel or null
34465 showPanel : function(panelId) {
34466 var rs = this.regions;
34467 for(var target in rs){
34468 var r = rs[target];
34469 if(typeof r != "function"){
34470 if(r.hasPanel(panelId)){
34471 return r.showPanel(panelId);
34479 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
34480 * @param {Roo.state.Provider} provider (optional) An alternate state provider
34483 restoreState : function(provider){
34485 provider = Roo.state.Manager;
34487 var sm = new Roo.LayoutStateManager();
34488 sm.init(this, provider);
34494 * Adds a xtype elements to the layout.
34498 xtype : 'ContentPanel',
34505 xtype : 'NestedLayoutPanel',
34511 items : [ ... list of content panels or nested layout panels.. ]
34515 * @param {Object} cfg Xtype definition of item to add.
34517 addxtype : function(cfg)
34519 // basically accepts a pannel...
34520 // can accept a layout region..!?!?
34521 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
34524 // theory? children can only be panels??
34526 //if (!cfg.xtype.match(/Panel$/)) {
34531 if (typeof(cfg.region) == 'undefined') {
34532 Roo.log("Failed to add Panel, region was not set");
34536 var region = cfg.region;
34542 xitems = cfg.items;
34549 case 'Content': // ContentPanel (el, cfg)
34550 case 'Scroll': // ContentPanel (el, cfg)
34552 cfg.autoCreate = true;
34553 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34555 // var el = this.el.createChild();
34556 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
34559 this.add(region, ret);
34563 case 'TreePanel': // our new panel!
34564 cfg.el = this.el.createChild();
34565 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
34566 this.add(region, ret);
34571 // create a new Layout (which is a Border Layout...
34573 var clayout = cfg.layout;
34574 clayout.el = this.el.createChild();
34575 clayout.items = clayout.items || [];
34579 // replace this exitems with the clayout ones..
34580 xitems = clayout.items;
34582 // force background off if it's in center...
34583 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
34584 cfg.background = false;
34586 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
34589 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34590 //console.log('adding nested layout panel ' + cfg.toSource());
34591 this.add(region, ret);
34592 nb = {}; /// find first...
34597 // needs grid and region
34599 //var el = this.getRegion(region).el.createChild();
34601 *var el = this.el.createChild();
34602 // create the grid first...
34603 cfg.grid.container = el;
34604 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
34607 if (region == 'center' && this.active ) {
34608 cfg.background = false;
34611 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34613 this.add(region, ret);
34615 if (cfg.background) {
34616 // render grid on panel activation (if panel background)
34617 ret.on('activate', function(gp) {
34618 if (!gp.grid.rendered) {
34619 // gp.grid.render(el);
34623 // cfg.grid.render(el);
34629 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
34630 // it was the old xcomponent building that caused this before.
34631 // espeically if border is the top element in the tree.
34641 if (typeof(Roo[cfg.xtype]) != 'undefined') {
34643 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
34644 this.add(region, ret);
34648 throw "Can not add '" + cfg.xtype + "' to Border";
34654 this.beginUpdate();
34658 Roo.each(xitems, function(i) {
34659 region = nb && i.region ? i.region : false;
34661 var add = ret.addxtype(i);
34664 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
34665 if (!i.background) {
34666 abn[region] = nb[region] ;
34673 // make the last non-background panel active..
34674 //if (nb) { Roo.log(abn); }
34677 for(var r in abn) {
34678 region = this.getRegion(r);
34680 // tried using nb[r], but it does not work..
34682 region.showPanel(abn[r]);
34693 factory : function(cfg)
34696 var validRegions = Roo.bootstrap.layout.Border.regions;
34698 var target = cfg.region;
34701 var r = Roo.bootstrap.layout;
34705 return new r.North(cfg);
34707 return new r.South(cfg);
34709 return new r.East(cfg);
34711 return new r.West(cfg);
34713 return new r.Center(cfg);
34715 throw 'Layout region "'+target+'" not supported.';
34722 * Ext JS Library 1.1.1
34723 * Copyright(c) 2006-2007, Ext JS, LLC.
34725 * Originally Released Under LGPL - original licence link has changed is not relivant.
34728 * <script type="text/javascript">
34732 * @class Roo.bootstrap.layout.Basic
34733 * @extends Roo.util.Observable
34734 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
34735 * and does not have a titlebar, tabs or any other features. All it does is size and position
34736 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
34737 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
34738 * @cfg {string} region the region that it inhabits..
34739 * @cfg {bool} skipConfig skip config?
34743 Roo.bootstrap.layout.Basic = function(config){
34745 this.mgr = config.mgr;
34747 this.position = config.region;
34749 var skipConfig = config.skipConfig;
34753 * @scope Roo.BasicLayoutRegion
34757 * @event beforeremove
34758 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
34759 * @param {Roo.LayoutRegion} this
34760 * @param {Roo.ContentPanel} panel The panel
34761 * @param {Object} e The cancel event object
34763 "beforeremove" : true,
34765 * @event invalidated
34766 * Fires when the layout for this region is changed.
34767 * @param {Roo.LayoutRegion} this
34769 "invalidated" : true,
34771 * @event visibilitychange
34772 * Fires when this region is shown or hidden
34773 * @param {Roo.LayoutRegion} this
34774 * @param {Boolean} visibility true or false
34776 "visibilitychange" : true,
34778 * @event paneladded
34779 * Fires when a panel is added.
34780 * @param {Roo.LayoutRegion} this
34781 * @param {Roo.ContentPanel} panel The panel
34783 "paneladded" : true,
34785 * @event panelremoved
34786 * Fires when a panel is removed.
34787 * @param {Roo.LayoutRegion} this
34788 * @param {Roo.ContentPanel} panel The panel
34790 "panelremoved" : true,
34792 * @event beforecollapse
34793 * Fires when this region before collapse.
34794 * @param {Roo.LayoutRegion} this
34796 "beforecollapse" : true,
34799 * Fires when this region is collapsed.
34800 * @param {Roo.LayoutRegion} this
34802 "collapsed" : true,
34805 * Fires when this region is expanded.
34806 * @param {Roo.LayoutRegion} this
34811 * Fires when this region is slid into view.
34812 * @param {Roo.LayoutRegion} this
34814 "slideshow" : true,
34817 * Fires when this region slides out of view.
34818 * @param {Roo.LayoutRegion} this
34820 "slidehide" : true,
34822 * @event panelactivated
34823 * Fires when a panel is activated.
34824 * @param {Roo.LayoutRegion} this
34825 * @param {Roo.ContentPanel} panel The activated panel
34827 "panelactivated" : true,
34830 * Fires when the user resizes this region.
34831 * @param {Roo.LayoutRegion} this
34832 * @param {Number} newSize The new size (width for east/west, height for north/south)
34836 /** A collection of panels in this region. @type Roo.util.MixedCollection */
34837 this.panels = new Roo.util.MixedCollection();
34838 this.panels.getKey = this.getPanelId.createDelegate(this);
34840 this.activePanel = null;
34841 // ensure listeners are added...
34843 if (config.listeners || config.events) {
34844 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
34845 listeners : config.listeners || {},
34846 events : config.events || {}
34850 if(skipConfig !== true){
34851 this.applyConfig(config);
34855 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
34857 getPanelId : function(p){
34861 applyConfig : function(config){
34862 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
34863 this.config = config;
34868 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
34869 * the width, for horizontal (north, south) the height.
34870 * @param {Number} newSize The new width or height
34872 resizeTo : function(newSize){
34873 var el = this.el ? this.el :
34874 (this.activePanel ? this.activePanel.getEl() : null);
34876 switch(this.position){
34879 el.setWidth(newSize);
34880 this.fireEvent("resized", this, newSize);
34884 el.setHeight(newSize);
34885 this.fireEvent("resized", this, newSize);
34891 getBox : function(){
34892 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
34895 getMargins : function(){
34896 return this.margins;
34899 updateBox : function(box){
34901 var el = this.activePanel.getEl();
34902 el.dom.style.left = box.x + "px";
34903 el.dom.style.top = box.y + "px";
34904 this.activePanel.setSize(box.width, box.height);
34908 * Returns the container element for this region.
34909 * @return {Roo.Element}
34911 getEl : function(){
34912 return this.activePanel;
34916 * Returns true if this region is currently visible.
34917 * @return {Boolean}
34919 isVisible : function(){
34920 return this.activePanel ? true : false;
34923 setActivePanel : function(panel){
34924 panel = this.getPanel(panel);
34925 if(this.activePanel && this.activePanel != panel){
34926 this.activePanel.setActiveState(false);
34927 this.activePanel.getEl().setLeftTop(-10000,-10000);
34929 this.activePanel = panel;
34930 panel.setActiveState(true);
34932 panel.setSize(this.box.width, this.box.height);
34934 this.fireEvent("panelactivated", this, panel);
34935 this.fireEvent("invalidated");
34939 * Show the specified panel.
34940 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
34941 * @return {Roo.ContentPanel} The shown panel or null
34943 showPanel : function(panel){
34944 panel = this.getPanel(panel);
34946 this.setActivePanel(panel);
34952 * Get the active panel for this region.
34953 * @return {Roo.ContentPanel} The active panel or null
34955 getActivePanel : function(){
34956 return this.activePanel;
34960 * Add the passed ContentPanel(s)
34961 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
34962 * @return {Roo.ContentPanel} The panel added (if only one was added)
34964 add : function(panel){
34965 if(arguments.length > 1){
34966 for(var i = 0, len = arguments.length; i < len; i++) {
34967 this.add(arguments[i]);
34971 if(this.hasPanel(panel)){
34972 this.showPanel(panel);
34975 var el = panel.getEl();
34976 if(el.dom.parentNode != this.mgr.el.dom){
34977 this.mgr.el.dom.appendChild(el.dom);
34979 if(panel.setRegion){
34980 panel.setRegion(this);
34982 this.panels.add(panel);
34983 el.setStyle("position", "absolute");
34984 if(!panel.background){
34985 this.setActivePanel(panel);
34986 if(this.config.initialSize && this.panels.getCount()==1){
34987 this.resizeTo(this.config.initialSize);
34990 this.fireEvent("paneladded", this, panel);
34995 * Returns true if the panel is in this region.
34996 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
34997 * @return {Boolean}
34999 hasPanel : function(panel){
35000 if(typeof panel == "object"){ // must be panel obj
35001 panel = panel.getId();
35003 return this.getPanel(panel) ? true : false;
35007 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35008 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35009 * @param {Boolean} preservePanel Overrides the config preservePanel option
35010 * @return {Roo.ContentPanel} The panel that was removed
35012 remove : function(panel, preservePanel){
35013 panel = this.getPanel(panel);
35018 this.fireEvent("beforeremove", this, panel, e);
35019 if(e.cancel === true){
35022 var panelId = panel.getId();
35023 this.panels.removeKey(panelId);
35028 * Returns the panel specified or null if it's not in this region.
35029 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35030 * @return {Roo.ContentPanel}
35032 getPanel : function(id){
35033 if(typeof id == "object"){ // must be panel obj
35036 return this.panels.get(id);
35040 * Returns this regions position (north/south/east/west/center).
35043 getPosition: function(){
35044 return this.position;
35048 * Ext JS Library 1.1.1
35049 * Copyright(c) 2006-2007, Ext JS, LLC.
35051 * Originally Released Under LGPL - original licence link has changed is not relivant.
35054 * <script type="text/javascript">
35058 * @class Roo.bootstrap.layout.Region
35059 * @extends Roo.bootstrap.layout.Basic
35060 * This class represents a region in a layout manager.
35062 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
35063 * @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})
35064 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
35065 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
35066 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
35067 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
35068 * @cfg {String} title The title for the region (overrides panel titles)
35069 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
35070 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
35071 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
35072 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
35073 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
35074 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
35075 * the space available, similar to FireFox 1.5 tabs (defaults to false)
35076 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
35077 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
35078 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
35080 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
35081 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
35082 * @cfg {Boolean} disableTabTips True to disable tab tooltips
35083 * @cfg {Number} width For East/West panels
35084 * @cfg {Number} height For North/South panels
35085 * @cfg {Boolean} split To show the splitter
35086 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
35088 * @cfg {string} cls Extra CSS classes to add to region
35090 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35091 * @cfg {string} region the region that it inhabits..
35094 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
35095 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
35097 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
35098 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
35099 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
35101 Roo.bootstrap.layout.Region = function(config)
35103 this.applyConfig(config);
35105 var mgr = config.mgr;
35106 var pos = config.region;
35107 config.skipConfig = true;
35108 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
35111 this.onRender(mgr.el);
35114 this.visible = true;
35115 this.collapsed = false;
35116 this.unrendered_panels = [];
35119 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
35121 position: '', // set by wrapper (eg. north/south etc..)
35122 unrendered_panels : null, // unrendered panels.
35123 createBody : function(){
35124 /** This region's body element
35125 * @type Roo.Element */
35126 this.bodyEl = this.el.createChild({
35128 cls: "roo-layout-panel-body tab-content" // bootstrap added...
35132 onRender: function(ctr, pos)
35134 var dh = Roo.DomHelper;
35135 /** This region's container element
35136 * @type Roo.Element */
35137 this.el = dh.append(ctr.dom, {
35139 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
35141 /** This region's title element
35142 * @type Roo.Element */
35144 this.titleEl = dh.append(this.el.dom,
35147 unselectable: "on",
35148 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
35150 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
35151 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
35154 this.titleEl.enableDisplayMode();
35155 /** This region's title text element
35156 * @type HTMLElement */
35157 this.titleTextEl = this.titleEl.dom.firstChild;
35158 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
35160 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
35161 this.closeBtn.enableDisplayMode();
35162 this.closeBtn.on("click", this.closeClicked, this);
35163 this.closeBtn.hide();
35165 this.createBody(this.config);
35166 if(this.config.hideWhenEmpty){
35168 this.on("paneladded", this.validateVisibility, this);
35169 this.on("panelremoved", this.validateVisibility, this);
35171 if(this.autoScroll){
35172 this.bodyEl.setStyle("overflow", "auto");
35174 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
35176 //if(c.titlebar !== false){
35177 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
35178 this.titleEl.hide();
35180 this.titleEl.show();
35181 if(this.config.title){
35182 this.titleTextEl.innerHTML = this.config.title;
35186 if(this.config.collapsed){
35187 this.collapse(true);
35189 if(this.config.hidden){
35193 if (this.unrendered_panels && this.unrendered_panels.length) {
35194 for (var i =0;i< this.unrendered_panels.length; i++) {
35195 this.add(this.unrendered_panels[i]);
35197 this.unrendered_panels = null;
35203 applyConfig : function(c)
35206 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
35207 var dh = Roo.DomHelper;
35208 if(c.titlebar !== false){
35209 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
35210 this.collapseBtn.on("click", this.collapse, this);
35211 this.collapseBtn.enableDisplayMode();
35213 if(c.showPin === true || this.showPin){
35214 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
35215 this.stickBtn.enableDisplayMode();
35216 this.stickBtn.on("click", this.expand, this);
35217 this.stickBtn.hide();
35222 /** This region's collapsed element
35223 * @type Roo.Element */
35226 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
35227 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
35230 if(c.floatable !== false){
35231 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
35232 this.collapsedEl.on("click", this.collapseClick, this);
35235 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
35236 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
35237 id: "message", unselectable: "on", style:{"float":"left"}});
35238 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
35240 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
35241 this.expandBtn.on("click", this.expand, this);
35245 if(this.collapseBtn){
35246 this.collapseBtn.setVisible(c.collapsible == true);
35249 this.cmargins = c.cmargins || this.cmargins ||
35250 (this.position == "west" || this.position == "east" ?
35251 {top: 0, left: 2, right:2, bottom: 0} :
35252 {top: 2, left: 0, right:0, bottom: 2});
35254 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35257 this.bottomTabs = c.tabPosition != "top";
35259 this.autoScroll = c.autoScroll || false;
35264 this.duration = c.duration || .30;
35265 this.slideDuration = c.slideDuration || .45;
35270 * Returns true if this region is currently visible.
35271 * @return {Boolean}
35273 isVisible : function(){
35274 return this.visible;
35278 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
35279 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
35281 //setCollapsedTitle : function(title){
35282 // title = title || " ";
35283 // if(this.collapsedTitleTextEl){
35284 // this.collapsedTitleTextEl.innerHTML = title;
35288 getBox : function(){
35290 // if(!this.collapsed){
35291 b = this.el.getBox(false, true);
35293 // b = this.collapsedEl.getBox(false, true);
35298 getMargins : function(){
35299 return this.margins;
35300 //return this.collapsed ? this.cmargins : this.margins;
35303 highlight : function(){
35304 this.el.addClass("x-layout-panel-dragover");
35307 unhighlight : function(){
35308 this.el.removeClass("x-layout-panel-dragover");
35311 updateBox : function(box)
35313 if (!this.bodyEl) {
35314 return; // not rendered yet..
35318 if(!this.collapsed){
35319 this.el.dom.style.left = box.x + "px";
35320 this.el.dom.style.top = box.y + "px";
35321 this.updateBody(box.width, box.height);
35323 this.collapsedEl.dom.style.left = box.x + "px";
35324 this.collapsedEl.dom.style.top = box.y + "px";
35325 this.collapsedEl.setSize(box.width, box.height);
35328 this.tabs.autoSizeTabs();
35332 updateBody : function(w, h)
35335 this.el.setWidth(w);
35336 w -= this.el.getBorderWidth("rl");
35337 if(this.config.adjustments){
35338 w += this.config.adjustments[0];
35341 if(h !== null && h > 0){
35342 this.el.setHeight(h);
35343 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
35344 h -= this.el.getBorderWidth("tb");
35345 if(this.config.adjustments){
35346 h += this.config.adjustments[1];
35348 this.bodyEl.setHeight(h);
35350 h = this.tabs.syncHeight(h);
35353 if(this.panelSize){
35354 w = w !== null ? w : this.panelSize.width;
35355 h = h !== null ? h : this.panelSize.height;
35357 if(this.activePanel){
35358 var el = this.activePanel.getEl();
35359 w = w !== null ? w : el.getWidth();
35360 h = h !== null ? h : el.getHeight();
35361 this.panelSize = {width: w, height: h};
35362 this.activePanel.setSize(w, h);
35364 if(Roo.isIE && this.tabs){
35365 this.tabs.el.repaint();
35370 * Returns the container element for this region.
35371 * @return {Roo.Element}
35373 getEl : function(){
35378 * Hides this region.
35381 //if(!this.collapsed){
35382 this.el.dom.style.left = "-2000px";
35385 // this.collapsedEl.dom.style.left = "-2000px";
35386 // this.collapsedEl.hide();
35388 this.visible = false;
35389 this.fireEvent("visibilitychange", this, false);
35393 * Shows this region if it was previously hidden.
35396 //if(!this.collapsed){
35399 // this.collapsedEl.show();
35401 this.visible = true;
35402 this.fireEvent("visibilitychange", this, true);
35405 closeClicked : function(){
35406 if(this.activePanel){
35407 this.remove(this.activePanel);
35411 collapseClick : function(e){
35413 e.stopPropagation();
35416 e.stopPropagation();
35422 * Collapses this region.
35423 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
35426 collapse : function(skipAnim, skipCheck = false){
35427 if(this.collapsed) {
35431 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
35433 this.collapsed = true;
35435 this.split.el.hide();
35437 if(this.config.animate && skipAnim !== true){
35438 this.fireEvent("invalidated", this);
35439 this.animateCollapse();
35441 this.el.setLocation(-20000,-20000);
35443 this.collapsedEl.show();
35444 this.fireEvent("collapsed", this);
35445 this.fireEvent("invalidated", this);
35451 animateCollapse : function(){
35456 * Expands this region if it was previously collapsed.
35457 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
35458 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
35461 expand : function(e, skipAnim){
35463 e.stopPropagation();
35465 if(!this.collapsed || this.el.hasActiveFx()) {
35469 this.afterSlideIn();
35472 this.collapsed = false;
35473 if(this.config.animate && skipAnim !== true){
35474 this.animateExpand();
35478 this.split.el.show();
35480 this.collapsedEl.setLocation(-2000,-2000);
35481 this.collapsedEl.hide();
35482 this.fireEvent("invalidated", this);
35483 this.fireEvent("expanded", this);
35487 animateExpand : function(){
35491 initTabs : function()
35493 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
35495 var ts = new Roo.bootstrap.panel.Tabs({
35496 el: this.bodyEl.dom,
35497 tabPosition: this.bottomTabs ? 'bottom' : 'top',
35498 disableTooltips: this.config.disableTabTips,
35499 toolbar : this.config.toolbar
35502 if(this.config.hideTabs){
35503 ts.stripWrap.setDisplayed(false);
35506 ts.resizeTabs = this.config.resizeTabs === true;
35507 ts.minTabWidth = this.config.minTabWidth || 40;
35508 ts.maxTabWidth = this.config.maxTabWidth || 250;
35509 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
35510 ts.monitorResize = false;
35511 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
35512 ts.bodyEl.addClass('roo-layout-tabs-body');
35513 this.panels.each(this.initPanelAsTab, this);
35516 initPanelAsTab : function(panel){
35517 var ti = this.tabs.addTab(
35521 this.config.closeOnTab && panel.isClosable(),
35524 if(panel.tabTip !== undefined){
35525 ti.setTooltip(panel.tabTip);
35527 ti.on("activate", function(){
35528 this.setActivePanel(panel);
35531 if(this.config.closeOnTab){
35532 ti.on("beforeclose", function(t, e){
35534 this.remove(panel);
35538 panel.tabItem = ti;
35543 updatePanelTitle : function(panel, title)
35545 if(this.activePanel == panel){
35546 this.updateTitle(title);
35549 var ti = this.tabs.getTab(panel.getEl().id);
35551 if(panel.tabTip !== undefined){
35552 ti.setTooltip(panel.tabTip);
35557 updateTitle : function(title){
35558 if(this.titleTextEl && !this.config.title){
35559 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
35563 setActivePanel : function(panel)
35565 panel = this.getPanel(panel);
35566 if(this.activePanel && this.activePanel != panel){
35567 if(this.activePanel.setActiveState(false) === false){
35571 this.activePanel = panel;
35572 panel.setActiveState(true);
35573 if(this.panelSize){
35574 panel.setSize(this.panelSize.width, this.panelSize.height);
35577 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
35579 this.updateTitle(panel.getTitle());
35581 this.fireEvent("invalidated", this);
35583 this.fireEvent("panelactivated", this, panel);
35587 * Shows the specified panel.
35588 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
35589 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
35591 showPanel : function(panel)
35593 panel = this.getPanel(panel);
35596 var tab = this.tabs.getTab(panel.getEl().id);
35597 if(tab.isHidden()){
35598 this.tabs.unhideTab(tab.id);
35602 this.setActivePanel(panel);
35609 * Get the active panel for this region.
35610 * @return {Roo.ContentPanel} The active panel or null
35612 getActivePanel : function(){
35613 return this.activePanel;
35616 validateVisibility : function(){
35617 if(this.panels.getCount() < 1){
35618 this.updateTitle(" ");
35619 this.closeBtn.hide();
35622 if(!this.isVisible()){
35629 * Adds the passed ContentPanel(s) to this region.
35630 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35631 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
35633 add : function(panel)
35635 if(arguments.length > 1){
35636 for(var i = 0, len = arguments.length; i < len; i++) {
35637 this.add(arguments[i]);
35642 // if we have not been rendered yet, then we can not really do much of this..
35643 if (!this.bodyEl) {
35644 this.unrendered_panels.push(panel);
35651 if(this.hasPanel(panel)){
35652 this.showPanel(panel);
35655 panel.setRegion(this);
35656 this.panels.add(panel);
35657 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
35658 // sinle panel - no tab...?? would it not be better to render it with the tabs,
35659 // and hide them... ???
35660 this.bodyEl.dom.appendChild(panel.getEl().dom);
35661 if(panel.background !== true){
35662 this.setActivePanel(panel);
35664 this.fireEvent("paneladded", this, panel);
35671 this.initPanelAsTab(panel);
35675 if(panel.background !== true){
35676 this.tabs.activate(panel.getEl().id);
35678 this.fireEvent("paneladded", this, panel);
35683 * Hides the tab for the specified panel.
35684 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
35686 hidePanel : function(panel){
35687 if(this.tabs && (panel = this.getPanel(panel))){
35688 this.tabs.hideTab(panel.getEl().id);
35693 * Unhides the tab for a previously hidden panel.
35694 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
35696 unhidePanel : function(panel){
35697 if(this.tabs && (panel = this.getPanel(panel))){
35698 this.tabs.unhideTab(panel.getEl().id);
35702 clearPanels : function(){
35703 while(this.panels.getCount() > 0){
35704 this.remove(this.panels.first());
35709 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35710 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
35711 * @param {Boolean} preservePanel Overrides the config preservePanel option
35712 * @return {Roo.ContentPanel} The panel that was removed
35714 remove : function(panel, preservePanel)
35716 panel = this.getPanel(panel);
35721 this.fireEvent("beforeremove", this, panel, e);
35722 if(e.cancel === true){
35725 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
35726 var panelId = panel.getId();
35727 this.panels.removeKey(panelId);
35729 document.body.appendChild(panel.getEl().dom);
35732 this.tabs.removeTab(panel.getEl().id);
35733 }else if (!preservePanel){
35734 this.bodyEl.dom.removeChild(panel.getEl().dom);
35736 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
35737 var p = this.panels.first();
35738 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
35739 tempEl.appendChild(p.getEl().dom);
35740 this.bodyEl.update("");
35741 this.bodyEl.dom.appendChild(p.getEl().dom);
35743 this.updateTitle(p.getTitle());
35745 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
35746 this.setActivePanel(p);
35748 panel.setRegion(null);
35749 if(this.activePanel == panel){
35750 this.activePanel = null;
35752 if(this.config.autoDestroy !== false && preservePanel !== true){
35753 try{panel.destroy();}catch(e){}
35755 this.fireEvent("panelremoved", this, panel);
35760 * Returns the TabPanel component used by this region
35761 * @return {Roo.TabPanel}
35763 getTabs : function(){
35767 createTool : function(parentEl, className){
35768 var btn = Roo.DomHelper.append(parentEl, {
35770 cls: "x-layout-tools-button",
35773 cls: "roo-layout-tools-button-inner " + className,
35777 btn.addClassOnOver("roo-layout-tools-button-over");
35782 * Ext JS Library 1.1.1
35783 * Copyright(c) 2006-2007, Ext JS, LLC.
35785 * Originally Released Under LGPL - original licence link has changed is not relivant.
35788 * <script type="text/javascript">
35794 * @class Roo.SplitLayoutRegion
35795 * @extends Roo.LayoutRegion
35796 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
35798 Roo.bootstrap.layout.Split = function(config){
35799 this.cursor = config.cursor;
35800 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
35803 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
35805 splitTip : "Drag to resize.",
35806 collapsibleSplitTip : "Drag to resize. Double click to hide.",
35807 useSplitTips : false,
35809 applyConfig : function(config){
35810 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
35813 onRender : function(ctr,pos) {
35815 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
35816 if(!this.config.split){
35821 var splitEl = Roo.DomHelper.append(ctr.dom, {
35823 id: this.el.id + "-split",
35824 cls: "roo-layout-split roo-layout-split-"+this.position,
35827 /** The SplitBar for this region
35828 * @type Roo.SplitBar */
35829 // does not exist yet...
35830 Roo.log([this.position, this.orientation]);
35832 this.split = new Roo.bootstrap.SplitBar({
35833 dragElement : splitEl,
35834 resizingElement: this.el,
35835 orientation : this.orientation
35838 this.split.on("moved", this.onSplitMove, this);
35839 this.split.useShim = this.config.useShim === true;
35840 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
35841 if(this.useSplitTips){
35842 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
35844 //if(config.collapsible){
35845 // this.split.el.on("dblclick", this.collapse, this);
35848 if(typeof this.config.minSize != "undefined"){
35849 this.split.minSize = this.config.minSize;
35851 if(typeof this.config.maxSize != "undefined"){
35852 this.split.maxSize = this.config.maxSize;
35854 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
35855 this.hideSplitter();
35860 getHMaxSize : function(){
35861 var cmax = this.config.maxSize || 10000;
35862 var center = this.mgr.getRegion("center");
35863 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
35866 getVMaxSize : function(){
35867 var cmax = this.config.maxSize || 10000;
35868 var center = this.mgr.getRegion("center");
35869 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
35872 onSplitMove : function(split, newSize){
35873 this.fireEvent("resized", this, newSize);
35877 * Returns the {@link Roo.SplitBar} for this region.
35878 * @return {Roo.SplitBar}
35880 getSplitBar : function(){
35885 this.hideSplitter();
35886 Roo.bootstrap.layout.Split.superclass.hide.call(this);
35889 hideSplitter : function(){
35891 this.split.el.setLocation(-2000,-2000);
35892 this.split.el.hide();
35898 this.split.el.show();
35900 Roo.bootstrap.layout.Split.superclass.show.call(this);
35903 beforeSlide: function(){
35904 if(Roo.isGecko){// firefox overflow auto bug workaround
35905 this.bodyEl.clip();
35907 this.tabs.bodyEl.clip();
35909 if(this.activePanel){
35910 this.activePanel.getEl().clip();
35912 if(this.activePanel.beforeSlide){
35913 this.activePanel.beforeSlide();
35919 afterSlide : function(){
35920 if(Roo.isGecko){// firefox overflow auto bug workaround
35921 this.bodyEl.unclip();
35923 this.tabs.bodyEl.unclip();
35925 if(this.activePanel){
35926 this.activePanel.getEl().unclip();
35927 if(this.activePanel.afterSlide){
35928 this.activePanel.afterSlide();
35934 initAutoHide : function(){
35935 if(this.autoHide !== false){
35936 if(!this.autoHideHd){
35937 var st = new Roo.util.DelayedTask(this.slideIn, this);
35938 this.autoHideHd = {
35939 "mouseout": function(e){
35940 if(!e.within(this.el, true)){
35944 "mouseover" : function(e){
35950 this.el.on(this.autoHideHd);
35954 clearAutoHide : function(){
35955 if(this.autoHide !== false){
35956 this.el.un("mouseout", this.autoHideHd.mouseout);
35957 this.el.un("mouseover", this.autoHideHd.mouseover);
35961 clearMonitor : function(){
35962 Roo.get(document).un("click", this.slideInIf, this);
35965 // these names are backwards but not changed for compat
35966 slideOut : function(){
35967 if(this.isSlid || this.el.hasActiveFx()){
35970 this.isSlid = true;
35971 if(this.collapseBtn){
35972 this.collapseBtn.hide();
35974 this.closeBtnState = this.closeBtn.getStyle('display');
35975 this.closeBtn.hide();
35977 this.stickBtn.show();
35980 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
35981 this.beforeSlide();
35982 this.el.setStyle("z-index", 10001);
35983 this.el.slideIn(this.getSlideAnchor(), {
35984 callback: function(){
35986 this.initAutoHide();
35987 Roo.get(document).on("click", this.slideInIf, this);
35988 this.fireEvent("slideshow", this);
35995 afterSlideIn : function(){
35996 this.clearAutoHide();
35997 this.isSlid = false;
35998 this.clearMonitor();
35999 this.el.setStyle("z-index", "");
36000 if(this.collapseBtn){
36001 this.collapseBtn.show();
36003 this.closeBtn.setStyle('display', this.closeBtnState);
36005 this.stickBtn.hide();
36007 this.fireEvent("slidehide", this);
36010 slideIn : function(cb){
36011 if(!this.isSlid || this.el.hasActiveFx()){
36015 this.isSlid = false;
36016 this.beforeSlide();
36017 this.el.slideOut(this.getSlideAnchor(), {
36018 callback: function(){
36019 this.el.setLeftTop(-10000, -10000);
36021 this.afterSlideIn();
36029 slideInIf : function(e){
36030 if(!e.within(this.el)){
36035 animateCollapse : function(){
36036 this.beforeSlide();
36037 this.el.setStyle("z-index", 20000);
36038 var anchor = this.getSlideAnchor();
36039 this.el.slideOut(anchor, {
36040 callback : function(){
36041 this.el.setStyle("z-index", "");
36042 this.collapsedEl.slideIn(anchor, {duration:.3});
36044 this.el.setLocation(-10000,-10000);
36046 this.fireEvent("collapsed", this);
36053 animateExpand : function(){
36054 this.beforeSlide();
36055 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
36056 this.el.setStyle("z-index", 20000);
36057 this.collapsedEl.hide({
36060 this.el.slideIn(this.getSlideAnchor(), {
36061 callback : function(){
36062 this.el.setStyle("z-index", "");
36065 this.split.el.show();
36067 this.fireEvent("invalidated", this);
36068 this.fireEvent("expanded", this);
36096 getAnchor : function(){
36097 return this.anchors[this.position];
36100 getCollapseAnchor : function(){
36101 return this.canchors[this.position];
36104 getSlideAnchor : function(){
36105 return this.sanchors[this.position];
36108 getAlignAdj : function(){
36109 var cm = this.cmargins;
36110 switch(this.position){
36126 getExpandAdj : function(){
36127 var c = this.collapsedEl, cm = this.cmargins;
36128 switch(this.position){
36130 return [-(cm.right+c.getWidth()+cm.left), 0];
36133 return [cm.right+c.getWidth()+cm.left, 0];
36136 return [0, -(cm.top+cm.bottom+c.getHeight())];
36139 return [0, cm.top+cm.bottom+c.getHeight()];
36145 * Ext JS Library 1.1.1
36146 * Copyright(c) 2006-2007, Ext JS, LLC.
36148 * Originally Released Under LGPL - original licence link has changed is not relivant.
36151 * <script type="text/javascript">
36154 * These classes are private internal classes
36156 Roo.bootstrap.layout.Center = function(config){
36157 config.region = "center";
36158 Roo.bootstrap.layout.Region.call(this, config);
36159 this.visible = true;
36160 this.minWidth = config.minWidth || 20;
36161 this.minHeight = config.minHeight || 20;
36164 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
36166 // center panel can't be hidden
36170 // center panel can't be hidden
36173 getMinWidth: function(){
36174 return this.minWidth;
36177 getMinHeight: function(){
36178 return this.minHeight;
36191 Roo.bootstrap.layout.North = function(config)
36193 config.region = 'north';
36194 config.cursor = 'n-resize';
36196 Roo.bootstrap.layout.Split.call(this, config);
36200 this.split.placement = Roo.bootstrap.SplitBar.TOP;
36201 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36202 this.split.el.addClass("roo-layout-split-v");
36204 var size = config.initialSize || config.height;
36205 if(typeof size != "undefined"){
36206 this.el.setHeight(size);
36209 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
36211 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36215 getBox : function(){
36216 if(this.collapsed){
36217 return this.collapsedEl.getBox();
36219 var box = this.el.getBox();
36221 box.height += this.split.el.getHeight();
36226 updateBox : function(box){
36227 if(this.split && !this.collapsed){
36228 box.height -= this.split.el.getHeight();
36229 this.split.el.setLeft(box.x);
36230 this.split.el.setTop(box.y+box.height);
36231 this.split.el.setWidth(box.width);
36233 if(this.collapsed){
36234 this.updateBody(box.width, null);
36236 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36244 Roo.bootstrap.layout.South = function(config){
36245 config.region = 'south';
36246 config.cursor = 's-resize';
36247 Roo.bootstrap.layout.Split.call(this, config);
36249 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
36250 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36251 this.split.el.addClass("roo-layout-split-v");
36253 var size = config.initialSize || config.height;
36254 if(typeof size != "undefined"){
36255 this.el.setHeight(size);
36259 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
36260 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36261 getBox : function(){
36262 if(this.collapsed){
36263 return this.collapsedEl.getBox();
36265 var box = this.el.getBox();
36267 var sh = this.split.el.getHeight();
36274 updateBox : function(box){
36275 if(this.split && !this.collapsed){
36276 var sh = this.split.el.getHeight();
36279 this.split.el.setLeft(box.x);
36280 this.split.el.setTop(box.y-sh);
36281 this.split.el.setWidth(box.width);
36283 if(this.collapsed){
36284 this.updateBody(box.width, null);
36286 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36290 Roo.bootstrap.layout.East = function(config){
36291 config.region = "east";
36292 config.cursor = "e-resize";
36293 Roo.bootstrap.layout.Split.call(this, config);
36295 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
36296 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36297 this.split.el.addClass("roo-layout-split-h");
36299 var size = config.initialSize || config.width;
36300 if(typeof size != "undefined"){
36301 this.el.setWidth(size);
36304 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
36305 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36306 getBox : function(){
36307 if(this.collapsed){
36308 return this.collapsedEl.getBox();
36310 var box = this.el.getBox();
36312 var sw = this.split.el.getWidth();
36319 updateBox : function(box){
36320 if(this.split && !this.collapsed){
36321 var sw = this.split.el.getWidth();
36323 this.split.el.setLeft(box.x);
36324 this.split.el.setTop(box.y);
36325 this.split.el.setHeight(box.height);
36328 if(this.collapsed){
36329 this.updateBody(null, box.height);
36331 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36335 Roo.bootstrap.layout.West = function(config){
36336 config.region = "west";
36337 config.cursor = "w-resize";
36339 Roo.bootstrap.layout.Split.call(this, config);
36341 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
36342 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36343 this.split.el.addClass("roo-layout-split-h");
36347 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
36348 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36350 onRender: function(ctr, pos)
36352 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
36353 var size = this.config.initialSize || this.config.width;
36354 if(typeof size != "undefined"){
36355 this.el.setWidth(size);
36359 getBox : function(){
36360 if(this.collapsed){
36361 return this.collapsedEl.getBox();
36363 var box = this.el.getBox();
36365 box.width += this.split.el.getWidth();
36370 updateBox : function(box){
36371 if(this.split && !this.collapsed){
36372 var sw = this.split.el.getWidth();
36374 this.split.el.setLeft(box.x+box.width);
36375 this.split.el.setTop(box.y);
36376 this.split.el.setHeight(box.height);
36378 if(this.collapsed){
36379 this.updateBody(null, box.height);
36381 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36384 Roo.namespace("Roo.bootstrap.panel");/*
36386 * Ext JS Library 1.1.1
36387 * Copyright(c) 2006-2007, Ext JS, LLC.
36389 * Originally Released Under LGPL - original licence link has changed is not relivant.
36392 * <script type="text/javascript">
36395 * @class Roo.ContentPanel
36396 * @extends Roo.util.Observable
36397 * A basic ContentPanel element.
36398 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
36399 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
36400 * @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
36401 * @cfg {Boolean} closable True if the panel can be closed/removed
36402 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
36403 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
36404 * @cfg {Toolbar} toolbar A toolbar for this panel
36405 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
36406 * @cfg {String} title The title for this panel
36407 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
36408 * @cfg {String} url Calls {@link #setUrl} with this value
36409 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
36410 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
36411 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
36412 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
36413 * @cfg {Boolean} badges render the badges
36416 * Create a new ContentPanel.
36417 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
36418 * @param {String/Object} config A string to set only the title or a config object
36419 * @param {String} content (optional) Set the HTML content for this panel
36420 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
36422 Roo.bootstrap.panel.Content = function( config){
36424 this.tpl = config.tpl || false;
36426 var el = config.el;
36427 var content = config.content;
36429 if(config.autoCreate){ // xtype is available if this is called from factory
36432 this.el = Roo.get(el);
36433 if(!this.el && config && config.autoCreate){
36434 if(typeof config.autoCreate == "object"){
36435 if(!config.autoCreate.id){
36436 config.autoCreate.id = config.id||el;
36438 this.el = Roo.DomHelper.append(document.body,
36439 config.autoCreate, true);
36441 var elcfg = { tag: "div",
36442 cls: "roo-layout-inactive-content",
36446 elcfg.html = config.html;
36450 this.el = Roo.DomHelper.append(document.body, elcfg , true);
36453 this.closable = false;
36454 this.loaded = false;
36455 this.active = false;
36458 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
36460 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
36462 this.wrapEl = this.el; //this.el.wrap();
36464 if (config.toolbar.items) {
36465 ti = config.toolbar.items ;
36466 delete config.toolbar.items ;
36470 this.toolbar.render(this.wrapEl, 'before');
36471 for(var i =0;i < ti.length;i++) {
36472 // Roo.log(['add child', items[i]]);
36473 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
36475 this.toolbar.items = nitems;
36476 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
36477 delete config.toolbar;
36481 // xtype created footer. - not sure if will work as we normally have to render first..
36482 if (this.footer && !this.footer.el && this.footer.xtype) {
36483 if (!this.wrapEl) {
36484 this.wrapEl = this.el.wrap();
36487 this.footer.container = this.wrapEl.createChild();
36489 this.footer = Roo.factory(this.footer, Roo);
36494 if(typeof config == "string"){
36495 this.title = config;
36497 Roo.apply(this, config);
36501 this.resizeEl = Roo.get(this.resizeEl, true);
36503 this.resizeEl = this.el;
36505 // handle view.xtype
36513 * Fires when this panel is activated.
36514 * @param {Roo.ContentPanel} this
36518 * @event deactivate
36519 * Fires when this panel is activated.
36520 * @param {Roo.ContentPanel} this
36522 "deactivate" : true,
36526 * Fires when this panel is resized if fitToFrame is true.
36527 * @param {Roo.ContentPanel} this
36528 * @param {Number} width The width after any component adjustments
36529 * @param {Number} height The height after any component adjustments
36535 * Fires when this tab is created
36536 * @param {Roo.ContentPanel} this
36547 if(this.autoScroll){
36548 this.resizeEl.setStyle("overflow", "auto");
36550 // fix randome scrolling
36551 //this.el.on('scroll', function() {
36552 // Roo.log('fix random scolling');
36553 // this.scrollTo('top',0);
36556 content = content || this.content;
36558 this.setContent(content);
36560 if(config && config.url){
36561 this.setUrl(this.url, this.params, this.loadOnce);
36566 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
36568 if (this.view && typeof(this.view.xtype) != 'undefined') {
36569 this.view.el = this.el.appendChild(document.createElement("div"));
36570 this.view = Roo.factory(this.view);
36571 this.view.render && this.view.render(false, '');
36575 this.fireEvent('render', this);
36578 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
36582 setRegion : function(region){
36583 this.region = region;
36584 this.setActiveClass(region && !this.background);
36588 setActiveClass: function(state)
36591 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
36592 this.el.setStyle('position','relative');
36594 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
36595 this.el.setStyle('position', 'absolute');
36600 * Returns the toolbar for this Panel if one was configured.
36601 * @return {Roo.Toolbar}
36603 getToolbar : function(){
36604 return this.toolbar;
36607 setActiveState : function(active)
36609 this.active = active;
36610 this.setActiveClass(active);
36612 if(this.fireEvent("deactivate", this) === false){
36617 this.fireEvent("activate", this);
36621 * Updates this panel's element
36622 * @param {String} content The new content
36623 * @param {Boolean} loadScripts (optional) true to look for and process scripts
36625 setContent : function(content, loadScripts){
36626 this.el.update(content, loadScripts);
36629 ignoreResize : function(w, h){
36630 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
36633 this.lastSize = {width: w, height: h};
36638 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
36639 * @return {Roo.UpdateManager} The UpdateManager
36641 getUpdateManager : function(){
36642 return this.el.getUpdateManager();
36645 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
36646 * @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:
36649 url: "your-url.php",
36650 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
36651 callback: yourFunction,
36652 scope: yourObject, //(optional scope)
36655 text: "Loading...",
36660 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
36661 * 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.
36662 * @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}
36663 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
36664 * @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.
36665 * @return {Roo.ContentPanel} this
36668 var um = this.el.getUpdateManager();
36669 um.update.apply(um, arguments);
36675 * 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.
36676 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
36677 * @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)
36678 * @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)
36679 * @return {Roo.UpdateManager} The UpdateManager
36681 setUrl : function(url, params, loadOnce){
36682 if(this.refreshDelegate){
36683 this.removeListener("activate", this.refreshDelegate);
36685 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
36686 this.on("activate", this.refreshDelegate);
36687 return this.el.getUpdateManager();
36690 _handleRefresh : function(url, params, loadOnce){
36691 if(!loadOnce || !this.loaded){
36692 var updater = this.el.getUpdateManager();
36693 updater.update(url, params, this._setLoaded.createDelegate(this));
36697 _setLoaded : function(){
36698 this.loaded = true;
36702 * Returns this panel's id
36705 getId : function(){
36710 * Returns this panel's element - used by regiosn to add.
36711 * @return {Roo.Element}
36713 getEl : function(){
36714 return this.wrapEl || this.el;
36719 adjustForComponents : function(width, height)
36721 //Roo.log('adjustForComponents ');
36722 if(this.resizeEl != this.el){
36723 width -= this.el.getFrameWidth('lr');
36724 height -= this.el.getFrameWidth('tb');
36727 var te = this.toolbar.getEl();
36728 te.setWidth(width);
36729 height -= te.getHeight();
36732 var te = this.footer.getEl();
36733 te.setWidth(width);
36734 height -= te.getHeight();
36738 if(this.adjustments){
36739 width += this.adjustments[0];
36740 height += this.adjustments[1];
36742 return {"width": width, "height": height};
36745 setSize : function(width, height){
36746 if(this.fitToFrame && !this.ignoreResize(width, height)){
36747 if(this.fitContainer && this.resizeEl != this.el){
36748 this.el.setSize(width, height);
36750 var size = this.adjustForComponents(width, height);
36751 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
36752 this.fireEvent('resize', this, size.width, size.height);
36757 * Returns this panel's title
36760 getTitle : function(){
36762 if (typeof(this.title) != 'object') {
36767 for (var k in this.title) {
36768 if (!this.title.hasOwnProperty(k)) {
36772 if (k.indexOf('-') >= 0) {
36773 var s = k.split('-');
36774 for (var i = 0; i<s.length; i++) {
36775 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
36778 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
36785 * Set this panel's title
36786 * @param {String} title
36788 setTitle : function(title){
36789 this.title = title;
36791 this.region.updatePanelTitle(this, title);
36796 * Returns true is this panel was configured to be closable
36797 * @return {Boolean}
36799 isClosable : function(){
36800 return this.closable;
36803 beforeSlide : function(){
36805 this.resizeEl.clip();
36808 afterSlide : function(){
36810 this.resizeEl.unclip();
36814 * Force a content refresh from the URL specified in the {@link #setUrl} method.
36815 * Will fail silently if the {@link #setUrl} method has not been called.
36816 * This does not activate the panel, just updates its content.
36818 refresh : function(){
36819 if(this.refreshDelegate){
36820 this.loaded = false;
36821 this.refreshDelegate();
36826 * Destroys this panel
36828 destroy : function(){
36829 this.el.removeAllListeners();
36830 var tempEl = document.createElement("span");
36831 tempEl.appendChild(this.el.dom);
36832 tempEl.innerHTML = "";
36838 * form - if the content panel contains a form - this is a reference to it.
36839 * @type {Roo.form.Form}
36843 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
36844 * This contains a reference to it.
36850 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
36860 * @param {Object} cfg Xtype definition of item to add.
36864 getChildContainer: function () {
36865 return this.getEl();
36870 var ret = new Roo.factory(cfg);
36875 if (cfg.xtype.match(/^Form$/)) {
36878 //if (this.footer) {
36879 // el = this.footer.container.insertSibling(false, 'before');
36881 el = this.el.createChild();
36884 this.form = new Roo.form.Form(cfg);
36887 if ( this.form.allItems.length) {
36888 this.form.render(el.dom);
36892 // should only have one of theses..
36893 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
36894 // views.. should not be just added - used named prop 'view''
36896 cfg.el = this.el.appendChild(document.createElement("div"));
36899 var ret = new Roo.factory(cfg);
36901 ret.render && ret.render(false, ''); // render blank..
36911 * @class Roo.bootstrap.panel.Grid
36912 * @extends Roo.bootstrap.panel.Content
36914 * Create a new GridPanel.
36915 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
36916 * @param {Object} config A the config object
36922 Roo.bootstrap.panel.Grid = function(config)
36926 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
36927 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
36929 config.el = this.wrapper;
36930 //this.el = this.wrapper;
36932 if (config.container) {
36933 // ctor'ed from a Border/panel.grid
36936 this.wrapper.setStyle("overflow", "hidden");
36937 this.wrapper.addClass('roo-grid-container');
36942 if(config.toolbar){
36943 var tool_el = this.wrapper.createChild();
36944 this.toolbar = Roo.factory(config.toolbar);
36946 if (config.toolbar.items) {
36947 ti = config.toolbar.items ;
36948 delete config.toolbar.items ;
36952 this.toolbar.render(tool_el);
36953 for(var i =0;i < ti.length;i++) {
36954 // Roo.log(['add child', items[i]]);
36955 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
36957 this.toolbar.items = nitems;
36959 delete config.toolbar;
36962 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
36963 config.grid.scrollBody = true;;
36964 config.grid.monitorWindowResize = false; // turn off autosizing
36965 config.grid.autoHeight = false;
36966 config.grid.autoWidth = false;
36968 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
36970 if (config.background) {
36971 // render grid on panel activation (if panel background)
36972 this.on('activate', function(gp) {
36973 if (!gp.grid.rendered) {
36974 gp.grid.render(this.wrapper);
36975 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
36980 this.grid.render(this.wrapper);
36981 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
36984 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
36985 // ??? needed ??? config.el = this.wrapper;
36990 // xtype created footer. - not sure if will work as we normally have to render first..
36991 if (this.footer && !this.footer.el && this.footer.xtype) {
36993 var ctr = this.grid.getView().getFooterPanel(true);
36994 this.footer.dataSource = this.grid.dataSource;
36995 this.footer = Roo.factory(this.footer, Roo);
36996 this.footer.render(ctr);
37006 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
37007 getId : function(){
37008 return this.grid.id;
37012 * Returns the grid for this panel
37013 * @return {Roo.bootstrap.Table}
37015 getGrid : function(){
37019 setSize : function(width, height){
37020 if(!this.ignoreResize(width, height)){
37021 var grid = this.grid;
37022 var size = this.adjustForComponents(width, height);
37023 var gridel = grid.getGridEl();
37024 gridel.setSize(size.width, size.height);
37026 var thd = grid.getGridEl().select('thead',true).first();
37027 var tbd = grid.getGridEl().select('tbody', true).first();
37029 tbd.setSize(width, height - thd.getHeight());
37038 beforeSlide : function(){
37039 this.grid.getView().scroller.clip();
37042 afterSlide : function(){
37043 this.grid.getView().scroller.unclip();
37046 destroy : function(){
37047 this.grid.destroy();
37049 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
37054 * @class Roo.bootstrap.panel.Nest
37055 * @extends Roo.bootstrap.panel.Content
37057 * Create a new Panel, that can contain a layout.Border.
37060 * @param {Roo.BorderLayout} layout The layout for this panel
37061 * @param {String/Object} config A string to set only the title or a config object
37063 Roo.bootstrap.panel.Nest = function(config)
37065 // construct with only one argument..
37066 /* FIXME - implement nicer consturctors
37067 if (layout.layout) {
37069 layout = config.layout;
37070 delete config.layout;
37072 if (layout.xtype && !layout.getEl) {
37073 // then layout needs constructing..
37074 layout = Roo.factory(layout, Roo);
37078 config.el = config.layout.getEl();
37080 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
37082 config.layout.monitorWindowResize = false; // turn off autosizing
37083 this.layout = config.layout;
37084 this.layout.getEl().addClass("roo-layout-nested-layout");
37091 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
37093 setSize : function(width, height){
37094 if(!this.ignoreResize(width, height)){
37095 var size = this.adjustForComponents(width, height);
37096 var el = this.layout.getEl();
37097 if (size.height < 1) {
37098 el.setWidth(size.width);
37100 el.setSize(size.width, size.height);
37102 var touch = el.dom.offsetWidth;
37103 this.layout.layout();
37104 // ie requires a double layout on the first pass
37105 if(Roo.isIE && !this.initialized){
37106 this.initialized = true;
37107 this.layout.layout();
37112 // activate all subpanels if not currently active..
37114 setActiveState : function(active){
37115 this.active = active;
37116 this.setActiveClass(active);
37119 this.fireEvent("deactivate", this);
37123 this.fireEvent("activate", this);
37124 // not sure if this should happen before or after..
37125 if (!this.layout) {
37126 return; // should not happen..
37129 for (var r in this.layout.regions) {
37130 reg = this.layout.getRegion(r);
37131 if (reg.getActivePanel()) {
37132 //reg.showPanel(reg.getActivePanel()); // force it to activate..
37133 reg.setActivePanel(reg.getActivePanel());
37136 if (!reg.panels.length) {
37139 reg.showPanel(reg.getPanel(0));
37148 * Returns the nested BorderLayout for this panel
37149 * @return {Roo.BorderLayout}
37151 getLayout : function(){
37152 return this.layout;
37156 * Adds a xtype elements to the layout of the nested panel
37160 xtype : 'ContentPanel',
37167 xtype : 'NestedLayoutPanel',
37173 items : [ ... list of content panels or nested layout panels.. ]
37177 * @param {Object} cfg Xtype definition of item to add.
37179 addxtype : function(cfg) {
37180 return this.layout.addxtype(cfg);
37185 * Ext JS Library 1.1.1
37186 * Copyright(c) 2006-2007, Ext JS, LLC.
37188 * Originally Released Under LGPL - original licence link has changed is not relivant.
37191 * <script type="text/javascript">
37194 * @class Roo.TabPanel
37195 * @extends Roo.util.Observable
37196 * A lightweight tab container.
37200 // basic tabs 1, built from existing content
37201 var tabs = new Roo.TabPanel("tabs1");
37202 tabs.addTab("script", "View Script");
37203 tabs.addTab("markup", "View Markup");
37204 tabs.activate("script");
37206 // more advanced tabs, built from javascript
37207 var jtabs = new Roo.TabPanel("jtabs");
37208 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
37210 // set up the UpdateManager
37211 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
37212 var updater = tab2.getUpdateManager();
37213 updater.setDefaultUrl("ajax1.htm");
37214 tab2.on('activate', updater.refresh, updater, true);
37216 // Use setUrl for Ajax loading
37217 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
37218 tab3.setUrl("ajax2.htm", null, true);
37221 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
37224 jtabs.activate("jtabs-1");
37227 * Create a new TabPanel.
37228 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
37229 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
37231 Roo.bootstrap.panel.Tabs = function(config){
37233 * The container element for this TabPanel.
37234 * @type Roo.Element
37236 this.el = Roo.get(config.el);
37239 if(typeof config == "boolean"){
37240 this.tabPosition = config ? "bottom" : "top";
37242 Roo.apply(this, config);
37246 if(this.tabPosition == "bottom"){
37247 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37248 this.el.addClass("roo-tabs-bottom");
37250 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
37251 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
37252 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
37254 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
37256 if(this.tabPosition != "bottom"){
37257 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
37258 * @type Roo.Element
37260 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37261 this.el.addClass("roo-tabs-top");
37265 this.bodyEl.setStyle("position", "relative");
37267 this.active = null;
37268 this.activateDelegate = this.activate.createDelegate(this);
37273 * Fires when the active tab changes
37274 * @param {Roo.TabPanel} this
37275 * @param {Roo.TabPanelItem} activePanel The new active tab
37279 * @event beforetabchange
37280 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
37281 * @param {Roo.TabPanel} this
37282 * @param {Object} e Set cancel to true on this object to cancel the tab change
37283 * @param {Roo.TabPanelItem} tab The tab being changed to
37285 "beforetabchange" : true
37288 Roo.EventManager.onWindowResize(this.onResize, this);
37289 this.cpad = this.el.getPadding("lr");
37290 this.hiddenCount = 0;
37293 // toolbar on the tabbar support...
37294 if (this.toolbar) {
37295 alert("no toolbar support yet");
37296 this.toolbar = false;
37298 var tcfg = this.toolbar;
37299 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
37300 this.toolbar = new Roo.Toolbar(tcfg);
37301 if (Roo.isSafari) {
37302 var tbl = tcfg.container.child('table', true);
37303 tbl.setAttribute('width', '100%');
37311 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
37314 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
37316 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
37318 tabPosition : "top",
37320 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
37322 currentTabWidth : 0,
37324 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
37328 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
37332 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
37334 preferredTabWidth : 175,
37336 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
37338 resizeTabs : false,
37340 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
37342 monitorResize : true,
37344 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
37349 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
37350 * @param {String} id The id of the div to use <b>or create</b>
37351 * @param {String} text The text for the tab
37352 * @param {String} content (optional) Content to put in the TabPanelItem body
37353 * @param {Boolean} closable (optional) True to create a close icon on the tab
37354 * @return {Roo.TabPanelItem} The created TabPanelItem
37356 addTab : function(id, text, content, closable, tpl)
37358 var item = new Roo.bootstrap.panel.TabItem({
37362 closable : closable,
37365 this.addTabItem(item);
37367 item.setContent(content);
37373 * Returns the {@link Roo.TabPanelItem} with the specified id/index
37374 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
37375 * @return {Roo.TabPanelItem}
37377 getTab : function(id){
37378 return this.items[id];
37382 * Hides the {@link Roo.TabPanelItem} with the specified id/index
37383 * @param {String/Number} id The id or index of the TabPanelItem to hide.
37385 hideTab : function(id){
37386 var t = this.items[id];
37389 this.hiddenCount++;
37390 this.autoSizeTabs();
37395 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
37396 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
37398 unhideTab : function(id){
37399 var t = this.items[id];
37401 t.setHidden(false);
37402 this.hiddenCount--;
37403 this.autoSizeTabs();
37408 * Adds an existing {@link Roo.TabPanelItem}.
37409 * @param {Roo.TabPanelItem} item The TabPanelItem to add
37411 addTabItem : function(item){
37412 this.items[item.id] = item;
37413 this.items.push(item);
37414 // if(this.resizeTabs){
37415 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
37416 // this.autoSizeTabs();
37418 // item.autoSize();
37423 * Removes a {@link Roo.TabPanelItem}.
37424 * @param {String/Number} id The id or index of the TabPanelItem to remove.
37426 removeTab : function(id){
37427 var items = this.items;
37428 var tab = items[id];
37429 if(!tab) { return; }
37430 var index = items.indexOf(tab);
37431 if(this.active == tab && items.length > 1){
37432 var newTab = this.getNextAvailable(index);
37437 this.stripEl.dom.removeChild(tab.pnode.dom);
37438 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
37439 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
37441 items.splice(index, 1);
37442 delete this.items[tab.id];
37443 tab.fireEvent("close", tab);
37444 tab.purgeListeners();
37445 this.autoSizeTabs();
37448 getNextAvailable : function(start){
37449 var items = this.items;
37451 // look for a next tab that will slide over to
37452 // replace the one being removed
37453 while(index < items.length){
37454 var item = items[++index];
37455 if(item && !item.isHidden()){
37459 // if one isn't found select the previous tab (on the left)
37462 var item = items[--index];
37463 if(item && !item.isHidden()){
37471 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
37472 * @param {String/Number} id The id or index of the TabPanelItem to disable.
37474 disableTab : function(id){
37475 var tab = this.items[id];
37476 if(tab && this.active != tab){
37482 * Enables a {@link Roo.TabPanelItem} that is disabled.
37483 * @param {String/Number} id The id or index of the TabPanelItem to enable.
37485 enableTab : function(id){
37486 var tab = this.items[id];
37491 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
37492 * @param {String/Number} id The id or index of the TabPanelItem to activate.
37493 * @return {Roo.TabPanelItem} The TabPanelItem.
37495 activate : function(id){
37496 var tab = this.items[id];
37500 if(tab == this.active || tab.disabled){
37504 this.fireEvent("beforetabchange", this, e, tab);
37505 if(e.cancel !== true && !tab.disabled){
37507 this.active.hide();
37509 this.active = this.items[id];
37510 this.active.show();
37511 this.fireEvent("tabchange", this, this.active);
37517 * Gets the active {@link Roo.TabPanelItem}.
37518 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
37520 getActiveTab : function(){
37521 return this.active;
37525 * Updates the tab body element to fit the height of the container element
37526 * for overflow scrolling
37527 * @param {Number} targetHeight (optional) Override the starting height from the elements height
37529 syncHeight : function(targetHeight){
37530 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
37531 var bm = this.bodyEl.getMargins();
37532 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
37533 this.bodyEl.setHeight(newHeight);
37537 onResize : function(){
37538 if(this.monitorResize){
37539 this.autoSizeTabs();
37544 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
37546 beginUpdate : function(){
37547 this.updating = true;
37551 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
37553 endUpdate : function(){
37554 this.updating = false;
37555 this.autoSizeTabs();
37559 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
37561 autoSizeTabs : function(){
37562 var count = this.items.length;
37563 var vcount = count - this.hiddenCount;
37564 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
37567 var w = Math.max(this.el.getWidth() - this.cpad, 10);
37568 var availWidth = Math.floor(w / vcount);
37569 var b = this.stripBody;
37570 if(b.getWidth() > w){
37571 var tabs = this.items;
37572 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
37573 if(availWidth < this.minTabWidth){
37574 /*if(!this.sleft){ // incomplete scrolling code
37575 this.createScrollButtons();
37578 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
37581 if(this.currentTabWidth < this.preferredTabWidth){
37582 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
37588 * Returns the number of tabs in this TabPanel.
37591 getCount : function(){
37592 return this.items.length;
37596 * Resizes all the tabs to the passed width
37597 * @param {Number} The new width
37599 setTabWidth : function(width){
37600 this.currentTabWidth = width;
37601 for(var i = 0, len = this.items.length; i < len; i++) {
37602 if(!this.items[i].isHidden()) {
37603 this.items[i].setWidth(width);
37609 * Destroys this TabPanel
37610 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
37612 destroy : function(removeEl){
37613 Roo.EventManager.removeResizeListener(this.onResize, this);
37614 for(var i = 0, len = this.items.length; i < len; i++){
37615 this.items[i].purgeListeners();
37617 if(removeEl === true){
37618 this.el.update("");
37623 createStrip : function(container)
37625 var strip = document.createElement("nav");
37626 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
37627 container.appendChild(strip);
37631 createStripList : function(strip)
37633 // div wrapper for retard IE
37634 // returns the "tr" element.
37635 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
37636 //'<div class="x-tabs-strip-wrap">'+
37637 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
37638 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
37639 return strip.firstChild; //.firstChild.firstChild.firstChild;
37641 createBody : function(container)
37643 var body = document.createElement("div");
37644 Roo.id(body, "tab-body");
37645 //Roo.fly(body).addClass("x-tabs-body");
37646 Roo.fly(body).addClass("tab-content");
37647 container.appendChild(body);
37650 createItemBody :function(bodyEl, id){
37651 var body = Roo.getDom(id);
37653 body = document.createElement("div");
37656 //Roo.fly(body).addClass("x-tabs-item-body");
37657 Roo.fly(body).addClass("tab-pane");
37658 bodyEl.insertBefore(body, bodyEl.firstChild);
37662 createStripElements : function(stripEl, text, closable, tpl)
37664 var td = document.createElement("li"); // was td..
37667 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
37670 stripEl.appendChild(td);
37672 td.className = "x-tabs-closable";
37673 if(!this.closeTpl){
37674 this.closeTpl = new Roo.Template(
37675 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
37676 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
37677 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
37680 var el = this.closeTpl.overwrite(td, {"text": text});
37681 var close = el.getElementsByTagName("div")[0];
37682 var inner = el.getElementsByTagName("em")[0];
37683 return {"el": el, "close": close, "inner": inner};
37686 // not sure what this is..
37687 // if(!this.tabTpl){
37688 //this.tabTpl = new Roo.Template(
37689 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
37690 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
37692 // this.tabTpl = new Roo.Template(
37693 // '<a href="#">' +
37694 // '<span unselectable="on"' +
37695 // (this.disableTooltips ? '' : ' title="{text}"') +
37696 // ' >{text}</span></a>'
37702 var template = tpl || this.tabTpl || false;
37706 template = new Roo.Template(
37708 '<span unselectable="on"' +
37709 (this.disableTooltips ? '' : ' title="{text}"') +
37710 ' >{text}</span></a>'
37714 switch (typeof(template)) {
37718 template = new Roo.Template(template);
37724 var el = template.overwrite(td, {"text": text});
37726 var inner = el.getElementsByTagName("span")[0];
37728 return {"el": el, "inner": inner};
37736 * @class Roo.TabPanelItem
37737 * @extends Roo.util.Observable
37738 * Represents an individual item (tab plus body) in a TabPanel.
37739 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
37740 * @param {String} id The id of this TabPanelItem
37741 * @param {String} text The text for the tab of this TabPanelItem
37742 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
37744 Roo.bootstrap.panel.TabItem = function(config){
37746 * The {@link Roo.TabPanel} this TabPanelItem belongs to
37747 * @type Roo.TabPanel
37749 this.tabPanel = config.panel;
37751 * The id for this TabPanelItem
37754 this.id = config.id;
37756 this.disabled = false;
37758 this.text = config.text;
37760 this.loaded = false;
37761 this.closable = config.closable;
37764 * The body element for this TabPanelItem.
37765 * @type Roo.Element
37767 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
37768 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
37769 this.bodyEl.setStyle("display", "block");
37770 this.bodyEl.setStyle("zoom", "1");
37771 //this.hideAction();
37773 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
37775 this.el = Roo.get(els.el);
37776 this.inner = Roo.get(els.inner, true);
37777 this.textEl = Roo.get(this.el.dom.firstChild, true);
37778 this.pnode = Roo.get(els.el.parentNode, true);
37779 // this.el.on("mousedown", this.onTabMouseDown, this);
37780 this.el.on("click", this.onTabClick, this);
37782 if(config.closable){
37783 var c = Roo.get(els.close, true);
37784 c.dom.title = this.closeText;
37785 c.addClassOnOver("close-over");
37786 c.on("click", this.closeClick, this);
37792 * Fires when this tab becomes the active tab.
37793 * @param {Roo.TabPanel} tabPanel The parent TabPanel
37794 * @param {Roo.TabPanelItem} this
37798 * @event beforeclose
37799 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
37800 * @param {Roo.TabPanelItem} this
37801 * @param {Object} e Set cancel to true on this object to cancel the close.
37803 "beforeclose": true,
37806 * Fires when this tab is closed.
37807 * @param {Roo.TabPanelItem} this
37811 * @event deactivate
37812 * Fires when this tab is no longer the active tab.
37813 * @param {Roo.TabPanel} tabPanel The parent TabPanel
37814 * @param {Roo.TabPanelItem} this
37816 "deactivate" : true
37818 this.hidden = false;
37820 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
37823 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
37825 purgeListeners : function(){
37826 Roo.util.Observable.prototype.purgeListeners.call(this);
37827 this.el.removeAllListeners();
37830 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
37833 this.pnode.addClass("active");
37836 this.tabPanel.stripWrap.repaint();
37838 this.fireEvent("activate", this.tabPanel, this);
37842 * Returns true if this tab is the active tab.
37843 * @return {Boolean}
37845 isActive : function(){
37846 return this.tabPanel.getActiveTab() == this;
37850 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
37853 this.pnode.removeClass("active");
37855 this.fireEvent("deactivate", this.tabPanel, this);
37858 hideAction : function(){
37859 this.bodyEl.hide();
37860 this.bodyEl.setStyle("position", "absolute");
37861 this.bodyEl.setLeft("-20000px");
37862 this.bodyEl.setTop("-20000px");
37865 showAction : function(){
37866 this.bodyEl.setStyle("position", "relative");
37867 this.bodyEl.setTop("");
37868 this.bodyEl.setLeft("");
37869 this.bodyEl.show();
37873 * Set the tooltip for the tab.
37874 * @param {String} tooltip The tab's tooltip
37876 setTooltip : function(text){
37877 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
37878 this.textEl.dom.qtip = text;
37879 this.textEl.dom.removeAttribute('title');
37881 this.textEl.dom.title = text;
37885 onTabClick : function(e){
37886 e.preventDefault();
37887 this.tabPanel.activate(this.id);
37890 onTabMouseDown : function(e){
37891 e.preventDefault();
37892 this.tabPanel.activate(this.id);
37895 getWidth : function(){
37896 return this.inner.getWidth();
37899 setWidth : function(width){
37900 var iwidth = width - this.pnode.getPadding("lr");
37901 this.inner.setWidth(iwidth);
37902 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
37903 this.pnode.setWidth(width);
37907 * Show or hide the tab
37908 * @param {Boolean} hidden True to hide or false to show.
37910 setHidden : function(hidden){
37911 this.hidden = hidden;
37912 this.pnode.setStyle("display", hidden ? "none" : "");
37916 * Returns true if this tab is "hidden"
37917 * @return {Boolean}
37919 isHidden : function(){
37920 return this.hidden;
37924 * Returns the text for this tab
37927 getText : function(){
37931 autoSize : function(){
37932 //this.el.beginMeasure();
37933 this.textEl.setWidth(1);
37935 * #2804 [new] Tabs in Roojs
37936 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
37938 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
37939 //this.el.endMeasure();
37943 * Sets the text for the tab (Note: this also sets the tooltip text)
37944 * @param {String} text The tab's text and tooltip
37946 setText : function(text){
37948 this.textEl.update(text);
37949 this.setTooltip(text);
37950 //if(!this.tabPanel.resizeTabs){
37951 // this.autoSize();
37955 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
37957 activate : function(){
37958 this.tabPanel.activate(this.id);
37962 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
37964 disable : function(){
37965 if(this.tabPanel.active != this){
37966 this.disabled = true;
37967 this.pnode.addClass("disabled");
37972 * Enables this TabPanelItem if it was previously disabled.
37974 enable : function(){
37975 this.disabled = false;
37976 this.pnode.removeClass("disabled");
37980 * Sets the content for this TabPanelItem.
37981 * @param {String} content The content
37982 * @param {Boolean} loadScripts true to look for and load scripts
37984 setContent : function(content, loadScripts){
37985 this.bodyEl.update(content, loadScripts);
37989 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
37990 * @return {Roo.UpdateManager} The UpdateManager
37992 getUpdateManager : function(){
37993 return this.bodyEl.getUpdateManager();
37997 * Set a URL to be used to load the content for this TabPanelItem.
37998 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
37999 * @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)
38000 * @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)
38001 * @return {Roo.UpdateManager} The UpdateManager
38003 setUrl : function(url, params, loadOnce){
38004 if(this.refreshDelegate){
38005 this.un('activate', this.refreshDelegate);
38007 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
38008 this.on("activate", this.refreshDelegate);
38009 return this.bodyEl.getUpdateManager();
38013 _handleRefresh : function(url, params, loadOnce){
38014 if(!loadOnce || !this.loaded){
38015 var updater = this.bodyEl.getUpdateManager();
38016 updater.update(url, params, this._setLoaded.createDelegate(this));
38021 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
38022 * Will fail silently if the setUrl method has not been called.
38023 * This does not activate the panel, just updates its content.
38025 refresh : function(){
38026 if(this.refreshDelegate){
38027 this.loaded = false;
38028 this.refreshDelegate();
38033 _setLoaded : function(){
38034 this.loaded = true;
38038 closeClick : function(e){
38041 this.fireEvent("beforeclose", this, o);
38042 if(o.cancel !== true){
38043 this.tabPanel.removeTab(this.id);
38047 * The text displayed in the tooltip for the close icon.
38050 closeText : "Close this tab"
38053 * This script refer to:
38054 * Title: International Telephone Input
38055 * Author: Jack O'Connor
38056 * Code version: v12.1.12
38057 * Availability: https://github.com/jackocnr/intl-tel-input.git
38060 Roo.bootstrap.PhoneInputData = function() {
38063 "Afghanistan (افغانستان)",
38068 "Albania (Shqipëri)",
38073 "Algeria (الجزائر)",
38098 "Antigua and Barbuda",
38108 "Armenia (Հայաստան)",
38124 "Austria (Österreich)",
38129 "Azerbaijan (Azərbaycan)",
38139 "Bahrain (البحرين)",
38144 "Bangladesh (বাংলাদেশ)",
38154 "Belarus (Беларусь)",
38159 "Belgium (België)",
38189 "Bosnia and Herzegovina (Босна и Херцеговина)",
38204 "British Indian Ocean Territory",
38209 "British Virgin Islands",
38219 "Bulgaria (България)",
38229 "Burundi (Uburundi)",
38234 "Cambodia (កម្ពុជា)",
38239 "Cameroon (Cameroun)",
38248 ["204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905"]
38251 "Cape Verde (Kabu Verdi)",
38256 "Caribbean Netherlands",
38267 "Central African Republic (République centrafricaine)",
38287 "Christmas Island",
38293 "Cocos (Keeling) Islands",
38304 "Comoros (جزر القمر)",
38309 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
38314 "Congo (Republic) (Congo-Brazzaville)",
38334 "Croatia (Hrvatska)",
38355 "Czech Republic (Česká republika)",
38360 "Denmark (Danmark)",
38375 "Dominican Republic (República Dominicana)",
38379 ["809", "829", "849"]
38397 "Equatorial Guinea (Guinea Ecuatorial)",
38417 "Falkland Islands (Islas Malvinas)",
38422 "Faroe Islands (Føroyar)",
38443 "French Guiana (Guyane française)",
38448 "French Polynesia (Polynésie française)",
38463 "Georgia (საქართველო)",
38468 "Germany (Deutschland)",
38488 "Greenland (Kalaallit Nunaat)",
38525 "Guinea-Bissau (Guiné Bissau)",
38550 "Hungary (Magyarország)",
38555 "Iceland (Ísland)",
38575 "Iraq (العراق)",
38591 "Israel (ישראל)",
38618 "Jordan (الأردن)",
38623 "Kazakhstan (Казахстан)",
38644 "Kuwait (الكويت)",
38649 "Kyrgyzstan (Кыргызстан)",
38659 "Latvia (Latvija)",
38664 "Lebanon (لبنان)",
38679 "Libya (ليبيا)",
38689 "Lithuania (Lietuva)",
38704 "Macedonia (FYROM) (Македонија)",
38709 "Madagascar (Madagasikara)",
38739 "Marshall Islands",
38749 "Mauritania (موريتانيا)",
38754 "Mauritius (Moris)",
38775 "Moldova (Republica Moldova)",
38785 "Mongolia (Монгол)",
38790 "Montenegro (Crna Gora)",
38800 "Morocco (المغرب)",
38806 "Mozambique (Moçambique)",
38811 "Myanmar (Burma) (မြန်မာ)",
38816 "Namibia (Namibië)",
38831 "Netherlands (Nederland)",
38836 "New Caledonia (Nouvelle-Calédonie)",
38871 "North Korea (조선 민주주의 인민 공화국)",
38876 "Northern Mariana Islands",
38892 "Pakistan (پاکستان)",
38902 "Palestine (فلسطين)",
38912 "Papua New Guinea",
38954 "Réunion (La Réunion)",
38960 "Romania (România)",
38976 "Saint Barthélemy",
38987 "Saint Kitts and Nevis",
38997 "Saint Martin (Saint-Martin (partie française))",
39003 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
39008 "Saint Vincent and the Grenadines",
39023 "São Tomé and Príncipe (São Tomé e Príncipe)",
39028 "Saudi Arabia (المملكة العربية السعودية)",
39033 "Senegal (Sénégal)",
39063 "Slovakia (Slovensko)",
39068 "Slovenia (Slovenija)",
39078 "Somalia (Soomaaliya)",
39088 "South Korea (대한민국)",
39093 "South Sudan (جنوب السودان)",
39103 "Sri Lanka (ශ්රී ලංකාව)",
39108 "Sudan (السودان)",
39118 "Svalbard and Jan Mayen",
39129 "Sweden (Sverige)",
39134 "Switzerland (Schweiz)",
39139 "Syria (سوريا)",
39184 "Trinidad and Tobago",
39189 "Tunisia (تونس)",
39194 "Turkey (Türkiye)",
39204 "Turks and Caicos Islands",
39214 "U.S. Virgin Islands",
39224 "Ukraine (Україна)",
39229 "United Arab Emirates (الإمارات العربية المتحدة)",
39251 "Uzbekistan (Oʻzbekiston)",
39261 "Vatican City (Città del Vaticano)",
39272 "Vietnam (Việt Nam)",
39277 "Wallis and Futuna (Wallis-et-Futuna)",
39282 "Western Sahara (الصحراء الغربية)",
39288 "Yemen (اليمن)",
39312 * This script refer to:
39313 * Title: International Telephone Input
39314 * Author: Jack O'Connor
39315 * Code version: v12.1.12
39316 * Availability: https://github.com/jackocnr/intl-tel-input.git
39320 * @class Roo.bootstrap.PhoneInput
39321 * @extends Roo.bootstrap.TriggerField
39322 * An input with International dial-code selection
39324 * @cfg {String} defaultDialCode default '+852'
39325 * @cfg {Array} preferedCountries default []
39328 * Create a new PhoneInput.
39329 * @param {Object} config Configuration options
39332 Roo.bootstrap.PhoneInput = function(config) {
39333 Roo.bootstrap.PhoneInput.superclass.constructor.call(this, config);
39336 Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
39338 listWidth: undefined,
39340 selectedClass: 'active',
39342 invalidClass : "has-warning",
39344 validClass: 'has-success',
39346 allowed: '0123456789',
39349 * @cfg {String} defaultDialCode The default dial code when initializing the input
39351 defaultDialCode: '+852',
39354 * @cfg {Array} preferedCountries A list of iso2 in array (e.g. ['hk','us']). Those related countries will show at the top of the input's choices
39356 preferedCountries: false,
39358 getAutoCreate : function()
39360 var data = Roo.bootstrap.PhoneInputData();
39361 var align = this.labelAlign || this.parentLabelAlign();
39364 this.allCountries = [];
39365 this.dialCodeMapping = [];
39367 for (var i = 0; i < data.length; i++) {
39369 this.allCountries[i] = {
39373 priority: c[3] || 0,
39374 areaCodes: c[4] || null
39376 this.dialCodeMapping[c[2]] = {
39379 priority: c[3] || 0,
39380 areaCodes: c[4] || null
39392 cls : 'form-control tel-input',
39393 autocomplete: 'new-password'
39396 var hiddenInput = {
39399 cls: 'hidden-tel-input'
39403 hiddenInput.name = this.name;
39406 if (this.disabled) {
39407 input.disabled = true;
39410 var flag_container = {
39427 cls: this.hasFeedback ? 'has-feedback' : '',
39433 cls: 'dial-code-holder',
39440 cls: 'roo-select2-container input-group',
39447 if (this.fieldLabel.length) {
39450 tooltip: 'This field is required'
39456 cls: 'control-label',
39462 html: this.fieldLabel
39465 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
39471 if(this.indicatorpos == 'right') {
39472 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
39479 if(align == 'left') {
39487 if(this.labelWidth > 12){
39488 label.style = "width: " + this.labelWidth + 'px';
39490 if(this.labelWidth < 13 && this.labelmd == 0){
39491 this.labelmd = this.labelWidth;
39493 if(this.labellg > 0){
39494 label.cls += ' col-lg-' + this.labellg;
39495 input.cls += ' col-lg-' + (12 - this.labellg);
39497 if(this.labelmd > 0){
39498 label.cls += ' col-md-' + this.labelmd;
39499 container.cls += ' col-md-' + (12 - this.labelmd);
39501 if(this.labelsm > 0){
39502 label.cls += ' col-sm-' + this.labelsm;
39503 container.cls += ' col-sm-' + (12 - this.labelsm);
39505 if(this.labelxs > 0){
39506 label.cls += ' col-xs-' + this.labelxs;
39507 container.cls += ' col-xs-' + (12 - this.labelxs);
39517 var settings = this;
39519 ['xs','sm','md','lg'].map(function(size){
39520 if (settings[size]) {
39521 cfg.cls += ' col-' + size + '-' + settings[size];
39525 this.store = new Roo.data.Store({
39526 proxy : new Roo.data.MemoryProxy({}),
39527 reader : new Roo.data.JsonReader({
39538 'name' : 'dialCode',
39542 'name' : 'priority',
39546 'name' : 'areaCodes',
39553 if(!this.preferedCountries) {
39554 this.preferedCountries = [
39561 var p = this.preferedCountries.reverse();
39564 for (var i = 0; i < p.length; i++) {
39565 for (var j = 0; j < this.allCountries.length; j++) {
39566 if(this.allCountries[j].iso2 == p[i]) {
39567 var t = this.allCountries[j];
39568 this.allCountries.splice(j,1);
39569 this.allCountries.unshift(t);
39575 this.store.proxy.data = {
39577 data: this.allCountries
39583 initEvents : function()
39586 Roo.bootstrap.PhoneInput.superclass.initEvents.call(this);
39588 this.indicator = this.indicatorEl();
39589 this.flag = this.flagEl();
39590 this.dialCodeHolder = this.dialCodeHolderEl();
39592 this.trigger = this.el.select('div.flag-box',true).first();
39593 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
39598 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
39599 _this.list.setWidth(lw);
39602 this.list.on('mouseover', this.onViewOver, this);
39603 this.list.on('mousemove', this.onViewMove, this);
39604 this.inputEl().on("keyup", this.onKeyUp, this);
39606 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
39608 this.view = new Roo.View(this.list, this.tpl, {
39609 singleSelect:true, store: this.store, selectedClass: this.selectedClass
39612 this.view.on('click', this.onViewClick, this);
39613 this.setValue(this.defaultDialCode);
39616 onTriggerClick : function(e)
39618 Roo.log('trigger click');
39623 if(this.isExpanded()){
39625 this.hasFocus = false;
39627 this.store.load({});
39628 this.hasFocus = true;
39633 isExpanded : function()
39635 return this.list.isVisible();
39638 collapse : function()
39640 if(!this.isExpanded()){
39644 Roo.get(document).un('mousedown', this.collapseIf, this);
39645 Roo.get(document).un('mousewheel', this.collapseIf, this);
39646 this.fireEvent('collapse', this);
39650 expand : function()
39654 if(this.isExpanded() || !this.hasFocus){
39658 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
39659 this.list.setWidth(lw);
39662 this.restrictHeight();
39664 Roo.get(document).on('mousedown', this.collapseIf, this);
39665 Roo.get(document).on('mousewheel', this.collapseIf, this);
39667 this.fireEvent('expand', this);
39670 restrictHeight : function()
39672 this.list.alignTo(this.inputEl(), this.listAlign);
39673 this.list.alignTo(this.inputEl(), this.listAlign);
39676 onViewOver : function(e, t)
39678 if(this.inKeyMode){
39681 var item = this.view.findItemFromChild(t);
39684 var index = this.view.indexOf(item);
39685 this.select(index, false);
39690 onViewClick : function(view, doFocus, el, e)
39692 var index = this.view.getSelectedIndexes()[0];
39694 var r = this.store.getAt(index);
39697 this.onSelect(r, index);
39699 if(doFocus !== false && !this.blockFocus){
39700 this.inputEl().focus();
39704 onViewMove : function(e, t)
39706 this.inKeyMode = false;
39709 select : function(index, scrollIntoView)
39711 this.selectedIndex = index;
39712 this.view.select(index);
39713 if(scrollIntoView !== false){
39714 var el = this.view.getNode(index);
39716 this.list.scrollChildIntoView(el, false);
39721 createList : function()
39723 this.list = Roo.get(document.body).createChild({
39725 cls: 'typeahead typeahead-long dropdown-menu tel-list',
39726 style: 'display:none'
39728 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
39731 collapseIf : function(e)
39733 var in_combo = e.within(this.el);
39734 var in_list = e.within(this.list);
39735 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
39737 if (in_combo || in_list || is_list) {
39743 onSelect : function(record, index)
39745 if(this.fireEvent('beforeselect', this, record, index) !== false){
39747 this.setFlagClass(record.data.iso2);
39748 this.setDialCode(record.data.dialCode);
39749 this.hasFocus = false;
39751 this.fireEvent('select', this, record, index);
39755 flagEl : function()
39757 var flag = this.el.select('div.flag',true).first();
39764 dialCodeHolderEl : function()
39766 var d = this.el.select('input.dial-code-holder',true).first();
39773 setDialCode : function(v)
39775 this.dialCodeHolder.dom.value = '+'+v;
39778 setFlagClass : function(n)
39780 this.flag.dom.className = 'flag '+n;
39783 getValue : function()
39785 var v = this.inputEl().getValue();
39786 if(this.dialCodeHolder) {
39787 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
39792 setValue : function(v)
39794 var d = this.getDialCode(v);
39796 //invalid dial code
39797 if(v.length == 0 || !d || d.length == 0) {
39799 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
39800 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
39806 this.setFlagClass(this.dialCodeMapping[d].iso2);
39807 this.setDialCode(d);
39808 this.inputEl().dom.value = v.replace('+'+d,'');
39809 this.hiddenEl().dom.value = this.getValue();
39814 getDialCode : function(v = '')
39816 if (v.length == 0) {
39817 return this.dialCodeHolder.dom.value;
39821 if (v.charAt(0) != "+") {
39824 var numericChars = "";
39825 for (var i = 1; i < v.length; i++) {
39826 var c = v.charAt(i);
39829 if (this.dialCodeMapping[numericChars]) {
39830 dialCode = v.substr(1, i);
39832 if (numericChars.length == 4) {
39842 this.setValue(this.defaultDialCode);
39846 hiddenEl : function()
39848 return this.el.select('input.hidden-tel-input',true).first();
39851 onKeyUp : function(e){
39853 var k = e.getKey();
39854 var c = e.getCharCode();
39857 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
39858 this.allowed.indexOf(String.fromCharCode(c)) === -1
39863 // if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
39866 if(this.allowed.indexOf(String.fromCharCode(c)) === -1){
39870 this.setValue(this.getValue());
39875 * @class Roo.bootstrap.MoneyField
39876 * @extends Roo.bootstrap.ComboBox
39877 * Bootstrap MoneyField class
39880 * Create a new MoneyField.
39881 * @param {Object} config Configuration options
39884 Roo.bootstrap.MoneyField = function(config) {
39886 Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
39890 Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
39893 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
39895 allowDecimals : true,
39897 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
39899 decimalSeparator : ".",
39901 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
39903 decimalPrecision : 2,
39905 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
39907 allowNegative : true,
39909 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
39911 minValue : Number.NEGATIVE_INFINITY,
39913 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
39915 maxValue : Number.MAX_VALUE,
39917 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
39919 minText : "The minimum value for this field is {0}",
39921 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
39923 maxText : "The maximum value for this field is {0}",
39925 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
39926 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
39928 nanText : "{0} is not a valid number",
39930 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
39941 getAutoCreate : function()
39943 var align = this.labelAlign || this.parentLabelAlign();
39955 cls : 'form-control roo-money-amount-input',
39956 autocomplete: 'new-password'
39960 input.name = this.name;
39963 if (this.disabled) {
39964 input.disabled = true;
39967 var clg = 12 - this.inputlg;
39968 var cmd = 12 - this.inputmd;
39969 var csm = 12 - this.inputsm;
39970 var cxs = 12 - this.inputxs;
39974 cls : 'row roo-money-field',
39978 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
39982 cls: 'roo-select2-container input-group',
39986 cls : 'form-control roo-money-currency-input',
39987 autocomplete: 'new-password',
39989 name : this.currencyName
39993 cls : 'input-group-addon',
40007 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
40011 cls: this.hasFeedback ? 'has-feedback' : '',
40022 if (this.fieldLabel.length) {
40025 tooltip: 'This field is required'
40031 cls: 'control-label',
40037 html: this.fieldLabel
40040 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40046 if(this.indicatorpos == 'right') {
40047 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40054 if(align == 'left') {
40062 if(this.labelWidth > 12){
40063 label.style = "width: " + this.labelWidth + 'px';
40065 if(this.labelWidth < 13 && this.labelmd == 0){
40066 this.labelmd = this.labelWidth;
40068 if(this.labellg > 0){
40069 label.cls += ' col-lg-' + this.labellg;
40070 input.cls += ' col-lg-' + (12 - this.labellg);
40072 if(this.labelmd > 0){
40073 label.cls += ' col-md-' + this.labelmd;
40074 container.cls += ' col-md-' + (12 - this.labelmd);
40076 if(this.labelsm > 0){
40077 label.cls += ' col-sm-' + this.labelsm;
40078 container.cls += ' col-sm-' + (12 - this.labelsm);
40080 if(this.labelxs > 0){
40081 label.cls += ' col-xs-' + this.labelxs;
40082 container.cls += ' col-xs-' + (12 - this.labelxs);
40092 var settings = this;
40094 ['xs','sm','md','lg'].map(function(size){
40095 if (settings[size]) {
40096 cfg.cls += ' col-' + size + '-' + settings[size];
40104 initEvents : function()
40106 this.indicator = this.indicatorEl();
40108 this.initCurrencyEvent();
40110 this.initNumberEvent();
40114 initCurrencyEvent : function()
40117 throw "can not find store for combo";
40120 this.store = Roo.factory(this.store, Roo.data);
40121 this.store.parent = this;
40125 this.triggerEl = this.el.select('.input-group-addon', true).first();
40127 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
40132 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40133 _this.list.setWidth(lw);
40136 this.list.on('mouseover', this.onViewOver, this);
40137 this.list.on('mousemove', this.onViewMove, this);
40138 this.list.on('scroll', this.onViewScroll, this);
40141 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
40144 this.view = new Roo.View(this.list, this.tpl, {
40145 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40148 this.view.on('click', this.onViewClick, this);
40150 this.store.on('beforeload', this.onBeforeLoad, this);
40151 this.store.on('load', this.onLoad, this);
40152 this.store.on('loadexception', this.onLoadException, this);
40154 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
40155 "up" : function(e){
40156 this.inKeyMode = true;
40160 "down" : function(e){
40161 if(!this.isExpanded()){
40162 this.onTriggerClick();
40164 this.inKeyMode = true;
40169 "enter" : function(e){
40172 if(this.fireEvent("specialkey", this, e)){
40173 this.onViewClick(false);
40179 "esc" : function(e){
40183 "tab" : function(e){
40186 if(this.fireEvent("specialkey", this, e)){
40187 this.onViewClick(false);
40195 doRelay : function(foo, bar, hname){
40196 if(hname == 'down' || this.scope.isExpanded()){
40197 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
40205 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
40209 initNumberEvent : function(e)
40211 this.inputEl().on("keydown" , this.fireKey, this);
40212 this.inputEl().on("focus", this.onFocus, this);
40213 this.inputEl().on("blur", this.onBlur, this);
40215 this.inputEl().relayEvent('keyup', this);
40217 if(this.indicator){
40218 this.indicator.addClass('invisible');
40221 this.originalValue = this.getValue();
40223 if(this.validationEvent == 'keyup'){
40224 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
40225 this.inputEl().on('keyup', this.filterValidation, this);
40227 else if(this.validationEvent !== false){
40228 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
40231 if(this.selectOnFocus){
40232 this.on("focus", this.preFocus, this);
40235 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
40236 this.inputEl().on("keypress", this.filterKeys, this);
40238 this.inputEl().relayEvent('keypress', this);
40241 var allowed = "0123456789";
40243 if(this.allowDecimals){
40244 allowed += this.decimalSeparator;
40247 if(this.allowNegative){
40251 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
40253 var keyPress = function(e){
40255 var k = e.getKey();
40257 var c = e.getCharCode();
40260 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40261 allowed.indexOf(String.fromCharCode(c)) === -1
40267 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40271 if(allowed.indexOf(String.fromCharCode(c)) === -1){
40276 this.inputEl().on("keypress", keyPress, this);
40280 onTriggerClick : function(e)
40287 this.loadNext = false;
40289 if(this.isExpanded()){
40294 this.hasFocus = true;
40296 if(this.triggerAction == 'all') {
40297 this.doQuery(this.allQuery, true);
40301 this.doQuery(this.getRawValue());
40304 getCurrency : function()
40306 var v = this.currencyEl().getValue();
40311 restrictHeight : function()
40313 this.list.alignTo(this.currencyEl(), this.listAlign);
40314 this.list.alignTo(this.currencyEl(), this.listAlign);
40317 onViewClick : function(view, doFocus, el, e)
40319 var index = this.view.getSelectedIndexes()[0];
40321 var r = this.store.getAt(index);
40324 this.onSelect(r, index);
40328 onSelect : function(record, index){
40330 if(this.fireEvent('beforeselect', this, record, index) !== false){
40332 this.setFromCurrencyData(index > -1 ? record.data : false);
40336 this.fireEvent('select', this, record, index);
40340 setFromCurrencyData : function(o)
40344 this.lastCurrency = o;
40346 if (this.currencyField) {
40347 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
40349 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
40352 this.lastSelectionText = currency;
40354 this.setCurrency(currency);
40357 setFromData : function(o)
40361 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
40363 this.setFromCurrencyData(c);
40368 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
40370 Roo.log('no value set for '+ (this.name ? this.name : this.id));
40373 this.setValue(value);
40377 setCurrency : function(v)
40379 this.currencyValue = v;
40382 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
40387 setValue : function(v)
40389 v = this.fixPrecision(v);
40391 v = String(v).replace(".", this.decimalSeparator);
40396 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
40401 getRawValue : function()
40403 var v = this.inputEl().getValue();
40408 getValue : function()
40410 return this.fixPrecision(this.parseValue(this.getRawValue()));
40413 parseValue : function(value)
40415 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
40416 return isNaN(value) ? '' : value;
40419 fixPrecision : function(value)
40421 var nan = isNaN(value);
40423 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
40424 return nan ? '' : value;
40427 return parseFloat(value).toFixed(this.decimalPrecision);
40430 decimalPrecisionFcn : function(v)
40432 return Math.floor(v);
40435 validateValue : function(value)
40437 if(!Roo.bootstrap.MoneyField.superclass.validateValue.call(this, value)){
40441 var num = this.parseValue(value);
40444 this.markInvalid(String.format(this.nanText, value));
40448 if(num < this.minValue){
40449 this.markInvalid(String.format(this.minText, this.minValue));
40453 if(num > this.maxValue){
40454 this.markInvalid(String.format(this.maxText, this.maxValue));
40461 validate : function()
40463 if(this.disabled || this.allowBlank){
40468 var currency = this.getCurrency();
40470 if(this.validateValue(this.getRawValue()) && currency.length){
40475 this.markInvalid();
40479 getName: function()
40484 beforeBlur : function()
40490 var v = this.parseValue(this.getRawValue());
40497 onBlur : function()
40501 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
40502 //this.el.removeClass(this.focusClass);
40505 this.hasFocus = false;
40507 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
40511 var v = this.getValue();
40513 if(String(v) !== String(this.startValue)){
40514 this.fireEvent('change', this, v, this.startValue);
40517 this.fireEvent("blur", this);
40520 inputEl : function()
40522 return this.el.select('.roo-money-amount-input', true).first();
40525 currencyEl : function()
40527 return this.el.select('.roo-money-currency-input', true).first();