2 * set the version of bootstrap based on the stylesheet...
6 Roo.bootstrap.version = (
9 Roo.each(document.styleSheets[0], function(s) {
10 if (s.href.match(/css-bootstrap4/)) {
18 * base class for bootstrap elements.
22 Roo.bootstrap = Roo.bootstrap || {};
24 * @class Roo.bootstrap.Component
25 * @extends Roo.Component
26 * Bootstrap Component base class
27 * @cfg {String} cls css class
28 * @cfg {String} style any extra css
29 * @cfg {Object} xattr extra attributes to add to 'element' (used by builder to store stuff.)
30 * @cfg {Boolean} can_build_overlaid True if element can be rebuild from a HTML page
31 * @cfg {string} dataId cutomer id
32 * @cfg {string} name Specifies name attribute
33 * @cfg {string} tooltip Text for the tooltip
34 * @cfg {string} container_method method to fetch parents container element (used by NavHeaderbar - getHeaderChildContainer)
35 * @cfg {string|object} visibilityEl (el|parent) What element to use for visibility (@see getVisibilityEl())
38 * Do not use directly - it does not do anything..
39 * @param {Object} config The config object
44 Roo.bootstrap.Component = function(config){
45 Roo.bootstrap.Component.superclass.constructor.call(this, config);
49 * @event childrenrendered
50 * Fires when the children have been rendered..
51 * @param {Roo.bootstrap.Component} this
53 "childrenrendered" : true
62 Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, {
65 allowDomMove : false, // to stop relocations in parent onRender...
75 * Initialize Events for the element
77 initEvents : function() { },
83 can_build_overlaid : true,
85 container_method : false,
92 // returns the parent component..
93 return Roo.ComponentMgr.get(this.parentId)
99 onRender : function(ct, position)
101 // Roo.log("Call onRender: " + this.xtype);
103 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
106 if (this.el.attr('xtype')) {
107 this.el.attr('xtypex', this.el.attr('xtype'));
108 this.el.dom.removeAttribute('xtype');
118 var cfg = Roo.apply({}, this.getAutoCreate());
120 cfg.id = this.id || Roo.id();
122 // fill in the extra attributes
123 if (this.xattr && typeof(this.xattr) =='object') {
124 for (var i in this.xattr) {
125 cfg[i] = this.xattr[i];
130 cfg.dataId = this.dataId;
134 cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
137 if (this.style) { // fixme needs to support more complex style data.
138 cfg.style = this.style;
142 cfg.name = this.name;
145 this.el = ct.createChild(cfg, position);
148 this.tooltipEl().attr('tooltip', this.tooltip);
151 if(this.tabIndex !== undefined){
152 this.el.dom.setAttribute('tabIndex', this.tabIndex);
159 * Fetch the element to add children to
160 * @return {Roo.Element} defaults to this.el
162 getChildContainer : function()
167 * Fetch the element to display the tooltip on.
168 * @return {Roo.Element} defaults to this.el
170 tooltipEl : function()
175 addxtype : function(tree,cntr)
179 cn = Roo.factory(tree);
180 //Roo.log(['addxtype', cn]);
182 cn.parentType = this.xtype; //??
183 cn.parentId = this.id;
185 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
186 if (typeof(cn.container_method) == 'string') {
187 cntr = cn.container_method;
191 var has_flexy_each = (typeof(tree['flexy:foreach']) != 'undefined');
193 var has_flexy_if = (typeof(tree['flexy:if']) != 'undefined');
195 var build_from_html = Roo.XComponent.build_from_html;
197 var is_body = (tree.xtype == 'Body') ;
199 var page_has_body = (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body');
201 var self_cntr_el = Roo.get(this[cntr](false));
203 // do not try and build conditional elements
204 if ((has_flexy_each || has_flexy_if || this.can_build_overlaid == false ) && build_from_html) {
208 if (!has_flexy_each || !build_from_html || is_body || !page_has_body) {
209 if(!has_flexy_if || typeof(tree.name) == 'undefined' || !build_from_html || is_body || !page_has_body){
210 return this.addxtypeChild(tree,cntr, is_body);
213 var echild =self_cntr_el ? self_cntr_el.child('>*[name=' + tree.name + ']') : false;
216 return this.addxtypeChild(Roo.apply({}, tree),cntr);
219 Roo.log('skipping render');
225 if (!build_from_html) {
229 // this i think handles overlaying multiple children of the same type
230 // with the sam eelement.. - which might be buggy..
232 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
238 if (echild && echild.attr('xtype').split('.').pop() != cn.xtype) {
242 ret = this.addxtypeChild(Roo.apply({}, tree),cntr);
249 addxtypeChild : function (tree, cntr, is_body)
251 Roo.debug && Roo.log('addxtypeChild:' + cntr);
253 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
256 var has_flexy = (typeof(tree['flexy:if']) != 'undefined') ||
257 (typeof(tree['flexy:foreach']) != 'undefined');
261 skip_children = false;
262 // render the element if it's not BODY.
265 // if parent was disabled, then do not try and create the children..
266 if(!this[cntr](true)){
271 cn = Roo.factory(tree);
273 cn.parentType = this.xtype; //??
274 cn.parentId = this.id;
276 var build_from_html = Roo.XComponent.build_from_html;
279 // does the container contain child eleemnts with 'xtype' attributes.
280 // that match this xtype..
281 // note - when we render we create these as well..
282 // so we should check to see if body has xtype set.
283 if (build_from_html && Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body') {
285 var self_cntr_el = Roo.get(this[cntr](false));
286 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
288 //Roo.log(Roo.XComponent.build_from_html);
289 //Roo.log("got echild:");
292 // there is a scenario where some of the child elements are flexy:if (and all of the same type)
293 // and are not displayed -this causes this to use up the wrong element when matching.
294 // at present the only work around for this is to nest flexy:if elements in another element that is always rendered.
297 if (echild && echild.attr('xtype').split('.').pop() == cn.xtype) {
298 // Roo.log("found child for " + this.xtype +": " + echild.attr('xtype') );
304 //echild.dom.removeAttribute('xtype');
306 Roo.debug && Roo.log("MISSING " + cn.xtype + " on child of " + (this.el ? this.el.attr('xbuilderid') : 'no parent'));
307 Roo.debug && Roo.log(self_cntr_el);
308 Roo.debug && Roo.log(echild);
309 Roo.debug && Roo.log(cn);
315 // if object has flexy:if - then it may or may not be rendered.
316 if (build_from_html && has_flexy && !cn.el && cn.can_build_overlaid) {
317 // skip a flexy if element.
318 Roo.debug && Roo.log('skipping render');
319 Roo.debug && Roo.log(tree);
321 Roo.debug && Roo.log('skipping all children');
322 skip_children = true;
327 // actually if flexy:foreach is found, we really want to create
328 // multiple copies here...
330 //Roo.log(this[cntr]());
331 // some elements do not have render methods.. like the layouts...
333 if(this[cntr](true) === false){
338 cn.render && cn.render(this[cntr](true));
341 // then add the element..
348 if (typeof (tree.menu) != 'undefined') {
349 tree.menu.parentType = cn.xtype;
350 tree.menu.triggerEl = cn.el;
351 nitems.push(cn.addxtype(Roo.apply({}, tree.menu)));
355 if (!tree.items || !tree.items.length) {
357 //Roo.log(["no children", this]);
362 var items = tree.items;
365 //Roo.log(items.length);
367 if (!skip_children) {
368 for(var i =0;i < items.length;i++) {
369 // Roo.log(['add child', items[i]]);
370 nitems.push(cn.addxtype(Roo.apply({}, items[i])));
376 //Roo.log("fire childrenrendered");
378 cn.fireEvent('childrenrendered', this);
384 * Set the element that will be used to show or hide
386 setVisibilityEl : function(el)
388 this.visibilityEl = el;
392 * Get the element that will be used to show or hide
394 getVisibilityEl : function()
396 if (typeof(this.visibilityEl) == 'object') {
397 return this.visibilityEl;
400 if (typeof(this.visibilityEl) == 'string') {
401 return this.visibilityEl == 'parent' ? this.parent().getEl() : this.getEl();
408 * Show a component - removes 'hidden' class
412 if(!this.getVisibilityEl()){
416 this.getVisibilityEl().removeClass('hidden');
418 this.fireEvent('show', this);
423 * Hide a component - adds 'hidden' class
427 if(!this.getVisibilityEl()){
431 this.getVisibilityEl().addClass('hidden');
433 this.fireEvent('hide', this);
446 * @class Roo.bootstrap.Body
447 * @extends Roo.bootstrap.Component
448 * Bootstrap Body class
452 * @param {Object} config The config object
455 Roo.bootstrap.Body = function(config){
457 config = config || {};
459 Roo.bootstrap.Body.superclass.constructor.call(this, config);
460 this.el = Roo.get(config.el ? config.el : document.body );
461 if (this.cls && this.cls.length) {
462 Roo.get(document.body).addClass(this.cls);
466 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, {
468 is_body : true,// just to make sure it's constructed?
473 onRender : function(ct, position)
475 /* Roo.log("Roo.bootstrap.Body - onRender");
476 if (this.cls && this.cls.length) {
477 Roo.get(document.body).addClass(this.cls);
496 * @class Roo.bootstrap.ButtonGroup
497 * @extends Roo.bootstrap.Component
498 * Bootstrap ButtonGroup class
499 * @cfg {String} size lg | sm | xs (default empty normal)
500 * @cfg {String} align vertical | justified (default none)
501 * @cfg {String} direction up | down (default down)
502 * @cfg {Boolean} toolbar false | true
503 * @cfg {Boolean} btn true | false
508 * @param {Object} config The config object
511 Roo.bootstrap.ButtonGroup = function(config){
512 Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
515 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, {
523 getAutoCreate : function(){
529 cfg.html = this.html || cfg.html;
540 if (['vertical','justified'].indexOf(this.align)!==-1) {
541 cfg.cls = 'btn-group-' + this.align;
543 if (this.align == 'justified') {
544 console.log(this.items);
548 if (['lg','sm','xs'].indexOf(this.size)!==-1) {
549 cfg.cls += ' btn-group-' + this.size;
552 if (this.direction == 'up') {
553 cfg.cls += ' dropup' ;
569 * @class Roo.bootstrap.Button
570 * @extends Roo.bootstrap.Component
571 * Bootstrap Button class
572 * @cfg {String} html The button content
573 * @cfg {String} weight (default | primary | success | info | warning | danger | link ) default
574 * @cfg {String} size ( lg | sm | xs)
575 * @cfg {String} tag ( a | input | submit)
576 * @cfg {String} href empty or href
577 * @cfg {Boolean} disabled default false;
578 * @cfg {Boolean} isClose default false;
579 * @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)
580 * @cfg {String} badge text for badge
581 * @cfg {String} theme (default|glow)
582 * @cfg {Boolean} inverse dark themed version
583 * @cfg {Boolean} toggle is it a slidy toggle button
584 * @cfg {Boolean} pressed (true|false) default null - if the button ahs active state
585 * @cfg {String} ontext text for on slidy toggle state
586 * @cfg {String} offtext text for off slidy toggle state
587 * @cfg {Boolean} preventDefault default true (stop click event triggering the URL if it's a link.)
588 * @cfg {Boolean} removeClass remove the standard class..
589 * @cfg {String} target target for a href. (_self|_blank|_parent|_top| other)
592 * Create a new button
593 * @param {Object} config The config object
597 Roo.bootstrap.Button = function(config){
598 Roo.bootstrap.Button.superclass.constructor.call(this, config);
599 this.weightClass = ["btn-default",
611 * When a butotn is pressed
612 * @param {Roo.bootstrap.Button} btn
613 * @param {Roo.EventObject} e
618 * After the button has been toggles
619 * @param {Roo.bootstrap.Button} btn
620 * @param {Roo.EventObject} e
621 * @param {boolean} pressed (also available as button.pressed)
627 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
645 preventDefault: true,
653 getAutoCreate : function(){
661 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
662 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
667 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
669 if (this.toggle == true) {
672 cls: 'slider-frame roo-button',
677 'data-off-text':'OFF',
678 cls: 'slider-button',
684 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
685 cfg.cls += ' '+this.weight;
694 cfg["aria-hidden"] = true;
696 cfg.html = "×";
702 if (this.theme==='default') {
703 cfg.cls = 'btn roo-button';
705 //if (this.parentType != 'Navbar') {
706 this.weight = this.weight.length ? this.weight : 'default';
708 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
710 cfg.cls += ' btn-' + this.weight;
712 } else if (this.theme==='glow') {
715 cfg.cls = 'btn-glow roo-button';
717 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
719 cfg.cls += ' ' + this.weight;
725 this.cls += ' inverse';
729 if (this.active || this.pressed === true) {
730 cfg.cls += ' active';
734 cfg.disabled = 'disabled';
738 Roo.log('changing to ul' );
740 this.glyphicon = 'caret';
743 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
745 //gsRoo.log(this.parentType);
746 if (this.parentType === 'Navbar' && !this.parent().bar) {
747 Roo.log('changing to li?');
756 href : this.href || '#'
759 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
760 cfg.cls += ' dropdown';
767 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
769 if (this.glyphicon) {
770 cfg.html = ' ' + cfg.html;
775 cls: 'glyphicon glyphicon-' + this.glyphicon
785 // cfg.cls='btn roo-button';
789 var value = cfg.html;
794 cls: 'glyphicon glyphicon-' + this.glyphicon,
813 cfg.cls += ' dropdown';
814 cfg.html = typeof(cfg.html) != 'undefined' ?
815 cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
818 if (cfg.tag !== 'a' && this.href !== '') {
819 throw "Tag must be a to set href.";
820 } else if (this.href.length > 0) {
821 cfg.href = this.href;
824 if(this.removeClass){
829 cfg.target = this.target;
834 initEvents: function() {
835 // Roo.log('init events?');
836 // Roo.log(this.el.dom);
839 if (typeof (this.menu) != 'undefined') {
840 this.menu.parentType = this.xtype;
841 this.menu.triggerEl = this.el;
842 this.addxtype(Roo.apply({}, this.menu));
846 if (this.el.hasClass('roo-button')) {
847 this.el.on('click', this.onClick, this);
849 this.el.select('.roo-button').on('click', this.onClick, this);
852 if(this.removeClass){
853 this.el.on('click', this.onClick, this);
856 this.el.enableDisplayMode();
859 onClick : function(e)
865 Roo.log('button on click ');
866 if(this.preventDefault){
870 if (this.pressed === true || this.pressed === false) {
871 this.toggleActive(e);
875 this.fireEvent('click', this, e);
879 * Enables this button
883 this.disabled = false;
884 this.el.removeClass('disabled');
888 * Disable this button
892 this.disabled = true;
893 this.el.addClass('disabled');
896 * sets the active state on/off,
897 * @param {Boolean} state (optional) Force a particular state
899 setActive : function(v) {
901 this.el[v ? 'addClass' : 'removeClass']('active');
905 * toggles the current active state
907 toggleActive : function(e)
909 this.setActive(!this.pressed);
910 this.fireEvent('toggle', this, e, !this.pressed);
913 * get the current active state
914 * @return {boolean} true if it's active
916 isActive : function()
918 return this.el.hasClass('active');
921 * set the text of the first selected button
923 setText : function(str)
925 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
928 * get the text of the first selected button
932 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
935 setWeight : function(str)
937 this.el.removeClass(this.weightClass);
938 this.el.addClass('btn-' + str);
952 * @class Roo.bootstrap.Column
953 * @extends Roo.bootstrap.Component
954 * Bootstrap Column class
955 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
956 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
957 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
958 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
959 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
960 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
961 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
962 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
965 * @cfg {Boolean} hidden (true|false) hide the element
966 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
967 * @cfg {String} fa (ban|check|...) font awesome icon
968 * @cfg {Number} fasize (1|2|....) font awsome size
970 * @cfg {String} icon (info-sign|check|...) glyphicon name
972 * @cfg {String} html content of column.
975 * Create a new Column
976 * @param {Object} config The config object
979 Roo.bootstrap.Column = function(config){
980 Roo.bootstrap.Column.superclass.constructor.call(this, config);
983 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
1001 getAutoCreate : function(){
1002 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
1010 ['xs','sm','md','lg'].map(function(size){
1011 //Roo.log( size + ':' + settings[size]);
1013 if (settings[size+'off'] !== false) {
1014 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
1017 if (settings[size] === false) {
1021 if (!settings[size]) { // 0 = hidden
1022 cfg.cls += ' hidden-' + size;
1025 cfg.cls += ' col-' + size + '-' + settings[size];
1030 cfg.cls += ' hidden';
1033 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1034 cfg.cls +=' alert alert-' + this.alert;
1038 if (this.html.length) {
1039 cfg.html = this.html;
1043 if (this.fasize > 1) {
1044 fasize = ' fa-' + this.fasize + 'x';
1046 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
1051 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
1070 * @class Roo.bootstrap.Container
1071 * @extends Roo.bootstrap.Component
1072 * Bootstrap Container class
1073 * @cfg {Boolean} jumbotron is it a jumbotron element
1074 * @cfg {String} html content of element
1075 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1076 * @cfg {String} panel (default|primary|success|info|warning|danger) render as panel - type - primary/success.....
1077 * @cfg {String} header content of header (for panel)
1078 * @cfg {String} footer content of footer (for panel)
1079 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1080 * @cfg {String} tag (header|aside|section) type of HTML tag.
1081 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1082 * @cfg {String} fa font awesome icon
1083 * @cfg {String} icon (info-sign|check|...) glyphicon name
1084 * @cfg {Boolean} hidden (true|false) hide the element
1085 * @cfg {Boolean} expandable (true|false) default false
1086 * @cfg {Boolean} expanded (true|false) default true
1087 * @cfg {String} rheader contet on the right of header
1088 * @cfg {Boolean} clickable (true|false) default false
1092 * Create a new Container
1093 * @param {Object} config The config object
1096 Roo.bootstrap.Container = function(config){
1097 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1103 * After the panel has been expand
1105 * @param {Roo.bootstrap.Container} this
1110 * After the panel has been collapsed
1112 * @param {Roo.bootstrap.Container} this
1117 * When a element is chick
1118 * @param {Roo.bootstrap.Container} this
1119 * @param {Roo.EventObject} e
1125 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1143 getChildContainer : function() {
1149 if (this.panel.length) {
1150 return this.el.select('.panel-body',true).first();
1157 getAutoCreate : function(){
1160 tag : this.tag || 'div',
1164 if (this.jumbotron) {
1165 cfg.cls = 'jumbotron';
1170 // - this is applied by the parent..
1172 // cfg.cls = this.cls + '';
1175 if (this.sticky.length) {
1177 var bd = Roo.get(document.body);
1178 if (!bd.hasClass('bootstrap-sticky')) {
1179 bd.addClass('bootstrap-sticky');
1180 Roo.select('html',true).setStyle('height', '100%');
1183 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1187 if (this.well.length) {
1188 switch (this.well) {
1191 cfg.cls +=' well well-' +this.well;
1200 cfg.cls += ' hidden';
1204 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1205 cfg.cls +=' alert alert-' + this.alert;
1210 if (this.panel.length) {
1211 cfg.cls += ' panel panel-' + this.panel;
1213 if (this.header.length) {
1217 if(this.expandable){
1219 cfg.cls = cfg.cls + ' expandable';
1223 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1231 cls : 'panel-title',
1232 html : (this.expandable ? ' ' : '') + this.header
1236 cls: 'panel-header-right',
1242 cls : 'panel-heading',
1243 style : this.expandable ? 'cursor: pointer' : '',
1251 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1256 if (this.footer.length) {
1258 cls : 'panel-footer',
1267 body.html = this.html || cfg.html;
1268 // prefix with the icons..
1270 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1273 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1278 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1279 cfg.cls = 'container';
1285 initEvents: function()
1287 if(this.expandable){
1288 var headerEl = this.headerEl();
1291 headerEl.on('click', this.onToggleClick, this);
1296 this.el.on('click', this.onClick, this);
1301 onToggleClick : function()
1303 var headerEl = this.headerEl();
1319 if(this.fireEvent('expand', this)) {
1321 this.expanded = true;
1323 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1325 this.el.select('.panel-body',true).first().removeClass('hide');
1327 var toggleEl = this.toggleEl();
1333 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1338 collapse : function()
1340 if(this.fireEvent('collapse', this)) {
1342 this.expanded = false;
1344 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1345 this.el.select('.panel-body',true).first().addClass('hide');
1347 var toggleEl = this.toggleEl();
1353 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1357 toggleEl : function()
1359 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1363 return this.el.select('.panel-heading .fa',true).first();
1366 headerEl : function()
1368 if(!this.el || !this.panel.length || !this.header.length){
1372 return this.el.select('.panel-heading',true).first()
1377 if(!this.el || !this.panel.length){
1381 return this.el.select('.panel-body',true).first()
1384 titleEl : function()
1386 if(!this.el || !this.panel.length || !this.header.length){
1390 return this.el.select('.panel-title',true).first();
1393 setTitle : function(v)
1395 var titleEl = this.titleEl();
1401 titleEl.dom.innerHTML = v;
1404 getTitle : function()
1407 var titleEl = this.titleEl();
1413 return titleEl.dom.innerHTML;
1416 setRightTitle : function(v)
1418 var t = this.el.select('.panel-header-right',true).first();
1424 t.dom.innerHTML = v;
1427 onClick : function(e)
1431 this.fireEvent('click', this, e);
1444 * @class Roo.bootstrap.Img
1445 * @extends Roo.bootstrap.Component
1446 * Bootstrap Img class
1447 * @cfg {Boolean} imgResponsive false | true
1448 * @cfg {String} border rounded | circle | thumbnail
1449 * @cfg {String} src image source
1450 * @cfg {String} alt image alternative text
1451 * @cfg {String} href a tag href
1452 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
1453 * @cfg {String} xsUrl xs image source
1454 * @cfg {String} smUrl sm image source
1455 * @cfg {String} mdUrl md image source
1456 * @cfg {String} lgUrl lg image source
1459 * Create a new Input
1460 * @param {Object} config The config object
1463 Roo.bootstrap.Img = function(config){
1464 Roo.bootstrap.Img.superclass.constructor.call(this, config);
1470 * The img click event for the img.
1471 * @param {Roo.EventObject} e
1477 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
1479 imgResponsive: true,
1489 getAutoCreate : function()
1491 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1492 return this.createSingleImg();
1497 cls: 'roo-image-responsive-group',
1502 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
1504 if(!_this[size + 'Url']){
1510 cls: (_this.imgResponsive) ? 'img-responsive' : '',
1511 html: _this.html || cfg.html,
1512 src: _this[size + 'Url']
1515 img.cls += ' roo-image-responsive-' + size;
1517 var s = ['xs', 'sm', 'md', 'lg'];
1519 s.splice(s.indexOf(size), 1);
1521 Roo.each(s, function(ss){
1522 img.cls += ' hidden-' + ss;
1525 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
1526 cfg.cls += ' img-' + _this.border;
1530 cfg.alt = _this.alt;
1543 a.target = _this.target;
1547 cfg.cn.push((_this.href) ? a : img);
1554 createSingleImg : function()
1558 cls: (this.imgResponsive) ? 'img-responsive' : '',
1560 src : 'about:blank' // just incase src get's set to undefined?!?
1563 cfg.html = this.html || cfg.html;
1565 cfg.src = this.src || cfg.src;
1567 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
1568 cfg.cls += ' img-' + this.border;
1585 a.target = this.target;
1590 return (this.href) ? a : cfg;
1593 initEvents: function()
1596 this.el.on('click', this.onClick, this);
1601 onClick : function(e)
1603 Roo.log('img onclick');
1604 this.fireEvent('click', this, e);
1607 * Sets the url of the image - used to update it
1608 * @param {String} url the url of the image
1611 setSrc : function(url)
1615 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1616 this.el.dom.src = url;
1620 this.el.select('img', true).first().dom.src = url;
1636 * @class Roo.bootstrap.Link
1637 * @extends Roo.bootstrap.Component
1638 * Bootstrap Link Class
1639 * @cfg {String} alt image alternative text
1640 * @cfg {String} href a tag href
1641 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
1642 * @cfg {String} html the content of the link.
1643 * @cfg {String} anchor name for the anchor link
1644 * @cfg {String} fa - favicon
1646 * @cfg {Boolean} preventDefault (true | false) default false
1650 * Create a new Input
1651 * @param {Object} config The config object
1654 Roo.bootstrap.Link = function(config){
1655 Roo.bootstrap.Link.superclass.constructor.call(this, config);
1661 * The img click event for the img.
1662 * @param {Roo.EventObject} e
1668 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
1672 preventDefault: false,
1678 getAutoCreate : function()
1680 var html = this.html || '';
1682 if (this.fa !== false) {
1683 html = '<i class="fa fa-' + this.fa + '"></i>';
1688 // anchor's do not require html/href...
1689 if (this.anchor === false) {
1691 cfg.href = this.href || '#';
1693 cfg.name = this.anchor;
1694 if (this.html !== false || this.fa !== false) {
1697 if (this.href !== false) {
1698 cfg.href = this.href;
1702 if(this.alt !== false){
1707 if(this.target !== false) {
1708 cfg.target = this.target;
1714 initEvents: function() {
1716 if(!this.href || this.preventDefault){
1717 this.el.on('click', this.onClick, this);
1721 onClick : function(e)
1723 if(this.preventDefault){
1726 //Roo.log('img onclick');
1727 this.fireEvent('click', this, e);
1740 * @class Roo.bootstrap.Header
1741 * @extends Roo.bootstrap.Component
1742 * Bootstrap Header class
1743 * @cfg {String} html content of header
1744 * @cfg {Number} level (1|2|3|4|5|6) default 1
1747 * Create a new Header
1748 * @param {Object} config The config object
1752 Roo.bootstrap.Header = function(config){
1753 Roo.bootstrap.Header.superclass.constructor.call(this, config);
1756 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
1764 getAutoCreate : function(){
1769 tag: 'h' + (1 *this.level),
1770 html: this.html || ''
1782 * Ext JS Library 1.1.1
1783 * Copyright(c) 2006-2007, Ext JS, LLC.
1785 * Originally Released Under LGPL - original licence link has changed is not relivant.
1788 * <script type="text/javascript">
1792 * @class Roo.bootstrap.MenuMgr
1793 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
1796 Roo.bootstrap.MenuMgr = function(){
1797 var menus, active, groups = {}, attached = false, lastShow = new Date();
1799 // private - called when first menu is created
1802 active = new Roo.util.MixedCollection();
1803 Roo.get(document).addKeyListener(27, function(){
1804 if(active.length > 0){
1812 if(active && active.length > 0){
1813 var c = active.clone();
1823 if(active.length < 1){
1824 Roo.get(document).un("mouseup", onMouseDown);
1832 var last = active.last();
1833 lastShow = new Date();
1836 Roo.get(document).on("mouseup", onMouseDown);
1841 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
1842 m.parentMenu.activeChild = m;
1843 }else if(last && last.isVisible()){
1844 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
1849 function onBeforeHide(m){
1851 m.activeChild.hide();
1853 if(m.autoHideTimer){
1854 clearTimeout(m.autoHideTimer);
1855 delete m.autoHideTimer;
1860 function onBeforeShow(m){
1861 var pm = m.parentMenu;
1862 if(!pm && !m.allowOtherMenus){
1864 }else if(pm && pm.activeChild && active != m){
1865 pm.activeChild.hide();
1869 // private this should really trigger on mouseup..
1870 function onMouseDown(e){
1871 Roo.log("on Mouse Up");
1873 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
1874 Roo.log("MenuManager hideAll");
1883 function onBeforeCheck(mi, state){
1885 var g = groups[mi.group];
1886 for(var i = 0, l = g.length; i < l; i++){
1888 g[i].setChecked(false);
1897 * Hides all menus that are currently visible
1899 hideAll : function(){
1904 register : function(menu){
1908 menus[menu.id] = menu;
1909 menu.on("beforehide", onBeforeHide);
1910 menu.on("hide", onHide);
1911 menu.on("beforeshow", onBeforeShow);
1912 menu.on("show", onShow);
1914 if(g && menu.events["checkchange"]){
1918 groups[g].push(menu);
1919 menu.on("checkchange", onCheck);
1924 * Returns a {@link Roo.menu.Menu} object
1925 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
1926 * be used to generate and return a new Menu instance.
1928 get : function(menu){
1929 if(typeof menu == "string"){ // menu id
1931 }else if(menu.events){ // menu instance
1934 /*else if(typeof menu.length == 'number'){ // array of menu items?
1935 return new Roo.bootstrap.Menu({items:menu});
1936 }else{ // otherwise, must be a config
1937 return new Roo.bootstrap.Menu(menu);
1944 unregister : function(menu){
1945 delete menus[menu.id];
1946 menu.un("beforehide", onBeforeHide);
1947 menu.un("hide", onHide);
1948 menu.un("beforeshow", onBeforeShow);
1949 menu.un("show", onShow);
1951 if(g && menu.events["checkchange"]){
1952 groups[g].remove(menu);
1953 menu.un("checkchange", onCheck);
1958 registerCheckable : function(menuItem){
1959 var g = menuItem.group;
1964 groups[g].push(menuItem);
1965 menuItem.on("beforecheckchange", onBeforeCheck);
1970 unregisterCheckable : function(menuItem){
1971 var g = menuItem.group;
1973 groups[g].remove(menuItem);
1974 menuItem.un("beforecheckchange", onBeforeCheck);
1986 * @class Roo.bootstrap.Menu
1987 * @extends Roo.bootstrap.Component
1988 * Bootstrap Menu class - container for MenuItems
1989 * @cfg {String} type (dropdown|treeview|submenu) type of menu
1990 * @cfg {bool} hidden if the menu should be hidden when rendered.
1991 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
1992 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
1996 * @param {Object} config The config object
2000 Roo.bootstrap.Menu = function(config){
2001 Roo.bootstrap.Menu.superclass.constructor.call(this, config);
2002 if (this.registerMenu && this.type != 'treeview') {
2003 Roo.bootstrap.MenuMgr.register(this);
2010 * Fires before this menu is displayed
2011 * @param {Roo.menu.Menu} this
2016 * Fires before this menu is hidden
2017 * @param {Roo.menu.Menu} this
2022 * Fires after this menu is displayed
2023 * @param {Roo.menu.Menu} this
2028 * Fires after this menu is hidden
2029 * @param {Roo.menu.Menu} this
2034 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
2035 * @param {Roo.menu.Menu} this
2036 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2037 * @param {Roo.EventObject} e
2042 * Fires when the mouse is hovering over this menu
2043 * @param {Roo.menu.Menu} this
2044 * @param {Roo.EventObject} e
2045 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2050 * Fires when the mouse exits this menu
2051 * @param {Roo.menu.Menu} this
2052 * @param {Roo.EventObject} e
2053 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2058 * Fires when a menu item contained in this menu is clicked
2059 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
2060 * @param {Roo.EventObject} e
2064 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
2067 Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component, {
2071 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
2074 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
2076 registerMenu : true,
2078 menuItems :false, // stores the menu items..
2088 getChildContainer : function() {
2092 getAutoCreate : function(){
2094 //if (['right'].indexOf(this.align)!==-1) {
2095 // cfg.cn[1].cls += ' pull-right'
2101 cls : 'dropdown-menu' ,
2102 style : 'z-index:1000'
2106 if (this.type === 'submenu') {
2107 cfg.cls = 'submenu active';
2109 if (this.type === 'treeview') {
2110 cfg.cls = 'treeview-menu';
2115 initEvents : function() {
2117 // Roo.log("ADD event");
2118 // Roo.log(this.triggerEl.dom);
2120 this.triggerEl.on('click', this.onTriggerClick, this);
2122 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
2125 if (this.triggerEl.hasClass('nav-item')) {
2126 // dropdown toggle on the 'a' in BS4?
2127 this.triggerEl.select('.nav-link',true).first().addClass('dropdown-toggle');
2129 this.triggerEl.addClass('dropdown-toggle');
2132 this.el.on('touchstart' , this.onTouch, this);
2134 this.el.on('click' , this.onClick, this);
2136 this.el.on("mouseover", this.onMouseOver, this);
2137 this.el.on("mouseout", this.onMouseOut, this);
2141 findTargetItem : function(e)
2143 var t = e.getTarget(".dropdown-menu-item", this.el, true);
2147 //Roo.log(t); Roo.log(t.id);
2149 //Roo.log(this.menuitems);
2150 return this.menuitems.get(t.id);
2152 //return this.items.get(t.menuItemId);
2158 onTouch : function(e)
2160 Roo.log("menu.onTouch");
2161 //e.stopEvent(); this make the user popdown broken
2165 onClick : function(e)
2167 Roo.log("menu.onClick");
2169 var t = this.findTargetItem(e);
2170 if(!t || t.isContainer){
2175 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
2176 if(t == this.activeItem && t.shouldDeactivate(e)){
2177 this.activeItem.deactivate();
2178 delete this.activeItem;
2182 this.setActiveItem(t, true);
2190 Roo.log('pass click event');
2194 this.fireEvent("click", this, t, e);
2198 if(!t.href.length || t.href == '#'){
2199 (function() { _this.hide(); }).defer(100);
2204 onMouseOver : function(e){
2205 var t = this.findTargetItem(e);
2208 // if(t.canActivate && !t.disabled){
2209 // this.setActiveItem(t, true);
2213 this.fireEvent("mouseover", this, e, t);
2215 isVisible : function(){
2216 return !this.hidden;
2218 onMouseOut : function(e){
2219 var t = this.findTargetItem(e);
2222 // if(t == this.activeItem && t.shouldDeactivate(e)){
2223 // this.activeItem.deactivate();
2224 // delete this.activeItem;
2227 this.fireEvent("mouseout", this, e, t);
2232 * Displays this menu relative to another element
2233 * @param {String/HTMLElement/Roo.Element} element The element to align to
2234 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
2235 * the element (defaults to this.defaultAlign)
2236 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2238 show : function(el, pos, parentMenu){
2239 this.parentMenu = parentMenu;
2243 this.fireEvent("beforeshow", this);
2244 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
2247 * Displays this menu at a specific xy position
2248 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
2249 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2251 showAt : function(xy, parentMenu, /* private: */_e){
2252 this.parentMenu = parentMenu;
2257 this.fireEvent("beforeshow", this);
2258 //xy = this.el.adjustForConstraints(xy);
2262 this.hideMenuItems();
2263 this.hidden = false;
2264 this.triggerEl.addClass('open');
2265 this.el.addClass('show');
2267 // reassign x when hitting right
2268 if(this.el.getWidth() + xy[0] >= Roo.lib.Dom.getViewWidth()){
2269 xy[0] = xy[0] - this.el.getWidth() + this.triggerEl.getWidth();
2272 // reassign y when hitting bottom
2273 if(this.el.getHeight() + xy[1] >= Roo.lib.Dom.getViewHeight()){
2274 xy[1] = xy[1] - this.el.getHeight() - this.triggerEl.getHeight();
2277 // but the list may align on trigger left or trigger top... should it be a properity?
2279 if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
2284 this.fireEvent("show", this);
2290 this.doFocus.defer(50, this);
2294 doFocus : function(){
2296 this.focusEl.focus();
2301 * Hides this menu and optionally all parent menus
2302 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
2304 hide : function(deep)
2307 this.hideMenuItems();
2308 if(this.el && this.isVisible()){
2309 this.fireEvent("beforehide", this);
2310 if(this.activeItem){
2311 this.activeItem.deactivate();
2312 this.activeItem = null;
2314 this.triggerEl.removeClass('open');;
2315 this.el.removeClass('show');
2317 this.fireEvent("hide", this);
2319 if(deep === true && this.parentMenu){
2320 this.parentMenu.hide(true);
2324 onTriggerClick : function(e)
2326 Roo.log('trigger click');
2328 var target = e.getTarget();
2330 Roo.log(target.nodeName.toLowerCase());
2332 if(target.nodeName.toLowerCase() === 'i'){
2338 onTriggerPress : function(e)
2340 Roo.log('trigger press');
2341 //Roo.log(e.getTarget());
2342 // Roo.log(this.triggerEl.dom);
2344 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
2345 var pel = Roo.get(e.getTarget());
2346 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
2347 Roo.log('is treeview or dropdown?');
2351 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
2355 if (this.isVisible()) {
2360 this.show(this.triggerEl, false, false);
2363 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
2370 hideMenuItems : function()
2372 Roo.log("hide Menu Items");
2376 //$(backdrop).remove()
2377 this.el.select('.open',true).each(function(aa) {
2379 aa.removeClass('open');
2380 //var parent = getParent($(this))
2381 //var relatedTarget = { relatedTarget: this }
2383 //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
2384 //if (e.isDefaultPrevented()) return
2385 //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
2388 addxtypeChild : function (tree, cntr) {
2389 var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
2391 this.menuitems.add(comp);
2403 this.getEl().dom.innerHTML = '';
2404 this.menuitems.clear();
2418 * @class Roo.bootstrap.MenuItem
2419 * @extends Roo.bootstrap.Component
2420 * Bootstrap MenuItem class
2421 * @cfg {String} html the menu label
2422 * @cfg {String} href the link
2423 * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
2424 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
2425 * @cfg {Boolean} active used on sidebars to highlight active itesm
2426 * @cfg {String} fa favicon to show on left of menu item.
2427 * @cfg {Roo.bootsrap.Menu} menu the child menu.
2431 * Create a new MenuItem
2432 * @param {Object} config The config object
2436 Roo.bootstrap.MenuItem = function(config){
2437 Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
2442 * The raw click event for the entire grid.
2443 * @param {Roo.bootstrap.MenuItem} this
2444 * @param {Roo.EventObject} e
2450 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component, {
2454 preventDefault: false,
2455 isContainer : false,
2459 getAutoCreate : function(){
2461 if(this.isContainer){
2464 cls: 'dropdown-menu-item dropdown-item'
2478 if (this.fa !== false) {
2481 cls : 'fa fa-' + this.fa
2490 cls: 'dropdown-menu-item dropdown-item',
2493 if (this.parent().type == 'treeview') {
2494 cfg.cls = 'treeview-menu';
2497 cfg.cls += ' active';
2502 anc.href = this.href || cfg.cn[0].href ;
2503 ctag.html = this.html || cfg.cn[0].html ;
2507 initEvents: function()
2509 if (this.parent().type == 'treeview') {
2510 this.el.select('a').on('click', this.onClick, this);
2514 this.menu.parentType = this.xtype;
2515 this.menu.triggerEl = this.el;
2516 this.menu = this.addxtype(Roo.apply({}, this.menu));
2520 onClick : function(e)
2522 Roo.log('item on click ');
2524 if(this.preventDefault){
2527 //this.parent().hideMenuItems();
2529 this.fireEvent('click', this, e);
2548 * @class Roo.bootstrap.MenuSeparator
2549 * @extends Roo.bootstrap.Component
2550 * Bootstrap MenuSeparator class
2553 * Create a new MenuItem
2554 * @param {Object} config The config object
2558 Roo.bootstrap.MenuSeparator = function(config){
2559 Roo.bootstrap.MenuSeparator.superclass.constructor.call(this, config);
2562 Roo.extend(Roo.bootstrap.MenuSeparator, Roo.bootstrap.Component, {
2564 getAutoCreate : function(){
2583 * @class Roo.bootstrap.Modal
2584 * @extends Roo.bootstrap.Component
2585 * Bootstrap Modal class
2586 * @cfg {String} title Title of dialog
2587 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
2588 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
2589 * @cfg {Boolean} specificTitle default false
2590 * @cfg {Array} buttons Array of buttons or standard button set..
2591 * @cfg {String} buttonPosition (left|right|center) default right
2592 * @cfg {Boolean} animate default true
2593 * @cfg {Boolean} allow_close default true
2594 * @cfg {Boolean} fitwindow default false
2595 * @cfg {String} size (sm|lg) default empty
2596 * @cfg {Number} max_width set the max width of modal
2600 * Create a new Modal Dialog
2601 * @param {Object} config The config object
2604 Roo.bootstrap.Modal = function(config){
2605 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2610 * The raw btnclick event for the button
2611 * @param {Roo.EventObject} e
2616 * Fire when dialog resize
2617 * @param {Roo.bootstrap.Modal} this
2618 * @param {Roo.EventObject} e
2622 this.buttons = this.buttons || [];
2625 this.tmpl = Roo.factory(this.tmpl);
2630 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
2632 title : 'test dialog',
2642 specificTitle: false,
2644 buttonPosition: 'right',
2667 onRender : function(ct, position)
2669 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2672 var cfg = Roo.apply({}, this.getAutoCreate());
2675 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2677 //if (!cfg.name.length) {
2681 cfg.cls += ' ' + this.cls;
2684 cfg.style = this.style;
2686 this.el = Roo.get(document.body).createChild(cfg, position);
2688 //var type = this.el.dom.type;
2691 if(this.tabIndex !== undefined){
2692 this.el.dom.setAttribute('tabIndex', this.tabIndex);
2695 this.dialogEl = this.el.select('.modal-dialog',true).first();
2696 this.bodyEl = this.el.select('.modal-body',true).first();
2697 this.closeEl = this.el.select('.modal-header .close', true).first();
2698 this.headerEl = this.el.select('.modal-header',true).first();
2699 this.titleEl = this.el.select('.modal-title',true).first();
2700 this.footerEl = this.el.select('.modal-footer',true).first();
2702 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2704 //this.el.addClass("x-dlg-modal");
2706 if (this.buttons.length) {
2707 Roo.each(this.buttons, function(bb) {
2708 var b = Roo.apply({}, bb);
2709 b.xns = b.xns || Roo.bootstrap;
2710 b.xtype = b.xtype || 'Button';
2711 if (typeof(b.listeners) == 'undefined') {
2712 b.listeners = { click : this.onButtonClick.createDelegate(this) };
2715 var btn = Roo.factory(b);
2717 btn.render(this.el.select('.modal-footer div').first());
2721 // render the children.
2724 if(typeof(this.items) != 'undefined'){
2725 var items = this.items;
2728 for(var i =0;i < items.length;i++) {
2729 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2733 this.items = nitems;
2735 // where are these used - they used to be body/close/footer
2739 //this.el.addClass([this.fieldClass, this.cls]);
2743 getAutoCreate : function()
2747 html : this.html || ''
2752 cls : 'modal-title',
2756 if(this.specificTitle){
2762 if (this.allow_close) {
2774 if(this.size.length){
2775 size = 'modal-' + this.size;
2782 cls: "modal-dialog " + size,
2785 cls : "modal-content",
2788 cls : 'modal-header',
2793 cls : 'modal-footer',
2797 cls: 'btn-' + this.buttonPosition
2814 modal.cls += ' fade';
2820 getChildContainer : function() {
2825 getButtonContainer : function() {
2826 return this.el.select('.modal-footer div',true).first();
2829 initEvents : function()
2831 if (this.allow_close) {
2832 this.closeEl.on('click', this.hide, this);
2834 Roo.EventManager.onWindowResize(this.resize, this, true);
2841 this.maskEl.setSize(
2842 Roo.lib.Dom.getViewWidth(true),
2843 Roo.lib.Dom.getViewHeight(true)
2846 if (this.fitwindow) {
2848 this.width || Roo.lib.Dom.getViewportWidth(true) - 30,
2849 this.height || Roo.lib.Dom.getViewportHeight(true) - 60
2854 if(this.max_width !== 0) {
2856 var w = Math.min(this.max_width, Roo.lib.Dom.getViewportWidth(true) - 30);
2859 this.setSize(w, this.height);
2863 if(this.max_height) {
2864 this.setSize(w,Math.min(
2866 Roo.lib.Dom.getViewportHeight(true) - 60
2872 if(!this.fit_content) {
2873 this.setSize(w, Roo.lib.Dom.getViewportHeight(true) - 60);
2877 this.setSize(w, Math.min(
2879 this.headerEl.getHeight() +
2880 this.footerEl.getHeight() +
2881 this.getChildHeight(this.bodyEl.dom.childNodes),
2882 Roo.lib.Dom.getViewportHeight(true) - 60)
2888 setSize : function(w,h)
2899 if (!this.rendered) {
2903 //this.el.setStyle('display', 'block');
2904 this.el.removeClass('hideing');
2905 this.el.addClass('show');
2907 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
2910 this.el.addClass('in');
2913 this.el.addClass('in');
2916 // not sure how we can show data in here..
2918 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2921 Roo.get(document.body).addClass("x-body-masked");
2923 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2924 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2925 this.maskEl.addClass('show');
2929 this.fireEvent('show', this);
2931 // set zindex here - otherwise it appears to be ignored...
2932 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2935 this.items.forEach( function(e) {
2936 e.layout ? e.layout() : false;
2944 if(this.fireEvent("beforehide", this) !== false){
2945 this.maskEl.removeClass('show');
2946 Roo.get(document.body).removeClass("x-body-masked");
2947 this.el.removeClass('in');
2948 this.el.select('.modal-dialog', true).first().setStyle('transform','');
2950 if(this.animate){ // why
2951 this.el.addClass('hideing');
2953 if (!this.el.hasClass('hideing')) {
2954 return; // it's been shown again...
2956 this.el.removeClass('show');
2957 this.el.removeClass('hideing');
2961 this.el.removeClass('show');
2963 this.fireEvent('hide', this);
2966 isVisible : function()
2969 return this.el.hasClass('show') && !this.el.hasClass('hideing');
2973 addButton : function(str, cb)
2977 var b = Roo.apply({}, { html : str } );
2978 b.xns = b.xns || Roo.bootstrap;
2979 b.xtype = b.xtype || 'Button';
2980 if (typeof(b.listeners) == 'undefined') {
2981 b.listeners = { click : cb.createDelegate(this) };
2984 var btn = Roo.factory(b);
2986 btn.render(this.el.select('.modal-footer div').first());
2992 setDefaultButton : function(btn)
2994 //this.el.select('.modal-footer').()
2998 resizeTo: function(w,h)
3002 this.dialogEl.setWidth(w);
3003 if (this.diff === false) {
3004 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
3007 this.bodyEl.setHeight(h - this.diff);
3009 this.fireEvent('resize', this);
3012 setContentSize : function(w, h)
3016 onButtonClick: function(btn,e)
3019 this.fireEvent('btnclick', btn.name, e);
3022 * Set the title of the Dialog
3023 * @param {String} str new Title
3025 setTitle: function(str) {
3026 this.titleEl.dom.innerHTML = str;
3029 * Set the body of the Dialog
3030 * @param {String} str new Title
3032 setBody: function(str) {
3033 this.bodyEl.dom.innerHTML = str;
3036 * Set the body of the Dialog using the template
3037 * @param {Obj} data - apply this data to the template and replace the body contents.
3039 applyBody: function(obj)
3042 Roo.log("Error - using apply Body without a template");
3045 this.tmpl.overwrite(this.bodyEl, obj);
3048 getChildHeight : function(child_nodes)
3052 child_nodes.length == 0
3057 var child_height = 0;
3059 for(var i = 0; i < child_nodes.length; i++) {
3062 * for modal with tabs...
3063 if(child_nodes[i].classList.contains('roo-layout-panel')) {
3065 var layout_childs = child_nodes[i].childNodes;
3067 for(var j = 0; j < layout_childs.length; j++) {
3069 if(layout_childs[j].classList.contains('roo-layout-panel-body')) {
3071 var layout_body_childs = layout_childs[j].childNodes;
3073 for(var k = 0; k < layout_body_childs.length; k++) {
3075 if(layout_body_childs[k].classList.contains('navbar')) {
3076 child_height += layout_body_childs[k].offsetHeight;
3080 if(layout_body_childs[k].classList.contains('roo-layout-tabs-body')) {
3082 var layout_body_tab_childs = layout_body_childs[k].childNodes;
3084 for(var m = 0; m < layout_body_tab_childs.length; m++) {
3086 if(layout_body_tab_childs[m].classList.contains('roo-layout-active-content')) {
3087 child_height += this.getChildHeight(layout_body_tab_childs[m].childNodes);
3102 child_height += child_nodes[i].offsetHeight;
3103 // Roo.log(child_nodes[i].offsetHeight);
3106 return child_height;
3112 Roo.apply(Roo.bootstrap.Modal, {
3114 * Button config that displays a single OK button
3123 * Button config that displays Yes and No buttons
3139 * Button config that displays OK and Cancel buttons
3154 * Button config that displays Yes, No and Cancel buttons
3178 * messagebox - can be used as a replace
3182 * @class Roo.MessageBox
3183 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
3187 Roo.Msg.alert('Status', 'Changes saved successfully.');
3189 // Prompt for user data:
3190 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
3192 // process text value...
3196 // Show a dialog using config options:
3198 title:'Save Changes?',
3199 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
3200 buttons: Roo.Msg.YESNOCANCEL,
3207 Roo.bootstrap.MessageBox = function(){
3208 var dlg, opt, mask, waitTimer;
3209 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
3210 var buttons, activeTextEl, bwidth;
3214 var handleButton = function(button){
3216 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
3220 var handleHide = function(){
3222 dlg.el.removeClass(opt.cls);
3225 // Roo.TaskMgr.stop(waitTimer);
3226 // waitTimer = null;
3231 var updateButtons = function(b){
3234 buttons["ok"].hide();
3235 buttons["cancel"].hide();
3236 buttons["yes"].hide();
3237 buttons["no"].hide();
3238 //dlg.footer.dom.style.display = 'none';
3241 dlg.footerEl.dom.style.display = '';
3242 for(var k in buttons){
3243 if(typeof buttons[k] != "function"){
3246 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
3247 width += buttons[k].el.getWidth()+15;
3257 var handleEsc = function(d, k, e){
3258 if(opt && opt.closable !== false){
3268 * Returns a reference to the underlying {@link Roo.BasicDialog} element
3269 * @return {Roo.BasicDialog} The BasicDialog element
3271 getDialog : function(){
3273 dlg = new Roo.bootstrap.Modal( {
3276 //constraintoviewport:false,
3278 //collapsible : false,
3283 //buttonAlign:"center",
3284 closeClick : function(){
3285 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3288 handleButton("cancel");
3293 dlg.on("hide", handleHide);
3295 //dlg.addKeyListener(27, handleEsc);
3297 this.buttons = buttons;
3298 var bt = this.buttonText;
3299 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3300 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3301 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3302 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3304 bodyEl = dlg.bodyEl.createChild({
3306 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3307 '<textarea class="roo-mb-textarea"></textarea>' +
3308 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
3310 msgEl = bodyEl.dom.firstChild;
3311 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3312 textboxEl.enableDisplayMode();
3313 textboxEl.addKeyListener([10,13], function(){
3314 if(dlg.isVisible() && opt && opt.buttons){
3317 }else if(opt.buttons.yes){
3318 handleButton("yes");
3322 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3323 textareaEl.enableDisplayMode();
3324 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3325 progressEl.enableDisplayMode();
3327 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
3328 var pf = progressEl.dom.firstChild;
3330 pp = Roo.get(pf.firstChild);
3331 pp.setHeight(pf.offsetHeight);
3339 * Updates the message box body text
3340 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3341 * the XHTML-compliant non-breaking space character '&#160;')
3342 * @return {Roo.MessageBox} This message box
3344 updateText : function(text)
3346 if(!dlg.isVisible() && !opt.width){
3347 dlg.dialogEl.setStyle({ 'max-width' : this.maxWidth});
3348 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
3350 msgEl.innerHTML = text || ' ';
3352 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3353 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3355 Math.min(opt.width || cw , this.maxWidth),
3356 Math.max(opt.minWidth || this.minWidth, bwidth)
3359 activeTextEl.setWidth(w);
3361 if(dlg.isVisible()){
3362 dlg.fixedcenter = false;
3364 // to big, make it scroll. = But as usual stupid IE does not support
3367 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3368 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3369 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3371 bodyEl.dom.style.height = '';
3372 bodyEl.dom.style.overflowY = '';
3375 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3377 bodyEl.dom.style.overflowX = '';
3380 dlg.setContentSize(w, bodyEl.getHeight());
3381 if(dlg.isVisible()){
3382 dlg.fixedcenter = true;
3388 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
3389 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3390 * @param {Number} value Any number between 0 and 1 (e.g., .5)
3391 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3392 * @return {Roo.MessageBox} This message box
3394 updateProgress : function(value, text){
3396 this.updateText(text);
3399 if (pp) { // weird bug on my firefox - for some reason this is not defined
3400 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3401 pp.setHeight(Math.floor(progressEl.dom.firstChild.offsetHeight));
3407 * Returns true if the message box is currently displayed
3408 * @return {Boolean} True if the message box is visible, else false
3410 isVisible : function(){
3411 return dlg && dlg.isVisible();
3415 * Hides the message box if it is displayed
3418 if(this.isVisible()){
3424 * Displays a new message box, or reinitializes an existing message box, based on the config options
3425 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3426 * The following config object properties are supported:
3428 Property Type Description
3429 ---------- --------------- ------------------------------------------------------------------------------------
3430 animEl String/Element An id or Element from which the message box should animate as it opens and
3431 closes (defaults to undefined)
3432 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3433 cancel:'Bar'}), or false to not show any buttons (defaults to false)
3434 closable Boolean False to hide the top-right close button (defaults to true). Note that
3435 progress and wait dialogs will ignore this property and always hide the
3436 close button as they can only be closed programmatically.
3437 cls String A custom CSS class to apply to the message box element
3438 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
3439 displayed (defaults to 75)
3440 fn Function A callback function to execute after closing the dialog. The arguments to the
3441 function will be btn (the name of the button that was clicked, if applicable,
3442 e.g. "ok"), and text (the value of the active text field, if applicable).
3443 Progress and wait dialogs will ignore this option since they do not respond to
3444 user actions and can only be closed programmatically, so any required function
3445 should be called by the same code after it closes the dialog.
3446 icon String A CSS class that provides a background image to be used as an icon for
3447 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3448 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
3449 minWidth Number The minimum width in pixels of the message box (defaults to 100)
3450 modal Boolean False to allow user interaction with the page while the message box is
3451 displayed (defaults to true)
3452 msg String A string that will replace the existing message box body text (defaults
3453 to the XHTML-compliant non-breaking space character ' ')
3454 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
3455 progress Boolean True to display a progress bar (defaults to false)
3456 progressText String The text to display inside the progress bar if progress = true (defaults to '')
3457 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
3458 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
3459 title String The title text
3460 value String The string value to set into the active textbox element if displayed
3461 wait Boolean True to display a progress bar (defaults to false)
3462 width Number The width of the dialog in pixels
3469 msg: 'Please enter your address:',
3471 buttons: Roo.MessageBox.OKCANCEL,
3474 animEl: 'addAddressBtn'
3477 * @param {Object} config Configuration options
3478 * @return {Roo.MessageBox} This message box
3480 show : function(options)
3483 // this causes nightmares if you show one dialog after another
3484 // especially on callbacks..
3486 if(this.isVisible()){
3489 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3490 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
3491 Roo.log("New Dialog Message:" + options.msg )
3492 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3493 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3496 var d = this.getDialog();
3498 d.setTitle(opt.title || " ");
3499 d.closeEl.setDisplayed(opt.closable !== false);
3500 activeTextEl = textboxEl;
3501 opt.prompt = opt.prompt || (opt.multiline ? true : false);
3506 textareaEl.setHeight(typeof opt.multiline == "number" ?
3507 opt.multiline : this.defaultTextHeight);
3508 activeTextEl = textareaEl;
3517 progressEl.setDisplayed(opt.progress === true);
3518 this.updateProgress(0);
3519 activeTextEl.dom.value = opt.value || "";
3521 dlg.setDefaultButton(activeTextEl);
3523 var bs = opt.buttons;
3527 }else if(bs && bs.yes){
3528 db = buttons["yes"];
3530 dlg.setDefaultButton(db);
3532 bwidth = updateButtons(opt.buttons);
3533 this.updateText(opt.msg);
3535 d.el.addClass(opt.cls);
3537 d.proxyDrag = opt.proxyDrag === true;
3538 d.modal = opt.modal !== false;
3539 d.mask = opt.modal !== false ? mask : false;
3541 // force it to the end of the z-index stack so it gets a cursor in FF
3542 document.body.appendChild(dlg.el.dom);
3543 d.animateTarget = null;
3544 d.show(options.animEl);
3550 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
3551 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3552 * and closing the message box when the process is complete.
3553 * @param {String} title The title bar text
3554 * @param {String} msg The message box body text
3555 * @return {Roo.MessageBox} This message box
3557 progress : function(title, msg){
3564 minWidth: this.minProgressWidth,
3571 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3572 * If a callback function is passed it will be called after the user clicks the button, and the
3573 * id of the button that was clicked will be passed as the only parameter to the callback
3574 * (could also be the top-right close button).
3575 * @param {String} title The title bar text
3576 * @param {String} msg The message box body text
3577 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3578 * @param {Object} scope (optional) The scope of the callback function
3579 * @return {Roo.MessageBox} This message box
3581 alert : function(title, msg, fn, scope)
3596 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
3597 * interaction while waiting for a long-running process to complete that does not have defined intervals.
3598 * You are responsible for closing the message box when the process is complete.
3599 * @param {String} msg The message box body text
3600 * @param {String} title (optional) The title bar text
3601 * @return {Roo.MessageBox} This message box
3603 wait : function(msg, title){
3614 waitTimer = Roo.TaskMgr.start({
3616 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3624 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3625 * If a callback function is passed it will be called after the user clicks either button, and the id of the
3626 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3627 * @param {String} title The title bar text
3628 * @param {String} msg The message box body text
3629 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3630 * @param {Object} scope (optional) The scope of the callback function
3631 * @return {Roo.MessageBox} This message box
3633 confirm : function(title, msg, fn, scope){
3637 buttons: this.YESNO,
3646 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3647 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
3648 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3649 * (could also be the top-right close button) and the text that was entered will be passed as the two
3650 * parameters to the callback.
3651 * @param {String} title The title bar text
3652 * @param {String} msg The message box body text
3653 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3654 * @param {Object} scope (optional) The scope of the callback function
3655 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3656 * property, or the height in pixels to create the textbox (defaults to false / single-line)
3657 * @return {Roo.MessageBox} This message box
3659 prompt : function(title, msg, fn, scope, multiline){
3663 buttons: this.OKCANCEL,
3668 multiline: multiline,
3675 * Button config that displays a single OK button
3680 * Button config that displays Yes and No buttons
3683 YESNO : {yes:true, no:true},
3685 * Button config that displays OK and Cancel buttons
3688 OKCANCEL : {ok:true, cancel:true},
3690 * Button config that displays Yes, No and Cancel buttons
3693 YESNOCANCEL : {yes:true, no:true, cancel:true},
3696 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3699 defaultTextHeight : 75,
3701 * The maximum width in pixels of the message box (defaults to 600)
3706 * The minimum width in pixels of the message box (defaults to 100)
3711 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
3712 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3715 minProgressWidth : 250,
3717 * An object containing the default button text strings that can be overriden for localized language support.
3718 * Supported properties are: ok, cancel, yes and no.
3719 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3732 * Shorthand for {@link Roo.MessageBox}
3734 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3735 Roo.Msg = Roo.Msg || Roo.MessageBox;
3744 * @class Roo.bootstrap.Navbar
3745 * @extends Roo.bootstrap.Component
3746 * Bootstrap Navbar class
3749 * Create a new Navbar
3750 * @param {Object} config The config object
3754 Roo.bootstrap.Navbar = function(config){
3755 Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3759 * @event beforetoggle
3760 * Fire before toggle the menu
3761 * @param {Roo.EventObject} e
3763 "beforetoggle" : true
3767 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component, {
3776 getAutoCreate : function(){
3779 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3783 initEvents :function ()
3785 //Roo.log(this.el.select('.navbar-toggle',true));
3786 this.el.select('.navbar-toggle',true).on('click', function() {
3787 if(this.fireEvent('beforetoggle', this) !== false){
3788 this.el.select('.navbar-collapse',true).toggleClass('in');
3798 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3800 var size = this.el.getSize();
3801 this.maskEl.setSize(size.width, size.height);
3802 this.maskEl.enableDisplayMode("block");
3811 getChildContainer : function()
3813 if (this.el.select('.collapse').getCount()) {
3814 return this.el.select('.collapse',true).first();
3847 * @class Roo.bootstrap.NavSimplebar
3848 * @extends Roo.bootstrap.Navbar
3849 * Bootstrap Sidebar class
3851 * @cfg {Boolean} inverse is inverted color
3853 * @cfg {String} type (nav | pills | tabs)
3854 * @cfg {Boolean} arrangement stacked | justified
3855 * @cfg {String} align (left | right) alignment
3857 * @cfg {Boolean} main (true|false) main nav bar? default false
3858 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3860 * @cfg {String} tag (header|footer|nav|div) default is nav
3866 * Create a new Sidebar
3867 * @param {Object} config The config object
3871 Roo.bootstrap.NavSimplebar = function(config){
3872 Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
3875 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar, {
3891 getAutoCreate : function(){
3895 tag : this.tag || 'div',
3908 this.type = this.type || 'nav';
3909 if (['tabs','pills'].indexOf(this.type)!==-1) {
3910 cfg.cn[0].cls += ' nav-' + this.type
3914 if (this.type!=='nav') {
3915 Roo.log('nav type must be nav/tabs/pills')
3917 cfg.cn[0].cls += ' navbar-nav'
3923 if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
3924 cfg.cn[0].cls += ' nav-' + this.arrangement;
3928 if (this.align === 'right') {
3929 cfg.cn[0].cls += ' navbar-right';
3933 cfg.cls += ' navbar-inverse';
3957 * navbar-expand-md fixed-top
3961 * @class Roo.bootstrap.NavHeaderbar
3962 * @extends Roo.bootstrap.NavSimplebar
3963 * Bootstrap Sidebar class
3965 * @cfg {String} brand what is brand
3966 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
3967 * @cfg {String} brand_href href of the brand
3968 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
3969 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
3970 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
3971 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
3974 * Create a new Sidebar
3975 * @param {Object} config The config object
3979 Roo.bootstrap.NavHeaderbar = function(config){
3980 Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
3984 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar, {
3991 desktopCenter : false,
3994 getAutoCreate : function(){
3997 tag: this.nav || 'nav',
3998 cls: 'navbar navbar-expand-md',
4004 if (this.desktopCenter) {
4005 cn.push({cls : 'container', cn : []});
4012 cls: 'navbar-header',
4017 cls: 'navbar-toggle navbar-toggler',
4018 'data-toggle': 'collapse',
4023 html: 'Toggle navigation'
4027 cls: 'icon-bar navbar-toggler-icon'
4045 cls: 'collapse navbar-collapse',
4049 cfg.cls += this.inverse ? ' navbar-inverse navbar-dark bg-dark' : ' navbar-default';
4051 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
4052 cfg.cls += ' navbar-' + this.position + ' ' + this.position ;
4054 // tag can override this..
4056 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
4059 if (this.brand !== '') {
4062 href: this.brand_href ? this.brand_href : '#',
4063 cls: 'navbar-brand',
4071 cfg.cls += ' main-nav';
4079 getHeaderChildContainer : function()
4081 if (this.srButton && this.el.select('.navbar-header').getCount()) {
4082 return this.el.select('.navbar-header',true).first();
4085 return this.getChildContainer();
4089 initEvents : function()
4091 Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
4093 if (this.autohide) {
4098 Roo.get(document).on('scroll',function(e) {
4099 var ns = Roo.get(document).getScroll().top;
4100 var os = prevScroll;
4104 ft.removeClass('slideDown');
4105 ft.addClass('slideUp');
4108 ft.removeClass('slideUp');
4109 ft.addClass('slideDown');
4130 * @class Roo.bootstrap.NavSidebar
4131 * @extends Roo.bootstrap.Navbar
4132 * Bootstrap Sidebar class
4135 * Create a new Sidebar
4136 * @param {Object} config The config object
4140 Roo.bootstrap.NavSidebar = function(config){
4141 Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
4144 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar, {
4146 sidebar : true, // used by Navbar Item and NavbarGroup at present...
4148 getAutoCreate : function(){
4153 cls: 'sidebar sidebar-nav'
4175 * @class Roo.bootstrap.NavGroup
4176 * @extends Roo.bootstrap.Component
4177 * Bootstrap NavGroup class
4178 * @cfg {String} align (left|right)
4179 * @cfg {Boolean} inverse
4180 * @cfg {String} type (nav|pills|tab) default nav
4181 * @cfg {String} navId - reference Id for navbar.
4185 * Create a new nav group
4186 * @param {Object} config The config object
4189 Roo.bootstrap.NavGroup = function(config){
4190 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
4193 Roo.bootstrap.NavGroup.register(this);
4197 * Fires when the active item changes
4198 * @param {Roo.bootstrap.NavGroup} this
4199 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
4200 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
4207 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
4218 getAutoCreate : function()
4220 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
4227 if (['tabs','pills'].indexOf(this.type)!==-1) {
4228 cfg.cls += ' nav-' + this.type
4230 if (this.type!=='nav') {
4231 Roo.log('nav type must be nav/tabs/pills')
4233 cfg.cls += ' navbar-nav mr-auto'
4236 if (this.parent() && this.parent().sidebar) {
4239 cls: 'dashboard-menu sidebar-menu'
4245 if (this.form === true) {
4251 if (this.align === 'right') {
4252 cfg.cls += ' navbar-right';
4254 cfg.cls += ' navbar-left';
4258 if (this.align === 'right') {
4259 cfg.cls += ' navbar-right';
4263 cfg.cls += ' navbar-inverse';
4271 * sets the active Navigation item
4272 * @param {Roo.bootstrap.NavItem} the new current navitem
4274 setActiveItem : function(item)
4277 Roo.each(this.navItems, function(v){
4282 v.setActive(false, true);
4289 item.setActive(true, true);
4290 this.fireEvent('changed', this, item, prev);
4295 * gets the active Navigation item
4296 * @return {Roo.bootstrap.NavItem} the current navitem
4298 getActive : function()
4302 Roo.each(this.navItems, function(v){
4313 indexOfNav : function()
4317 Roo.each(this.navItems, function(v,i){
4328 * adds a Navigation item
4329 * @param {Roo.bootstrap.NavItem} the navitem to add
4331 addItem : function(cfg)
4333 var cn = new Roo.bootstrap.NavItem(cfg);
4335 cn.parentId = this.id;
4336 cn.onRender(this.el, null);
4340 * register a Navigation item
4341 * @param {Roo.bootstrap.NavItem} the navitem to add
4343 register : function(item)
4345 this.navItems.push( item);
4346 item.navId = this.navId;
4351 * clear all the Navigation item
4354 clearAll : function()
4357 this.el.dom.innerHTML = '';
4360 getNavItem: function(tabId)
4363 Roo.each(this.navItems, function(e) {
4364 if (e.tabId == tabId) {
4374 setActiveNext : function()
4376 var i = this.indexOfNav(this.getActive());
4377 if (i > this.navItems.length) {
4380 this.setActiveItem(this.navItems[i+1]);
4382 setActivePrev : function()
4384 var i = this.indexOfNav(this.getActive());
4388 this.setActiveItem(this.navItems[i-1]);
4390 clearWasActive : function(except) {
4391 Roo.each(this.navItems, function(e) {
4392 if (e.tabId != except.tabId && e.was_active) {
4393 e.was_active = false;
4400 getWasActive : function ()
4403 Roo.each(this.navItems, function(e) {
4418 Roo.apply(Roo.bootstrap.NavGroup, {
4422 * register a Navigation Group
4423 * @param {Roo.bootstrap.NavGroup} the navgroup to add
4425 register : function(navgrp)
4427 this.groups[navgrp.navId] = navgrp;
4431 * fetch a Navigation Group based on the navigation ID
4432 * @param {string} the navgroup to add
4433 * @returns {Roo.bootstrap.NavGroup} the navgroup
4435 get: function(navId) {
4436 if (typeof(this.groups[navId]) == 'undefined') {
4438 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4440 return this.groups[navId] ;
4455 * @class Roo.bootstrap.NavItem
4456 * @extends Roo.bootstrap.Component
4457 * Bootstrap Navbar.NavItem class
4458 * @cfg {String} href link to
4459 * @cfg {String} html content of button
4460 * @cfg {String} badge text inside badge
4461 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4462 * @cfg {String} glyphicon name of glyphicon
4463 * @cfg {String} icon name of font awesome icon
4464 * @cfg {Boolean} active Is item active
4465 * @cfg {Boolean} disabled Is item disabled
4467 * @cfg {Boolean} preventDefault (true | false) default false
4468 * @cfg {String} tabId the tab that this item activates.
4469 * @cfg {String} tagtype (a|span) render as a href or span?
4470 * @cfg {Boolean} animateRef (true|false) link to element default false
4473 * Create a new Navbar Item
4474 * @param {Object} config The config object
4476 Roo.bootstrap.NavItem = function(config){
4477 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4482 * The raw click event for the entire grid.
4483 * @param {Roo.EventObject} e
4488 * Fires when the active item active state changes
4489 * @param {Roo.bootstrap.NavItem} this
4490 * @param {boolean} state the new state
4496 * Fires when scroll to element
4497 * @param {Roo.bootstrap.NavItem} this
4498 * @param {Object} options
4499 * @param {Roo.EventObject} e
4507 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
4515 preventDefault : false,
4522 getAutoCreate : function(){
4531 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4533 if (this.disabled) {
4534 cfg.cls += ' disabled';
4537 if (this.href || this.html || this.glyphicon || this.icon) {
4541 href : this.href || "#",
4542 html: this.html || ''
4545 if (this.tagtype == 'a') {
4546 cfg.cn[0].cls = 'nav-link';
4549 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4552 if(this.glyphicon) {
4553 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
4558 cfg.cn[0].html += " <span class='caret'></span>";
4562 if (this.badge !== '') {
4564 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
4572 initEvents: function()
4574 if (typeof (this.menu) != 'undefined') {
4575 this.menu.parentType = this.xtype;
4576 this.menu.triggerEl = this.el;
4577 this.menu = this.addxtype(Roo.apply({}, this.menu));
4580 this.el.select('a',true).on('click', this.onClick, this);
4582 if(this.tagtype == 'span'){
4583 this.el.select('span',true).on('click', this.onClick, this);
4586 // at this point parent should be available..
4587 this.parent().register(this);
4590 onClick : function(e)
4592 if (e.getTarget('.dropdown-menu-item')) {
4593 // did you click on a menu itemm.... - then don't trigger onclick..
4598 this.preventDefault ||
4601 Roo.log("NavItem - prevent Default?");
4605 if (this.disabled) {
4609 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4610 if (tg && tg.transition) {
4611 Roo.log("waiting for the transitionend");
4617 //Roo.log("fire event clicked");
4618 if(this.fireEvent('click', this, e) === false){
4622 if(this.tagtype == 'span'){
4626 //Roo.log(this.href);
4627 var ael = this.el.select('a',true).first();
4630 if(ael && this.animateRef && this.href.indexOf('#') > -1){
4631 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4632 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4633 return; // ignore... - it's a 'hash' to another page.
4635 Roo.log("NavItem - prevent Default?");
4637 this.scrollToElement(e);
4641 var p = this.parent();
4643 if (['tabs','pills'].indexOf(p.type)!==-1) {
4644 if (typeof(p.setActiveItem) !== 'undefined') {
4645 p.setActiveItem(this);
4649 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4650 if (p.parentType == 'NavHeaderbar' && !this.menu) {
4651 // remove the collapsed menu expand...
4652 p.parent().el.select('.navbar-collapse',true).removeClass('in');
4656 isActive: function () {
4659 setActive : function(state, fire, is_was_active)
4661 if (this.active && !state && this.navId) {
4662 this.was_active = true;
4663 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4665 nv.clearWasActive(this);
4669 this.active = state;
4672 this.el.removeClass('active');
4673 } else if (!this.el.hasClass('active')) {
4674 this.el.addClass('active');
4677 this.fireEvent('changed', this, state);
4680 // show a panel if it's registered and related..
4682 if (!this.navId || !this.tabId || !state || is_was_active) {
4686 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4690 var pan = tg.getPanelByName(this.tabId);
4694 // if we can not flip to new panel - go back to old nav highlight..
4695 if (false == tg.showPanel(pan)) {
4696 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4698 var onav = nv.getWasActive();
4700 onav.setActive(true, false, true);
4709 // this should not be here...
4710 setDisabled : function(state)
4712 this.disabled = state;
4714 this.el.removeClass('disabled');
4715 } else if (!this.el.hasClass('disabled')) {
4716 this.el.addClass('disabled');
4722 * Fetch the element to display the tooltip on.
4723 * @return {Roo.Element} defaults to this.el
4725 tooltipEl : function()
4727 return this.el.select('' + this.tagtype + '', true).first();
4730 scrollToElement : function(e)
4732 var c = document.body;
4735 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4737 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4738 c = document.documentElement;
4741 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4747 var o = target.calcOffsetsTo(c);
4754 this.fireEvent('scrollto', this, options, e);
4756 Roo.get(c).scrollTo('top', options.value, true);
4769 * <span> icon </span>
4770 * <span> text </span>
4771 * <span>badge </span>
4775 * @class Roo.bootstrap.NavSidebarItem
4776 * @extends Roo.bootstrap.NavItem
4777 * Bootstrap Navbar.NavSidebarItem class
4778 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4779 * {Boolean} open is the menu open
4780 * {Boolean} buttonView use button as the tigger el rather that a (default false)
4781 * {String} buttonWeight (default|primary|success|info|warning|danger)the extra classes for the button
4782 * {String} buttonSize (sm|md|lg)the extra classes for the button
4783 * {Boolean} showArrow show arrow next to the text (default true)
4785 * Create a new Navbar Button
4786 * @param {Object} config The config object
4788 Roo.bootstrap.NavSidebarItem = function(config){
4789 Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4794 * The raw click event for the entire grid.
4795 * @param {Roo.EventObject} e
4800 * Fires when the active item active state changes
4801 * @param {Roo.bootstrap.NavSidebarItem} this
4802 * @param {boolean} state the new state
4810 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem, {
4812 badgeWeight : 'default',
4818 buttonWeight : 'default',
4824 getAutoCreate : function(){
4829 href : this.href || '#',
4835 if(this.buttonView){
4838 href : this.href || '#',
4839 cls: 'btn btn-' + this.buttonWeight + ' btn-' + this.buttonSize + 'roo-button-dropdown-toggle',
4852 cfg.cls += ' active';
4855 if (this.disabled) {
4856 cfg.cls += ' disabled';
4859 cfg.cls += ' open x-open';
4862 if (this.glyphicon || this.icon) {
4863 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
4864 a.cn.push({ tag : 'i', cls : c }) ;
4867 if(!this.buttonView){
4870 html : this.html || ''
4877 if (this.badge !== '') {
4878 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
4884 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
4887 a.cls += ' dropdown-toggle treeview' ;
4893 initEvents : function()
4895 if (typeof (this.menu) != 'undefined') {
4896 this.menu.parentType = this.xtype;
4897 this.menu.triggerEl = this.el;
4898 this.menu = this.addxtype(Roo.apply({}, this.menu));
4901 this.el.on('click', this.onClick, this);
4903 if(this.badge !== ''){
4904 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
4909 onClick : function(e)
4916 if(this.preventDefault){
4920 this.fireEvent('click', this);
4923 disable : function()
4925 this.setDisabled(true);
4930 this.setDisabled(false);
4933 setDisabled : function(state)
4935 if(this.disabled == state){
4939 this.disabled = state;
4942 this.el.addClass('disabled');
4946 this.el.removeClass('disabled');
4951 setActive : function(state)
4953 if(this.active == state){
4957 this.active = state;
4960 this.el.addClass('active');
4964 this.el.removeClass('active');
4969 isActive: function ()
4974 setBadge : function(str)
4980 this.badgeEl.dom.innerHTML = str;
4997 * @class Roo.bootstrap.Row
4998 * @extends Roo.bootstrap.Component
4999 * Bootstrap Row class (contains columns...)
5003 * @param {Object} config The config object
5006 Roo.bootstrap.Row = function(config){
5007 Roo.bootstrap.Row.superclass.constructor.call(this, config);
5010 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
5012 getAutoCreate : function(){
5031 * @class Roo.bootstrap.Element
5032 * @extends Roo.bootstrap.Component
5033 * Bootstrap Element class
5034 * @cfg {String} html contents of the element
5035 * @cfg {String} tag tag of the element
5036 * @cfg {String} cls class of the element
5037 * @cfg {Boolean} preventDefault (true|false) default false
5038 * @cfg {Boolean} clickable (true|false) default false
5041 * Create a new Element
5042 * @param {Object} config The config object
5045 Roo.bootstrap.Element = function(config){
5046 Roo.bootstrap.Element.superclass.constructor.call(this, config);
5052 * When a element is chick
5053 * @param {Roo.bootstrap.Element} this
5054 * @param {Roo.EventObject} e
5060 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
5065 preventDefault: false,
5068 getAutoCreate : function(){
5072 // cls: this.cls, double assign in parent class Component.js :: onRender
5079 initEvents: function()
5081 Roo.bootstrap.Element.superclass.initEvents.call(this);
5084 this.el.on('click', this.onClick, this);
5089 onClick : function(e)
5091 if(this.preventDefault){
5095 this.fireEvent('click', this, e);
5098 getValue : function()
5100 return this.el.dom.innerHTML;
5103 setValue : function(value)
5105 this.el.dom.innerHTML = value;
5120 * @class Roo.bootstrap.Pagination
5121 * @extends Roo.bootstrap.Component
5122 * Bootstrap Pagination class
5123 * @cfg {String} size xs | sm | md | lg
5124 * @cfg {Boolean} inverse false | true
5127 * Create a new Pagination
5128 * @param {Object} config The config object
5131 Roo.bootstrap.Pagination = function(config){
5132 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
5135 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
5141 getAutoCreate : function(){
5147 cfg.cls += ' inverse';
5153 cfg.cls += " " + this.cls;
5171 * @class Roo.bootstrap.PaginationItem
5172 * @extends Roo.bootstrap.Component
5173 * Bootstrap PaginationItem class
5174 * @cfg {String} html text
5175 * @cfg {String} href the link
5176 * @cfg {Boolean} preventDefault (true | false) default true
5177 * @cfg {Boolean} active (true | false) default false
5178 * @cfg {Boolean} disabled default false
5182 * Create a new PaginationItem
5183 * @param {Object} config The config object
5187 Roo.bootstrap.PaginationItem = function(config){
5188 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
5193 * The raw click event for the entire grid.
5194 * @param {Roo.EventObject} e
5200 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
5204 preventDefault: true,
5209 getAutoCreate : function(){
5215 href : this.href ? this.href : '#',
5216 html : this.html ? this.html : ''
5226 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
5230 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
5236 initEvents: function() {
5238 this.el.on('click', this.onClick, this);
5241 onClick : function(e)
5243 Roo.log('PaginationItem on click ');
5244 if(this.preventDefault){
5252 this.fireEvent('click', this, e);
5268 * @class Roo.bootstrap.Slider
5269 * @extends Roo.bootstrap.Component
5270 * Bootstrap Slider class
5273 * Create a new Slider
5274 * @param {Object} config The config object
5277 Roo.bootstrap.Slider = function(config){
5278 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
5281 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
5283 getAutoCreate : function(){
5287 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
5291 cls: 'ui-slider-handle ui-state-default ui-corner-all'
5303 * Ext JS Library 1.1.1
5304 * Copyright(c) 2006-2007, Ext JS, LLC.
5306 * Originally Released Under LGPL - original licence link has changed is not relivant.
5309 * <script type="text/javascript">
5314 * @class Roo.grid.ColumnModel
5315 * @extends Roo.util.Observable
5316 * This is the default implementation of a ColumnModel used by the Grid. It defines
5317 * the columns in the grid.
5320 var colModel = new Roo.grid.ColumnModel([
5321 {header: "Ticker", width: 60, sortable: true, locked: true},
5322 {header: "Company Name", width: 150, sortable: true},
5323 {header: "Market Cap.", width: 100, sortable: true},
5324 {header: "$ Sales", width: 100, sortable: true, renderer: money},
5325 {header: "Employees", width: 100, sortable: true, resizable: false}
5330 * The config options listed for this class are options which may appear in each
5331 * individual column definition.
5332 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5334 * @param {Object} config An Array of column config objects. See this class's
5335 * config objects for details.
5337 Roo.grid.ColumnModel = function(config){
5339 * The config passed into the constructor
5341 this.config = config;
5344 // if no id, create one
5345 // if the column does not have a dataIndex mapping,
5346 // map it to the order it is in the config
5347 for(var i = 0, len = config.length; i < len; i++){
5349 if(typeof c.dataIndex == "undefined"){
5352 if(typeof c.renderer == "string"){
5353 c.renderer = Roo.util.Format[c.renderer];
5355 if(typeof c.id == "undefined"){
5358 if(c.editor && c.editor.xtype){
5359 c.editor = Roo.factory(c.editor, Roo.grid);
5361 if(c.editor && c.editor.isFormField){
5362 c.editor = new Roo.grid.GridEditor(c.editor);
5364 this.lookup[c.id] = c;
5368 * The width of columns which have no width specified (defaults to 100)
5371 this.defaultWidth = 100;
5374 * Default sortable of columns which have no sortable specified (defaults to false)
5377 this.defaultSortable = false;
5381 * @event widthchange
5382 * Fires when the width of a column changes.
5383 * @param {ColumnModel} this
5384 * @param {Number} columnIndex The column index
5385 * @param {Number} newWidth The new width
5387 "widthchange": true,
5389 * @event headerchange
5390 * Fires when the text of a header changes.
5391 * @param {ColumnModel} this
5392 * @param {Number} columnIndex The column index
5393 * @param {Number} newText The new header text
5395 "headerchange": true,
5397 * @event hiddenchange
5398 * Fires when a column is hidden or "unhidden".
5399 * @param {ColumnModel} this
5400 * @param {Number} columnIndex The column index
5401 * @param {Boolean} hidden true if hidden, false otherwise
5403 "hiddenchange": true,
5405 * @event columnmoved
5406 * Fires when a column is moved.
5407 * @param {ColumnModel} this
5408 * @param {Number} oldIndex
5409 * @param {Number} newIndex
5411 "columnmoved" : true,
5413 * @event columlockchange
5414 * Fires when a column's locked state is changed
5415 * @param {ColumnModel} this
5416 * @param {Number} colIndex
5417 * @param {Boolean} locked true if locked
5419 "columnlockchange" : true
5421 Roo.grid.ColumnModel.superclass.constructor.call(this);
5423 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5425 * @cfg {String} header The header text to display in the Grid view.
5428 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5429 * {@link Roo.data.Record} definition from which to draw the column's value. If not
5430 * specified, the column's index is used as an index into the Record's data Array.
5433 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5434 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5437 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5438 * Defaults to the value of the {@link #defaultSortable} property.
5439 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5442 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
5445 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
5448 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5451 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5454 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5455 * given the cell's data value. See {@link #setRenderer}. If not specified, the
5456 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
5457 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5460 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
5463 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
5466 * @cfg {String} valign (Optional) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc). Defaults to undefined.
5469 * @cfg {String} cursor (Optional)
5472 * @cfg {String} tooltip (Optional)
5475 * @cfg {Number} xs (Optional)
5478 * @cfg {Number} sm (Optional)
5481 * @cfg {Number} md (Optional)
5484 * @cfg {Number} lg (Optional)
5487 * Returns the id of the column at the specified index.
5488 * @param {Number} index The column index
5489 * @return {String} the id
5491 getColumnId : function(index){
5492 return this.config[index].id;
5496 * Returns the column for a specified id.
5497 * @param {String} id The column id
5498 * @return {Object} the column
5500 getColumnById : function(id){
5501 return this.lookup[id];
5506 * Returns the column for a specified dataIndex.
5507 * @param {String} dataIndex The column dataIndex
5508 * @return {Object|Boolean} the column or false if not found
5510 getColumnByDataIndex: function(dataIndex){
5511 var index = this.findColumnIndex(dataIndex);
5512 return index > -1 ? this.config[index] : false;
5516 * Returns the index for a specified column id.
5517 * @param {String} id The column id
5518 * @return {Number} the index, or -1 if not found
5520 getIndexById : function(id){
5521 for(var i = 0, len = this.config.length; i < len; i++){
5522 if(this.config[i].id == id){
5530 * Returns the index for a specified column dataIndex.
5531 * @param {String} dataIndex The column dataIndex
5532 * @return {Number} the index, or -1 if not found
5535 findColumnIndex : function(dataIndex){
5536 for(var i = 0, len = this.config.length; i < len; i++){
5537 if(this.config[i].dataIndex == dataIndex){
5545 moveColumn : function(oldIndex, newIndex){
5546 var c = this.config[oldIndex];
5547 this.config.splice(oldIndex, 1);
5548 this.config.splice(newIndex, 0, c);
5549 this.dataMap = null;
5550 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5553 isLocked : function(colIndex){
5554 return this.config[colIndex].locked === true;
5557 setLocked : function(colIndex, value, suppressEvent){
5558 if(this.isLocked(colIndex) == value){
5561 this.config[colIndex].locked = value;
5563 this.fireEvent("columnlockchange", this, colIndex, value);
5567 getTotalLockedWidth : function(){
5569 for(var i = 0; i < this.config.length; i++){
5570 if(this.isLocked(i) && !this.isHidden(i)){
5571 this.totalWidth += this.getColumnWidth(i);
5577 getLockedCount : function(){
5578 for(var i = 0, len = this.config.length; i < len; i++){
5579 if(!this.isLocked(i)){
5584 return this.config.length;
5588 * Returns the number of columns.
5591 getColumnCount : function(visibleOnly){
5592 if(visibleOnly === true){
5594 for(var i = 0, len = this.config.length; i < len; i++){
5595 if(!this.isHidden(i)){
5601 return this.config.length;
5605 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5606 * @param {Function} fn
5607 * @param {Object} scope (optional)
5608 * @return {Array} result
5610 getColumnsBy : function(fn, scope){
5612 for(var i = 0, len = this.config.length; i < len; i++){
5613 var c = this.config[i];
5614 if(fn.call(scope||this, c, i) === true){
5622 * Returns true if the specified column is sortable.
5623 * @param {Number} col The column index
5626 isSortable : function(col){
5627 if(typeof this.config[col].sortable == "undefined"){
5628 return this.defaultSortable;
5630 return this.config[col].sortable;
5634 * Returns the rendering (formatting) function defined for the column.
5635 * @param {Number} col The column index.
5636 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5638 getRenderer : function(col){
5639 if(!this.config[col].renderer){
5640 return Roo.grid.ColumnModel.defaultRenderer;
5642 return this.config[col].renderer;
5646 * Sets the rendering (formatting) function for a column.
5647 * @param {Number} col The column index
5648 * @param {Function} fn The function to use to process the cell's raw data
5649 * to return HTML markup for the grid view. The render function is called with
5650 * the following parameters:<ul>
5651 * <li>Data value.</li>
5652 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5653 * <li>css A CSS style string to apply to the table cell.</li>
5654 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5655 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5656 * <li>Row index</li>
5657 * <li>Column index</li>
5658 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5660 setRenderer : function(col, fn){
5661 this.config[col].renderer = fn;
5665 * Returns the width for the specified column.
5666 * @param {Number} col The column index
5669 getColumnWidth : function(col){
5670 return this.config[col].width * 1 || this.defaultWidth;
5674 * Sets the width for a column.
5675 * @param {Number} col The column index
5676 * @param {Number} width The new width
5678 setColumnWidth : function(col, width, suppressEvent){
5679 this.config[col].width = width;
5680 this.totalWidth = null;
5682 this.fireEvent("widthchange", this, col, width);
5687 * Returns the total width of all columns.
5688 * @param {Boolean} includeHidden True to include hidden column widths
5691 getTotalWidth : function(includeHidden){
5692 if(!this.totalWidth){
5693 this.totalWidth = 0;
5694 for(var i = 0, len = this.config.length; i < len; i++){
5695 if(includeHidden || !this.isHidden(i)){
5696 this.totalWidth += this.getColumnWidth(i);
5700 return this.totalWidth;
5704 * Returns the header for the specified column.
5705 * @param {Number} col The column index
5708 getColumnHeader : function(col){
5709 return this.config[col].header;
5713 * Sets the header for a column.
5714 * @param {Number} col The column index
5715 * @param {String} header The new header
5717 setColumnHeader : function(col, header){
5718 this.config[col].header = header;
5719 this.fireEvent("headerchange", this, col, header);
5723 * Returns the tooltip for the specified column.
5724 * @param {Number} col The column index
5727 getColumnTooltip : function(col){
5728 return this.config[col].tooltip;
5731 * Sets the tooltip for a column.
5732 * @param {Number} col The column index
5733 * @param {String} tooltip The new tooltip
5735 setColumnTooltip : function(col, tooltip){
5736 this.config[col].tooltip = tooltip;
5740 * Returns the dataIndex for the specified column.
5741 * @param {Number} col The column index
5744 getDataIndex : function(col){
5745 return this.config[col].dataIndex;
5749 * Sets the dataIndex for a column.
5750 * @param {Number} col The column index
5751 * @param {Number} dataIndex The new dataIndex
5753 setDataIndex : function(col, dataIndex){
5754 this.config[col].dataIndex = dataIndex;
5760 * Returns true if the cell is editable.
5761 * @param {Number} colIndex The column index
5762 * @param {Number} rowIndex The row index - this is nto actually used..?
5765 isCellEditable : function(colIndex, rowIndex){
5766 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5770 * Returns the editor defined for the cell/column.
5771 * return false or null to disable editing.
5772 * @param {Number} colIndex The column index
5773 * @param {Number} rowIndex The row index
5776 getCellEditor : function(colIndex, rowIndex){
5777 return this.config[colIndex].editor;
5781 * Sets if a column is editable.
5782 * @param {Number} col The column index
5783 * @param {Boolean} editable True if the column is editable
5785 setEditable : function(col, editable){
5786 this.config[col].editable = editable;
5791 * Returns true if the column is hidden.
5792 * @param {Number} colIndex The column index
5795 isHidden : function(colIndex){
5796 return this.config[colIndex].hidden;
5801 * Returns true if the column width cannot be changed
5803 isFixed : function(colIndex){
5804 return this.config[colIndex].fixed;
5808 * Returns true if the column can be resized
5811 isResizable : function(colIndex){
5812 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5815 * Sets if a column is hidden.
5816 * @param {Number} colIndex The column index
5817 * @param {Boolean} hidden True if the column is hidden
5819 setHidden : function(colIndex, hidden){
5820 this.config[colIndex].hidden = hidden;
5821 this.totalWidth = null;
5822 this.fireEvent("hiddenchange", this, colIndex, hidden);
5826 * Sets the editor for a column.
5827 * @param {Number} col The column index
5828 * @param {Object} editor The editor object
5830 setEditor : function(col, editor){
5831 this.config[col].editor = editor;
5835 Roo.grid.ColumnModel.defaultRenderer = function(value)
5837 if(typeof value == "object") {
5840 if(typeof value == "string" && value.length < 1){
5844 return String.format("{0}", value);
5847 // Alias for backwards compatibility
5848 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
5851 * Ext JS Library 1.1.1
5852 * Copyright(c) 2006-2007, Ext JS, LLC.
5854 * Originally Released Under LGPL - original licence link has changed is not relivant.
5857 * <script type="text/javascript">
5861 * @class Roo.LoadMask
5862 * A simple utility class for generically masking elements while loading data. If the element being masked has
5863 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
5864 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
5865 * element's UpdateManager load indicator and will be destroyed after the initial load.
5867 * Create a new LoadMask
5868 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
5869 * @param {Object} config The config object
5871 Roo.LoadMask = function(el, config){
5872 this.el = Roo.get(el);
5873 Roo.apply(this, config);
5875 this.store.on('beforeload', this.onBeforeLoad, this);
5876 this.store.on('load', this.onLoad, this);
5877 this.store.on('loadexception', this.onLoadException, this);
5878 this.removeMask = false;
5880 var um = this.el.getUpdateManager();
5881 um.showLoadIndicator = false; // disable the default indicator
5882 um.on('beforeupdate', this.onBeforeLoad, this);
5883 um.on('update', this.onLoad, this);
5884 um.on('failure', this.onLoad, this);
5885 this.removeMask = true;
5889 Roo.LoadMask.prototype = {
5891 * @cfg {Boolean} removeMask
5892 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
5893 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
5897 * The text to display in a centered loading message box (defaults to 'Loading...')
5901 * @cfg {String} msgCls
5902 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
5904 msgCls : 'x-mask-loading',
5907 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
5913 * Disables the mask to prevent it from being displayed
5915 disable : function(){
5916 this.disabled = true;
5920 * Enables the mask so that it can be displayed
5922 enable : function(){
5923 this.disabled = false;
5926 onLoadException : function()
5930 if (typeof(arguments[3]) != 'undefined') {
5931 Roo.MessageBox.alert("Error loading",arguments[3]);
5935 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
5936 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
5943 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5948 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5952 onBeforeLoad : function(){
5954 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
5959 destroy : function(){
5961 this.store.un('beforeload', this.onBeforeLoad, this);
5962 this.store.un('load', this.onLoad, this);
5963 this.store.un('loadexception', this.onLoadException, this);
5965 var um = this.el.getUpdateManager();
5966 um.un('beforeupdate', this.onBeforeLoad, this);
5967 um.un('update', this.onLoad, this);
5968 um.un('failure', this.onLoad, this);
5979 * @class Roo.bootstrap.Table
5980 * @extends Roo.bootstrap.Component
5981 * Bootstrap Table class
5982 * @cfg {String} cls table class
5983 * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
5984 * @cfg {String} bgcolor Specifies the background color for a table
5985 * @cfg {Number} border Specifies whether the table cells should have borders or not
5986 * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
5987 * @cfg {Number} cellspacing Specifies the space between cells
5988 * @cfg {String} frame Specifies which parts of the outside borders that should be visible
5989 * @cfg {String} rules Specifies which parts of the inside borders that should be visible
5990 * @cfg {String} sortable Specifies that the table should be sortable
5991 * @cfg {String} summary Specifies a summary of the content of a table
5992 * @cfg {Number} width Specifies the width of a table
5993 * @cfg {String} layout table layout (auto | fixed | initial | inherit)
5995 * @cfg {boolean} striped Should the rows be alternative striped
5996 * @cfg {boolean} bordered Add borders to the table
5997 * @cfg {boolean} hover Add hover highlighting
5998 * @cfg {boolean} condensed Format condensed
5999 * @cfg {boolean} responsive Format condensed
6000 * @cfg {Boolean} loadMask (true|false) default false
6001 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
6002 * @cfg {Boolean} headerShow (true|false) generate thead, default true
6003 * @cfg {Boolean} rowSelection (true|false) default false
6004 * @cfg {Boolean} cellSelection (true|false) default false
6005 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
6006 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
6007 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
6008 * @cfg {Boolean} auto_hide_footer auto hide footer if only one page (default false)
6012 * Create a new Table
6013 * @param {Object} config The config object
6016 Roo.bootstrap.Table = function(config){
6017 Roo.bootstrap.Table.superclass.constructor.call(this, config);
6022 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
6023 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
6024 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
6025 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
6027 this.sm = this.sm || {xtype: 'RowSelectionModel'};
6029 this.sm.grid = this;
6030 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
6031 this.sm = this.selModel;
6032 this.sm.xmodule = this.xmodule || false;
6035 if (this.cm && typeof(this.cm.config) == 'undefined') {
6036 this.colModel = new Roo.grid.ColumnModel(this.cm);
6037 this.cm = this.colModel;
6038 this.cm.xmodule = this.xmodule || false;
6041 this.store= Roo.factory(this.store, Roo.data);
6042 this.ds = this.store;
6043 this.ds.xmodule = this.xmodule || false;
6046 if (this.footer && this.store) {
6047 this.footer.dataSource = this.ds;
6048 this.footer = Roo.factory(this.footer);
6055 * Fires when a cell is clicked
6056 * @param {Roo.bootstrap.Table} this
6057 * @param {Roo.Element} el
6058 * @param {Number} rowIndex
6059 * @param {Number} columnIndex
6060 * @param {Roo.EventObject} e
6064 * @event celldblclick
6065 * Fires when a cell is double clicked
6066 * @param {Roo.bootstrap.Table} this
6067 * @param {Roo.Element} el
6068 * @param {Number} rowIndex
6069 * @param {Number} columnIndex
6070 * @param {Roo.EventObject} e
6072 "celldblclick" : true,
6075 * Fires when a row is clicked
6076 * @param {Roo.bootstrap.Table} this
6077 * @param {Roo.Element} el
6078 * @param {Number} rowIndex
6079 * @param {Roo.EventObject} e
6083 * @event rowdblclick
6084 * Fires when a row is double clicked
6085 * @param {Roo.bootstrap.Table} this
6086 * @param {Roo.Element} el
6087 * @param {Number} rowIndex
6088 * @param {Roo.EventObject} e
6090 "rowdblclick" : true,
6093 * Fires when a mouseover occur
6094 * @param {Roo.bootstrap.Table} this
6095 * @param {Roo.Element} el
6096 * @param {Number} rowIndex
6097 * @param {Number} columnIndex
6098 * @param {Roo.EventObject} e
6103 * Fires when a mouseout occur
6104 * @param {Roo.bootstrap.Table} this
6105 * @param {Roo.Element} el
6106 * @param {Number} rowIndex
6107 * @param {Number} columnIndex
6108 * @param {Roo.EventObject} e
6113 * Fires when a row is rendered, so you can change add a style to it.
6114 * @param {Roo.bootstrap.Table} this
6115 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
6119 * @event rowsrendered
6120 * Fires when all the rows have been rendered
6121 * @param {Roo.bootstrap.Table} this
6123 'rowsrendered' : true,
6125 * @event contextmenu
6126 * The raw contextmenu event for the entire grid.
6127 * @param {Roo.EventObject} e
6129 "contextmenu" : true,
6131 * @event rowcontextmenu
6132 * Fires when a row is right clicked
6133 * @param {Roo.bootstrap.Table} this
6134 * @param {Number} rowIndex
6135 * @param {Roo.EventObject} e
6137 "rowcontextmenu" : true,
6139 * @event cellcontextmenu
6140 * Fires when a cell is right clicked
6141 * @param {Roo.bootstrap.Table} this
6142 * @param {Number} rowIndex
6143 * @param {Number} cellIndex
6144 * @param {Roo.EventObject} e
6146 "cellcontextmenu" : true,
6148 * @event headercontextmenu
6149 * Fires when a header is right clicked
6150 * @param {Roo.bootstrap.Table} this
6151 * @param {Number} columnIndex
6152 * @param {Roo.EventObject} e
6154 "headercontextmenu" : true
6158 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
6184 rowSelection : false,
6185 cellSelection : false,
6188 // Roo.Element - the tbody
6190 // Roo.Element - thead element
6193 container: false, // used by gridpanel...
6199 auto_hide_footer : false,
6201 getAutoCreate : function()
6203 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
6210 if (this.scrollBody) {
6211 cfg.cls += ' table-body-fixed';
6214 cfg.cls += ' table-striped';
6218 cfg.cls += ' table-hover';
6220 if (this.bordered) {
6221 cfg.cls += ' table-bordered';
6223 if (this.condensed) {
6224 cfg.cls += ' table-condensed';
6226 if (this.responsive) {
6227 cfg.cls += ' table-responsive';
6231 cfg.cls+= ' ' +this.cls;
6234 // this lot should be simplifed...
6247 ].forEach(function(k) {
6255 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
6258 if(this.store || this.cm){
6259 if(this.headerShow){
6260 cfg.cn.push(this.renderHeader());
6263 cfg.cn.push(this.renderBody());
6265 if(this.footerShow){
6266 cfg.cn.push(this.renderFooter());
6268 // where does this come from?
6269 //cfg.cls+= ' TableGrid';
6272 return { cn : [ cfg ] };
6275 initEvents : function()
6277 if(!this.store || !this.cm){
6280 if (this.selModel) {
6281 this.selModel.initEvents();
6285 //Roo.log('initEvents with ds!!!!');
6287 this.mainBody = this.el.select('tbody', true).first();
6288 this.mainHead = this.el.select('thead', true).first();
6289 this.mainFoot = this.el.select('tfoot', true).first();
6295 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6296 e.on('click', _this.sort, _this);
6299 this.mainBody.on("click", this.onClick, this);
6300 this.mainBody.on("dblclick", this.onDblClick, this);
6302 // why is this done????? = it breaks dialogs??
6303 //this.parent().el.setStyle('position', 'relative');
6307 this.footer.parentId = this.id;
6308 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
6311 this.el.select('tfoot tr td').first().addClass('hide');
6316 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
6319 this.store.on('load', this.onLoad, this);
6320 this.store.on('beforeload', this.onBeforeLoad, this);
6321 this.store.on('update', this.onUpdate, this);
6322 this.store.on('add', this.onAdd, this);
6323 this.store.on("clear", this.clear, this);
6325 this.el.on("contextmenu", this.onContextMenu, this);
6327 this.mainBody.on('scroll', this.onBodyScroll, this);
6329 this.cm.on("headerchange", this.onHeaderChange, this);
6331 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
6335 onContextMenu : function(e, t)
6337 this.processEvent("contextmenu", e);
6340 processEvent : function(name, e)
6342 if (name != 'touchstart' ) {
6343 this.fireEvent(name, e);
6346 var t = e.getTarget();
6348 var cell = Roo.get(t);
6354 if(cell.findParent('tfoot', false, true)){
6358 if(cell.findParent('thead', false, true)){
6360 if(e.getTarget().nodeName.toLowerCase() != 'th'){
6361 cell = Roo.get(t).findParent('th', false, true);
6363 Roo.log("failed to find th in thead?");
6364 Roo.log(e.getTarget());
6369 var cellIndex = cell.dom.cellIndex;
6371 var ename = name == 'touchstart' ? 'click' : name;
6372 this.fireEvent("header" + ename, this, cellIndex, e);
6377 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6378 cell = Roo.get(t).findParent('td', false, true);
6380 Roo.log("failed to find th in tbody?");
6381 Roo.log(e.getTarget());
6386 var row = cell.findParent('tr', false, true);
6387 var cellIndex = cell.dom.cellIndex;
6388 var rowIndex = row.dom.rowIndex - 1;
6392 this.fireEvent("row" + name, this, rowIndex, e);
6396 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6402 onMouseover : function(e, el)
6404 var cell = Roo.get(el);
6410 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6411 cell = cell.findParent('td', false, true);
6414 var row = cell.findParent('tr', false, true);
6415 var cellIndex = cell.dom.cellIndex;
6416 var rowIndex = row.dom.rowIndex - 1; // start from 0
6418 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
6422 onMouseout : function(e, el)
6424 var cell = Roo.get(el);
6430 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6431 cell = cell.findParent('td', false, true);
6434 var row = cell.findParent('tr', false, true);
6435 var cellIndex = cell.dom.cellIndex;
6436 var rowIndex = row.dom.rowIndex - 1; // start from 0
6438 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6442 onClick : function(e, el)
6444 var cell = Roo.get(el);
6446 if(!cell || (!this.cellSelection && !this.rowSelection)){
6450 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6451 cell = cell.findParent('td', false, true);
6454 if(!cell || typeof(cell) == 'undefined'){
6458 var row = cell.findParent('tr', false, true);
6460 if(!row || typeof(row) == 'undefined'){
6464 var cellIndex = cell.dom.cellIndex;
6465 var rowIndex = this.getRowIndex(row);
6467 // why??? - should these not be based on SelectionModel?
6468 if(this.cellSelection){
6469 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6472 if(this.rowSelection){
6473 this.fireEvent('rowclick', this, row, rowIndex, e);
6479 onDblClick : function(e,el)
6481 var cell = Roo.get(el);
6483 if(!cell || (!this.cellSelection && !this.rowSelection)){
6487 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6488 cell = cell.findParent('td', false, true);
6491 if(!cell || typeof(cell) == 'undefined'){
6495 var row = cell.findParent('tr', false, true);
6497 if(!row || typeof(row) == 'undefined'){
6501 var cellIndex = cell.dom.cellIndex;
6502 var rowIndex = this.getRowIndex(row);
6504 if(this.cellSelection){
6505 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6508 if(this.rowSelection){
6509 this.fireEvent('rowdblclick', this, row, rowIndex, e);
6513 sort : function(e,el)
6515 var col = Roo.get(el);
6517 if(!col.hasClass('sortable')){
6521 var sort = col.attr('sort');
6524 if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6528 this.store.sortInfo = {field : sort, direction : dir};
6531 Roo.log("calling footer first");
6532 this.footer.onClick('first');
6535 this.store.load({ params : { start : 0 } });
6539 renderHeader : function()
6547 this.totalWidth = 0;
6549 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6551 var config = cm.config[i];
6555 cls : 'x-hcol-' + i,
6557 html: cm.getColumnHeader(i)
6562 if(typeof(config.sortable) != 'undefined' && config.sortable){
6564 c.html = '<i class="glyphicon"></i>' + c.html;
6567 if(typeof(config.lgHeader) != 'undefined'){
6568 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6571 if(typeof(config.mdHeader) != 'undefined'){
6572 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6575 if(typeof(config.smHeader) != 'undefined'){
6576 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6579 if(typeof(config.xsHeader) != 'undefined'){
6580 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6587 if(typeof(config.tooltip) != 'undefined'){
6588 c.tooltip = config.tooltip;
6591 if(typeof(config.colspan) != 'undefined'){
6592 c.colspan = config.colspan;
6595 if(typeof(config.hidden) != 'undefined' && config.hidden){
6596 c.style += ' display:none;';
6599 if(typeof(config.dataIndex) != 'undefined'){
6600 c.sort = config.dataIndex;
6605 if(typeof(config.align) != 'undefined' && config.align.length){
6606 c.style += ' text-align:' + config.align + ';';
6609 if(typeof(config.width) != 'undefined'){
6610 c.style += ' width:' + config.width + 'px;';
6611 this.totalWidth += config.width;
6613 this.totalWidth += 100; // assume minimum of 100 per column?
6616 if(typeof(config.cls) != 'undefined'){
6617 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6620 ['xs','sm','md','lg'].map(function(size){
6622 if(typeof(config[size]) == 'undefined'){
6626 if (!config[size]) { // 0 = hidden
6627 c.cls += ' hidden-' + size;
6631 c.cls += ' col-' + size + '-' + config[size];
6641 renderBody : function()
6651 colspan : this.cm.getColumnCount()
6661 renderFooter : function()
6671 colspan : this.cm.getColumnCount()
6685 // Roo.log('ds onload');
6690 var ds = this.store;
6692 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6693 e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6694 if (_this.store.sortInfo) {
6696 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6697 e.select('i', true).addClass(['glyphicon-arrow-up']);
6700 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6701 e.select('i', true).addClass(['glyphicon-arrow-down']);
6706 var tbody = this.mainBody;
6708 if(ds.getCount() > 0){
6709 ds.data.each(function(d,rowIndex){
6710 var row = this.renderRow(cm, ds, rowIndex);
6712 tbody.createChild(row);
6716 if(row.cellObjects.length){
6717 Roo.each(row.cellObjects, function(r){
6718 _this.renderCellObject(r);
6725 var tfoot = this.el.select('tfoot', true).first();
6727 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
6729 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
6731 var total = this.ds.getTotalCount();
6733 if(this.footer.pageSize < total){
6734 this.mainFoot.show();
6738 Roo.each(this.el.select('tbody td', true).elements, function(e){
6739 e.on('mouseover', _this.onMouseover, _this);
6742 Roo.each(this.el.select('tbody td', true).elements, function(e){
6743 e.on('mouseout', _this.onMouseout, _this);
6745 this.fireEvent('rowsrendered', this);
6751 onUpdate : function(ds,record)
6753 this.refreshRow(record);
6757 onRemove : function(ds, record, index, isUpdate){
6758 if(isUpdate !== true){
6759 this.fireEvent("beforerowremoved", this, index, record);
6761 var bt = this.mainBody.dom;
6763 var rows = this.el.select('tbody > tr', true).elements;
6765 if(typeof(rows[index]) != 'undefined'){
6766 bt.removeChild(rows[index].dom);
6769 // if(bt.rows[index]){
6770 // bt.removeChild(bt.rows[index]);
6773 if(isUpdate !== true){
6774 //this.stripeRows(index);
6775 //this.syncRowHeights(index, index);
6777 this.fireEvent("rowremoved", this, index, record);
6781 onAdd : function(ds, records, rowIndex)
6783 //Roo.log('on Add called');
6784 // - note this does not handle multiple adding very well..
6785 var bt = this.mainBody.dom;
6786 for (var i =0 ; i < records.length;i++) {
6787 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6788 //Roo.log(records[i]);
6789 //Roo.log(this.store.getAt(rowIndex+i));
6790 this.insertRow(this.store, rowIndex + i, false);
6797 refreshRow : function(record){
6798 var ds = this.store, index;
6799 if(typeof record == 'number'){
6801 record = ds.getAt(index);
6803 index = ds.indexOf(record);
6805 this.insertRow(ds, index, true);
6807 this.onRemove(ds, record, index+1, true);
6809 //this.syncRowHeights(index, index);
6811 this.fireEvent("rowupdated", this, index, record);
6814 insertRow : function(dm, rowIndex, isUpdate){
6817 this.fireEvent("beforerowsinserted", this, rowIndex);
6819 //var s = this.getScrollState();
6820 var row = this.renderRow(this.cm, this.store, rowIndex);
6821 // insert before rowIndex..
6822 var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
6826 if(row.cellObjects.length){
6827 Roo.each(row.cellObjects, function(r){
6828 _this.renderCellObject(r);
6833 this.fireEvent("rowsinserted", this, rowIndex);
6834 //this.syncRowHeights(firstRow, lastRow);
6835 //this.stripeRows(firstRow);
6842 getRowDom : function(rowIndex)
6844 var rows = this.el.select('tbody > tr', true).elements;
6846 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
6849 // returns the object tree for a tr..
6852 renderRow : function(cm, ds, rowIndex)
6854 var d = ds.getAt(rowIndex);
6858 cls : 'x-row-' + rowIndex,
6862 var cellObjects = [];
6864 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6865 var config = cm.config[i];
6867 var renderer = cm.getRenderer(i);
6871 if(typeof(renderer) !== 'undefined'){
6872 value = renderer(d.data[cm.getDataIndex(i)], false, d);
6874 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
6875 // and are rendered into the cells after the row is rendered - using the id for the element.
6877 if(typeof(value) === 'object'){
6887 rowIndex : rowIndex,
6892 this.fireEvent('rowclass', this, rowcfg);
6896 cls : rowcfg.rowClass + ' x-col-' + i,
6898 html: (typeof(value) === 'object') ? '' : value
6905 if(typeof(config.colspan) != 'undefined'){
6906 td.colspan = config.colspan;
6909 if(typeof(config.hidden) != 'undefined' && config.hidden){
6910 td.style += ' display:none;';
6913 if(typeof(config.align) != 'undefined' && config.align.length){
6914 td.style += ' text-align:' + config.align + ';';
6916 if(typeof(config.valign) != 'undefined' && config.valign.length){
6917 td.style += ' vertical-align:' + config.valign + ';';
6920 if(typeof(config.width) != 'undefined'){
6921 td.style += ' width:' + config.width + 'px;';
6924 if(typeof(config.cursor) != 'undefined'){
6925 td.style += ' cursor:' + config.cursor + ';';
6928 if(typeof(config.cls) != 'undefined'){
6929 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
6932 ['xs','sm','md','lg'].map(function(size){
6934 if(typeof(config[size]) == 'undefined'){
6938 if (!config[size]) { // 0 = hidden
6939 td.cls += ' hidden-' + size;
6943 td.cls += ' col-' + size + '-' + config[size];
6951 row.cellObjects = cellObjects;
6959 onBeforeLoad : function()
6968 this.el.select('tbody', true).first().dom.innerHTML = '';
6971 * Show or hide a row.
6972 * @param {Number} rowIndex to show or hide
6973 * @param {Boolean} state hide
6975 setRowVisibility : function(rowIndex, state)
6977 var bt = this.mainBody.dom;
6979 var rows = this.el.select('tbody > tr', true).elements;
6981 if(typeof(rows[rowIndex]) == 'undefined'){
6984 rows[rowIndex].dom.style.display = state ? '' : 'none';
6988 getSelectionModel : function(){
6990 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
6992 return this.selModel;
6995 * Render the Roo.bootstrap object from renderder
6997 renderCellObject : function(r)
7001 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
7003 var t = r.cfg.render(r.container);
7006 Roo.each(r.cfg.cn, function(c){
7008 container: t.getChildContainer(),
7011 _this.renderCellObject(child);
7016 getRowIndex : function(row)
7020 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
7031 * Returns the grid's underlying element = used by panel.Grid
7032 * @return {Element} The element
7034 getGridEl : function(){
7038 * Forces a resize - used by panel.Grid
7039 * @return {Element} The element
7041 autoSize : function()
7043 //var ctr = Roo.get(this.container.dom.parentElement);
7044 var ctr = Roo.get(this.el.dom);
7046 var thd = this.getGridEl().select('thead',true).first();
7047 var tbd = this.getGridEl().select('tbody', true).first();
7048 var tfd = this.getGridEl().select('tfoot', true).first();
7050 var cw = ctr.getWidth();
7054 tbd.setSize(ctr.getWidth(),
7055 ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
7057 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
7060 cw = Math.max(cw, this.totalWidth);
7061 this.getGridEl().select('tr',true).setWidth(cw);
7062 // resize 'expandable coloumn?
7064 return; // we doe not have a view in this design..
7067 onBodyScroll: function()
7069 //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
7071 this.mainHead.setStyle({
7072 'position' : 'relative',
7073 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
7079 var scrollHeight = this.mainBody.dom.scrollHeight;
7081 var scrollTop = Math.ceil(this.mainBody.getScroll().top);
7083 var height = this.mainBody.getHeight();
7085 if(scrollHeight - height == scrollTop) {
7087 var total = this.ds.getTotalCount();
7089 if(this.footer.cursor + this.footer.pageSize < total){
7091 this.footer.ds.load({
7093 start : this.footer.cursor + this.footer.pageSize,
7094 limit : this.footer.pageSize
7104 onHeaderChange : function()
7106 var header = this.renderHeader();
7107 var table = this.el.select('table', true).first();
7109 this.mainHead.remove();
7110 this.mainHead = table.createChild(header, this.mainBody, false);
7113 onHiddenChange : function(colModel, colIndex, hidden)
7115 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
7116 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
7118 this.CSS.updateRule(thSelector, "display", "");
7119 this.CSS.updateRule(tdSelector, "display", "");
7122 this.CSS.updateRule(thSelector, "display", "none");
7123 this.CSS.updateRule(tdSelector, "display", "none");
7126 this.onHeaderChange();
7130 setColumnWidth: function(col_index, width)
7132 // width = "md-2 xs-2..."
7133 if(!this.colModel.config[col_index]) {
7137 var w = width.split(" ");
7139 var rows = this.el.dom.getElementsByClassName("x-col-"+col_index);
7141 var h_row = this.el.dom.getElementsByClassName("x-hcol-"+col_index);
7144 for(var j = 0; j < w.length; j++) {
7150 var size_cls = w[j].split("-");
7152 if(!Number.isInteger(size_cls[1] * 1)) {
7156 if(!this.colModel.config[col_index][size_cls[0]]) {
7160 if(!h_row[0].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
7164 h_row[0].classList.replace(
7165 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
7166 "col-"+size_cls[0]+"-"+size_cls[1]
7169 for(var i = 0; i < rows.length; i++) {
7171 var size_cls = w[j].split("-");
7173 if(!Number.isInteger(size_cls[1] * 1)) {
7177 if(!this.colModel.config[col_index][size_cls[0]]) {
7181 if(!rows[i].classList.contains("col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]])) {
7185 rows[i].classList.replace(
7186 "col-"+size_cls[0]+"-"+this.colModel.config[col_index][size_cls[0]],
7187 "col-"+size_cls[0]+"-"+size_cls[1]
7191 this.colModel.config[col_index][size_cls[0]] = size_cls[1];
7206 * @class Roo.bootstrap.TableCell
7207 * @extends Roo.bootstrap.Component
7208 * Bootstrap TableCell class
7209 * @cfg {String} html cell contain text
7210 * @cfg {String} cls cell class
7211 * @cfg {String} tag cell tag (td|th) default td
7212 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
7213 * @cfg {String} align Aligns the content in a cell
7214 * @cfg {String} axis Categorizes cells
7215 * @cfg {String} bgcolor Specifies the background color of a cell
7216 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7217 * @cfg {Number} colspan Specifies the number of columns a cell should span
7218 * @cfg {String} headers Specifies one or more header cells a cell is related to
7219 * @cfg {Number} height Sets the height of a cell
7220 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
7221 * @cfg {Number} rowspan Sets the number of rows a cell should span
7222 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
7223 * @cfg {String} valign Vertical aligns the content in a cell
7224 * @cfg {Number} width Specifies the width of a cell
7227 * Create a new TableCell
7228 * @param {Object} config The config object
7231 Roo.bootstrap.TableCell = function(config){
7232 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
7235 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
7255 getAutoCreate : function(){
7256 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
7276 cfg.align=this.align
7282 cfg.bgcolor=this.bgcolor
7285 cfg.charoff=this.charoff
7288 cfg.colspan=this.colspan
7291 cfg.headers=this.headers
7294 cfg.height=this.height
7297 cfg.nowrap=this.nowrap
7300 cfg.rowspan=this.rowspan
7303 cfg.scope=this.scope
7306 cfg.valign=this.valign
7309 cfg.width=this.width
7328 * @class Roo.bootstrap.TableRow
7329 * @extends Roo.bootstrap.Component
7330 * Bootstrap TableRow class
7331 * @cfg {String} cls row class
7332 * @cfg {String} align Aligns the content in a table row
7333 * @cfg {String} bgcolor Specifies a background color for a table row
7334 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7335 * @cfg {String} valign Vertical aligns the content in a table row
7338 * Create a new TableRow
7339 * @param {Object} config The config object
7342 Roo.bootstrap.TableRow = function(config){
7343 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
7346 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
7354 getAutoCreate : function(){
7355 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
7365 cfg.align = this.align;
7368 cfg.bgcolor = this.bgcolor;
7371 cfg.charoff = this.charoff;
7374 cfg.valign = this.valign;
7392 * @class Roo.bootstrap.TableBody
7393 * @extends Roo.bootstrap.Component
7394 * Bootstrap TableBody class
7395 * @cfg {String} cls element class
7396 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
7397 * @cfg {String} align Aligns the content inside the element
7398 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
7399 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
7402 * Create a new TableBody
7403 * @param {Object} config The config object
7406 Roo.bootstrap.TableBody = function(config){
7407 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
7410 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
7418 getAutoCreate : function(){
7419 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
7433 cfg.align = this.align;
7436 cfg.charoff = this.charoff;
7439 cfg.valign = this.valign;
7446 // initEvents : function()
7453 // this.store = Roo.factory(this.store, Roo.data);
7454 // this.store.on('load', this.onLoad, this);
7456 // this.store.load();
7460 // onLoad: function ()
7462 // this.fireEvent('load', this);
7472 * Ext JS Library 1.1.1
7473 * Copyright(c) 2006-2007, Ext JS, LLC.
7475 * Originally Released Under LGPL - original licence link has changed is not relivant.
7478 * <script type="text/javascript">
7481 // as we use this in bootstrap.
7482 Roo.namespace('Roo.form');
7484 * @class Roo.form.Action
7485 * Internal Class used to handle form actions
7487 * @param {Roo.form.BasicForm} el The form element or its id
7488 * @param {Object} config Configuration options
7493 // define the action interface
7494 Roo.form.Action = function(form, options){
7496 this.options = options || {};
7499 * Client Validation Failed
7502 Roo.form.Action.CLIENT_INVALID = 'client';
7504 * Server Validation Failed
7507 Roo.form.Action.SERVER_INVALID = 'server';
7509 * Connect to Server Failed
7512 Roo.form.Action.CONNECT_FAILURE = 'connect';
7514 * Reading Data from Server Failed
7517 Roo.form.Action.LOAD_FAILURE = 'load';
7519 Roo.form.Action.prototype = {
7521 failureType : undefined,
7522 response : undefined,
7526 run : function(options){
7531 success : function(response){
7536 handleResponse : function(response){
7540 // default connection failure
7541 failure : function(response){
7543 this.response = response;
7544 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7545 this.form.afterAction(this, false);
7548 processResponse : function(response){
7549 this.response = response;
7550 if(!response.responseText){
7553 this.result = this.handleResponse(response);
7557 // utility functions used internally
7558 getUrl : function(appendParams){
7559 var url = this.options.url || this.form.url || this.form.el.dom.action;
7561 var p = this.getParams();
7563 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7569 getMethod : function(){
7570 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7573 getParams : function(){
7574 var bp = this.form.baseParams;
7575 var p = this.options.params;
7577 if(typeof p == "object"){
7578 p = Roo.urlEncode(Roo.applyIf(p, bp));
7579 }else if(typeof p == 'string' && bp){
7580 p += '&' + Roo.urlEncode(bp);
7583 p = Roo.urlEncode(bp);
7588 createCallback : function(){
7590 success: this.success,
7591 failure: this.failure,
7593 timeout: (this.form.timeout*1000),
7594 upload: this.form.fileUpload ? this.success : undefined
7599 Roo.form.Action.Submit = function(form, options){
7600 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7603 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7606 haveProgress : false,
7607 uploadComplete : false,
7609 // uploadProgress indicator.
7610 uploadProgress : function()
7612 if (!this.form.progressUrl) {
7616 if (!this.haveProgress) {
7617 Roo.MessageBox.progress("Uploading", "Uploading");
7619 if (this.uploadComplete) {
7620 Roo.MessageBox.hide();
7624 this.haveProgress = true;
7626 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7628 var c = new Roo.data.Connection();
7630 url : this.form.progressUrl,
7635 success : function(req){
7636 //console.log(data);
7640 rdata = Roo.decode(req.responseText)
7642 Roo.log("Invalid data from server..");
7646 if (!rdata || !rdata.success) {
7648 Roo.MessageBox.alert(Roo.encode(rdata));
7651 var data = rdata.data;
7653 if (this.uploadComplete) {
7654 Roo.MessageBox.hide();
7659 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7660 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7663 this.uploadProgress.defer(2000,this);
7666 failure: function(data) {
7667 Roo.log('progress url failed ');
7678 // run get Values on the form, so it syncs any secondary forms.
7679 this.form.getValues();
7681 var o = this.options;
7682 var method = this.getMethod();
7683 var isPost = method == 'POST';
7684 if(o.clientValidation === false || this.form.isValid()){
7686 if (this.form.progressUrl) {
7687 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7688 (new Date() * 1) + '' + Math.random());
7693 Roo.Ajax.request(Roo.apply(this.createCallback(), {
7694 form:this.form.el.dom,
7695 url:this.getUrl(!isPost),
7697 params:isPost ? this.getParams() : null,
7698 isUpload: this.form.fileUpload
7701 this.uploadProgress();
7703 }else if (o.clientValidation !== false){ // client validation failed
7704 this.failureType = Roo.form.Action.CLIENT_INVALID;
7705 this.form.afterAction(this, false);
7709 success : function(response)
7711 this.uploadComplete= true;
7712 if (this.haveProgress) {
7713 Roo.MessageBox.hide();
7717 var result = this.processResponse(response);
7718 if(result === true || result.success){
7719 this.form.afterAction(this, true);
7723 this.form.markInvalid(result.errors);
7724 this.failureType = Roo.form.Action.SERVER_INVALID;
7726 this.form.afterAction(this, false);
7728 failure : function(response)
7730 this.uploadComplete= true;
7731 if (this.haveProgress) {
7732 Roo.MessageBox.hide();
7735 this.response = response;
7736 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7737 this.form.afterAction(this, false);
7740 handleResponse : function(response){
7741 if(this.form.errorReader){
7742 var rs = this.form.errorReader.read(response);
7745 for(var i = 0, len = rs.records.length; i < len; i++) {
7746 var r = rs.records[i];
7750 if(errors.length < 1){
7754 success : rs.success,
7760 ret = Roo.decode(response.responseText);
7764 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7774 Roo.form.Action.Load = function(form, options){
7775 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7776 this.reader = this.form.reader;
7779 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7784 Roo.Ajax.request(Roo.apply(
7785 this.createCallback(), {
7786 method:this.getMethod(),
7787 url:this.getUrl(false),
7788 params:this.getParams()
7792 success : function(response){
7794 var result = this.processResponse(response);
7795 if(result === true || !result.success || !result.data){
7796 this.failureType = Roo.form.Action.LOAD_FAILURE;
7797 this.form.afterAction(this, false);
7800 this.form.clearInvalid();
7801 this.form.setValues(result.data);
7802 this.form.afterAction(this, true);
7805 handleResponse : function(response){
7806 if(this.form.reader){
7807 var rs = this.form.reader.read(response);
7808 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7810 success : rs.success,
7814 return Roo.decode(response.responseText);
7818 Roo.form.Action.ACTION_TYPES = {
7819 'load' : Roo.form.Action.Load,
7820 'submit' : Roo.form.Action.Submit
7829 * @class Roo.bootstrap.Form
7830 * @extends Roo.bootstrap.Component
7831 * Bootstrap Form class
7832 * @cfg {String} method GET | POST (default POST)
7833 * @cfg {String} labelAlign top | left (default top)
7834 * @cfg {String} align left | right - for navbars
7835 * @cfg {Boolean} loadMask load mask when submit (default true)
7840 * @param {Object} config The config object
7844 Roo.bootstrap.Form = function(config){
7846 Roo.bootstrap.Form.superclass.constructor.call(this, config);
7848 Roo.bootstrap.Form.popover.apply();
7852 * @event clientvalidation
7853 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
7854 * @param {Form} this
7855 * @param {Boolean} valid true if the form has passed client-side validation
7857 clientvalidation: true,
7859 * @event beforeaction
7860 * Fires before any action is performed. Return false to cancel the action.
7861 * @param {Form} this
7862 * @param {Action} action The action to be performed
7866 * @event actionfailed
7867 * Fires when an action fails.
7868 * @param {Form} this
7869 * @param {Action} action The action that failed
7871 actionfailed : true,
7873 * @event actioncomplete
7874 * Fires when an action is completed.
7875 * @param {Form} this
7876 * @param {Action} action The action that completed
7878 actioncomplete : true
7882 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component, {
7885 * @cfg {String} method
7886 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
7891 * The URL to use for form actions if one isn't supplied in the action options.
7894 * @cfg {Boolean} fileUpload
7895 * Set to true if this form is a file upload.
7899 * @cfg {Object} baseParams
7900 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
7904 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
7908 * @cfg {Sting} align (left|right) for navbar forms
7913 activeAction : null,
7916 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
7917 * element by passing it or its id or mask the form itself by passing in true.
7920 waitMsgTarget : false,
7925 * @cfg {Boolean} errorMask (true|false) default false
7930 * @cfg {Number} maskOffset Default 100
7935 * @cfg {Boolean} maskBody
7939 getAutoCreate : function(){
7943 method : this.method || 'POST',
7944 id : this.id || Roo.id(),
7947 if (this.parent().xtype.match(/^Nav/)) {
7948 cfg.cls = 'navbar-form navbar-' + this.align;
7952 if (this.labelAlign == 'left' ) {
7953 cfg.cls += ' form-horizontal';
7959 initEvents : function()
7961 this.el.on('submit', this.onSubmit, this);
7962 // this was added as random key presses on the form where triggering form submit.
7963 this.el.on('keypress', function(e) {
7964 if (e.getCharCode() != 13) {
7967 // we might need to allow it for textareas.. and some other items.
7968 // check e.getTarget().
7970 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
7974 Roo.log("keypress blocked");
7982 onSubmit : function(e){
7987 * Returns true if client-side validation on the form is successful.
7990 isValid : function(){
7991 var items = this.getItems();
7995 items.each(function(f){
8001 Roo.log('invalid field: ' + f.name);
8005 if(!target && f.el.isVisible(true)){
8011 if(this.errorMask && !valid){
8012 Roo.bootstrap.Form.popover.mask(this, target);
8019 * Returns true if any fields in this form have changed since their original load.
8022 isDirty : function(){
8024 var items = this.getItems();
8025 items.each(function(f){
8035 * Performs a predefined action (submit or load) or custom actions you define on this form.
8036 * @param {String} actionName The name of the action type
8037 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
8038 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
8039 * accept other config options):
8041 Property Type Description
8042 ---------------- --------------- ----------------------------------------------------------------------------------
8043 url String The url for the action (defaults to the form's url)
8044 method String The form method to use (defaults to the form's method, or POST if not defined)
8045 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
8046 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
8047 validate the form on the client (defaults to false)
8049 * @return {BasicForm} this
8051 doAction : function(action, options){
8052 if(typeof action == 'string'){
8053 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
8055 if(this.fireEvent('beforeaction', this, action) !== false){
8056 this.beforeAction(action);
8057 action.run.defer(100, action);
8063 beforeAction : function(action){
8064 var o = action.options;
8069 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
8071 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
8074 // not really supported yet.. ??
8076 //if(this.waitMsgTarget === true){
8077 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
8078 //}else if(this.waitMsgTarget){
8079 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
8080 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
8082 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
8088 afterAction : function(action, success){
8089 this.activeAction = null;
8090 var o = action.options;
8095 Roo.get(document.body).unmask();
8101 //if(this.waitMsgTarget === true){
8102 // this.el.unmask();
8103 //}else if(this.waitMsgTarget){
8104 // this.waitMsgTarget.unmask();
8106 // Roo.MessageBox.updateProgress(1);
8107 // Roo.MessageBox.hide();
8114 Roo.callback(o.success, o.scope, [this, action]);
8115 this.fireEvent('actioncomplete', this, action);
8119 // failure condition..
8120 // we have a scenario where updates need confirming.
8121 // eg. if a locking scenario exists..
8122 // we look for { errors : { needs_confirm : true }} in the response.
8124 (typeof(action.result) != 'undefined') &&
8125 (typeof(action.result.errors) != 'undefined') &&
8126 (typeof(action.result.errors.needs_confirm) != 'undefined')
8129 Roo.log("not supported yet");
8132 Roo.MessageBox.confirm(
8133 "Change requires confirmation",
8134 action.result.errorMsg,
8139 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
8149 Roo.callback(o.failure, o.scope, [this, action]);
8150 // show an error message if no failed handler is set..
8151 if (!this.hasListener('actionfailed')) {
8152 Roo.log("need to add dialog support");
8154 Roo.MessageBox.alert("Error",
8155 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
8156 action.result.errorMsg :
8157 "Saving Failed, please check your entries or try again"
8162 this.fireEvent('actionfailed', this, action);
8167 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
8168 * @param {String} id The value to search for
8171 findField : function(id){
8172 var items = this.getItems();
8173 var field = items.get(id);
8175 items.each(function(f){
8176 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
8183 return field || null;
8186 * Mark fields in this form invalid in bulk.
8187 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
8188 * @return {BasicForm} this
8190 markInvalid : function(errors){
8191 if(errors instanceof Array){
8192 for(var i = 0, len = errors.length; i < len; i++){
8193 var fieldError = errors[i];
8194 var f = this.findField(fieldError.id);
8196 f.markInvalid(fieldError.msg);
8202 if(typeof errors[id] != 'function' && (field = this.findField(id))){
8203 field.markInvalid(errors[id]);
8207 //Roo.each(this.childForms || [], function (f) {
8208 // f.markInvalid(errors);
8215 * Set values for fields in this form in bulk.
8216 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
8217 * @return {BasicForm} this
8219 setValues : function(values){
8220 if(values instanceof Array){ // array of objects
8221 for(var i = 0, len = values.length; i < len; i++){
8223 var f = this.findField(v.id);
8225 f.setValue(v.value);
8226 if(this.trackResetOnLoad){
8227 f.originalValue = f.getValue();
8231 }else{ // object hash
8234 if(typeof values[id] != 'function' && (field = this.findField(id))){
8236 if (field.setFromData &&
8238 field.displayField &&
8239 // combos' with local stores can
8240 // be queried via setValue()
8241 // to set their value..
8242 (field.store && !field.store.isLocal)
8246 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
8247 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
8248 field.setFromData(sd);
8250 } else if(field.setFromData && (field.store && !field.store.isLocal)) {
8252 field.setFromData(values);
8255 field.setValue(values[id]);
8259 if(this.trackResetOnLoad){
8260 field.originalValue = field.getValue();
8266 //Roo.each(this.childForms || [], function (f) {
8267 // f.setValues(values);
8274 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
8275 * they are returned as an array.
8276 * @param {Boolean} asString
8279 getValues : function(asString){
8280 //if (this.childForms) {
8281 // copy values from the child forms
8282 // Roo.each(this.childForms, function (f) {
8283 // this.setValues(f.getValues());
8289 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
8290 if(asString === true){
8293 return Roo.urlDecode(fs);
8297 * Returns the fields in this form as an object with key/value pairs.
8298 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
8301 getFieldValues : function(with_hidden)
8303 var items = this.getItems();
8305 items.each(function(f){
8311 var v = f.getValue();
8313 if (f.inputType =='radio') {
8314 if (typeof(ret[f.getName()]) == 'undefined') {
8315 ret[f.getName()] = ''; // empty..
8318 if (!f.el.dom.checked) {
8326 if(f.xtype == 'MoneyField'){
8327 ret[f.currencyName] = f.getCurrency();
8330 // not sure if this supported any more..
8331 if ((typeof(v) == 'object') && f.getRawValue) {
8332 v = f.getRawValue() ; // dates..
8334 // combo boxes where name != hiddenName...
8335 if (f.name !== false && f.name != '' && f.name != f.getName()) {
8336 ret[f.name] = f.getRawValue();
8338 ret[f.getName()] = v;
8345 * Clears all invalid messages in this form.
8346 * @return {BasicForm} this
8348 clearInvalid : function(){
8349 var items = this.getItems();
8351 items.each(function(f){
8360 * @return {BasicForm} this
8363 var items = this.getItems();
8364 items.each(function(f){
8368 Roo.each(this.childForms || [], function (f) {
8376 getItems : function()
8378 var r=new Roo.util.MixedCollection(false, function(o){
8379 return o.id || (o.id = Roo.id());
8381 var iter = function(el) {
8388 Roo.each(el.items,function(e) {
8397 hideFields : function(items)
8399 Roo.each(items, function(i){
8401 var f = this.findField(i);
8412 showFields : function(items)
8414 Roo.each(items, function(i){
8416 var f = this.findField(i);
8429 Roo.apply(Roo.bootstrap.Form, {
8456 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
8457 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
8458 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
8459 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
8462 this.maskEl.top.enableDisplayMode("block");
8463 this.maskEl.left.enableDisplayMode("block");
8464 this.maskEl.bottom.enableDisplayMode("block");
8465 this.maskEl.right.enableDisplayMode("block");
8467 this.toolTip = new Roo.bootstrap.Tooltip({
8468 cls : 'roo-form-error-popover',
8470 'left' : ['r-l', [-2,0], 'right'],
8471 'right' : ['l-r', [2,0], 'left'],
8472 'bottom' : ['tl-bl', [0,2], 'top'],
8473 'top' : [ 'bl-tl', [0,-2], 'bottom']
8477 this.toolTip.render(Roo.get(document.body));
8479 this.toolTip.el.enableDisplayMode("block");
8481 Roo.get(document.body).on('click', function(){
8485 Roo.get(document.body).on('touchstart', function(){
8489 this.isApplied = true
8492 mask : function(form, target)
8496 this.target = target;
8498 if(!this.form.errorMask || !target.el){
8502 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
8504 Roo.log(scrollable);
8506 var ot = this.target.el.calcOffsetsTo(scrollable);
8508 var scrollTo = ot[1] - this.form.maskOffset;
8510 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
8512 scrollable.scrollTo('top', scrollTo);
8514 var box = this.target.el.getBox();
8516 var zIndex = Roo.bootstrap.Modal.zIndex++;
8519 this.maskEl.top.setStyle('position', 'absolute');
8520 this.maskEl.top.setStyle('z-index', zIndex);
8521 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
8522 this.maskEl.top.setLeft(0);
8523 this.maskEl.top.setTop(0);
8524 this.maskEl.top.show();
8526 this.maskEl.left.setStyle('position', 'absolute');
8527 this.maskEl.left.setStyle('z-index', zIndex);
8528 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
8529 this.maskEl.left.setLeft(0);
8530 this.maskEl.left.setTop(box.y - this.padding);
8531 this.maskEl.left.show();
8533 this.maskEl.bottom.setStyle('position', 'absolute');
8534 this.maskEl.bottom.setStyle('z-index', zIndex);
8535 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
8536 this.maskEl.bottom.setLeft(0);
8537 this.maskEl.bottom.setTop(box.bottom + this.padding);
8538 this.maskEl.bottom.show();
8540 this.maskEl.right.setStyle('position', 'absolute');
8541 this.maskEl.right.setStyle('z-index', zIndex);
8542 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
8543 this.maskEl.right.setLeft(box.right + this.padding);
8544 this.maskEl.right.setTop(box.y - this.padding);
8545 this.maskEl.right.show();
8547 this.toolTip.bindEl = this.target.el;
8549 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
8551 var tip = this.target.blankText;
8553 if(this.target.getValue() !== '' ) {
8555 if (this.target.invalidText.length) {
8556 tip = this.target.invalidText;
8557 } else if (this.target.regexText.length){
8558 tip = this.target.regexText;
8562 this.toolTip.show(tip);
8564 this.intervalID = window.setInterval(function() {
8565 Roo.bootstrap.Form.popover.unmask();
8568 window.onwheel = function(){ return false;};
8570 (function(){ this.isMasked = true; }).defer(500, this);
8576 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
8580 this.maskEl.top.setStyle('position', 'absolute');
8581 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
8582 this.maskEl.top.hide();
8584 this.maskEl.left.setStyle('position', 'absolute');
8585 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
8586 this.maskEl.left.hide();
8588 this.maskEl.bottom.setStyle('position', 'absolute');
8589 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
8590 this.maskEl.bottom.hide();
8592 this.maskEl.right.setStyle('position', 'absolute');
8593 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
8594 this.maskEl.right.hide();
8596 this.toolTip.hide();
8598 this.toolTip.el.hide();
8600 window.onwheel = function(){ return true;};
8602 if(this.intervalID){
8603 window.clearInterval(this.intervalID);
8604 this.intervalID = false;
8607 this.isMasked = false;
8617 * Ext JS Library 1.1.1
8618 * Copyright(c) 2006-2007, Ext JS, LLC.
8620 * Originally Released Under LGPL - original licence link has changed is not relivant.
8623 * <script type="text/javascript">
8626 * @class Roo.form.VTypes
8627 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
8630 Roo.form.VTypes = function(){
8631 // closure these in so they are only created once.
8632 var alpha = /^[a-zA-Z_]+$/;
8633 var alphanum = /^[a-zA-Z0-9_]+$/;
8634 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
8635 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
8637 // All these messages and functions are configurable
8640 * The function used to validate email addresses
8641 * @param {String} value The email address
8643 'email' : function(v){
8644 return email.test(v);
8647 * The error text to display when the email validation function returns false
8650 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
8652 * The keystroke filter mask to be applied on email input
8655 'emailMask' : /[a-z0-9_\.\-@]/i,
8658 * The function used to validate URLs
8659 * @param {String} value The URL
8661 'url' : function(v){
8665 * The error text to display when the url validation function returns false
8668 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
8671 * The function used to validate alpha values
8672 * @param {String} value The value
8674 'alpha' : function(v){
8675 return alpha.test(v);
8678 * The error text to display when the alpha validation function returns false
8681 'alphaText' : 'This field should only contain letters and _',
8683 * The keystroke filter mask to be applied on alpha input
8686 'alphaMask' : /[a-z_]/i,
8689 * The function used to validate alphanumeric values
8690 * @param {String} value The value
8692 'alphanum' : function(v){
8693 return alphanum.test(v);
8696 * The error text to display when the alphanumeric validation function returns false
8699 'alphanumText' : 'This field should only contain letters, numbers and _',
8701 * The keystroke filter mask to be applied on alphanumeric input
8704 'alphanumMask' : /[a-z0-9_]/i
8714 * @class Roo.bootstrap.Input
8715 * @extends Roo.bootstrap.Component
8716 * Bootstrap Input class
8717 * @cfg {Boolean} disabled is it disabled
8718 * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
8719 * @cfg {String} name name of the input
8720 * @cfg {string} fieldLabel - the label associated
8721 * @cfg {string} placeholder - placeholder to put in text.
8722 * @cfg {string} before - input group add on before
8723 * @cfg {string} after - input group add on after
8724 * @cfg {string} size - (lg|sm) or leave empty..
8725 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
8726 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
8727 * @cfg {Number} md colspan out of 12 for computer-sized screens
8728 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
8729 * @cfg {string} value default value of the input
8730 * @cfg {Number} labelWidth set the width of label
8731 * @cfg {Number} labellg set the width of label (1-12)
8732 * @cfg {Number} labelmd set the width of label (1-12)
8733 * @cfg {Number} labelsm set the width of label (1-12)
8734 * @cfg {Number} labelxs set the width of label (1-12)
8735 * @cfg {String} labelAlign (top|left)
8736 * @cfg {Boolean} readOnly Specifies that the field should be read-only
8737 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8738 * @cfg {String} indicatorpos (left|right) default left
8739 * @cfg {String} capture (user|camera) use for file input only. (default empty)
8740 * @cfg {String} accept (image|video|audio) use for file input only. (default empty)
8742 * @cfg {String} align (left|center|right) Default left
8743 * @cfg {Boolean} forceFeedback (true|false) Default false
8746 * Create a new Input
8747 * @param {Object} config The config object
8750 Roo.bootstrap.Input = function(config){
8752 Roo.bootstrap.Input.superclass.constructor.call(this, config);
8757 * Fires when this field receives input focus.
8758 * @param {Roo.form.Field} this
8763 * Fires when this field loses input focus.
8764 * @param {Roo.form.Field} this
8769 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8770 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8771 * @param {Roo.form.Field} this
8772 * @param {Roo.EventObject} e The event object
8777 * Fires just before the field blurs if the field value has changed.
8778 * @param {Roo.form.Field} this
8779 * @param {Mixed} newValue The new value
8780 * @param {Mixed} oldValue The original value
8785 * Fires after the field has been marked as invalid.
8786 * @param {Roo.form.Field} this
8787 * @param {String} msg The validation message
8792 * Fires after the field has been validated with no errors.
8793 * @param {Roo.form.Field} this
8798 * Fires after the key up
8799 * @param {Roo.form.Field} this
8800 * @param {Roo.EventObject} e The event Object
8806 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component, {
8808 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8809 automatic validation (defaults to "keyup").
8811 validationEvent : "keyup",
8813 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8815 validateOnBlur : true,
8817 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
8819 validationDelay : 250,
8821 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
8823 focusClass : "x-form-focus", // not needed???
8827 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
8829 invalidClass : "has-warning",
8832 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
8834 validClass : "has-success",
8837 * @cfg {Boolean} hasFeedback (true|false) default true
8842 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8844 invalidFeedbackClass : "glyphicon-warning-sign",
8847 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8849 validFeedbackClass : "glyphicon-ok",
8852 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
8854 selectOnFocus : false,
8857 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
8861 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
8866 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
8868 disableKeyFilter : false,
8871 * @cfg {Boolean} disabled True to disable the field (defaults to false).
8875 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
8879 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
8881 blankText : "Please complete this mandatory field",
8884 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
8888 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
8890 maxLength : Number.MAX_VALUE,
8892 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
8894 minLengthText : "The minimum length for this field is {0}",
8896 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
8898 maxLengthText : "The maximum length for this field is {0}",
8902 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
8903 * If available, this function will be called only after the basic validators all return true, and will be passed the
8904 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
8908 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
8909 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
8910 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
8914 * @cfg {String} regexText -- Depricated - use Invalid Text
8919 * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
8925 autocomplete: false,
8944 formatedValue : false,
8945 forceFeedback : false,
8947 indicatorpos : 'left',
8957 parentLabelAlign : function()
8960 while (parent.parent()) {
8961 parent = parent.parent();
8962 if (typeof(parent.labelAlign) !='undefined') {
8963 return parent.labelAlign;
8970 getAutoCreate : function()
8972 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8978 if(this.inputType != 'hidden'){
8979 cfg.cls = 'form-group' //input-group
8985 type : this.inputType,
8987 cls : 'form-control',
8988 placeholder : this.placeholder || '',
8989 autocomplete : this.autocomplete || 'new-password'
8992 if(this.capture.length){
8993 input.capture = this.capture;
8996 if(this.accept.length){
8997 input.accept = this.accept + "/*";
9001 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
9004 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9005 input.maxLength = this.maxLength;
9008 if (this.disabled) {
9009 input.disabled=true;
9012 if (this.readOnly) {
9013 input.readonly=true;
9017 input.name = this.name;
9021 input.cls += ' input-' + this.size;
9025 ['xs','sm','md','lg'].map(function(size){
9026 if (settings[size]) {
9027 cfg.cls += ' col-' + size + '-' + settings[size];
9031 var inputblock = input;
9035 cls: 'glyphicon form-control-feedback'
9038 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9041 cls : 'has-feedback',
9049 if (this.before || this.after) {
9052 cls : 'input-group',
9056 if (this.before && typeof(this.before) == 'string') {
9058 inputblock.cn.push({
9060 cls : 'roo-input-before input-group-addon',
9064 if (this.before && typeof(this.before) == 'object') {
9065 this.before = Roo.factory(this.before);
9067 inputblock.cn.push({
9069 cls : 'roo-input-before input-group-' +
9070 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
9074 inputblock.cn.push(input);
9076 if (this.after && typeof(this.after) == 'string') {
9077 inputblock.cn.push({
9079 cls : 'roo-input-after input-group-addon',
9083 if (this.after && typeof(this.after) == 'object') {
9084 this.after = Roo.factory(this.after);
9086 inputblock.cn.push({
9088 cls : 'roo-input-after input-group-' +
9089 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
9093 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9094 inputblock.cls += ' has-feedback';
9095 inputblock.cn.push(feedback);
9099 if (align ==='left' && this.fieldLabel.length) {
9101 cfg.cls += ' roo-form-group-label-left';
9106 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9107 tooltip : 'This field is required'
9112 cls : 'control-label',
9113 html : this.fieldLabel
9124 var labelCfg = cfg.cn[1];
9125 var contentCfg = cfg.cn[2];
9127 if(this.indicatorpos == 'right'){
9132 cls : 'control-label',
9136 html : this.fieldLabel
9140 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9141 tooltip : 'This field is required'
9154 labelCfg = cfg.cn[0];
9155 contentCfg = cfg.cn[1];
9159 if(this.labelWidth > 12){
9160 labelCfg.style = "width: " + this.labelWidth + 'px';
9163 if(this.labelWidth < 13 && this.labelmd == 0){
9164 this.labelmd = this.labelWidth;
9167 if(this.labellg > 0){
9168 labelCfg.cls += ' col-lg-' + this.labellg;
9169 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
9172 if(this.labelmd > 0){
9173 labelCfg.cls += ' col-md-' + this.labelmd;
9174 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
9177 if(this.labelsm > 0){
9178 labelCfg.cls += ' col-sm-' + this.labelsm;
9179 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
9182 if(this.labelxs > 0){
9183 labelCfg.cls += ' col-xs-' + this.labelxs;
9184 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
9188 } else if ( this.fieldLabel.length) {
9193 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9194 tooltip : 'This field is required'
9198 //cls : 'input-group-addon',
9199 html : this.fieldLabel
9207 if(this.indicatorpos == 'right'){
9212 //cls : 'input-group-addon',
9213 html : this.fieldLabel
9218 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9219 tooltip : 'This field is required'
9239 if (this.parentType === 'Navbar' && this.parent().bar) {
9240 cfg.cls += ' navbar-form';
9243 if (this.parentType === 'NavGroup') {
9244 cfg.cls += ' navbar-form';
9252 * return the real input element.
9254 inputEl: function ()
9256 return this.el.select('input.form-control',true).first();
9259 tooltipEl : function()
9261 return this.inputEl();
9264 indicatorEl : function()
9266 var indicator = this.el.select('i.roo-required-indicator',true).first();
9276 setDisabled : function(v)
9278 var i = this.inputEl().dom;
9280 i.removeAttribute('disabled');
9284 i.setAttribute('disabled','true');
9286 initEvents : function()
9289 this.inputEl().on("keydown" , this.fireKey, this);
9290 this.inputEl().on("focus", this.onFocus, this);
9291 this.inputEl().on("blur", this.onBlur, this);
9293 this.inputEl().relayEvent('keyup', this);
9295 this.indicator = this.indicatorEl();
9298 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible'); // changed from invisible??? -
9301 // reference to original value for reset
9302 this.originalValue = this.getValue();
9303 //Roo.form.TextField.superclass.initEvents.call(this);
9304 if(this.validationEvent == 'keyup'){
9305 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
9306 this.inputEl().on('keyup', this.filterValidation, this);
9308 else if(this.validationEvent !== false){
9309 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
9312 if(this.selectOnFocus){
9313 this.on("focus", this.preFocus, this);
9316 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
9317 this.inputEl().on("keypress", this.filterKeys, this);
9319 this.inputEl().relayEvent('keypress', this);
9322 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
9323 this.el.on("click", this.autoSize, this);
9326 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
9327 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
9330 if (typeof(this.before) == 'object') {
9331 this.before.render(this.el.select('.roo-input-before',true).first());
9333 if (typeof(this.after) == 'object') {
9334 this.after.render(this.el.select('.roo-input-after',true).first());
9337 this.inputEl().on('change', this.onChange, this);
9340 filterValidation : function(e){
9341 if(!e.isNavKeyPress()){
9342 this.validationTask.delay(this.validationDelay);
9346 * Validates the field value
9347 * @return {Boolean} True if the value is valid, else false
9349 validate : function(){
9350 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
9351 if(this.disabled || this.validateValue(this.getRawValue())){
9362 * Validates a value according to the field's validation rules and marks the field as invalid
9363 * if the validation fails
9364 * @param {Mixed} value The value to validate
9365 * @return {Boolean} True if the value is valid, else false
9367 validateValue : function(value)
9369 if(this.getVisibilityEl().hasClass('hidden')){
9373 if(value.length < 1) { // if it's blank
9374 if(this.allowBlank){
9380 if(value.length < this.minLength){
9383 if(value.length > this.maxLength){
9387 var vt = Roo.form.VTypes;
9388 if(!vt[this.vtype](value, this)){
9392 if(typeof this.validator == "function"){
9393 var msg = this.validator(value);
9397 if (typeof(msg) == 'string') {
9398 this.invalidText = msg;
9402 if(this.regex && !this.regex.test(value)){
9410 fireKey : function(e){
9411 //Roo.log('field ' + e.getKey());
9412 if(e.isNavKeyPress()){
9413 this.fireEvent("specialkey", this, e);
9416 focus : function (selectText){
9418 this.inputEl().focus();
9419 if(selectText === true){
9420 this.inputEl().dom.select();
9426 onFocus : function(){
9427 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9428 // this.el.addClass(this.focusClass);
9431 this.hasFocus = true;
9432 this.startValue = this.getValue();
9433 this.fireEvent("focus", this);
9437 beforeBlur : Roo.emptyFn,
9441 onBlur : function(){
9443 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9444 //this.el.removeClass(this.focusClass);
9446 this.hasFocus = false;
9447 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
9450 var v = this.getValue();
9451 if(String(v) !== String(this.startValue)){
9452 this.fireEvent('change', this, v, this.startValue);
9454 this.fireEvent("blur", this);
9457 onChange : function(e)
9459 var v = this.getValue();
9460 if(String(v) !== String(this.startValue)){
9461 this.fireEvent('change', this, v, this.startValue);
9467 * Resets the current field value to the originally loaded value and clears any validation messages
9470 this.setValue(this.originalValue);
9474 * Returns the name of the field
9475 * @return {Mixed} name The name field
9477 getName: function(){
9481 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
9482 * @return {Mixed} value The field value
9484 getValue : function(){
9486 var v = this.inputEl().getValue();
9491 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
9492 * @return {Mixed} value The field value
9494 getRawValue : function(){
9495 var v = this.inputEl().getValue();
9501 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
9502 * @param {Mixed} value The value to set
9504 setRawValue : function(v){
9505 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9508 selectText : function(start, end){
9509 var v = this.getRawValue();
9511 start = start === undefined ? 0 : start;
9512 end = end === undefined ? v.length : end;
9513 var d = this.inputEl().dom;
9514 if(d.setSelectionRange){
9515 d.setSelectionRange(start, end);
9516 }else if(d.createTextRange){
9517 var range = d.createTextRange();
9518 range.moveStart("character", start);
9519 range.moveEnd("character", v.length-end);
9526 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
9527 * @param {Mixed} value The value to set
9529 setValue : function(v){
9532 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9538 processValue : function(value){
9539 if(this.stripCharsRe){
9540 var newValue = value.replace(this.stripCharsRe, '');
9541 if(newValue !== value){
9542 this.setRawValue(newValue);
9549 preFocus : function(){
9551 if(this.selectOnFocus){
9552 this.inputEl().dom.select();
9555 filterKeys : function(e){
9557 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
9560 var c = e.getCharCode(), cc = String.fromCharCode(c);
9561 if(Roo.isIE && (e.isSpecialKey() || !cc)){
9564 if(!this.maskRe.test(cc)){
9569 * Clear any invalid styles/messages for this field
9571 clearInvalid : function(){
9573 if(!this.el || this.preventMark){ // not rendered
9578 this.el.removeClass(this.invalidClass);
9580 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9582 var feedback = this.el.select('.form-control-feedback', true).first();
9585 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9591 this.indicator.removeClass('visible');
9592 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9595 this.fireEvent('valid', this);
9599 * Mark this field as valid
9601 markValid : function()
9603 if(!this.el || this.preventMark){ // not rendered...
9607 this.el.removeClass([this.invalidClass, this.validClass]);
9609 var feedback = this.el.select('.form-control-feedback', true).first();
9612 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9616 this.indicator.removeClass('visible');
9617 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9624 if(this.allowBlank && !this.getRawValue().length){
9628 this.el.addClass(this.validClass);
9630 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9632 var feedback = this.el.select('.form-control-feedback', true).first();
9635 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9636 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9641 this.fireEvent('valid', this);
9645 * Mark this field as invalid
9646 * @param {String} msg The validation message
9648 markInvalid : function(msg)
9650 if(!this.el || this.preventMark){ // not rendered
9654 this.el.removeClass([this.invalidClass, this.validClass]);
9656 var feedback = this.el.select('.form-control-feedback', true).first();
9659 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9666 if(this.allowBlank && !this.getRawValue().length){
9671 this.indicator.removeClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9672 this.indicator.addClass('visible');
9675 this.el.addClass(this.invalidClass);
9677 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9679 var feedback = this.el.select('.form-control-feedback', true).first();
9682 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9684 if(this.getValue().length || this.forceFeedback){
9685 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9692 this.fireEvent('invalid', this, msg);
9695 SafariOnKeyDown : function(event)
9697 // this is a workaround for a password hang bug on chrome/ webkit.
9698 if (this.inputEl().dom.type != 'password') {
9702 var isSelectAll = false;
9704 if(this.inputEl().dom.selectionEnd > 0){
9705 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
9707 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
9708 event.preventDefault();
9713 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
9715 event.preventDefault();
9716 // this is very hacky as keydown always get's upper case.
9718 var cc = String.fromCharCode(event.getCharCode());
9719 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
9723 adjustWidth : function(tag, w){
9724 tag = tag.toLowerCase();
9725 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
9726 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
9730 if(tag == 'textarea'){
9733 }else if(Roo.isOpera){
9737 if(tag == 'textarea'){
9745 setFieldLabel : function(v)
9752 var ar = this.el.select('label > span',true);
9754 if (ar.elements.length) {
9755 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9756 this.fieldLabel = v;
9760 var br = this.el.select('label',true);
9762 if(br.elements.length) {
9763 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9764 this.fieldLabel = v;
9768 Roo.log('Cannot Found any of label > span || label in input');
9772 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9773 this.fieldLabel = v;
9788 * @class Roo.bootstrap.TextArea
9789 * @extends Roo.bootstrap.Input
9790 * Bootstrap TextArea class
9791 * @cfg {Number} cols Specifies the visible width of a text area
9792 * @cfg {Number} rows Specifies the visible number of lines in a text area
9793 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
9794 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
9795 * @cfg {string} html text
9798 * Create a new TextArea
9799 * @param {Object} config The config object
9802 Roo.bootstrap.TextArea = function(config){
9803 Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
9807 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input, {
9817 getAutoCreate : function(){
9819 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
9825 if(this.inputType != 'hidden'){
9826 cfg.cls = 'form-group' //input-group
9834 value : this.value || '',
9835 html: this.html || '',
9836 cls : 'form-control',
9837 placeholder : this.placeholder || ''
9841 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9842 input.maxLength = this.maxLength;
9846 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
9850 input.cols = this.cols;
9853 if (this.readOnly) {
9854 input.readonly = true;
9858 input.name = this.name;
9862 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
9866 ['xs','sm','md','lg'].map(function(size){
9867 if (settings[size]) {
9868 cfg.cls += ' col-' + size + '-' + settings[size];
9872 var inputblock = input;
9874 if(this.hasFeedback && !this.allowBlank){
9878 cls: 'glyphicon form-control-feedback'
9882 cls : 'has-feedback',
9891 if (this.before || this.after) {
9894 cls : 'input-group',
9898 inputblock.cn.push({
9900 cls : 'input-group-addon',
9905 inputblock.cn.push(input);
9907 if(this.hasFeedback && !this.allowBlank){
9908 inputblock.cls += ' has-feedback';
9909 inputblock.cn.push(feedback);
9913 inputblock.cn.push({
9915 cls : 'input-group-addon',
9922 if (align ==='left' && this.fieldLabel.length) {
9927 cls : 'control-label',
9928 html : this.fieldLabel
9939 if(this.labelWidth > 12){
9940 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
9943 if(this.labelWidth < 13 && this.labelmd == 0){
9944 this.labelmd = this.labelWidth;
9947 if(this.labellg > 0){
9948 cfg.cn[0].cls += ' col-lg-' + this.labellg;
9949 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
9952 if(this.labelmd > 0){
9953 cfg.cn[0].cls += ' col-md-' + this.labelmd;
9954 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
9957 if(this.labelsm > 0){
9958 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
9959 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
9962 if(this.labelxs > 0){
9963 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
9964 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
9967 } else if ( this.fieldLabel.length) {
9972 //cls : 'input-group-addon',
9973 html : this.fieldLabel
9991 if (this.disabled) {
9992 input.disabled=true;
9999 * return the real textarea element.
10001 inputEl: function ()
10003 return this.el.select('textarea.form-control',true).first();
10007 * Clear any invalid styles/messages for this field
10009 clearInvalid : function()
10012 if(!this.el || this.preventMark){ // not rendered
10016 var label = this.el.select('label', true).first();
10017 var icon = this.el.select('i.fa-star', true).first();
10023 this.el.removeClass(this.invalidClass);
10025 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
10027 var feedback = this.el.select('.form-control-feedback', true).first();
10030 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
10035 this.fireEvent('valid', this);
10039 * Mark this field as valid
10041 markValid : function()
10043 if(!this.el || this.preventMark){ // not rendered
10047 this.el.removeClass([this.invalidClass, this.validClass]);
10049 var feedback = this.el.select('.form-control-feedback', true).first();
10052 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10055 if(this.disabled || this.allowBlank){
10059 var label = this.el.select('label', true).first();
10060 var icon = this.el.select('i.fa-star', true).first();
10066 this.el.addClass(this.validClass);
10068 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
10070 var feedback = this.el.select('.form-control-feedback', true).first();
10073 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10074 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
10079 this.fireEvent('valid', this);
10083 * Mark this field as invalid
10084 * @param {String} msg The validation message
10086 markInvalid : function(msg)
10088 if(!this.el || this.preventMark){ // not rendered
10092 this.el.removeClass([this.invalidClass, this.validClass]);
10094 var feedback = this.el.select('.form-control-feedback', true).first();
10097 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10100 if(this.disabled || this.allowBlank){
10104 var label = this.el.select('label', true).first();
10105 var icon = this.el.select('i.fa-star', true).first();
10107 if(!this.getValue().length && label && !icon){
10108 this.el.createChild({
10110 cls : 'text-danger fa fa-lg fa-star',
10111 tooltip : 'This field is required',
10112 style : 'margin-right:5px;'
10116 this.el.addClass(this.invalidClass);
10118 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
10120 var feedback = this.el.select('.form-control-feedback', true).first();
10123 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10125 if(this.getValue().length || this.forceFeedback){
10126 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
10133 this.fireEvent('invalid', this, msg);
10141 * trigger field - base class for combo..
10146 * @class Roo.bootstrap.TriggerField
10147 * @extends Roo.bootstrap.Input
10148 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
10149 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
10150 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
10151 * for which you can provide a custom implementation. For example:
10153 var trigger = new Roo.bootstrap.TriggerField();
10154 trigger.onTriggerClick = myTriggerFn;
10155 trigger.applyTo('my-field');
10158 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
10159 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
10160 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
10161 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
10162 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
10165 * Create a new TriggerField.
10166 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
10167 * to the base TextField)
10169 Roo.bootstrap.TriggerField = function(config){
10170 this.mimicing = false;
10171 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
10174 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
10176 * @cfg {String} triggerClass A CSS class to apply to the trigger
10179 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
10184 * @cfg {Boolean} removable (true|false) special filter default false
10188 /** @cfg {Boolean} grow @hide */
10189 /** @cfg {Number} growMin @hide */
10190 /** @cfg {Number} growMax @hide */
10196 autoSize: Roo.emptyFn,
10200 deferHeight : true,
10203 actionMode : 'wrap',
10208 getAutoCreate : function(){
10210 var align = this.labelAlign || this.parentLabelAlign();
10215 cls: 'form-group' //input-group
10222 type : this.inputType,
10223 cls : 'form-control',
10224 autocomplete: 'new-password',
10225 placeholder : this.placeholder || ''
10229 input.name = this.name;
10232 input.cls += ' input-' + this.size;
10235 if (this.disabled) {
10236 input.disabled=true;
10239 var inputblock = input;
10241 if(this.hasFeedback && !this.allowBlank){
10245 cls: 'glyphicon form-control-feedback'
10248 if(this.removable && !this.editable && !this.tickable){
10250 cls : 'has-feedback',
10256 cls : 'roo-combo-removable-btn close'
10263 cls : 'has-feedback',
10272 if(this.removable && !this.editable && !this.tickable){
10274 cls : 'roo-removable',
10280 cls : 'roo-combo-removable-btn close'
10287 if (this.before || this.after) {
10290 cls : 'input-group',
10294 inputblock.cn.push({
10296 cls : 'input-group-addon',
10301 inputblock.cn.push(input);
10303 if(this.hasFeedback && !this.allowBlank){
10304 inputblock.cls += ' has-feedback';
10305 inputblock.cn.push(feedback);
10309 inputblock.cn.push({
10311 cls : 'input-group-addon',
10324 cls: 'form-hidden-field'
10338 cls: 'form-hidden-field'
10342 cls: 'roo-select2-choices',
10346 cls: 'roo-select2-search-field',
10359 cls: 'roo-select2-container input-group',
10364 // cls: 'typeahead typeahead-long dropdown-menu',
10365 // style: 'display:none'
10370 if(!this.multiple && this.showToggleBtn){
10376 if (this.caret != false) {
10379 cls: 'fa fa-' + this.caret
10386 cls : 'input-group-addon btn dropdown-toggle',
10391 cls: 'combobox-clear',
10405 combobox.cls += ' roo-select2-container-multi';
10408 if (align ==='left' && this.fieldLabel.length) {
10410 cfg.cls += ' roo-form-group-label-left';
10415 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10416 tooltip : 'This field is required'
10421 cls : 'control-label',
10422 html : this.fieldLabel
10434 var labelCfg = cfg.cn[1];
10435 var contentCfg = cfg.cn[2];
10437 if(this.indicatorpos == 'right'){
10442 cls : 'control-label',
10446 html : this.fieldLabel
10450 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10451 tooltip : 'This field is required'
10464 labelCfg = cfg.cn[0];
10465 contentCfg = cfg.cn[1];
10468 if(this.labelWidth > 12){
10469 labelCfg.style = "width: " + this.labelWidth + 'px';
10472 if(this.labelWidth < 13 && this.labelmd == 0){
10473 this.labelmd = this.labelWidth;
10476 if(this.labellg > 0){
10477 labelCfg.cls += ' col-lg-' + this.labellg;
10478 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
10481 if(this.labelmd > 0){
10482 labelCfg.cls += ' col-md-' + this.labelmd;
10483 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
10486 if(this.labelsm > 0){
10487 labelCfg.cls += ' col-sm-' + this.labelsm;
10488 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
10491 if(this.labelxs > 0){
10492 labelCfg.cls += ' col-xs-' + this.labelxs;
10493 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
10496 } else if ( this.fieldLabel.length) {
10497 // Roo.log(" label");
10501 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10502 tooltip : 'This field is required'
10506 //cls : 'input-group-addon',
10507 html : this.fieldLabel
10515 if(this.indicatorpos == 'right'){
10523 html : this.fieldLabel
10527 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10528 tooltip : 'This field is required'
10541 // Roo.log(" no label && no align");
10548 ['xs','sm','md','lg'].map(function(size){
10549 if (settings[size]) {
10550 cfg.cls += ' col-' + size + '-' + settings[size];
10561 onResize : function(w, h){
10562 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
10563 // if(typeof w == 'number'){
10564 // var x = w - this.trigger.getWidth();
10565 // this.inputEl().setWidth(this.adjustWidth('input', x));
10566 // this.trigger.setStyle('left', x+'px');
10571 adjustSize : Roo.BoxComponent.prototype.adjustSize,
10574 getResizeEl : function(){
10575 return this.inputEl();
10579 getPositionEl : function(){
10580 return this.inputEl();
10584 alignErrorIcon : function(){
10585 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
10589 initEvents : function(){
10593 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
10594 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
10595 if(!this.multiple && this.showToggleBtn){
10596 this.trigger = this.el.select('span.dropdown-toggle',true).first();
10597 if(this.hideTrigger){
10598 this.trigger.setDisplayed(false);
10600 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
10604 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
10607 if(this.removable && !this.editable && !this.tickable){
10608 var close = this.closeTriggerEl();
10611 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
10612 close.on('click', this.removeBtnClick, this, close);
10616 //this.trigger.addClassOnOver('x-form-trigger-over');
10617 //this.trigger.addClassOnClick('x-form-trigger-click');
10620 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
10624 closeTriggerEl : function()
10626 var close = this.el.select('.roo-combo-removable-btn', true).first();
10627 return close ? close : false;
10630 removeBtnClick : function(e, h, el)
10632 e.preventDefault();
10634 if(this.fireEvent("remove", this) !== false){
10636 this.fireEvent("afterremove", this)
10640 createList : function()
10642 this.list = Roo.get(document.body).createChild({
10644 cls: 'typeahead typeahead-long dropdown-menu',
10645 style: 'display:none'
10648 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
10653 initTrigger : function(){
10658 onDestroy : function(){
10660 this.trigger.removeAllListeners();
10661 // this.trigger.remove();
10664 // this.wrap.remove();
10666 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
10670 onFocus : function(){
10671 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
10673 if(!this.mimicing){
10674 this.wrap.addClass('x-trigger-wrap-focus');
10675 this.mimicing = true;
10676 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
10677 if(this.monitorTab){
10678 this.el.on("keydown", this.checkTab, this);
10685 checkTab : function(e){
10686 if(e.getKey() == e.TAB){
10687 this.triggerBlur();
10692 onBlur : function(){
10697 mimicBlur : function(e, t){
10699 if(!this.wrap.contains(t) && this.validateBlur()){
10700 this.triggerBlur();
10706 triggerBlur : function(){
10707 this.mimicing = false;
10708 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
10709 if(this.monitorTab){
10710 this.el.un("keydown", this.checkTab, this);
10712 //this.wrap.removeClass('x-trigger-wrap-focus');
10713 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
10717 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
10718 validateBlur : function(e, t){
10723 onDisable : function(){
10724 this.inputEl().dom.disabled = true;
10725 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
10727 // this.wrap.addClass('x-item-disabled');
10732 onEnable : function(){
10733 this.inputEl().dom.disabled = false;
10734 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
10736 // this.el.removeClass('x-item-disabled');
10741 onShow : function(){
10742 var ae = this.getActionEl();
10745 ae.dom.style.display = '';
10746 ae.dom.style.visibility = 'visible';
10752 onHide : function(){
10753 var ae = this.getActionEl();
10754 ae.dom.style.display = 'none';
10758 * The function that should handle the trigger's click event. This method does nothing by default until overridden
10759 * by an implementing function.
10761 * @param {EventObject} e
10763 onTriggerClick : Roo.emptyFn
10767 * Ext JS Library 1.1.1
10768 * Copyright(c) 2006-2007, Ext JS, LLC.
10770 * Originally Released Under LGPL - original licence link has changed is not relivant.
10773 * <script type="text/javascript">
10778 * @class Roo.data.SortTypes
10780 * Defines the default sorting (casting?) comparison functions used when sorting data.
10782 Roo.data.SortTypes = {
10784 * Default sort that does nothing
10785 * @param {Mixed} s The value being converted
10786 * @return {Mixed} The comparison value
10788 none : function(s){
10793 * The regular expression used to strip tags
10797 stripTagsRE : /<\/?[^>]+>/gi,
10800 * Strips all HTML tags to sort on text only
10801 * @param {Mixed} s The value being converted
10802 * @return {String} The comparison value
10804 asText : function(s){
10805 return String(s).replace(this.stripTagsRE, "");
10809 * Strips all HTML tags to sort on text only - Case insensitive
10810 * @param {Mixed} s The value being converted
10811 * @return {String} The comparison value
10813 asUCText : function(s){
10814 return String(s).toUpperCase().replace(this.stripTagsRE, "");
10818 * Case insensitive string
10819 * @param {Mixed} s The value being converted
10820 * @return {String} The comparison value
10822 asUCString : function(s) {
10823 return String(s).toUpperCase();
10828 * @param {Mixed} s The value being converted
10829 * @return {Number} The comparison value
10831 asDate : function(s) {
10835 if(s instanceof Date){
10836 return s.getTime();
10838 return Date.parse(String(s));
10843 * @param {Mixed} s The value being converted
10844 * @return {Float} The comparison value
10846 asFloat : function(s) {
10847 var val = parseFloat(String(s).replace(/,/g, ""));
10856 * @param {Mixed} s The value being converted
10857 * @return {Number} The comparison value
10859 asInt : function(s) {
10860 var val = parseInt(String(s).replace(/,/g, ""));
10868 * Ext JS Library 1.1.1
10869 * Copyright(c) 2006-2007, Ext JS, LLC.
10871 * Originally Released Under LGPL - original licence link has changed is not relivant.
10874 * <script type="text/javascript">
10878 * @class Roo.data.Record
10879 * Instances of this class encapsulate both record <em>definition</em> information, and record
10880 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
10881 * to access Records cached in an {@link Roo.data.Store} object.<br>
10883 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
10884 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
10887 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
10889 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
10890 * {@link #create}. The parameters are the same.
10891 * @param {Array} data An associative Array of data values keyed by the field name.
10892 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
10893 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
10894 * not specified an integer id is generated.
10896 Roo.data.Record = function(data, id){
10897 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
10902 * Generate a constructor for a specific record layout.
10903 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
10904 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
10905 * Each field definition object may contain the following properties: <ul>
10906 * <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,
10907 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
10908 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
10909 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
10910 * is being used, then this is a string containing the javascript expression to reference the data relative to
10911 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
10912 * to the data item relative to the record element. If the mapping expression is the same as the field name,
10913 * this may be omitted.</p></li>
10914 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
10915 * <ul><li>auto (Default, implies no conversion)</li>
10920 * <li>date</li></ul></p></li>
10921 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
10922 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
10923 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
10924 * by the Reader into an object that will be stored in the Record. It is passed the
10925 * following parameters:<ul>
10926 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
10928 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
10930 * <br>usage:<br><pre><code>
10931 var TopicRecord = Roo.data.Record.create(
10932 {name: 'title', mapping: 'topic_title'},
10933 {name: 'author', mapping: 'username'},
10934 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
10935 {name: 'lastPost', mapping: 'post_time', type: 'date'},
10936 {name: 'lastPoster', mapping: 'user2'},
10937 {name: 'excerpt', mapping: 'post_text'}
10940 var myNewRecord = new TopicRecord({
10941 title: 'Do my job please',
10944 lastPost: new Date(),
10945 lastPoster: 'Animal',
10946 excerpt: 'No way dude!'
10948 myStore.add(myNewRecord);
10953 Roo.data.Record.create = function(o){
10954 var f = function(){
10955 f.superclass.constructor.apply(this, arguments);
10957 Roo.extend(f, Roo.data.Record);
10958 var p = f.prototype;
10959 p.fields = new Roo.util.MixedCollection(false, function(field){
10962 for(var i = 0, len = o.length; i < len; i++){
10963 p.fields.add(new Roo.data.Field(o[i]));
10965 f.getField = function(name){
10966 return p.fields.get(name);
10971 Roo.data.Record.AUTO_ID = 1000;
10972 Roo.data.Record.EDIT = 'edit';
10973 Roo.data.Record.REJECT = 'reject';
10974 Roo.data.Record.COMMIT = 'commit';
10976 Roo.data.Record.prototype = {
10978 * Readonly flag - true if this record has been modified.
10987 join : function(store){
10988 this.store = store;
10992 * Set the named field to the specified value.
10993 * @param {String} name The name of the field to set.
10994 * @param {Object} value The value to set the field to.
10996 set : function(name, value){
10997 if(this.data[name] == value){
11001 if(!this.modified){
11002 this.modified = {};
11004 if(typeof this.modified[name] == 'undefined'){
11005 this.modified[name] = this.data[name];
11007 this.data[name] = value;
11008 if(!this.editing && this.store){
11009 this.store.afterEdit(this);
11014 * Get the value of the named field.
11015 * @param {String} name The name of the field to get the value of.
11016 * @return {Object} The value of the field.
11018 get : function(name){
11019 return this.data[name];
11023 beginEdit : function(){
11024 this.editing = true;
11025 this.modified = {};
11029 cancelEdit : function(){
11030 this.editing = false;
11031 delete this.modified;
11035 endEdit : function(){
11036 this.editing = false;
11037 if(this.dirty && this.store){
11038 this.store.afterEdit(this);
11043 * Usually called by the {@link Roo.data.Store} which owns the Record.
11044 * Rejects all changes made to the Record since either creation, or the last commit operation.
11045 * Modified fields are reverted to their original values.
11047 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
11048 * of reject operations.
11050 reject : function(){
11051 var m = this.modified;
11053 if(typeof m[n] != "function"){
11054 this.data[n] = m[n];
11057 this.dirty = false;
11058 delete this.modified;
11059 this.editing = false;
11061 this.store.afterReject(this);
11066 * Usually called by the {@link Roo.data.Store} which owns the Record.
11067 * Commits all changes made to the Record since either creation, or the last commit operation.
11069 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
11070 * of commit operations.
11072 commit : function(){
11073 this.dirty = false;
11074 delete this.modified;
11075 this.editing = false;
11077 this.store.afterCommit(this);
11082 hasError : function(){
11083 return this.error != null;
11087 clearError : function(){
11092 * Creates a copy of this record.
11093 * @param {String} id (optional) A new record id if you don't want to use this record's id
11096 copy : function(newId) {
11097 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
11101 * Ext JS Library 1.1.1
11102 * Copyright(c) 2006-2007, Ext JS, LLC.
11104 * Originally Released Under LGPL - original licence link has changed is not relivant.
11107 * <script type="text/javascript">
11113 * @class Roo.data.Store
11114 * @extends Roo.util.Observable
11115 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
11116 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
11118 * 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
11119 * has no knowledge of the format of the data returned by the Proxy.<br>
11121 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
11122 * instances from the data object. These records are cached and made available through accessor functions.
11124 * Creates a new Store.
11125 * @param {Object} config A config object containing the objects needed for the Store to access data,
11126 * and read the data into Records.
11128 Roo.data.Store = function(config){
11129 this.data = new Roo.util.MixedCollection(false);
11130 this.data.getKey = function(o){
11133 this.baseParams = {};
11135 this.paramNames = {
11140 "multisort" : "_multisort"
11143 if(config && config.data){
11144 this.inlineData = config.data;
11145 delete config.data;
11148 Roo.apply(this, config);
11150 if(this.reader){ // reader passed
11151 this.reader = Roo.factory(this.reader, Roo.data);
11152 this.reader.xmodule = this.xmodule || false;
11153 if(!this.recordType){
11154 this.recordType = this.reader.recordType;
11156 if(this.reader.onMetaChange){
11157 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
11161 if(this.recordType){
11162 this.fields = this.recordType.prototype.fields;
11164 this.modified = [];
11168 * @event datachanged
11169 * Fires when the data cache has changed, and a widget which is using this Store
11170 * as a Record cache should refresh its view.
11171 * @param {Store} this
11173 datachanged : true,
11175 * @event metachange
11176 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
11177 * @param {Store} this
11178 * @param {Object} meta The JSON metadata
11183 * Fires when Records have been added to the Store
11184 * @param {Store} this
11185 * @param {Roo.data.Record[]} records The array of Records added
11186 * @param {Number} index The index at which the record(s) were added
11191 * Fires when a Record has been removed from the Store
11192 * @param {Store} this
11193 * @param {Roo.data.Record} record The Record that was removed
11194 * @param {Number} index The index at which the record was removed
11199 * Fires when a Record has been updated
11200 * @param {Store} this
11201 * @param {Roo.data.Record} record The Record that was updated
11202 * @param {String} operation The update operation being performed. Value may be one of:
11204 Roo.data.Record.EDIT
11205 Roo.data.Record.REJECT
11206 Roo.data.Record.COMMIT
11212 * Fires when the data cache has been cleared.
11213 * @param {Store} this
11217 * @event beforeload
11218 * Fires before a request is made for a new data object. If the beforeload handler returns false
11219 * the load action will be canceled.
11220 * @param {Store} this
11221 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11225 * @event beforeloadadd
11226 * Fires after a new set of Records has been loaded.
11227 * @param {Store} this
11228 * @param {Roo.data.Record[]} records The Records that were loaded
11229 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11231 beforeloadadd : true,
11234 * Fires after a new set of Records has been loaded, before they are added to the store.
11235 * @param {Store} this
11236 * @param {Roo.data.Record[]} records The Records that were loaded
11237 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11238 * @params {Object} return from reader
11242 * @event loadexception
11243 * Fires if an exception occurs in the Proxy during loading.
11244 * Called with the signature of the Proxy's "loadexception" event.
11245 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
11248 * @param {Object} return from JsonData.reader() - success, totalRecords, records
11249 * @param {Object} load options
11250 * @param {Object} jsonData from your request (normally this contains the Exception)
11252 loadexception : true
11256 this.proxy = Roo.factory(this.proxy, Roo.data);
11257 this.proxy.xmodule = this.xmodule || false;
11258 this.relayEvents(this.proxy, ["loadexception"]);
11260 this.sortToggle = {};
11261 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
11263 Roo.data.Store.superclass.constructor.call(this);
11265 if(this.inlineData){
11266 this.loadData(this.inlineData);
11267 delete this.inlineData;
11271 Roo.extend(Roo.data.Store, Roo.util.Observable, {
11273 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
11274 * without a remote query - used by combo/forms at present.
11278 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
11281 * @cfg {Array} data Inline data to be loaded when the store is initialized.
11284 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
11285 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
11288 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
11289 * on any HTTP request
11292 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
11295 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
11299 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
11300 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
11302 remoteSort : false,
11305 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
11306 * loaded or when a record is removed. (defaults to false).
11308 pruneModifiedRecords : false,
11311 lastOptions : null,
11314 * Add Records to the Store and fires the add event.
11315 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11317 add : function(records){
11318 records = [].concat(records);
11319 for(var i = 0, len = records.length; i < len; i++){
11320 records[i].join(this);
11322 var index = this.data.length;
11323 this.data.addAll(records);
11324 this.fireEvent("add", this, records, index);
11328 * Remove a Record from the Store and fires the remove event.
11329 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
11331 remove : function(record){
11332 var index = this.data.indexOf(record);
11333 this.data.removeAt(index);
11335 if(this.pruneModifiedRecords){
11336 this.modified.remove(record);
11338 this.fireEvent("remove", this, record, index);
11342 * Remove all Records from the Store and fires the clear event.
11344 removeAll : function(){
11346 if(this.pruneModifiedRecords){
11347 this.modified = [];
11349 this.fireEvent("clear", this);
11353 * Inserts Records to the Store at the given index and fires the add event.
11354 * @param {Number} index The start index at which to insert the passed Records.
11355 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11357 insert : function(index, records){
11358 records = [].concat(records);
11359 for(var i = 0, len = records.length; i < len; i++){
11360 this.data.insert(index, records[i]);
11361 records[i].join(this);
11363 this.fireEvent("add", this, records, index);
11367 * Get the index within the cache of the passed Record.
11368 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
11369 * @return {Number} The index of the passed Record. Returns -1 if not found.
11371 indexOf : function(record){
11372 return this.data.indexOf(record);
11376 * Get the index within the cache of the Record with the passed id.
11377 * @param {String} id The id of the Record to find.
11378 * @return {Number} The index of the Record. Returns -1 if not found.
11380 indexOfId : function(id){
11381 return this.data.indexOfKey(id);
11385 * Get the Record with the specified id.
11386 * @param {String} id The id of the Record to find.
11387 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
11389 getById : function(id){
11390 return this.data.key(id);
11394 * Get the Record at the specified index.
11395 * @param {Number} index The index of the Record to find.
11396 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
11398 getAt : function(index){
11399 return this.data.itemAt(index);
11403 * Returns a range of Records between specified indices.
11404 * @param {Number} startIndex (optional) The starting index (defaults to 0)
11405 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
11406 * @return {Roo.data.Record[]} An array of Records
11408 getRange : function(start, end){
11409 return this.data.getRange(start, end);
11413 storeOptions : function(o){
11414 o = Roo.apply({}, o);
11417 this.lastOptions = o;
11421 * Loads the Record cache from the configured Proxy using the configured Reader.
11423 * If using remote paging, then the first load call must specify the <em>start</em>
11424 * and <em>limit</em> properties in the options.params property to establish the initial
11425 * position within the dataset, and the number of Records to cache on each read from the Proxy.
11427 * <strong>It is important to note that for remote data sources, loading is asynchronous,
11428 * and this call will return before the new data has been loaded. Perform any post-processing
11429 * in a callback function, or in a "load" event handler.</strong>
11431 * @param {Object} options An object containing properties which control loading options:<ul>
11432 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
11433 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
11434 * passed the following arguments:<ul>
11435 * <li>r : Roo.data.Record[]</li>
11436 * <li>options: Options object from the load call</li>
11437 * <li>success: Boolean success indicator</li></ul></li>
11438 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
11439 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
11442 load : function(options){
11443 options = options || {};
11444 if(this.fireEvent("beforeload", this, options) !== false){
11445 this.storeOptions(options);
11446 var p = Roo.apply(options.params || {}, this.baseParams);
11447 // if meta was not loaded from remote source.. try requesting it.
11448 if (!this.reader.metaFromRemote) {
11449 p._requestMeta = 1;
11451 if(this.sortInfo && this.remoteSort){
11452 var pn = this.paramNames;
11453 p[pn["sort"]] = this.sortInfo.field;
11454 p[pn["dir"]] = this.sortInfo.direction;
11456 if (this.multiSort) {
11457 var pn = this.paramNames;
11458 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
11461 this.proxy.load(p, this.reader, this.loadRecords, this, options);
11466 * Reloads the Record cache from the configured Proxy using the configured Reader and
11467 * the options from the last load operation performed.
11468 * @param {Object} options (optional) An object containing properties which may override the options
11469 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
11470 * the most recently used options are reused).
11472 reload : function(options){
11473 this.load(Roo.applyIf(options||{}, this.lastOptions));
11477 // Called as a callback by the Reader during a load operation.
11478 loadRecords : function(o, options, success){
11479 if(!o || success === false){
11480 if(success !== false){
11481 this.fireEvent("load", this, [], options, o);
11483 if(options.callback){
11484 options.callback.call(options.scope || this, [], options, false);
11488 // if data returned failure - throw an exception.
11489 if (o.success === false) {
11490 // show a message if no listener is registered.
11491 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
11492 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
11494 // loadmask wil be hooked into this..
11495 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
11498 var r = o.records, t = o.totalRecords || r.length;
11500 this.fireEvent("beforeloadadd", this, r, options, o);
11502 if(!options || options.add !== true){
11503 if(this.pruneModifiedRecords){
11504 this.modified = [];
11506 for(var i = 0, len = r.length; i < len; i++){
11510 this.data = this.snapshot;
11511 delete this.snapshot;
11514 this.data.addAll(r);
11515 this.totalLength = t;
11517 this.fireEvent("datachanged", this);
11519 this.totalLength = Math.max(t, this.data.length+r.length);
11523 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
11525 var e = new Roo.data.Record({});
11527 e.set(this.parent.displayField, this.parent.emptyTitle);
11528 e.set(this.parent.valueField, '');
11533 this.fireEvent("load", this, r, options, o);
11534 if(options.callback){
11535 options.callback.call(options.scope || this, r, options, true);
11541 * Loads data from a passed data block. A Reader which understands the format of the data
11542 * must have been configured in the constructor.
11543 * @param {Object} data The data block from which to read the Records. The format of the data expected
11544 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
11545 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
11547 loadData : function(o, append){
11548 var r = this.reader.readRecords(o);
11549 this.loadRecords(r, {add: append}, true);
11553 * Gets the number of cached records.
11555 * <em>If using paging, this may not be the total size of the dataset. If the data object
11556 * used by the Reader contains the dataset size, then the getTotalCount() function returns
11557 * the data set size</em>
11559 getCount : function(){
11560 return this.data.length || 0;
11564 * Gets the total number of records in the dataset as returned by the server.
11566 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
11567 * the dataset size</em>
11569 getTotalCount : function(){
11570 return this.totalLength || 0;
11574 * Returns the sort state of the Store as an object with two properties:
11576 field {String} The name of the field by which the Records are sorted
11577 direction {String} The sort order, "ASC" or "DESC"
11580 getSortState : function(){
11581 return this.sortInfo;
11585 applySort : function(){
11586 if(this.sortInfo && !this.remoteSort){
11587 var s = this.sortInfo, f = s.field;
11588 var st = this.fields.get(f).sortType;
11589 var fn = function(r1, r2){
11590 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
11591 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
11593 this.data.sort(s.direction, fn);
11594 if(this.snapshot && this.snapshot != this.data){
11595 this.snapshot.sort(s.direction, fn);
11601 * Sets the default sort column and order to be used by the next load operation.
11602 * @param {String} fieldName The name of the field to sort by.
11603 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11605 setDefaultSort : function(field, dir){
11606 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
11610 * Sort the Records.
11611 * If remote sorting is used, the sort is performed on the server, and the cache is
11612 * reloaded. If local sorting is used, the cache is sorted internally.
11613 * @param {String} fieldName The name of the field to sort by.
11614 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11616 sort : function(fieldName, dir){
11617 var f = this.fields.get(fieldName);
11619 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
11621 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
11622 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
11627 this.sortToggle[f.name] = dir;
11628 this.sortInfo = {field: f.name, direction: dir};
11629 if(!this.remoteSort){
11631 this.fireEvent("datachanged", this);
11633 this.load(this.lastOptions);
11638 * Calls the specified function for each of the Records in the cache.
11639 * @param {Function} fn The function to call. The Record is passed as the first parameter.
11640 * Returning <em>false</em> aborts and exits the iteration.
11641 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
11643 each : function(fn, scope){
11644 this.data.each(fn, scope);
11648 * Gets all records modified since the last commit. Modified records are persisted across load operations
11649 * (e.g., during paging).
11650 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
11652 getModifiedRecords : function(){
11653 return this.modified;
11657 createFilterFn : function(property, value, anyMatch){
11658 if(!value.exec){ // not a regex
11659 value = String(value);
11660 if(value.length == 0){
11663 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
11665 return function(r){
11666 return value.test(r.data[property]);
11671 * Sums the value of <i>property</i> for each record between start and end and returns the result.
11672 * @param {String} property A field on your records
11673 * @param {Number} start The record index to start at (defaults to 0)
11674 * @param {Number} end The last record index to include (defaults to length - 1)
11675 * @return {Number} The sum
11677 sum : function(property, start, end){
11678 var rs = this.data.items, v = 0;
11679 start = start || 0;
11680 end = (end || end === 0) ? end : rs.length-1;
11682 for(var i = start; i <= end; i++){
11683 v += (rs[i].data[property] || 0);
11689 * Filter the records by a specified property.
11690 * @param {String} field A field on your records
11691 * @param {String/RegExp} value Either a string that the field
11692 * should start with or a RegExp to test against the field
11693 * @param {Boolean} anyMatch True to match any part not just the beginning
11695 filter : function(property, value, anyMatch){
11696 var fn = this.createFilterFn(property, value, anyMatch);
11697 return fn ? this.filterBy(fn) : this.clearFilter();
11701 * Filter by a function. The specified function will be called with each
11702 * record in this data source. If the function returns true the record is included,
11703 * otherwise it is filtered.
11704 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11705 * @param {Object} scope (optional) The scope of the function (defaults to this)
11707 filterBy : function(fn, scope){
11708 this.snapshot = this.snapshot || this.data;
11709 this.data = this.queryBy(fn, scope||this);
11710 this.fireEvent("datachanged", this);
11714 * Query the records by a specified property.
11715 * @param {String} field A field on your records
11716 * @param {String/RegExp} value Either a string that the field
11717 * should start with or a RegExp to test against the field
11718 * @param {Boolean} anyMatch True to match any part not just the beginning
11719 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11721 query : function(property, value, anyMatch){
11722 var fn = this.createFilterFn(property, value, anyMatch);
11723 return fn ? this.queryBy(fn) : this.data.clone();
11727 * Query by a function. The specified function will be called with each
11728 * record in this data source. If the function returns true the record is included
11730 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11731 * @param {Object} scope (optional) The scope of the function (defaults to this)
11732 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11734 queryBy : function(fn, scope){
11735 var data = this.snapshot || this.data;
11736 return data.filterBy(fn, scope||this);
11740 * Collects unique values for a particular dataIndex from this store.
11741 * @param {String} dataIndex The property to collect
11742 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
11743 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
11744 * @return {Array} An array of the unique values
11746 collect : function(dataIndex, allowNull, bypassFilter){
11747 var d = (bypassFilter === true && this.snapshot) ?
11748 this.snapshot.items : this.data.items;
11749 var v, sv, r = [], l = {};
11750 for(var i = 0, len = d.length; i < len; i++){
11751 v = d[i].data[dataIndex];
11753 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
11762 * Revert to a view of the Record cache with no filtering applied.
11763 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
11765 clearFilter : function(suppressEvent){
11766 if(this.snapshot && this.snapshot != this.data){
11767 this.data = this.snapshot;
11768 delete this.snapshot;
11769 if(suppressEvent !== true){
11770 this.fireEvent("datachanged", this);
11776 afterEdit : function(record){
11777 if(this.modified.indexOf(record) == -1){
11778 this.modified.push(record);
11780 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
11784 afterReject : function(record){
11785 this.modified.remove(record);
11786 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
11790 afterCommit : function(record){
11791 this.modified.remove(record);
11792 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
11796 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
11797 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
11799 commitChanges : function(){
11800 var m = this.modified.slice(0);
11801 this.modified = [];
11802 for(var i = 0, len = m.length; i < len; i++){
11808 * Cancel outstanding changes on all changed records.
11810 rejectChanges : function(){
11811 var m = this.modified.slice(0);
11812 this.modified = [];
11813 for(var i = 0, len = m.length; i < len; i++){
11818 onMetaChange : function(meta, rtype, o){
11819 this.recordType = rtype;
11820 this.fields = rtype.prototype.fields;
11821 delete this.snapshot;
11822 this.sortInfo = meta.sortInfo || this.sortInfo;
11823 this.modified = [];
11824 this.fireEvent('metachange', this, this.reader.meta);
11827 moveIndex : function(data, type)
11829 var index = this.indexOf(data);
11831 var newIndex = index + type;
11835 this.insert(newIndex, data);
11840 * Ext JS Library 1.1.1
11841 * Copyright(c) 2006-2007, Ext JS, LLC.
11843 * Originally Released Under LGPL - original licence link has changed is not relivant.
11846 * <script type="text/javascript">
11850 * @class Roo.data.SimpleStore
11851 * @extends Roo.data.Store
11852 * Small helper class to make creating Stores from Array data easier.
11853 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
11854 * @cfg {Array} fields An array of field definition objects, or field name strings.
11855 * @cfg {Array} data The multi-dimensional array of data
11857 * @param {Object} config
11859 Roo.data.SimpleStore = function(config){
11860 Roo.data.SimpleStore.superclass.constructor.call(this, {
11862 reader: new Roo.data.ArrayReader({
11865 Roo.data.Record.create(config.fields)
11867 proxy : new Roo.data.MemoryProxy(config.data)
11871 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
11873 * Ext JS Library 1.1.1
11874 * Copyright(c) 2006-2007, Ext JS, LLC.
11876 * Originally Released Under LGPL - original licence link has changed is not relivant.
11879 * <script type="text/javascript">
11884 * @extends Roo.data.Store
11885 * @class Roo.data.JsonStore
11886 * Small helper class to make creating Stores for JSON data easier. <br/>
11888 var store = new Roo.data.JsonStore({
11889 url: 'get-images.php',
11891 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
11894 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
11895 * JsonReader and HttpProxy (unless inline data is provided).</b>
11896 * @cfg {Array} fields An array of field definition objects, or field name strings.
11898 * @param {Object} config
11900 Roo.data.JsonStore = function(c){
11901 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
11902 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
11903 reader: new Roo.data.JsonReader(c, c.fields)
11906 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
11908 * Ext JS Library 1.1.1
11909 * Copyright(c) 2006-2007, Ext JS, LLC.
11911 * Originally Released Under LGPL - original licence link has changed is not relivant.
11914 * <script type="text/javascript">
11918 Roo.data.Field = function(config){
11919 if(typeof config == "string"){
11920 config = {name: config};
11922 Roo.apply(this, config);
11925 this.type = "auto";
11928 var st = Roo.data.SortTypes;
11929 // named sortTypes are supported, here we look them up
11930 if(typeof this.sortType == "string"){
11931 this.sortType = st[this.sortType];
11934 // set default sortType for strings and dates
11935 if(!this.sortType){
11938 this.sortType = st.asUCString;
11941 this.sortType = st.asDate;
11944 this.sortType = st.none;
11949 var stripRe = /[\$,%]/g;
11951 // prebuilt conversion function for this field, instead of
11952 // switching every time we're reading a value
11954 var cv, dateFormat = this.dateFormat;
11959 cv = function(v){ return v; };
11962 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
11966 return v !== undefined && v !== null && v !== '' ?
11967 parseInt(String(v).replace(stripRe, ""), 10) : '';
11972 return v !== undefined && v !== null && v !== '' ?
11973 parseFloat(String(v).replace(stripRe, ""), 10) : '';
11978 cv = function(v){ return v === true || v === "true" || v == 1; };
11985 if(v instanceof Date){
11989 if(dateFormat == "timestamp"){
11990 return new Date(v*1000);
11992 return Date.parseDate(v, dateFormat);
11994 var parsed = Date.parse(v);
11995 return parsed ? new Date(parsed) : null;
12004 Roo.data.Field.prototype = {
12012 * Ext JS Library 1.1.1
12013 * Copyright(c) 2006-2007, Ext JS, LLC.
12015 * Originally Released Under LGPL - original licence link has changed is not relivant.
12018 * <script type="text/javascript">
12021 // Base class for reading structured data from a data source. This class is intended to be
12022 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
12025 * @class Roo.data.DataReader
12026 * Base class for reading structured data from a data source. This class is intended to be
12027 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
12030 Roo.data.DataReader = function(meta, recordType){
12034 this.recordType = recordType instanceof Array ?
12035 Roo.data.Record.create(recordType) : recordType;
12038 Roo.data.DataReader.prototype = {
12040 * Create an empty record
12041 * @param {Object} data (optional) - overlay some values
12042 * @return {Roo.data.Record} record created.
12044 newRow : function(d) {
12046 this.recordType.prototype.fields.each(function(c) {
12048 case 'int' : da[c.name] = 0; break;
12049 case 'date' : da[c.name] = new Date(); break;
12050 case 'float' : da[c.name] = 0.0; break;
12051 case 'boolean' : da[c.name] = false; break;
12052 default : da[c.name] = ""; break;
12056 return new this.recordType(Roo.apply(da, d));
12061 * Ext JS Library 1.1.1
12062 * Copyright(c) 2006-2007, Ext JS, LLC.
12064 * Originally Released Under LGPL - original licence link has changed is not relivant.
12067 * <script type="text/javascript">
12071 * @class Roo.data.DataProxy
12072 * @extends Roo.data.Observable
12073 * This class is an abstract base class for implementations which provide retrieval of
12074 * unformatted data objects.<br>
12076 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
12077 * (of the appropriate type which knows how to parse the data object) to provide a block of
12078 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
12080 * Custom implementations must implement the load method as described in
12081 * {@link Roo.data.HttpProxy#load}.
12083 Roo.data.DataProxy = function(){
12086 * @event beforeload
12087 * Fires before a network request is made to retrieve a data object.
12088 * @param {Object} This DataProxy object.
12089 * @param {Object} params The params parameter to the load function.
12094 * Fires before the load method's callback is called.
12095 * @param {Object} This DataProxy object.
12096 * @param {Object} o The data object.
12097 * @param {Object} arg The callback argument object passed to the load function.
12101 * @event loadexception
12102 * Fires if an Exception occurs during data retrieval.
12103 * @param {Object} This DataProxy object.
12104 * @param {Object} o The data object.
12105 * @param {Object} arg The callback argument object passed to the load function.
12106 * @param {Object} e The Exception.
12108 loadexception : true
12110 Roo.data.DataProxy.superclass.constructor.call(this);
12113 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
12116 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
12120 * Ext JS Library 1.1.1
12121 * Copyright(c) 2006-2007, Ext JS, LLC.
12123 * Originally Released Under LGPL - original licence link has changed is not relivant.
12126 * <script type="text/javascript">
12129 * @class Roo.data.MemoryProxy
12130 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
12131 * to the Reader when its load method is called.
12133 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
12135 Roo.data.MemoryProxy = function(data){
12139 Roo.data.MemoryProxy.superclass.constructor.call(this);
12143 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
12146 * Load data from the requested source (in this case an in-memory
12147 * data object passed to the constructor), read the data object into
12148 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12149 * process that block using the passed callback.
12150 * @param {Object} params This parameter is not used by the MemoryProxy class.
12151 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12152 * object into a block of Roo.data.Records.
12153 * @param {Function} callback The function into which to pass the block of Roo.data.records.
12154 * The function must be passed <ul>
12155 * <li>The Record block object</li>
12156 * <li>The "arg" argument from the load function</li>
12157 * <li>A boolean success indicator</li>
12159 * @param {Object} scope The scope in which to call the callback
12160 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12162 load : function(params, reader, callback, scope, arg){
12163 params = params || {};
12166 result = reader.readRecords(this.data);
12168 this.fireEvent("loadexception", this, arg, null, e);
12169 callback.call(scope, null, arg, false);
12172 callback.call(scope, result, arg, true);
12176 update : function(params, records){
12181 * Ext JS Library 1.1.1
12182 * Copyright(c) 2006-2007, Ext JS, LLC.
12184 * Originally Released Under LGPL - original licence link has changed is not relivant.
12187 * <script type="text/javascript">
12190 * @class Roo.data.HttpProxy
12191 * @extends Roo.data.DataProxy
12192 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
12193 * configured to reference a certain URL.<br><br>
12195 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
12196 * from which the running page was served.<br><br>
12198 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
12200 * Be aware that to enable the browser to parse an XML document, the server must set
12201 * the Content-Type header in the HTTP response to "text/xml".
12203 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
12204 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
12205 * will be used to make the request.
12207 Roo.data.HttpProxy = function(conn){
12208 Roo.data.HttpProxy.superclass.constructor.call(this);
12209 // is conn a conn config or a real conn?
12211 this.useAjax = !conn || !conn.events;
12215 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
12216 // thse are take from connection...
12219 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
12222 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
12223 * extra parameters to each request made by this object. (defaults to undefined)
12226 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
12227 * to each request made by this object. (defaults to undefined)
12230 * @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)
12233 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
12236 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
12242 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
12246 * Return the {@link Roo.data.Connection} object being used by this Proxy.
12247 * @return {Connection} The Connection object. This object may be used to subscribe to events on
12248 * a finer-grained basis than the DataProxy events.
12250 getConnection : function(){
12251 return this.useAjax ? Roo.Ajax : this.conn;
12255 * Load data from the configured {@link Roo.data.Connection}, read the data object into
12256 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
12257 * process that block using the passed callback.
12258 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12259 * for the request to the remote server.
12260 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12261 * object into a block of Roo.data.Records.
12262 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12263 * The function must be passed <ul>
12264 * <li>The Record block object</li>
12265 * <li>The "arg" argument from the load function</li>
12266 * <li>A boolean success indicator</li>
12268 * @param {Object} scope The scope in which to call the callback
12269 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12271 load : function(params, reader, callback, scope, arg){
12272 if(this.fireEvent("beforeload", this, params) !== false){
12274 params : params || {},
12276 callback : callback,
12281 callback : this.loadResponse,
12285 Roo.applyIf(o, this.conn);
12286 if(this.activeRequest){
12287 Roo.Ajax.abort(this.activeRequest);
12289 this.activeRequest = Roo.Ajax.request(o);
12291 this.conn.request(o);
12294 callback.call(scope||this, null, arg, false);
12299 loadResponse : function(o, success, response){
12300 delete this.activeRequest;
12302 this.fireEvent("loadexception", this, o, response);
12303 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12308 result = o.reader.read(response);
12310 this.fireEvent("loadexception", this, o, response, e);
12311 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12315 this.fireEvent("load", this, o, o.request.arg);
12316 o.request.callback.call(o.request.scope, result, o.request.arg, true);
12320 update : function(dataSet){
12325 updateResponse : function(dataSet){
12330 * Ext JS Library 1.1.1
12331 * Copyright(c) 2006-2007, Ext JS, LLC.
12333 * Originally Released Under LGPL - original licence link has changed is not relivant.
12336 * <script type="text/javascript">
12340 * @class Roo.data.ScriptTagProxy
12341 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
12342 * other than the originating domain of the running page.<br><br>
12344 * <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
12345 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
12347 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
12348 * source code that is used as the source inside a <script> tag.<br><br>
12350 * In order for the browser to process the returned data, the server must wrap the data object
12351 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
12352 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
12353 * depending on whether the callback name was passed:
12356 boolean scriptTag = false;
12357 String cb = request.getParameter("callback");
12360 response.setContentType("text/javascript");
12362 response.setContentType("application/x-json");
12364 Writer out = response.getWriter();
12366 out.write(cb + "(");
12368 out.print(dataBlock.toJsonString());
12375 * @param {Object} config A configuration object.
12377 Roo.data.ScriptTagProxy = function(config){
12378 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
12379 Roo.apply(this, config);
12380 this.head = document.getElementsByTagName("head")[0];
12383 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
12385 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
12387 * @cfg {String} url The URL from which to request the data object.
12390 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
12394 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
12395 * the server the name of the callback function set up by the load call to process the returned data object.
12396 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
12397 * javascript output which calls this named function passing the data object as its only parameter.
12399 callbackParam : "callback",
12401 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
12402 * name to the request.
12407 * Load data from the configured URL, read the data object into
12408 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12409 * process that block using the passed callback.
12410 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12411 * for the request to the remote server.
12412 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12413 * object into a block of Roo.data.Records.
12414 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12415 * The function must be passed <ul>
12416 * <li>The Record block object</li>
12417 * <li>The "arg" argument from the load function</li>
12418 * <li>A boolean success indicator</li>
12420 * @param {Object} scope The scope in which to call the callback
12421 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12423 load : function(params, reader, callback, scope, arg){
12424 if(this.fireEvent("beforeload", this, params) !== false){
12426 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
12428 var url = this.url;
12429 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
12431 url += "&_dc=" + (new Date().getTime());
12433 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
12436 cb : "stcCallback"+transId,
12437 scriptId : "stcScript"+transId,
12441 callback : callback,
12447 window[trans.cb] = function(o){
12448 conn.handleResponse(o, trans);
12451 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
12453 if(this.autoAbort !== false){
12457 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
12459 var script = document.createElement("script");
12460 script.setAttribute("src", url);
12461 script.setAttribute("type", "text/javascript");
12462 script.setAttribute("id", trans.scriptId);
12463 this.head.appendChild(script);
12465 this.trans = trans;
12467 callback.call(scope||this, null, arg, false);
12472 isLoading : function(){
12473 return this.trans ? true : false;
12477 * Abort the current server request.
12479 abort : function(){
12480 if(this.isLoading()){
12481 this.destroyTrans(this.trans);
12486 destroyTrans : function(trans, isLoaded){
12487 this.head.removeChild(document.getElementById(trans.scriptId));
12488 clearTimeout(trans.timeoutId);
12490 window[trans.cb] = undefined;
12492 delete window[trans.cb];
12495 // if hasn't been loaded, wait for load to remove it to prevent script error
12496 window[trans.cb] = function(){
12497 window[trans.cb] = undefined;
12499 delete window[trans.cb];
12506 handleResponse : function(o, trans){
12507 this.trans = false;
12508 this.destroyTrans(trans, true);
12511 result = trans.reader.readRecords(o);
12513 this.fireEvent("loadexception", this, o, trans.arg, e);
12514 trans.callback.call(trans.scope||window, null, trans.arg, false);
12517 this.fireEvent("load", this, o, trans.arg);
12518 trans.callback.call(trans.scope||window, result, trans.arg, true);
12522 handleFailure : function(trans){
12523 this.trans = false;
12524 this.destroyTrans(trans, false);
12525 this.fireEvent("loadexception", this, null, trans.arg);
12526 trans.callback.call(trans.scope||window, null, trans.arg, false);
12530 * Ext JS Library 1.1.1
12531 * Copyright(c) 2006-2007, Ext JS, LLC.
12533 * Originally Released Under LGPL - original licence link has changed is not relivant.
12536 * <script type="text/javascript">
12540 * @class Roo.data.JsonReader
12541 * @extends Roo.data.DataReader
12542 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
12543 * based on mappings in a provided Roo.data.Record constructor.
12545 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
12546 * in the reply previously.
12551 var RecordDef = Roo.data.Record.create([
12552 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
12553 {name: 'occupation'} // This field will use "occupation" as the mapping.
12555 var myReader = new Roo.data.JsonReader({
12556 totalProperty: "results", // The property which contains the total dataset size (optional)
12557 root: "rows", // The property which contains an Array of row objects
12558 id: "id" // The property within each row object that provides an ID for the record (optional)
12562 * This would consume a JSON file like this:
12564 { 'results': 2, 'rows': [
12565 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
12566 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
12569 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
12570 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
12571 * paged from the remote server.
12572 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
12573 * @cfg {String} root name of the property which contains the Array of row objects.
12574 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
12575 * @cfg {Array} fields Array of field definition objects
12577 * Create a new JsonReader
12578 * @param {Object} meta Metadata configuration options
12579 * @param {Object} recordType Either an Array of field definition objects,
12580 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
12582 Roo.data.JsonReader = function(meta, recordType){
12585 // set some defaults:
12586 Roo.applyIf(meta, {
12587 totalProperty: 'total',
12588 successProperty : 'success',
12593 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
12595 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
12598 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
12599 * Used by Store query builder to append _requestMeta to params.
12602 metaFromRemote : false,
12604 * This method is only used by a DataProxy which has retrieved data from a remote server.
12605 * @param {Object} response The XHR object which contains the JSON data in its responseText.
12606 * @return {Object} data A data block which is used by an Roo.data.Store object as
12607 * a cache of Roo.data.Records.
12609 read : function(response){
12610 var json = response.responseText;
12612 var o = /* eval:var:o */ eval("("+json+")");
12614 throw {message: "JsonReader.read: Json object not found"};
12620 this.metaFromRemote = true;
12621 this.meta = o.metaData;
12622 this.recordType = Roo.data.Record.create(o.metaData.fields);
12623 this.onMetaChange(this.meta, this.recordType, o);
12625 return this.readRecords(o);
12628 // private function a store will implement
12629 onMetaChange : function(meta, recordType, o){
12636 simpleAccess: function(obj, subsc) {
12643 getJsonAccessor: function(){
12645 return function(expr) {
12647 return(re.test(expr))
12648 ? new Function("obj", "return obj." + expr)
12653 return Roo.emptyFn;
12658 * Create a data block containing Roo.data.Records from an XML document.
12659 * @param {Object} o An object which contains an Array of row objects in the property specified
12660 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
12661 * which contains the total size of the dataset.
12662 * @return {Object} data A data block which is used by an Roo.data.Store object as
12663 * a cache of Roo.data.Records.
12665 readRecords : function(o){
12667 * After any data loads, the raw JSON data is available for further custom processing.
12671 var s = this.meta, Record = this.recordType,
12672 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
12674 // Generate extraction functions for the totalProperty, the root, the id, and for each field
12676 if(s.totalProperty) {
12677 this.getTotal = this.getJsonAccessor(s.totalProperty);
12679 if(s.successProperty) {
12680 this.getSuccess = this.getJsonAccessor(s.successProperty);
12682 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
12684 var g = this.getJsonAccessor(s.id);
12685 this.getId = function(rec) {
12687 return (r === undefined || r === "") ? null : r;
12690 this.getId = function(){return null;};
12693 for(var jj = 0; jj < fl; jj++){
12695 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
12696 this.ef[jj] = this.getJsonAccessor(map);
12700 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
12701 if(s.totalProperty){
12702 var vt = parseInt(this.getTotal(o), 10);
12707 if(s.successProperty){
12708 var vs = this.getSuccess(o);
12709 if(vs === false || vs === 'false'){
12714 for(var i = 0; i < c; i++){
12717 var id = this.getId(n);
12718 for(var j = 0; j < fl; j++){
12720 var v = this.ef[j](n);
12722 Roo.log('missing convert for ' + f.name);
12726 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
12728 var record = new Record(values, id);
12730 records[i] = record;
12736 totalRecords : totalRecords
12741 * Ext JS Library 1.1.1
12742 * Copyright(c) 2006-2007, Ext JS, LLC.
12744 * Originally Released Under LGPL - original licence link has changed is not relivant.
12747 * <script type="text/javascript">
12751 * @class Roo.data.ArrayReader
12752 * @extends Roo.data.DataReader
12753 * Data reader class to create an Array of Roo.data.Record objects from an Array.
12754 * Each element of that Array represents a row of data fields. The
12755 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
12756 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
12760 var RecordDef = Roo.data.Record.create([
12761 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
12762 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
12764 var myReader = new Roo.data.ArrayReader({
12765 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
12769 * This would consume an Array like this:
12771 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
12773 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
12775 * Create a new JsonReader
12776 * @param {Object} meta Metadata configuration options.
12777 * @param {Object} recordType Either an Array of field definition objects
12778 * as specified to {@link Roo.data.Record#create},
12779 * or an {@link Roo.data.Record} object
12780 * created using {@link Roo.data.Record#create}.
12782 Roo.data.ArrayReader = function(meta, recordType){
12783 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
12786 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
12788 * Create a data block containing Roo.data.Records from an XML document.
12789 * @param {Object} o An Array of row objects which represents the dataset.
12790 * @return {Object} data A data block which is used by an Roo.data.Store object as
12791 * a cache of Roo.data.Records.
12793 readRecords : function(o){
12794 var sid = this.meta ? this.meta.id : null;
12795 var recordType = this.recordType, fields = recordType.prototype.fields;
12798 for(var i = 0; i < root.length; i++){
12801 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
12802 for(var j = 0, jlen = fields.length; j < jlen; j++){
12803 var f = fields.items[j];
12804 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
12805 var v = n[k] !== undefined ? n[k] : f.defaultValue;
12807 values[f.name] = v;
12809 var record = new recordType(values, id);
12811 records[records.length] = record;
12815 totalRecords : records.length
12824 * @class Roo.bootstrap.ComboBox
12825 * @extends Roo.bootstrap.TriggerField
12826 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
12827 * @cfg {Boolean} append (true|false) default false
12828 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12829 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
12830 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
12831 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
12832 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
12833 * @cfg {Boolean} animate default true
12834 * @cfg {Boolean} emptyResultText only for touch device
12835 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
12836 * @cfg {String} emptyTitle default ''
12838 * Create a new ComboBox.
12839 * @param {Object} config Configuration options
12841 Roo.bootstrap.ComboBox = function(config){
12842 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
12846 * Fires when the dropdown list is expanded
12847 * @param {Roo.bootstrap.ComboBox} combo This combo box
12852 * Fires when the dropdown list is collapsed
12853 * @param {Roo.bootstrap.ComboBox} combo This combo box
12857 * @event beforeselect
12858 * Fires before a list item is selected. Return false to cancel the selection.
12859 * @param {Roo.bootstrap.ComboBox} combo This combo box
12860 * @param {Roo.data.Record} record The data record returned from the underlying store
12861 * @param {Number} index The index of the selected item in the dropdown list
12863 'beforeselect' : true,
12866 * Fires when a list item is selected
12867 * @param {Roo.bootstrap.ComboBox} combo This combo box
12868 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
12869 * @param {Number} index The index of the selected item in the dropdown list
12873 * @event beforequery
12874 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
12875 * The event object passed has these properties:
12876 * @param {Roo.bootstrap.ComboBox} combo This combo box
12877 * @param {String} query The query
12878 * @param {Boolean} forceAll true to force "all" query
12879 * @param {Boolean} cancel true to cancel the query
12880 * @param {Object} e The query event object
12882 'beforequery': true,
12885 * Fires when the 'add' icon is pressed (add a listener to enable add button)
12886 * @param {Roo.bootstrap.ComboBox} combo This combo box
12891 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
12892 * @param {Roo.bootstrap.ComboBox} combo This combo box
12893 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
12898 * Fires when the remove value from the combobox array
12899 * @param {Roo.bootstrap.ComboBox} combo This combo box
12903 * @event afterremove
12904 * Fires when the remove value from the combobox array
12905 * @param {Roo.bootstrap.ComboBox} combo This combo box
12907 'afterremove' : true,
12909 * @event specialfilter
12910 * Fires when specialfilter
12911 * @param {Roo.bootstrap.ComboBox} combo This combo box
12913 'specialfilter' : true,
12916 * Fires when tick the element
12917 * @param {Roo.bootstrap.ComboBox} combo This combo box
12921 * @event touchviewdisplay
12922 * Fires when touch view require special display (default is using displayField)
12923 * @param {Roo.bootstrap.ComboBox} combo This combo box
12924 * @param {Object} cfg set html .
12926 'touchviewdisplay' : true
12931 this.tickItems = [];
12933 this.selectedIndex = -1;
12934 if(this.mode == 'local'){
12935 if(config.queryDelay === undefined){
12936 this.queryDelay = 10;
12938 if(config.minChars === undefined){
12944 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
12947 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
12948 * rendering into an Roo.Editor, defaults to false)
12951 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
12952 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
12955 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
12958 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
12959 * the dropdown list (defaults to undefined, with no header element)
12963 * @cfg {String/Roo.Template} tpl The template to use to render the output
12967 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
12969 listWidth: undefined,
12971 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
12972 * mode = 'remote' or 'text' if mode = 'local')
12974 displayField: undefined,
12977 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
12978 * mode = 'remote' or 'value' if mode = 'local').
12979 * Note: use of a valueField requires the user make a selection
12980 * in order for a value to be mapped.
12982 valueField: undefined,
12984 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
12989 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
12990 * field's data value (defaults to the underlying DOM element's name)
12992 hiddenName: undefined,
12994 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
12998 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
13000 selectedClass: 'active',
13003 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
13007 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
13008 * anchor positions (defaults to 'tl-bl')
13010 listAlign: 'tl-bl?',
13012 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
13016 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
13017 * query specified by the allQuery config option (defaults to 'query')
13019 triggerAction: 'query',
13021 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
13022 * (defaults to 4, does not apply if editable = false)
13026 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
13027 * delay (typeAheadDelay) if it matches a known value (defaults to false)
13031 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
13032 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
13036 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
13037 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
13041 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
13042 * when editable = true (defaults to false)
13044 selectOnFocus:false,
13046 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
13048 queryParam: 'query',
13050 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
13051 * when mode = 'remote' (defaults to 'Loading...')
13053 loadingText: 'Loading...',
13055 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
13059 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
13063 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
13064 * traditional select (defaults to true)
13068 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
13072 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
13076 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
13077 * listWidth has a higher value)
13081 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
13082 * allow the user to set arbitrary text into the field (defaults to false)
13084 forceSelection:false,
13086 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
13087 * if typeAhead = true (defaults to 250)
13089 typeAheadDelay : 250,
13091 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
13092 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
13094 valueNotFoundText : undefined,
13096 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
13098 blockFocus : false,
13101 * @cfg {Boolean} disableClear Disable showing of clear button.
13103 disableClear : false,
13105 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
13107 alwaysQuery : false,
13110 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
13115 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
13117 invalidClass : "has-warning",
13120 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
13122 validClass : "has-success",
13125 * @cfg {Boolean} specialFilter (true|false) special filter default false
13127 specialFilter : false,
13130 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
13132 mobileTouchView : true,
13135 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
13137 useNativeIOS : false,
13140 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
13142 mobile_restrict_height : false,
13144 ios_options : false,
13156 btnPosition : 'right',
13157 triggerList : true,
13158 showToggleBtn : true,
13160 emptyResultText: 'Empty',
13161 triggerText : 'Select',
13164 // element that contains real text value.. (when hidden is used..)
13166 getAutoCreate : function()
13171 * Render classic select for iso
13174 if(Roo.isIOS && this.useNativeIOS){
13175 cfg = this.getAutoCreateNativeIOS();
13183 if(Roo.isTouch && this.mobileTouchView){
13184 cfg = this.getAutoCreateTouchView();
13191 if(!this.tickable){
13192 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
13197 * ComboBox with tickable selections
13200 var align = this.labelAlign || this.parentLabelAlign();
13203 cls : 'form-group roo-combobox-tickable' //input-group
13206 var btn_text_select = '';
13207 var btn_text_done = '';
13208 var btn_text_cancel = '';
13210 if (this.btn_text_show) {
13211 btn_text_select = 'Select';
13212 btn_text_done = 'Done';
13213 btn_text_cancel = 'Cancel';
13218 cls : 'tickable-buttons',
13223 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
13224 //html : this.triggerText
13225 html: btn_text_select
13231 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
13233 html: btn_text_done
13239 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
13241 html: btn_text_cancel
13247 buttons.cn.unshift({
13249 cls: 'roo-select2-search-field-input'
13255 Roo.each(buttons.cn, function(c){
13257 c.cls += ' btn-' + _this.size;
13260 if (_this.disabled) {
13271 cls: 'form-hidden-field'
13275 cls: 'roo-select2-choices',
13279 cls: 'roo-select2-search-field',
13290 cls: 'roo-select2-container input-group roo-select2-container-multi',
13295 // cls: 'typeahead typeahead-long dropdown-menu',
13296 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
13301 if(this.hasFeedback && !this.allowBlank){
13305 cls: 'glyphicon form-control-feedback'
13308 combobox.cn.push(feedback);
13312 if (align ==='left' && this.fieldLabel.length) {
13314 cfg.cls += ' roo-form-group-label-left';
13319 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13320 tooltip : 'This field is required'
13325 cls : 'control-label',
13326 html : this.fieldLabel
13338 var labelCfg = cfg.cn[1];
13339 var contentCfg = cfg.cn[2];
13342 if(this.indicatorpos == 'right'){
13348 cls : 'control-label',
13352 html : this.fieldLabel
13356 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13357 tooltip : 'This field is required'
13372 labelCfg = cfg.cn[0];
13373 contentCfg = cfg.cn[1];
13377 if(this.labelWidth > 12){
13378 labelCfg.style = "width: " + this.labelWidth + 'px';
13381 if(this.labelWidth < 13 && this.labelmd == 0){
13382 this.labelmd = this.labelWidth;
13385 if(this.labellg > 0){
13386 labelCfg.cls += ' col-lg-' + this.labellg;
13387 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
13390 if(this.labelmd > 0){
13391 labelCfg.cls += ' col-md-' + this.labelmd;
13392 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
13395 if(this.labelsm > 0){
13396 labelCfg.cls += ' col-sm-' + this.labelsm;
13397 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
13400 if(this.labelxs > 0){
13401 labelCfg.cls += ' col-xs-' + this.labelxs;
13402 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
13406 } else if ( this.fieldLabel.length) {
13407 // Roo.log(" label");
13411 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13412 tooltip : 'This field is required'
13416 //cls : 'input-group-addon',
13417 html : this.fieldLabel
13422 if(this.indicatorpos == 'right'){
13426 //cls : 'input-group-addon',
13427 html : this.fieldLabel
13431 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13432 tooltip : 'This field is required'
13441 // Roo.log(" no label && no align");
13448 ['xs','sm','md','lg'].map(function(size){
13449 if (settings[size]) {
13450 cfg.cls += ' col-' + size + '-' + settings[size];
13458 _initEventsCalled : false,
13461 initEvents: function()
13463 if (this._initEventsCalled) { // as we call render... prevent looping...
13466 this._initEventsCalled = true;
13469 throw "can not find store for combo";
13472 this.indicator = this.indicatorEl();
13474 this.store = Roo.factory(this.store, Roo.data);
13475 this.store.parent = this;
13477 // if we are building from html. then this element is so complex, that we can not really
13478 // use the rendered HTML.
13479 // so we have to trash and replace the previous code.
13480 if (Roo.XComponent.build_from_html) {
13481 // remove this element....
13482 var e = this.el.dom, k=0;
13483 while (e ) { e = e.previousSibling; ++k;}
13488 this.rendered = false;
13490 this.render(this.parent().getChildContainer(true), k);
13493 if(Roo.isIOS && this.useNativeIOS){
13494 this.initIOSView();
13502 if(Roo.isTouch && this.mobileTouchView){
13503 this.initTouchView();
13508 this.initTickableEvents();
13512 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
13514 if(this.hiddenName){
13516 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13518 this.hiddenField.dom.value =
13519 this.hiddenValue !== undefined ? this.hiddenValue :
13520 this.value !== undefined ? this.value : '';
13522 // prevent input submission
13523 this.el.dom.removeAttribute('name');
13524 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13529 // this.el.dom.setAttribute('autocomplete', 'off');
13532 var cls = 'x-combo-list';
13534 //this.list = new Roo.Layer({
13535 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
13541 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13542 _this.list.setWidth(lw);
13545 this.list.on('mouseover', this.onViewOver, this);
13546 this.list.on('mousemove', this.onViewMove, this);
13547 this.list.on('scroll', this.onViewScroll, this);
13550 this.list.swallowEvent('mousewheel');
13551 this.assetHeight = 0;
13554 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
13555 this.assetHeight += this.header.getHeight();
13558 this.innerList = this.list.createChild({cls:cls+'-inner'});
13559 this.innerList.on('mouseover', this.onViewOver, this);
13560 this.innerList.on('mousemove', this.onViewMove, this);
13561 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13563 if(this.allowBlank && !this.pageSize && !this.disableClear){
13564 this.footer = this.list.createChild({cls:cls+'-ft'});
13565 this.pageTb = new Roo.Toolbar(this.footer);
13569 this.footer = this.list.createChild({cls:cls+'-ft'});
13570 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
13571 {pageSize: this.pageSize});
13575 if (this.pageTb && this.allowBlank && !this.disableClear) {
13577 this.pageTb.add(new Roo.Toolbar.Fill(), {
13578 cls: 'x-btn-icon x-btn-clear',
13580 handler: function()
13583 _this.clearValue();
13584 _this.onSelect(false, -1);
13589 this.assetHeight += this.footer.getHeight();
13594 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
13597 this.view = new Roo.View(this.list, this.tpl, {
13598 singleSelect:true, store: this.store, selectedClass: this.selectedClass
13600 //this.view.wrapEl.setDisplayed(false);
13601 this.view.on('click', this.onViewClick, this);
13604 this.store.on('beforeload', this.onBeforeLoad, this);
13605 this.store.on('load', this.onLoad, this);
13606 this.store.on('loadexception', this.onLoadException, this);
13608 if(this.resizable){
13609 this.resizer = new Roo.Resizable(this.list, {
13610 pinned:true, handles:'se'
13612 this.resizer.on('resize', function(r, w, h){
13613 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
13614 this.listWidth = w;
13615 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
13616 this.restrictHeight();
13618 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
13621 if(!this.editable){
13622 this.editable = true;
13623 this.setEditable(false);
13628 if (typeof(this.events.add.listeners) != 'undefined') {
13630 this.addicon = this.wrap.createChild(
13631 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
13633 this.addicon.on('click', function(e) {
13634 this.fireEvent('add', this);
13637 if (typeof(this.events.edit.listeners) != 'undefined') {
13639 this.editicon = this.wrap.createChild(
13640 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
13641 if (this.addicon) {
13642 this.editicon.setStyle('margin-left', '40px');
13644 this.editicon.on('click', function(e) {
13646 // we fire even if inothing is selected..
13647 this.fireEvent('edit', this, this.lastData );
13653 this.keyNav = new Roo.KeyNav(this.inputEl(), {
13654 "up" : function(e){
13655 this.inKeyMode = true;
13659 "down" : function(e){
13660 if(!this.isExpanded()){
13661 this.onTriggerClick();
13663 this.inKeyMode = true;
13668 "enter" : function(e){
13669 // this.onViewClick();
13673 if(this.fireEvent("specialkey", this, e)){
13674 this.onViewClick(false);
13680 "esc" : function(e){
13684 "tab" : function(e){
13687 if(this.fireEvent("specialkey", this, e)){
13688 this.onViewClick(false);
13696 doRelay : function(foo, bar, hname){
13697 if(hname == 'down' || this.scope.isExpanded()){
13698 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13707 this.queryDelay = Math.max(this.queryDelay || 10,
13708 this.mode == 'local' ? 10 : 250);
13711 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13713 if(this.typeAhead){
13714 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13716 if(this.editable !== false){
13717 this.inputEl().on("keyup", this.onKeyUp, this);
13719 if(this.forceSelection){
13720 this.inputEl().on('blur', this.doForce, this);
13724 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13725 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13729 initTickableEvents: function()
13733 if(this.hiddenName){
13735 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13737 this.hiddenField.dom.value =
13738 this.hiddenValue !== undefined ? this.hiddenValue :
13739 this.value !== undefined ? this.value : '';
13741 // prevent input submission
13742 this.el.dom.removeAttribute('name');
13743 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13748 // this.list = this.el.select('ul.dropdown-menu',true).first();
13750 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13751 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13752 if(this.triggerList){
13753 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
13756 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
13757 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
13759 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
13760 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
13762 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
13763 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
13765 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
13766 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
13767 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
13770 this.cancelBtn.hide();
13775 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13776 _this.list.setWidth(lw);
13779 this.list.on('mouseover', this.onViewOver, this);
13780 this.list.on('mousemove', this.onViewMove, this);
13782 this.list.on('scroll', this.onViewScroll, this);
13785 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
13786 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
13789 this.view = new Roo.View(this.list, this.tpl, {
13794 selectedClass: this.selectedClass
13797 //this.view.wrapEl.setDisplayed(false);
13798 this.view.on('click', this.onViewClick, this);
13802 this.store.on('beforeload', this.onBeforeLoad, this);
13803 this.store.on('load', this.onLoad, this);
13804 this.store.on('loadexception', this.onLoadException, this);
13807 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
13808 "up" : function(e){
13809 this.inKeyMode = true;
13813 "down" : function(e){
13814 this.inKeyMode = true;
13818 "enter" : function(e){
13819 if(this.fireEvent("specialkey", this, e)){
13820 this.onViewClick(false);
13826 "esc" : function(e){
13827 this.onTickableFooterButtonClick(e, false, false);
13830 "tab" : function(e){
13831 this.fireEvent("specialkey", this, e);
13833 this.onTickableFooterButtonClick(e, false, false);
13840 doRelay : function(e, fn, key){
13841 if(this.scope.isExpanded()){
13842 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13851 this.queryDelay = Math.max(this.queryDelay || 10,
13852 this.mode == 'local' ? 10 : 250);
13855 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13857 if(this.typeAhead){
13858 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13861 if(this.editable !== false){
13862 this.tickableInputEl().on("keyup", this.onKeyUp, this);
13865 this.indicator = this.indicatorEl();
13867 if(this.indicator){
13868 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
13869 this.indicator.hide();
13874 onDestroy : function(){
13876 this.view.setStore(null);
13877 this.view.el.removeAllListeners();
13878 this.view.el.remove();
13879 this.view.purgeListeners();
13882 this.list.dom.innerHTML = '';
13886 this.store.un('beforeload', this.onBeforeLoad, this);
13887 this.store.un('load', this.onLoad, this);
13888 this.store.un('loadexception', this.onLoadException, this);
13890 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
13894 fireKey : function(e){
13895 if(e.isNavKeyPress() && !this.list.isVisible()){
13896 this.fireEvent("specialkey", this, e);
13901 onResize: function(w, h){
13902 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
13904 // if(typeof w != 'number'){
13905 // // we do not handle it!?!?
13908 // var tw = this.trigger.getWidth();
13909 // // tw += this.addicon ? this.addicon.getWidth() : 0;
13910 // // tw += this.editicon ? this.editicon.getWidth() : 0;
13912 // this.inputEl().setWidth( this.adjustWidth('input', x));
13914 // //this.trigger.setStyle('left', x+'px');
13916 // if(this.list && this.listWidth === undefined){
13917 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
13918 // this.list.setWidth(lw);
13919 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13927 * Allow or prevent the user from directly editing the field text. If false is passed,
13928 * the user will only be able to select from the items defined in the dropdown list. This method
13929 * is the runtime equivalent of setting the 'editable' config option at config time.
13930 * @param {Boolean} value True to allow the user to directly edit the field text
13932 setEditable : function(value){
13933 if(value == this.editable){
13936 this.editable = value;
13938 this.inputEl().dom.setAttribute('readOnly', true);
13939 this.inputEl().on('mousedown', this.onTriggerClick, this);
13940 this.inputEl().addClass('x-combo-noedit');
13942 this.inputEl().dom.setAttribute('readOnly', false);
13943 this.inputEl().un('mousedown', this.onTriggerClick, this);
13944 this.inputEl().removeClass('x-combo-noedit');
13950 onBeforeLoad : function(combo,opts){
13951 if(!this.hasFocus){
13955 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
13957 this.restrictHeight();
13958 this.selectedIndex = -1;
13962 onLoad : function(){
13964 this.hasQuery = false;
13966 if(!this.hasFocus){
13970 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13971 this.loading.hide();
13974 if(this.store.getCount() > 0){
13977 this.restrictHeight();
13978 if(this.lastQuery == this.allQuery){
13979 if(this.editable && !this.tickable){
13980 this.inputEl().dom.select();
13984 !this.selectByValue(this.value, true) &&
13987 !this.store.lastOptions ||
13988 typeof(this.store.lastOptions.add) == 'undefined' ||
13989 this.store.lastOptions.add != true
13992 this.select(0, true);
13995 if(this.autoFocus){
13998 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
13999 this.taTask.delay(this.typeAheadDelay);
14003 this.onEmptyResults();
14009 onLoadException : function()
14011 this.hasQuery = false;
14013 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
14014 this.loading.hide();
14017 if(this.tickable && this.editable){
14022 // only causes errors at present
14023 //Roo.log(this.store.reader.jsonData);
14024 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
14026 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
14032 onTypeAhead : function(){
14033 if(this.store.getCount() > 0){
14034 var r = this.store.getAt(0);
14035 var newValue = r.data[this.displayField];
14036 var len = newValue.length;
14037 var selStart = this.getRawValue().length;
14039 if(selStart != len){
14040 this.setRawValue(newValue);
14041 this.selectText(selStart, newValue.length);
14047 onSelect : function(record, index){
14049 if(this.fireEvent('beforeselect', this, record, index) !== false){
14051 this.setFromData(index > -1 ? record.data : false);
14054 this.fireEvent('select', this, record, index);
14059 * Returns the currently selected field value or empty string if no value is set.
14060 * @return {String} value The selected value
14062 getValue : function()
14064 if(Roo.isIOS && this.useNativeIOS){
14065 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
14069 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
14072 if(this.valueField){
14073 return typeof this.value != 'undefined' ? this.value : '';
14075 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
14079 getRawValue : function()
14081 if(Roo.isIOS && this.useNativeIOS){
14082 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
14085 var v = this.inputEl().getValue();
14091 * Clears any text/value currently set in the field
14093 clearValue : function(){
14095 if(this.hiddenField){
14096 this.hiddenField.dom.value = '';
14099 this.setRawValue('');
14100 this.lastSelectionText = '';
14101 this.lastData = false;
14103 var close = this.closeTriggerEl();
14114 * Sets the specified value into the field. If the value finds a match, the corresponding record text
14115 * will be displayed in the field. If the value does not match the data value of an existing item,
14116 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
14117 * Otherwise the field will be blank (although the value will still be set).
14118 * @param {String} value The value to match
14120 setValue : function(v)
14122 if(Roo.isIOS && this.useNativeIOS){
14123 this.setIOSValue(v);
14133 if(this.valueField){
14134 var r = this.findRecord(this.valueField, v);
14136 text = r.data[this.displayField];
14137 }else if(this.valueNotFoundText !== undefined){
14138 text = this.valueNotFoundText;
14141 this.lastSelectionText = text;
14142 if(this.hiddenField){
14143 this.hiddenField.dom.value = v;
14145 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
14148 var close = this.closeTriggerEl();
14151 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
14157 * @property {Object} the last set data for the element
14162 * Sets the value of the field based on a object which is related to the record format for the store.
14163 * @param {Object} value the value to set as. or false on reset?
14165 setFromData : function(o){
14172 var dv = ''; // display value
14173 var vv = ''; // value value..
14175 if (this.displayField) {
14176 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14178 // this is an error condition!!!
14179 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14182 if(this.valueField){
14183 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
14186 var close = this.closeTriggerEl();
14189 if(dv.length || vv * 1 > 0){
14191 this.blockFocus=true;
14197 if(this.hiddenField){
14198 this.hiddenField.dom.value = vv;
14200 this.lastSelectionText = dv;
14201 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14205 // no hidden field.. - we store the value in 'value', but still display
14206 // display field!!!!
14207 this.lastSelectionText = dv;
14208 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14215 reset : function(){
14216 // overridden so that last data is reset..
14223 this.setValue(this.originalValue);
14224 //this.clearInvalid();
14225 this.lastData = false;
14227 this.view.clearSelections();
14233 findRecord : function(prop, value){
14235 if(this.store.getCount() > 0){
14236 this.store.each(function(r){
14237 if(r.data[prop] == value){
14247 getName: function()
14249 // returns hidden if it's set..
14250 if (!this.rendered) {return ''};
14251 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
14255 onViewMove : function(e, t){
14256 this.inKeyMode = false;
14260 onViewOver : function(e, t){
14261 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
14264 var item = this.view.findItemFromChild(t);
14267 var index = this.view.indexOf(item);
14268 this.select(index, false);
14273 onViewClick : function(view, doFocus, el, e)
14275 var index = this.view.getSelectedIndexes()[0];
14277 var r = this.store.getAt(index);
14281 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
14288 Roo.each(this.tickItems, function(v,k){
14290 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
14292 _this.tickItems.splice(k, 1);
14294 if(typeof(e) == 'undefined' && view == false){
14295 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
14307 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
14308 this.tickItems.push(r.data);
14311 if(typeof(e) == 'undefined' && view == false){
14312 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
14319 this.onSelect(r, index);
14321 if(doFocus !== false && !this.blockFocus){
14322 this.inputEl().focus();
14327 restrictHeight : function(){
14328 //this.innerList.dom.style.height = '';
14329 //var inner = this.innerList.dom;
14330 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
14331 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
14332 //this.list.beginUpdate();
14333 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
14334 this.list.alignTo(this.inputEl(), this.listAlign);
14335 this.list.alignTo(this.inputEl(), this.listAlign);
14336 //this.list.endUpdate();
14340 onEmptyResults : function(){
14342 if(this.tickable && this.editable){
14343 this.hasFocus = false;
14344 this.restrictHeight();
14352 * Returns true if the dropdown list is expanded, else false.
14354 isExpanded : function(){
14355 return this.list.isVisible();
14359 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
14360 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14361 * @param {String} value The data value of the item to select
14362 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14363 * selected item if it is not currently in view (defaults to true)
14364 * @return {Boolean} True if the value matched an item in the list, else false
14366 selectByValue : function(v, scrollIntoView){
14367 if(v !== undefined && v !== null){
14368 var r = this.findRecord(this.valueField || this.displayField, v);
14370 this.select(this.store.indexOf(r), scrollIntoView);
14378 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
14379 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14380 * @param {Number} index The zero-based index of the list item to select
14381 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14382 * selected item if it is not currently in view (defaults to true)
14384 select : function(index, scrollIntoView){
14385 this.selectedIndex = index;
14386 this.view.select(index);
14387 if(scrollIntoView !== false){
14388 var el = this.view.getNode(index);
14390 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
14393 this.list.scrollChildIntoView(el, false);
14399 selectNext : function(){
14400 var ct = this.store.getCount();
14402 if(this.selectedIndex == -1){
14404 }else if(this.selectedIndex < ct-1){
14405 this.select(this.selectedIndex+1);
14411 selectPrev : function(){
14412 var ct = this.store.getCount();
14414 if(this.selectedIndex == -1){
14416 }else if(this.selectedIndex != 0){
14417 this.select(this.selectedIndex-1);
14423 onKeyUp : function(e){
14424 if(this.editable !== false && !e.isSpecialKey()){
14425 this.lastKey = e.getKey();
14426 this.dqTask.delay(this.queryDelay);
14431 validateBlur : function(){
14432 return !this.list || !this.list.isVisible();
14436 initQuery : function(){
14438 var v = this.getRawValue();
14440 if(this.tickable && this.editable){
14441 v = this.tickableInputEl().getValue();
14448 doForce : function(){
14449 if(this.inputEl().dom.value.length > 0){
14450 this.inputEl().dom.value =
14451 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
14457 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
14458 * query allowing the query action to be canceled if needed.
14459 * @param {String} query The SQL query to execute
14460 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
14461 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
14462 * saved in the current store (defaults to false)
14464 doQuery : function(q, forceAll){
14466 if(q === undefined || q === null){
14471 forceAll: forceAll,
14475 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
14480 forceAll = qe.forceAll;
14481 if(forceAll === true || (q.length >= this.minChars)){
14483 this.hasQuery = true;
14485 if(this.lastQuery != q || this.alwaysQuery){
14486 this.lastQuery = q;
14487 if(this.mode == 'local'){
14488 this.selectedIndex = -1;
14490 this.store.clearFilter();
14493 if(this.specialFilter){
14494 this.fireEvent('specialfilter', this);
14499 this.store.filter(this.displayField, q);
14502 this.store.fireEvent("datachanged", this.store);
14509 this.store.baseParams[this.queryParam] = q;
14511 var options = {params : this.getParams(q)};
14514 options.add = true;
14515 options.params.start = this.page * this.pageSize;
14518 this.store.load(options);
14521 * this code will make the page width larger, at the beginning, the list not align correctly,
14522 * we should expand the list on onLoad
14523 * so command out it
14528 this.selectedIndex = -1;
14533 this.loadNext = false;
14537 getParams : function(q){
14539 //p[this.queryParam] = q;
14543 p.limit = this.pageSize;
14549 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
14551 collapse : function(){
14552 if(!this.isExpanded()){
14558 this.hasFocus = false;
14562 this.cancelBtn.hide();
14563 this.trigger.show();
14566 this.tickableInputEl().dom.value = '';
14567 this.tickableInputEl().blur();
14572 Roo.get(document).un('mousedown', this.collapseIf, this);
14573 Roo.get(document).un('mousewheel', this.collapseIf, this);
14574 if (!this.editable) {
14575 Roo.get(document).un('keydown', this.listKeyPress, this);
14577 this.fireEvent('collapse', this);
14583 collapseIf : function(e){
14584 var in_combo = e.within(this.el);
14585 var in_list = e.within(this.list);
14586 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
14588 if (in_combo || in_list || is_list) {
14589 //e.stopPropagation();
14594 this.onTickableFooterButtonClick(e, false, false);
14602 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
14604 expand : function(){
14606 if(this.isExpanded() || !this.hasFocus){
14610 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
14611 this.list.setWidth(lw);
14617 this.restrictHeight();
14621 this.tickItems = Roo.apply([], this.item);
14624 this.cancelBtn.show();
14625 this.trigger.hide();
14628 this.tickableInputEl().focus();
14633 Roo.get(document).on('mousedown', this.collapseIf, this);
14634 Roo.get(document).on('mousewheel', this.collapseIf, this);
14635 if (!this.editable) {
14636 Roo.get(document).on('keydown', this.listKeyPress, this);
14639 this.fireEvent('expand', this);
14643 // Implements the default empty TriggerField.onTriggerClick function
14644 onTriggerClick : function(e)
14646 Roo.log('trigger click');
14648 if(this.disabled || !this.triggerList){
14653 this.loadNext = false;
14655 if(this.isExpanded()){
14657 if (!this.blockFocus) {
14658 this.inputEl().focus();
14662 this.hasFocus = true;
14663 if(this.triggerAction == 'all') {
14664 this.doQuery(this.allQuery, true);
14666 this.doQuery(this.getRawValue());
14668 if (!this.blockFocus) {
14669 this.inputEl().focus();
14674 onTickableTriggerClick : function(e)
14681 this.loadNext = false;
14682 this.hasFocus = true;
14684 if(this.triggerAction == 'all') {
14685 this.doQuery(this.allQuery, true);
14687 this.doQuery(this.getRawValue());
14691 onSearchFieldClick : function(e)
14693 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
14694 this.onTickableFooterButtonClick(e, false, false);
14698 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
14703 this.loadNext = false;
14704 this.hasFocus = true;
14706 if(this.triggerAction == 'all') {
14707 this.doQuery(this.allQuery, true);
14709 this.doQuery(this.getRawValue());
14713 listKeyPress : function(e)
14715 //Roo.log('listkeypress');
14716 // scroll to first matching element based on key pres..
14717 if (e.isSpecialKey()) {
14720 var k = String.fromCharCode(e.getKey()).toUpperCase();
14723 var csel = this.view.getSelectedNodes();
14724 var cselitem = false;
14726 var ix = this.view.indexOf(csel[0]);
14727 cselitem = this.store.getAt(ix);
14728 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
14734 this.store.each(function(v) {
14736 // start at existing selection.
14737 if (cselitem.id == v.id) {
14743 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
14744 match = this.store.indexOf(v);
14750 if (match === false) {
14751 return true; // no more action?
14754 this.view.select(match);
14755 var sn = Roo.get(this.view.getSelectedNodes()[0]);
14756 sn.scrollIntoView(sn.dom.parentNode, false);
14759 onViewScroll : function(e, t){
14761 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){
14765 this.hasQuery = true;
14767 this.loading = this.list.select('.loading', true).first();
14769 if(this.loading === null){
14770 this.list.createChild({
14772 cls: 'loading roo-select2-more-results roo-select2-active',
14773 html: 'Loading more results...'
14776 this.loading = this.list.select('.loading', true).first();
14778 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
14780 this.loading.hide();
14783 this.loading.show();
14788 this.loadNext = true;
14790 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
14795 addItem : function(o)
14797 var dv = ''; // display value
14799 if (this.displayField) {
14800 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14802 // this is an error condition!!!
14803 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14810 var choice = this.choices.createChild({
14812 cls: 'roo-select2-search-choice',
14821 cls: 'roo-select2-search-choice-close fa fa-times',
14826 }, this.searchField);
14828 var close = choice.select('a.roo-select2-search-choice-close', true).first();
14830 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
14838 this.inputEl().dom.value = '';
14843 onRemoveItem : function(e, _self, o)
14845 e.preventDefault();
14847 this.lastItem = Roo.apply([], this.item);
14849 var index = this.item.indexOf(o.data) * 1;
14852 Roo.log('not this item?!');
14856 this.item.splice(index, 1);
14861 this.fireEvent('remove', this, e);
14867 syncValue : function()
14869 if(!this.item.length){
14876 Roo.each(this.item, function(i){
14877 if(_this.valueField){
14878 value.push(i[_this.valueField]);
14885 this.value = value.join(',');
14887 if(this.hiddenField){
14888 this.hiddenField.dom.value = this.value;
14891 this.store.fireEvent("datachanged", this.store);
14896 clearItem : function()
14898 if(!this.multiple){
14904 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
14912 if(this.tickable && !Roo.isTouch){
14913 this.view.refresh();
14917 inputEl: function ()
14919 if(Roo.isIOS && this.useNativeIOS){
14920 return this.el.select('select.roo-ios-select', true).first();
14923 if(Roo.isTouch && this.mobileTouchView){
14924 return this.el.select('input.form-control',true).first();
14928 return this.searchField;
14931 return this.el.select('input.form-control',true).first();
14934 onTickableFooterButtonClick : function(e, btn, el)
14936 e.preventDefault();
14938 this.lastItem = Roo.apply([], this.item);
14940 if(btn && btn.name == 'cancel'){
14941 this.tickItems = Roo.apply([], this.item);
14950 Roo.each(this.tickItems, function(o){
14958 validate : function()
14960 if(this.getVisibilityEl().hasClass('hidden')){
14964 var v = this.getRawValue();
14967 v = this.getValue();
14970 if(this.disabled || this.allowBlank || v.length){
14975 this.markInvalid();
14979 tickableInputEl : function()
14981 if(!this.tickable || !this.editable){
14982 return this.inputEl();
14985 return this.inputEl().select('.roo-select2-search-field-input', true).first();
14989 getAutoCreateTouchView : function()
14994 cls: 'form-group' //input-group
15000 type : this.inputType,
15001 cls : 'form-control x-combo-noedit',
15002 autocomplete: 'new-password',
15003 placeholder : this.placeholder || '',
15008 input.name = this.name;
15012 input.cls += ' input-' + this.size;
15015 if (this.disabled) {
15016 input.disabled = true;
15027 inputblock.cls += ' input-group';
15029 inputblock.cn.unshift({
15031 cls : 'input-group-addon',
15036 if(this.removable && !this.multiple){
15037 inputblock.cls += ' roo-removable';
15039 inputblock.cn.push({
15042 cls : 'roo-combo-removable-btn close'
15046 if(this.hasFeedback && !this.allowBlank){
15048 inputblock.cls += ' has-feedback';
15050 inputblock.cn.push({
15052 cls: 'glyphicon form-control-feedback'
15059 inputblock.cls += (this.before) ? '' : ' input-group';
15061 inputblock.cn.push({
15063 cls : 'input-group-addon',
15074 cls: 'form-hidden-field'
15088 cls: 'form-hidden-field'
15092 cls: 'roo-select2-choices',
15096 cls: 'roo-select2-search-field',
15109 cls: 'roo-select2-container input-group roo-touchview-combobox ',
15115 if(!this.multiple && this.showToggleBtn){
15122 if (this.caret != false) {
15125 cls: 'fa fa-' + this.caret
15132 cls : 'input-group-addon btn dropdown-toggle',
15137 cls: 'combobox-clear',
15151 combobox.cls += ' roo-select2-container-multi';
15154 var align = this.labelAlign || this.parentLabelAlign();
15156 if (align ==='left' && this.fieldLabel.length) {
15161 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15162 tooltip : 'This field is required'
15166 cls : 'control-label',
15167 html : this.fieldLabel
15178 var labelCfg = cfg.cn[1];
15179 var contentCfg = cfg.cn[2];
15182 if(this.indicatorpos == 'right'){
15187 cls : 'control-label',
15191 html : this.fieldLabel
15195 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15196 tooltip : 'This field is required'
15209 labelCfg = cfg.cn[0];
15210 contentCfg = cfg.cn[1];
15215 if(this.labelWidth > 12){
15216 labelCfg.style = "width: " + this.labelWidth + 'px';
15219 if(this.labelWidth < 13 && this.labelmd == 0){
15220 this.labelmd = this.labelWidth;
15223 if(this.labellg > 0){
15224 labelCfg.cls += ' col-lg-' + this.labellg;
15225 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
15228 if(this.labelmd > 0){
15229 labelCfg.cls += ' col-md-' + this.labelmd;
15230 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
15233 if(this.labelsm > 0){
15234 labelCfg.cls += ' col-sm-' + this.labelsm;
15235 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
15238 if(this.labelxs > 0){
15239 labelCfg.cls += ' col-xs-' + this.labelxs;
15240 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
15244 } else if ( this.fieldLabel.length) {
15248 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15249 tooltip : 'This field is required'
15253 cls : 'control-label',
15254 html : this.fieldLabel
15265 if(this.indicatorpos == 'right'){
15269 cls : 'control-label',
15270 html : this.fieldLabel,
15274 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15275 tooltip : 'This field is required'
15292 var settings = this;
15294 ['xs','sm','md','lg'].map(function(size){
15295 if (settings[size]) {
15296 cfg.cls += ' col-' + size + '-' + settings[size];
15303 initTouchView : function()
15305 this.renderTouchView();
15307 this.touchViewEl.on('scroll', function(){
15308 this.el.dom.scrollTop = 0;
15311 this.originalValue = this.getValue();
15313 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
15315 this.inputEl().on("click", this.showTouchView, this);
15316 if (this.triggerEl) {
15317 this.triggerEl.on("click", this.showTouchView, this);
15321 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
15322 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
15324 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
15326 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
15327 this.store.on('load', this.onTouchViewLoad, this);
15328 this.store.on('loadexception', this.onTouchViewLoadException, this);
15330 if(this.hiddenName){
15332 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
15334 this.hiddenField.dom.value =
15335 this.hiddenValue !== undefined ? this.hiddenValue :
15336 this.value !== undefined ? this.value : '';
15338 this.el.dom.removeAttribute('name');
15339 this.hiddenField.dom.setAttribute('name', this.hiddenName);
15343 this.choices = this.el.select('ul.roo-select2-choices', true).first();
15344 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
15347 if(this.removable && !this.multiple){
15348 var close = this.closeTriggerEl();
15350 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
15351 close.on('click', this.removeBtnClick, this, close);
15355 * fix the bug in Safari iOS8
15357 this.inputEl().on("focus", function(e){
15358 document.activeElement.blur();
15361 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
15368 renderTouchView : function()
15370 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
15371 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15373 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
15374 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15376 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
15377 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15378 this.touchViewBodyEl.setStyle('overflow', 'auto');
15380 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
15381 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15383 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
15384 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15388 showTouchView : function()
15394 this.touchViewHeaderEl.hide();
15396 if(this.modalTitle.length){
15397 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
15398 this.touchViewHeaderEl.show();
15401 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
15402 this.touchViewEl.show();
15404 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
15406 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
15407 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15409 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15411 if(this.modalTitle.length){
15412 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15415 this.touchViewBodyEl.setHeight(bodyHeight);
15419 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
15421 this.touchViewEl.addClass('in');
15424 if(this._touchViewMask){
15425 Roo.get(document.body).addClass("x-body-masked");
15426 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15427 this._touchViewMask.setStyle('z-index', 10000);
15428 this._touchViewMask.addClass('show');
15431 this.doTouchViewQuery();
15435 hideTouchView : function()
15437 this.touchViewEl.removeClass('in');
15441 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
15443 this.touchViewEl.setStyle('display', 'none');
15446 if(this._touchViewMask){
15447 this._touchViewMask.removeClass('show');
15448 Roo.get(document.body).removeClass("x-body-masked");
15452 setTouchViewValue : function()
15459 Roo.each(this.tickItems, function(o){
15464 this.hideTouchView();
15467 doTouchViewQuery : function()
15476 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
15480 if(!this.alwaysQuery || this.mode == 'local'){
15481 this.onTouchViewLoad();
15488 onTouchViewBeforeLoad : function(combo,opts)
15494 onTouchViewLoad : function()
15496 if(this.store.getCount() < 1){
15497 this.onTouchViewEmptyResults();
15501 this.clearTouchView();
15503 var rawValue = this.getRawValue();
15505 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
15507 this.tickItems = [];
15509 this.store.data.each(function(d, rowIndex){
15510 var row = this.touchViewListGroup.createChild(template);
15512 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
15513 row.addClass(d.data.cls);
15516 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15519 html : d.data[this.displayField]
15522 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
15523 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
15526 row.removeClass('selected');
15527 if(!this.multiple && this.valueField &&
15528 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
15531 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15532 row.addClass('selected');
15535 if(this.multiple && this.valueField &&
15536 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
15540 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15541 this.tickItems.push(d.data);
15544 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
15548 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
15550 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15552 if(this.modalTitle.length){
15553 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15556 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
15558 if(this.mobile_restrict_height && listHeight < bodyHeight){
15559 this.touchViewBodyEl.setHeight(listHeight);
15564 if(firstChecked && listHeight > bodyHeight){
15565 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
15570 onTouchViewLoadException : function()
15572 this.hideTouchView();
15575 onTouchViewEmptyResults : function()
15577 this.clearTouchView();
15579 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
15581 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
15585 clearTouchView : function()
15587 this.touchViewListGroup.dom.innerHTML = '';
15590 onTouchViewClick : function(e, el, o)
15592 e.preventDefault();
15595 var rowIndex = o.rowIndex;
15597 var r = this.store.getAt(rowIndex);
15599 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
15601 if(!this.multiple){
15602 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
15603 c.dom.removeAttribute('checked');
15606 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15608 this.setFromData(r.data);
15610 var close = this.closeTriggerEl();
15616 this.hideTouchView();
15618 this.fireEvent('select', this, r, rowIndex);
15623 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
15624 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
15625 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
15629 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15630 this.addItem(r.data);
15631 this.tickItems.push(r.data);
15635 getAutoCreateNativeIOS : function()
15638 cls: 'form-group' //input-group,
15643 cls : 'roo-ios-select'
15647 combobox.name = this.name;
15650 if (this.disabled) {
15651 combobox.disabled = true;
15654 var settings = this;
15656 ['xs','sm','md','lg'].map(function(size){
15657 if (settings[size]) {
15658 cfg.cls += ' col-' + size + '-' + settings[size];
15668 initIOSView : function()
15670 this.store.on('load', this.onIOSViewLoad, this);
15675 onIOSViewLoad : function()
15677 if(this.store.getCount() < 1){
15681 this.clearIOSView();
15683 if(this.allowBlank) {
15685 var default_text = '-- SELECT --';
15687 if(this.placeholder.length){
15688 default_text = this.placeholder;
15691 if(this.emptyTitle.length){
15692 default_text += ' - ' + this.emptyTitle + ' -';
15695 var opt = this.inputEl().createChild({
15698 html : default_text
15702 o[this.valueField] = 0;
15703 o[this.displayField] = default_text;
15705 this.ios_options.push({
15712 this.store.data.each(function(d, rowIndex){
15716 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15717 html = d.data[this.displayField];
15722 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
15723 value = d.data[this.valueField];
15732 if(this.value == d.data[this.valueField]){
15733 option['selected'] = true;
15736 var opt = this.inputEl().createChild(option);
15738 this.ios_options.push({
15745 this.inputEl().on('change', function(){
15746 this.fireEvent('select', this);
15751 clearIOSView: function()
15753 this.inputEl().dom.innerHTML = '';
15755 this.ios_options = [];
15758 setIOSValue: function(v)
15762 if(!this.ios_options){
15766 Roo.each(this.ios_options, function(opts){
15768 opts.el.dom.removeAttribute('selected');
15770 if(opts.data[this.valueField] != v){
15774 opts.el.dom.setAttribute('selected', true);
15780 * @cfg {Boolean} grow
15784 * @cfg {Number} growMin
15788 * @cfg {Number} growMax
15797 Roo.apply(Roo.bootstrap.ComboBox, {
15801 cls: 'modal-header',
15823 cls: 'list-group-item',
15827 cls: 'roo-combobox-list-group-item-value'
15831 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
15845 listItemCheckbox : {
15847 cls: 'list-group-item',
15851 cls: 'roo-combobox-list-group-item-value'
15855 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
15871 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
15876 cls: 'modal-footer',
15884 cls: 'col-xs-6 text-left',
15887 cls: 'btn btn-danger roo-touch-view-cancel',
15893 cls: 'col-xs-6 text-right',
15896 cls: 'btn btn-success roo-touch-view-ok',
15907 Roo.apply(Roo.bootstrap.ComboBox, {
15909 touchViewTemplate : {
15911 cls: 'modal fade roo-combobox-touch-view',
15915 cls: 'modal-dialog',
15916 style : 'position:fixed', // we have to fix position....
15920 cls: 'modal-content',
15922 Roo.bootstrap.ComboBox.header,
15923 Roo.bootstrap.ComboBox.body,
15924 Roo.bootstrap.ComboBox.footer
15933 * Ext JS Library 1.1.1
15934 * Copyright(c) 2006-2007, Ext JS, LLC.
15936 * Originally Released Under LGPL - original licence link has changed is not relivant.
15939 * <script type="text/javascript">
15944 * @extends Roo.util.Observable
15945 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
15946 * This class also supports single and multi selection modes. <br>
15947 * Create a data model bound view:
15949 var store = new Roo.data.Store(...);
15951 var view = new Roo.View({
15953 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
15955 singleSelect: true,
15956 selectedClass: "ydataview-selected",
15960 // listen for node click?
15961 view.on("click", function(vw, index, node, e){
15962 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
15966 dataModel.load("foobar.xml");
15968 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
15970 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
15971 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
15973 * Note: old style constructor is still suported (container, template, config)
15976 * Create a new View
15977 * @param {Object} config The config object
15980 Roo.View = function(config, depreciated_tpl, depreciated_config){
15982 this.parent = false;
15984 if (typeof(depreciated_tpl) == 'undefined') {
15985 // new way.. - universal constructor.
15986 Roo.apply(this, config);
15987 this.el = Roo.get(this.el);
15990 this.el = Roo.get(config);
15991 this.tpl = depreciated_tpl;
15992 Roo.apply(this, depreciated_config);
15994 this.wrapEl = this.el.wrap().wrap();
15995 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
15998 if(typeof(this.tpl) == "string"){
15999 this.tpl = new Roo.Template(this.tpl);
16001 // support xtype ctors..
16002 this.tpl = new Roo.factory(this.tpl, Roo);
16006 this.tpl.compile();
16011 * @event beforeclick
16012 * Fires before a click is processed. Returns false to cancel the default action.
16013 * @param {Roo.View} this
16014 * @param {Number} index The index of the target node
16015 * @param {HTMLElement} node The target node
16016 * @param {Roo.EventObject} e The raw event object
16018 "beforeclick" : true,
16021 * Fires when a template node is clicked.
16022 * @param {Roo.View} this
16023 * @param {Number} index The index of the target node
16024 * @param {HTMLElement} node The target node
16025 * @param {Roo.EventObject} e The raw event object
16030 * Fires when a template node is double clicked.
16031 * @param {Roo.View} this
16032 * @param {Number} index The index of the target node
16033 * @param {HTMLElement} node The target node
16034 * @param {Roo.EventObject} e The raw event object
16038 * @event contextmenu
16039 * Fires when a template node is right clicked.
16040 * @param {Roo.View} this
16041 * @param {Number} index The index of the target node
16042 * @param {HTMLElement} node The target node
16043 * @param {Roo.EventObject} e The raw event object
16045 "contextmenu" : true,
16047 * @event selectionchange
16048 * Fires when the selected nodes change.
16049 * @param {Roo.View} this
16050 * @param {Array} selections Array of the selected nodes
16052 "selectionchange" : true,
16055 * @event beforeselect
16056 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
16057 * @param {Roo.View} this
16058 * @param {HTMLElement} node The node to be selected
16059 * @param {Array} selections Array of currently selected nodes
16061 "beforeselect" : true,
16063 * @event preparedata
16064 * Fires on every row to render, to allow you to change the data.
16065 * @param {Roo.View} this
16066 * @param {Object} data to be rendered (change this)
16068 "preparedata" : true
16076 "click": this.onClick,
16077 "dblclick": this.onDblClick,
16078 "contextmenu": this.onContextMenu,
16082 this.selections = [];
16084 this.cmp = new Roo.CompositeElementLite([]);
16086 this.store = Roo.factory(this.store, Roo.data);
16087 this.setStore(this.store, true);
16090 if ( this.footer && this.footer.xtype) {
16092 var fctr = this.wrapEl.appendChild(document.createElement("div"));
16094 this.footer.dataSource = this.store;
16095 this.footer.container = fctr;
16096 this.footer = Roo.factory(this.footer, Roo);
16097 fctr.insertFirst(this.el);
16099 // this is a bit insane - as the paging toolbar seems to detach the el..
16100 // dom.parentNode.parentNode.parentNode
16101 // they get detached?
16105 Roo.View.superclass.constructor.call(this);
16110 Roo.extend(Roo.View, Roo.util.Observable, {
16113 * @cfg {Roo.data.Store} store Data store to load data from.
16118 * @cfg {String|Roo.Element} el The container element.
16123 * @cfg {String|Roo.Template} tpl The template used by this View
16127 * @cfg {String} dataName the named area of the template to use as the data area
16128 * Works with domtemplates roo-name="name"
16132 * @cfg {String} selectedClass The css class to add to selected nodes
16134 selectedClass : "x-view-selected",
16136 * @cfg {String} emptyText The empty text to show when nothing is loaded.
16141 * @cfg {String} text to display on mask (default Loading)
16145 * @cfg {Boolean} multiSelect Allow multiple selection
16147 multiSelect : false,
16149 * @cfg {Boolean} singleSelect Allow single selection
16151 singleSelect: false,
16154 * @cfg {Boolean} toggleSelect - selecting
16156 toggleSelect : false,
16159 * @cfg {Boolean} tickable - selecting
16164 * Returns the element this view is bound to.
16165 * @return {Roo.Element}
16167 getEl : function(){
16168 return this.wrapEl;
16174 * Refreshes the view. - called by datachanged on the store. - do not call directly.
16176 refresh : function(){
16177 //Roo.log('refresh');
16180 // if we are using something like 'domtemplate', then
16181 // the what gets used is:
16182 // t.applySubtemplate(NAME, data, wrapping data..)
16183 // the outer template then get' applied with
16184 // the store 'extra data'
16185 // and the body get's added to the
16186 // roo-name="data" node?
16187 // <span class='roo-tpl-{name}'></span> ?????
16191 this.clearSelections();
16192 this.el.update("");
16194 var records = this.store.getRange();
16195 if(records.length < 1) {
16197 // is this valid?? = should it render a template??
16199 this.el.update(this.emptyText);
16203 if (this.dataName) {
16204 this.el.update(t.apply(this.store.meta)); //????
16205 el = this.el.child('.roo-tpl-' + this.dataName);
16208 for(var i = 0, len = records.length; i < len; i++){
16209 var data = this.prepareData(records[i].data, i, records[i]);
16210 this.fireEvent("preparedata", this, data, i, records[i]);
16212 var d = Roo.apply({}, data);
16215 Roo.apply(d, {'roo-id' : Roo.id()});
16219 Roo.each(this.parent.item, function(item){
16220 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
16223 Roo.apply(d, {'roo-data-checked' : 'checked'});
16227 html[html.length] = Roo.util.Format.trim(
16229 t.applySubtemplate(this.dataName, d, this.store.meta) :
16236 el.update(html.join(""));
16237 this.nodes = el.dom.childNodes;
16238 this.updateIndexes(0);
16243 * Function to override to reformat the data that is sent to
16244 * the template for each node.
16245 * DEPRICATED - use the preparedata event handler.
16246 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
16247 * a JSON object for an UpdateManager bound view).
16249 prepareData : function(data, index, record)
16251 this.fireEvent("preparedata", this, data, index, record);
16255 onUpdate : function(ds, record){
16256 // Roo.log('on update');
16257 this.clearSelections();
16258 var index = this.store.indexOf(record);
16259 var n = this.nodes[index];
16260 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
16261 n.parentNode.removeChild(n);
16262 this.updateIndexes(index, index);
16268 onAdd : function(ds, records, index)
16270 //Roo.log(['on Add', ds, records, index] );
16271 this.clearSelections();
16272 if(this.nodes.length == 0){
16276 var n = this.nodes[index];
16277 for(var i = 0, len = records.length; i < len; i++){
16278 var d = this.prepareData(records[i].data, i, records[i]);
16280 this.tpl.insertBefore(n, d);
16283 this.tpl.append(this.el, d);
16286 this.updateIndexes(index);
16289 onRemove : function(ds, record, index){
16290 // Roo.log('onRemove');
16291 this.clearSelections();
16292 var el = this.dataName ?
16293 this.el.child('.roo-tpl-' + this.dataName) :
16296 el.dom.removeChild(this.nodes[index]);
16297 this.updateIndexes(index);
16301 * Refresh an individual node.
16302 * @param {Number} index
16304 refreshNode : function(index){
16305 this.onUpdate(this.store, this.store.getAt(index));
16308 updateIndexes : function(startIndex, endIndex){
16309 var ns = this.nodes;
16310 startIndex = startIndex || 0;
16311 endIndex = endIndex || ns.length - 1;
16312 for(var i = startIndex; i <= endIndex; i++){
16313 ns[i].nodeIndex = i;
16318 * Changes the data store this view uses and refresh the view.
16319 * @param {Store} store
16321 setStore : function(store, initial){
16322 if(!initial && this.store){
16323 this.store.un("datachanged", this.refresh);
16324 this.store.un("add", this.onAdd);
16325 this.store.un("remove", this.onRemove);
16326 this.store.un("update", this.onUpdate);
16327 this.store.un("clear", this.refresh);
16328 this.store.un("beforeload", this.onBeforeLoad);
16329 this.store.un("load", this.onLoad);
16330 this.store.un("loadexception", this.onLoad);
16334 store.on("datachanged", this.refresh, this);
16335 store.on("add", this.onAdd, this);
16336 store.on("remove", this.onRemove, this);
16337 store.on("update", this.onUpdate, this);
16338 store.on("clear", this.refresh, this);
16339 store.on("beforeload", this.onBeforeLoad, this);
16340 store.on("load", this.onLoad, this);
16341 store.on("loadexception", this.onLoad, this);
16349 * onbeforeLoad - masks the loading area.
16352 onBeforeLoad : function(store,opts)
16354 //Roo.log('onBeforeLoad');
16356 this.el.update("");
16358 this.el.mask(this.mask ? this.mask : "Loading" );
16360 onLoad : function ()
16367 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
16368 * @param {HTMLElement} node
16369 * @return {HTMLElement} The template node
16371 findItemFromChild : function(node){
16372 var el = this.dataName ?
16373 this.el.child('.roo-tpl-' + this.dataName,true) :
16376 if(!node || node.parentNode == el){
16379 var p = node.parentNode;
16380 while(p && p != el){
16381 if(p.parentNode == el){
16390 onClick : function(e){
16391 var item = this.findItemFromChild(e.getTarget());
16393 var index = this.indexOf(item);
16394 if(this.onItemClick(item, index, e) !== false){
16395 this.fireEvent("click", this, index, item, e);
16398 this.clearSelections();
16403 onContextMenu : function(e){
16404 var item = this.findItemFromChild(e.getTarget());
16406 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
16411 onDblClick : function(e){
16412 var item = this.findItemFromChild(e.getTarget());
16414 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
16418 onItemClick : function(item, index, e)
16420 if(this.fireEvent("beforeclick", this, index, item, e) === false){
16423 if (this.toggleSelect) {
16424 var m = this.isSelected(item) ? 'unselect' : 'select';
16427 _t[m](item, true, false);
16430 if(this.multiSelect || this.singleSelect){
16431 if(this.multiSelect && e.shiftKey && this.lastSelection){
16432 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
16434 this.select(item, this.multiSelect && e.ctrlKey);
16435 this.lastSelection = item;
16438 if(!this.tickable){
16439 e.preventDefault();
16447 * Get the number of selected nodes.
16450 getSelectionCount : function(){
16451 return this.selections.length;
16455 * Get the currently selected nodes.
16456 * @return {Array} An array of HTMLElements
16458 getSelectedNodes : function(){
16459 return this.selections;
16463 * Get the indexes of the selected nodes.
16466 getSelectedIndexes : function(){
16467 var indexes = [], s = this.selections;
16468 for(var i = 0, len = s.length; i < len; i++){
16469 indexes.push(s[i].nodeIndex);
16475 * Clear all selections
16476 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
16478 clearSelections : function(suppressEvent){
16479 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
16480 this.cmp.elements = this.selections;
16481 this.cmp.removeClass(this.selectedClass);
16482 this.selections = [];
16483 if(!suppressEvent){
16484 this.fireEvent("selectionchange", this, this.selections);
16490 * Returns true if the passed node is selected
16491 * @param {HTMLElement/Number} node The node or node index
16492 * @return {Boolean}
16494 isSelected : function(node){
16495 var s = this.selections;
16499 node = this.getNode(node);
16500 return s.indexOf(node) !== -1;
16505 * @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
16506 * @param {Boolean} keepExisting (optional) true to keep existing selections
16507 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16509 select : function(nodeInfo, keepExisting, suppressEvent){
16510 if(nodeInfo instanceof Array){
16512 this.clearSelections(true);
16514 for(var i = 0, len = nodeInfo.length; i < len; i++){
16515 this.select(nodeInfo[i], true, true);
16519 var node = this.getNode(nodeInfo);
16520 if(!node || this.isSelected(node)){
16521 return; // already selected.
16524 this.clearSelections(true);
16527 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
16528 Roo.fly(node).addClass(this.selectedClass);
16529 this.selections.push(node);
16530 if(!suppressEvent){
16531 this.fireEvent("selectionchange", this, this.selections);
16539 * @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
16540 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
16541 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16543 unselect : function(nodeInfo, keepExisting, suppressEvent)
16545 if(nodeInfo instanceof Array){
16546 Roo.each(this.selections, function(s) {
16547 this.unselect(s, nodeInfo);
16551 var node = this.getNode(nodeInfo);
16552 if(!node || !this.isSelected(node)){
16553 //Roo.log("not selected");
16554 return; // not selected.
16558 Roo.each(this.selections, function(s) {
16560 Roo.fly(node).removeClass(this.selectedClass);
16567 this.selections= ns;
16568 this.fireEvent("selectionchange", this, this.selections);
16572 * Gets a template node.
16573 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16574 * @return {HTMLElement} The node or null if it wasn't found
16576 getNode : function(nodeInfo){
16577 if(typeof nodeInfo == "string"){
16578 return document.getElementById(nodeInfo);
16579 }else if(typeof nodeInfo == "number"){
16580 return this.nodes[nodeInfo];
16586 * Gets a range template nodes.
16587 * @param {Number} startIndex
16588 * @param {Number} endIndex
16589 * @return {Array} An array of nodes
16591 getNodes : function(start, end){
16592 var ns = this.nodes;
16593 start = start || 0;
16594 end = typeof end == "undefined" ? ns.length - 1 : end;
16597 for(var i = start; i <= end; i++){
16601 for(var i = start; i >= end; i--){
16609 * Finds the index of the passed node
16610 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16611 * @return {Number} The index of the node or -1
16613 indexOf : function(node){
16614 node = this.getNode(node);
16615 if(typeof node.nodeIndex == "number"){
16616 return node.nodeIndex;
16618 var ns = this.nodes;
16619 for(var i = 0, len = ns.length; i < len; i++){
16630 * based on jquery fullcalendar
16634 Roo.bootstrap = Roo.bootstrap || {};
16636 * @class Roo.bootstrap.Calendar
16637 * @extends Roo.bootstrap.Component
16638 * Bootstrap Calendar class
16639 * @cfg {Boolean} loadMask (true|false) default false
16640 * @cfg {Object} header generate the user specific header of the calendar, default false
16643 * Create a new Container
16644 * @param {Object} config The config object
16649 Roo.bootstrap.Calendar = function(config){
16650 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
16654 * Fires when a date is selected
16655 * @param {DatePicker} this
16656 * @param {Date} date The selected date
16660 * @event monthchange
16661 * Fires when the displayed month changes
16662 * @param {DatePicker} this
16663 * @param {Date} date The selected month
16665 'monthchange': true,
16667 * @event evententer
16668 * Fires when mouse over an event
16669 * @param {Calendar} this
16670 * @param {event} Event
16672 'evententer': true,
16674 * @event eventleave
16675 * Fires when the mouse leaves an
16676 * @param {Calendar} this
16679 'eventleave': true,
16681 * @event eventclick
16682 * Fires when the mouse click an
16683 * @param {Calendar} this
16692 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
16695 * @cfg {Number} startDay
16696 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
16704 getAutoCreate : function(){
16707 var fc_button = function(name, corner, style, content ) {
16708 return Roo.apply({},{
16710 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
16712 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
16715 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
16726 style : 'width:100%',
16733 cls : 'fc-header-left',
16735 fc_button('prev', 'left', 'arrow', '‹' ),
16736 fc_button('next', 'right', 'arrow', '›' ),
16737 { tag: 'span', cls: 'fc-header-space' },
16738 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
16746 cls : 'fc-header-center',
16750 cls: 'fc-header-title',
16753 html : 'month / year'
16761 cls : 'fc-header-right',
16763 /* fc_button('month', 'left', '', 'month' ),
16764 fc_button('week', '', '', 'week' ),
16765 fc_button('day', 'right', '', 'day' )
16777 header = this.header;
16780 var cal_heads = function() {
16782 // fixme - handle this.
16784 for (var i =0; i < Date.dayNames.length; i++) {
16785 var d = Date.dayNames[i];
16788 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
16789 html : d.substring(0,3)
16793 ret[0].cls += ' fc-first';
16794 ret[6].cls += ' fc-last';
16797 var cal_cell = function(n) {
16800 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
16805 cls: 'fc-day-number',
16809 cls: 'fc-day-content',
16813 style: 'position: relative;' // height: 17px;
16825 var cal_rows = function() {
16828 for (var r = 0; r < 6; r++) {
16835 for (var i =0; i < Date.dayNames.length; i++) {
16836 var d = Date.dayNames[i];
16837 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
16840 row.cn[0].cls+=' fc-first';
16841 row.cn[0].cn[0].style = 'min-height:90px';
16842 row.cn[6].cls+=' fc-last';
16846 ret[0].cls += ' fc-first';
16847 ret[4].cls += ' fc-prev-last';
16848 ret[5].cls += ' fc-last';
16855 cls: 'fc-border-separate',
16856 style : 'width:100%',
16864 cls : 'fc-first fc-last',
16882 cls : 'fc-content',
16883 style : "position: relative;",
16886 cls : 'fc-view fc-view-month fc-grid',
16887 style : 'position: relative',
16888 unselectable : 'on',
16891 cls : 'fc-event-container',
16892 style : 'position:absolute;z-index:8;top:0;left:0;'
16910 initEvents : function()
16913 throw "can not find store for calendar";
16919 style: "text-align:center",
16923 style: "background-color:white;width:50%;margin:250 auto",
16927 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
16938 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
16940 var size = this.el.select('.fc-content', true).first().getSize();
16941 this.maskEl.setSize(size.width, size.height);
16942 this.maskEl.enableDisplayMode("block");
16943 if(!this.loadMask){
16944 this.maskEl.hide();
16947 this.store = Roo.factory(this.store, Roo.data);
16948 this.store.on('load', this.onLoad, this);
16949 this.store.on('beforeload', this.onBeforeLoad, this);
16953 this.cells = this.el.select('.fc-day',true);
16954 //Roo.log(this.cells);
16955 this.textNodes = this.el.query('.fc-day-number');
16956 this.cells.addClassOnOver('fc-state-hover');
16958 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
16959 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
16960 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
16961 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
16963 this.on('monthchange', this.onMonthChange, this);
16965 this.update(new Date().clearTime());
16968 resize : function() {
16969 var sz = this.el.getSize();
16971 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
16972 this.el.select('.fc-day-content div',true).setHeight(34);
16977 showPrevMonth : function(e){
16978 this.update(this.activeDate.add("mo", -1));
16980 showToday : function(e){
16981 this.update(new Date().clearTime());
16984 showNextMonth : function(e){
16985 this.update(this.activeDate.add("mo", 1));
16989 showPrevYear : function(){
16990 this.update(this.activeDate.add("y", -1));
16994 showNextYear : function(){
16995 this.update(this.activeDate.add("y", 1));
17000 update : function(date)
17002 var vd = this.activeDate;
17003 this.activeDate = date;
17004 // if(vd && this.el){
17005 // var t = date.getTime();
17006 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
17007 // Roo.log('using add remove');
17009 // this.fireEvent('monthchange', this, date);
17011 // this.cells.removeClass("fc-state-highlight");
17012 // this.cells.each(function(c){
17013 // if(c.dateValue == t){
17014 // c.addClass("fc-state-highlight");
17015 // setTimeout(function(){
17016 // try{c.dom.firstChild.focus();}catch(e){}
17026 var days = date.getDaysInMonth();
17028 var firstOfMonth = date.getFirstDateOfMonth();
17029 var startingPos = firstOfMonth.getDay()-this.startDay;
17031 if(startingPos < this.startDay){
17035 var pm = date.add(Date.MONTH, -1);
17036 var prevStart = pm.getDaysInMonth()-startingPos;
17038 this.cells = this.el.select('.fc-day',true);
17039 this.textNodes = this.el.query('.fc-day-number');
17040 this.cells.addClassOnOver('fc-state-hover');
17042 var cells = this.cells.elements;
17043 var textEls = this.textNodes;
17045 Roo.each(cells, function(cell){
17046 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
17049 days += startingPos;
17051 // convert everything to numbers so it's fast
17052 var day = 86400000;
17053 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
17056 //Roo.log(prevStart);
17058 var today = new Date().clearTime().getTime();
17059 var sel = date.clearTime().getTime();
17060 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
17061 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
17062 var ddMatch = this.disabledDatesRE;
17063 var ddText = this.disabledDatesText;
17064 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
17065 var ddaysText = this.disabledDaysText;
17066 var format = this.format;
17068 var setCellClass = function(cal, cell){
17072 //Roo.log('set Cell Class');
17074 var t = d.getTime();
17078 cell.dateValue = t;
17080 cell.className += " fc-today";
17081 cell.className += " fc-state-highlight";
17082 cell.title = cal.todayText;
17085 // disable highlight in other month..
17086 //cell.className += " fc-state-highlight";
17091 cell.className = " fc-state-disabled";
17092 cell.title = cal.minText;
17096 cell.className = " fc-state-disabled";
17097 cell.title = cal.maxText;
17101 if(ddays.indexOf(d.getDay()) != -1){
17102 cell.title = ddaysText;
17103 cell.className = " fc-state-disabled";
17106 if(ddMatch && format){
17107 var fvalue = d.dateFormat(format);
17108 if(ddMatch.test(fvalue)){
17109 cell.title = ddText.replace("%0", fvalue);
17110 cell.className = " fc-state-disabled";
17114 if (!cell.initialClassName) {
17115 cell.initialClassName = cell.dom.className;
17118 cell.dom.className = cell.initialClassName + ' ' + cell.className;
17123 for(; i < startingPos; i++) {
17124 textEls[i].innerHTML = (++prevStart);
17125 d.setDate(d.getDate()+1);
17127 cells[i].className = "fc-past fc-other-month";
17128 setCellClass(this, cells[i]);
17133 for(; i < days; i++){
17134 intDay = i - startingPos + 1;
17135 textEls[i].innerHTML = (intDay);
17136 d.setDate(d.getDate()+1);
17138 cells[i].className = ''; // "x-date-active";
17139 setCellClass(this, cells[i]);
17143 for(; i < 42; i++) {
17144 textEls[i].innerHTML = (++extraDays);
17145 d.setDate(d.getDate()+1);
17147 cells[i].className = "fc-future fc-other-month";
17148 setCellClass(this, cells[i]);
17151 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
17153 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
17155 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
17156 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
17158 if(totalRows != 6){
17159 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
17160 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
17163 this.fireEvent('monthchange', this, date);
17167 if(!this.internalRender){
17168 var main = this.el.dom.firstChild;
17169 var w = main.offsetWidth;
17170 this.el.setWidth(w + this.el.getBorderWidth("lr"));
17171 Roo.fly(main).setWidth(w);
17172 this.internalRender = true;
17173 // opera does not respect the auto grow header center column
17174 // then, after it gets a width opera refuses to recalculate
17175 // without a second pass
17176 if(Roo.isOpera && !this.secondPass){
17177 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
17178 this.secondPass = true;
17179 this.update.defer(10, this, [date]);
17186 findCell : function(dt) {
17187 dt = dt.clearTime().getTime();
17189 this.cells.each(function(c){
17190 //Roo.log("check " +c.dateValue + '?=' + dt);
17191 if(c.dateValue == dt){
17201 findCells : function(ev) {
17202 var s = ev.start.clone().clearTime().getTime();
17204 var e= ev.end.clone().clearTime().getTime();
17207 this.cells.each(function(c){
17208 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
17210 if(c.dateValue > e){
17213 if(c.dateValue < s){
17222 // findBestRow: function(cells)
17226 // for (var i =0 ; i < cells.length;i++) {
17227 // ret = Math.max(cells[i].rows || 0,ret);
17234 addItem : function(ev)
17236 // look for vertical location slot in
17237 var cells = this.findCells(ev);
17239 // ev.row = this.findBestRow(cells);
17241 // work out the location.
17245 for(var i =0; i < cells.length; i++) {
17247 cells[i].row = cells[0].row;
17250 cells[i].row = cells[i].row + 1;
17260 if (crow.start.getY() == cells[i].getY()) {
17262 crow.end = cells[i];
17279 cells[0].events.push(ev);
17281 this.calevents.push(ev);
17284 clearEvents: function() {
17286 if(!this.calevents){
17290 Roo.each(this.cells.elements, function(c){
17296 Roo.each(this.calevents, function(e) {
17297 Roo.each(e.els, function(el) {
17298 el.un('mouseenter' ,this.onEventEnter, this);
17299 el.un('mouseleave' ,this.onEventLeave, this);
17304 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
17310 renderEvents: function()
17314 this.cells.each(function(c) {
17323 if(c.row != c.events.length){
17324 r = 4 - (4 - (c.row - c.events.length));
17327 c.events = ev.slice(0, r);
17328 c.more = ev.slice(r);
17330 if(c.more.length && c.more.length == 1){
17331 c.events.push(c.more.pop());
17334 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
17338 this.cells.each(function(c) {
17340 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
17343 for (var e = 0; e < c.events.length; e++){
17344 var ev = c.events[e];
17345 var rows = ev.rows;
17347 for(var i = 0; i < rows.length; i++) {
17349 // how many rows should it span..
17352 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
17353 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
17355 unselectable : "on",
17358 cls: 'fc-event-inner',
17362 // cls: 'fc-event-time',
17363 // html : cells.length > 1 ? '' : ev.time
17367 cls: 'fc-event-title',
17368 html : String.format('{0}', ev.title)
17375 cls: 'ui-resizable-handle ui-resizable-e',
17376 html : '  '
17383 cfg.cls += ' fc-event-start';
17385 if ((i+1) == rows.length) {
17386 cfg.cls += ' fc-event-end';
17389 var ctr = _this.el.select('.fc-event-container',true).first();
17390 var cg = ctr.createChild(cfg);
17392 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
17393 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
17395 var r = (c.more.length) ? 1 : 0;
17396 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
17397 cg.setWidth(ebox.right - sbox.x -2);
17399 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
17400 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
17401 cg.on('click', _this.onEventClick, _this, ev);
17412 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
17413 style : 'position: absolute',
17414 unselectable : "on",
17417 cls: 'fc-event-inner',
17421 cls: 'fc-event-title',
17429 cls: 'ui-resizable-handle ui-resizable-e',
17430 html : '  '
17436 var ctr = _this.el.select('.fc-event-container',true).first();
17437 var cg = ctr.createChild(cfg);
17439 var sbox = c.select('.fc-day-content',true).first().getBox();
17440 var ebox = c.select('.fc-day-content',true).first().getBox();
17442 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
17443 cg.setWidth(ebox.right - sbox.x -2);
17445 cg.on('click', _this.onMoreEventClick, _this, c.more);
17455 onEventEnter: function (e, el,event,d) {
17456 this.fireEvent('evententer', this, el, event);
17459 onEventLeave: function (e, el,event,d) {
17460 this.fireEvent('eventleave', this, el, event);
17463 onEventClick: function (e, el,event,d) {
17464 this.fireEvent('eventclick', this, el, event);
17467 onMonthChange: function () {
17471 onMoreEventClick: function(e, el, more)
17475 this.calpopover.placement = 'right';
17476 this.calpopover.setTitle('More');
17478 this.calpopover.setContent('');
17480 var ctr = this.calpopover.el.select('.popover-content', true).first();
17482 Roo.each(more, function(m){
17484 cls : 'fc-event-hori fc-event-draggable',
17487 var cg = ctr.createChild(cfg);
17489 cg.on('click', _this.onEventClick, _this, m);
17492 this.calpopover.show(el);
17497 onLoad: function ()
17499 this.calevents = [];
17502 if(this.store.getCount() > 0){
17503 this.store.data.each(function(d){
17506 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
17507 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
17508 time : d.data.start_time,
17509 title : d.data.title,
17510 description : d.data.description,
17511 venue : d.data.venue
17516 this.renderEvents();
17518 if(this.calevents.length && this.loadMask){
17519 this.maskEl.hide();
17523 onBeforeLoad: function()
17525 this.clearEvents();
17527 this.maskEl.show();
17541 * @class Roo.bootstrap.Popover
17542 * @extends Roo.bootstrap.Component
17543 * Bootstrap Popover class
17544 * @cfg {String} html contents of the popover (or false to use children..)
17545 * @cfg {String} title of popover (or false to hide)
17546 * @cfg {String} placement how it is placed
17547 * @cfg {String} trigger click || hover (or false to trigger manually)
17548 * @cfg {String} over what (parent or false to trigger manually.)
17549 * @cfg {Number} delay - delay before showing
17552 * Create a new Popover
17553 * @param {Object} config The config object
17556 Roo.bootstrap.Popover = function(config){
17557 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
17563 * After the popover show
17565 * @param {Roo.bootstrap.Popover} this
17570 * After the popover hide
17572 * @param {Roo.bootstrap.Popover} this
17578 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
17580 title: 'Fill in a title',
17583 placement : 'right',
17584 trigger : 'hover', // hover
17590 can_build_overlaid : false,
17592 getChildContainer : function()
17594 return this.el.select('.popover-content',true).first();
17597 getAutoCreate : function(){
17600 cls : 'popover roo-dynamic',
17601 style: 'display:block',
17607 cls : 'popover-inner',
17611 cls: 'popover-title',
17615 cls : 'popover-content',
17626 setTitle: function(str)
17629 this.el.select('.popover-title',true).first().dom.innerHTML = str;
17631 setContent: function(str)
17634 this.el.select('.popover-content',true).first().dom.innerHTML = str;
17636 // as it get's added to the bottom of the page.
17637 onRender : function(ct, position)
17639 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
17641 var cfg = Roo.apply({}, this.getAutoCreate());
17645 cfg.cls += ' ' + this.cls;
17648 cfg.style = this.style;
17650 //Roo.log("adding to ");
17651 this.el = Roo.get(document.body).createChild(cfg, position);
17652 // Roo.log(this.el);
17657 initEvents : function()
17659 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
17660 this.el.enableDisplayMode('block');
17662 if (this.over === false) {
17665 if (this.triggers === false) {
17668 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17669 var triggers = this.trigger ? this.trigger.split(' ') : [];
17670 Roo.each(triggers, function(trigger) {
17672 if (trigger == 'click') {
17673 on_el.on('click', this.toggle, this);
17674 } else if (trigger != 'manual') {
17675 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
17676 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
17678 on_el.on(eventIn ,this.enter, this);
17679 on_el.on(eventOut, this.leave, this);
17690 toggle : function () {
17691 this.hoverState == 'in' ? this.leave() : this.enter();
17694 enter : function () {
17696 clearTimeout(this.timeout);
17698 this.hoverState = 'in';
17700 if (!this.delay || !this.delay.show) {
17705 this.timeout = setTimeout(function () {
17706 if (_t.hoverState == 'in') {
17709 }, this.delay.show)
17712 leave : function() {
17713 clearTimeout(this.timeout);
17715 this.hoverState = 'out';
17717 if (!this.delay || !this.delay.hide) {
17722 this.timeout = setTimeout(function () {
17723 if (_t.hoverState == 'out') {
17726 }, this.delay.hide)
17729 show : function (on_el)
17732 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17736 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
17737 if (this.html !== false) {
17738 this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
17740 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
17741 if (!this.title.length) {
17742 this.el.select('.popover-title',true).hide();
17745 var placement = typeof this.placement == 'function' ?
17746 this.placement.call(this, this.el, on_el) :
17749 var autoToken = /\s?auto?\s?/i;
17750 var autoPlace = autoToken.test(placement);
17752 placement = placement.replace(autoToken, '') || 'top';
17756 //this.el.setXY([0,0]);
17758 this.el.dom.style.display='block';
17759 this.el.addClass(placement);
17761 //this.el.appendTo(on_el);
17763 var p = this.getPosition();
17764 var box = this.el.getBox();
17769 var align = Roo.bootstrap.Popover.alignment[placement];
17772 this.el.alignTo(on_el, align[0],align[1]);
17773 //var arrow = this.el.select('.arrow',true).first();
17774 //arrow.set(align[2],
17776 this.el.addClass('in');
17779 if (this.el.hasClass('fade')) {
17783 this.hoverState = 'in';
17785 this.fireEvent('show', this);
17790 this.el.setXY([0,0]);
17791 this.el.removeClass('in');
17793 this.hoverState = null;
17795 this.fireEvent('hide', this);
17800 Roo.bootstrap.Popover.alignment = {
17801 'left' : ['r-l', [-10,0], 'right'],
17802 'right' : ['l-r', [10,0], 'left'],
17803 'bottom' : ['t-b', [0,10], 'top'],
17804 'top' : [ 'b-t', [0,-10], 'bottom']
17815 * @class Roo.bootstrap.Progress
17816 * @extends Roo.bootstrap.Component
17817 * Bootstrap Progress class
17818 * @cfg {Boolean} striped striped of the progress bar
17819 * @cfg {Boolean} active animated of the progress bar
17823 * Create a new Progress
17824 * @param {Object} config The config object
17827 Roo.bootstrap.Progress = function(config){
17828 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
17831 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
17836 getAutoCreate : function(){
17844 cfg.cls += ' progress-striped';
17848 cfg.cls += ' active';
17867 * @class Roo.bootstrap.ProgressBar
17868 * @extends Roo.bootstrap.Component
17869 * Bootstrap ProgressBar class
17870 * @cfg {Number} aria_valuenow aria-value now
17871 * @cfg {Number} aria_valuemin aria-value min
17872 * @cfg {Number} aria_valuemax aria-value max
17873 * @cfg {String} label label for the progress bar
17874 * @cfg {String} panel (success | info | warning | danger )
17875 * @cfg {String} role role of the progress bar
17876 * @cfg {String} sr_only text
17880 * Create a new ProgressBar
17881 * @param {Object} config The config object
17884 Roo.bootstrap.ProgressBar = function(config){
17885 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
17888 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
17892 aria_valuemax : 100,
17898 getAutoCreate : function()
17903 cls: 'progress-bar',
17904 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
17916 cfg.role = this.role;
17919 if(this.aria_valuenow){
17920 cfg['aria-valuenow'] = this.aria_valuenow;
17923 if(this.aria_valuemin){
17924 cfg['aria-valuemin'] = this.aria_valuemin;
17927 if(this.aria_valuemax){
17928 cfg['aria-valuemax'] = this.aria_valuemax;
17931 if(this.label && !this.sr_only){
17932 cfg.html = this.label;
17936 cfg.cls += ' progress-bar-' + this.panel;
17942 update : function(aria_valuenow)
17944 this.aria_valuenow = aria_valuenow;
17946 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
17961 * @class Roo.bootstrap.TabGroup
17962 * @extends Roo.bootstrap.Column
17963 * Bootstrap Column class
17964 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
17965 * @cfg {Boolean} carousel true to make the group behave like a carousel
17966 * @cfg {Boolean} bullets show bullets for the panels
17967 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
17968 * @cfg {Number} timer auto slide timer .. default 0 millisecond
17969 * @cfg {Boolean} showarrow (true|false) show arrow default true
17972 * Create a new TabGroup
17973 * @param {Object} config The config object
17976 Roo.bootstrap.TabGroup = function(config){
17977 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
17979 this.navId = Roo.id();
17982 Roo.bootstrap.TabGroup.register(this);
17986 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
17989 transition : false,
17994 slideOnTouch : false,
17997 getAutoCreate : function()
17999 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
18001 cfg.cls += ' tab-content';
18003 if (this.carousel) {
18004 cfg.cls += ' carousel slide';
18007 cls : 'carousel-inner',
18011 if(this.bullets && !Roo.isTouch){
18014 cls : 'carousel-bullets',
18018 if(this.bullets_cls){
18019 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
18026 cfg.cn[0].cn.push(bullets);
18029 if(this.showarrow){
18030 cfg.cn[0].cn.push({
18032 class : 'carousel-arrow',
18036 class : 'carousel-prev',
18040 class : 'fa fa-chevron-left'
18046 class : 'carousel-next',
18050 class : 'fa fa-chevron-right'
18063 initEvents: function()
18065 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
18066 // this.el.on("touchstart", this.onTouchStart, this);
18069 if(this.autoslide){
18072 this.slideFn = window.setInterval(function() {
18073 _this.showPanelNext();
18077 if(this.showarrow){
18078 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
18079 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
18085 // onTouchStart : function(e, el, o)
18087 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
18091 // this.showPanelNext();
18095 getChildContainer : function()
18097 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
18101 * register a Navigation item
18102 * @param {Roo.bootstrap.NavItem} the navitem to add
18104 register : function(item)
18106 this.tabs.push( item);
18107 item.navId = this.navId; // not really needed..
18112 getActivePanel : function()
18115 Roo.each(this.tabs, function(t) {
18125 getPanelByName : function(n)
18128 Roo.each(this.tabs, function(t) {
18129 if (t.tabId == n) {
18137 indexOfPanel : function(p)
18140 Roo.each(this.tabs, function(t,i) {
18141 if (t.tabId == p.tabId) {
18150 * show a specific panel
18151 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
18152 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
18154 showPanel : function (pan)
18156 if(this.transition || typeof(pan) == 'undefined'){
18157 Roo.log("waiting for the transitionend");
18161 if (typeof(pan) == 'number') {
18162 pan = this.tabs[pan];
18165 if (typeof(pan) == 'string') {
18166 pan = this.getPanelByName(pan);
18169 var cur = this.getActivePanel();
18172 Roo.log('pan or acitve pan is undefined');
18176 if (pan.tabId == this.getActivePanel().tabId) {
18180 if (false === cur.fireEvent('beforedeactivate')) {
18184 if(this.bullets > 0 && !Roo.isTouch){
18185 this.setActiveBullet(this.indexOfPanel(pan));
18188 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
18190 this.transition = true;
18191 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
18192 var lr = dir == 'next' ? 'left' : 'right';
18193 pan.el.addClass(dir); // or prev
18194 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
18195 cur.el.addClass(lr); // or right
18196 pan.el.addClass(lr);
18199 cur.el.on('transitionend', function() {
18200 Roo.log("trans end?");
18202 pan.el.removeClass([lr,dir]);
18203 pan.setActive(true);
18205 cur.el.removeClass([lr]);
18206 cur.setActive(false);
18208 _this.transition = false;
18210 }, this, { single: true } );
18215 cur.setActive(false);
18216 pan.setActive(true);
18221 showPanelNext : function()
18223 var i = this.indexOfPanel(this.getActivePanel());
18225 if (i >= this.tabs.length - 1 && !this.autoslide) {
18229 if (i >= this.tabs.length - 1 && this.autoslide) {
18233 this.showPanel(this.tabs[i+1]);
18236 showPanelPrev : function()
18238 var i = this.indexOfPanel(this.getActivePanel());
18240 if (i < 1 && !this.autoslide) {
18244 if (i < 1 && this.autoslide) {
18245 i = this.tabs.length;
18248 this.showPanel(this.tabs[i-1]);
18252 addBullet: function()
18254 if(!this.bullets || Roo.isTouch){
18257 var ctr = this.el.select('.carousel-bullets',true).first();
18258 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
18259 var bullet = ctr.createChild({
18260 cls : 'bullet bullet-' + i
18261 },ctr.dom.lastChild);
18266 bullet.on('click', (function(e, el, o, ii, t){
18268 e.preventDefault();
18270 this.showPanel(ii);
18272 if(this.autoslide && this.slideFn){
18273 clearInterval(this.slideFn);
18274 this.slideFn = window.setInterval(function() {
18275 _this.showPanelNext();
18279 }).createDelegate(this, [i, bullet], true));
18284 setActiveBullet : function(i)
18290 Roo.each(this.el.select('.bullet', true).elements, function(el){
18291 el.removeClass('selected');
18294 var bullet = this.el.select('.bullet-' + i, true).first();
18300 bullet.addClass('selected');
18311 Roo.apply(Roo.bootstrap.TabGroup, {
18315 * register a Navigation Group
18316 * @param {Roo.bootstrap.NavGroup} the navgroup to add
18318 register : function(navgrp)
18320 this.groups[navgrp.navId] = navgrp;
18324 * fetch a Navigation Group based on the navigation ID
18325 * if one does not exist , it will get created.
18326 * @param {string} the navgroup to add
18327 * @returns {Roo.bootstrap.NavGroup} the navgroup
18329 get: function(navId) {
18330 if (typeof(this.groups[navId]) == 'undefined') {
18331 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
18333 return this.groups[navId] ;
18348 * @class Roo.bootstrap.TabPanel
18349 * @extends Roo.bootstrap.Component
18350 * Bootstrap TabPanel class
18351 * @cfg {Boolean} active panel active
18352 * @cfg {String} html panel content
18353 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
18354 * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
18355 * @cfg {String} href click to link..
18359 * Create a new TabPanel
18360 * @param {Object} config The config object
18363 Roo.bootstrap.TabPanel = function(config){
18364 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
18368 * Fires when the active status changes
18369 * @param {Roo.bootstrap.TabPanel} this
18370 * @param {Boolean} state the new state
18375 * @event beforedeactivate
18376 * Fires before a tab is de-activated - can be used to do validation on a form.
18377 * @param {Roo.bootstrap.TabPanel} this
18378 * @return {Boolean} false if there is an error
18381 'beforedeactivate': true
18384 this.tabId = this.tabId || Roo.id();
18388 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
18396 getAutoCreate : function(){
18399 // item is needed for carousel - not sure if it has any effect otherwise
18400 cls: 'tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
18401 html: this.html || ''
18405 cfg.cls += ' active';
18409 cfg.tabId = this.tabId;
18416 initEvents: function()
18418 var p = this.parent();
18420 this.navId = this.navId || p.navId;
18422 if (typeof(this.navId) != 'undefined') {
18423 // not really needed.. but just in case.. parent should be a NavGroup.
18424 var tg = Roo.bootstrap.TabGroup.get(this.navId);
18428 var i = tg.tabs.length - 1;
18430 if(this.active && tg.bullets > 0 && i < tg.bullets){
18431 tg.setActiveBullet(i);
18435 this.el.on('click', this.onClick, this);
18438 this.el.on("touchstart", this.onTouchStart, this);
18439 this.el.on("touchmove", this.onTouchMove, this);
18440 this.el.on("touchend", this.onTouchEnd, this);
18445 onRender : function(ct, position)
18447 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
18450 setActive : function(state)
18452 Roo.log("panel - set active " + this.tabId + "=" + state);
18454 this.active = state;
18456 this.el.removeClass('active');
18458 } else if (!this.el.hasClass('active')) {
18459 this.el.addClass('active');
18462 this.fireEvent('changed', this, state);
18465 onClick : function(e)
18467 e.preventDefault();
18469 if(!this.href.length){
18473 window.location.href = this.href;
18482 onTouchStart : function(e)
18484 this.swiping = false;
18486 this.startX = e.browserEvent.touches[0].clientX;
18487 this.startY = e.browserEvent.touches[0].clientY;
18490 onTouchMove : function(e)
18492 this.swiping = true;
18494 this.endX = e.browserEvent.touches[0].clientX;
18495 this.endY = e.browserEvent.touches[0].clientY;
18498 onTouchEnd : function(e)
18505 var tabGroup = this.parent();
18507 if(this.endX > this.startX){ // swiping right
18508 tabGroup.showPanelPrev();
18512 if(this.startX > this.endX){ // swiping left
18513 tabGroup.showPanelNext();
18532 * @class Roo.bootstrap.DateField
18533 * @extends Roo.bootstrap.Input
18534 * Bootstrap DateField class
18535 * @cfg {Number} weekStart default 0
18536 * @cfg {String} viewMode default empty, (months|years)
18537 * @cfg {String} minViewMode default empty, (months|years)
18538 * @cfg {Number} startDate default -Infinity
18539 * @cfg {Number} endDate default Infinity
18540 * @cfg {Boolean} todayHighlight default false
18541 * @cfg {Boolean} todayBtn default false
18542 * @cfg {Boolean} calendarWeeks default false
18543 * @cfg {Object} daysOfWeekDisabled default empty
18544 * @cfg {Boolean} singleMode default false (true | false)
18546 * @cfg {Boolean} keyboardNavigation default true
18547 * @cfg {String} language default en
18550 * Create a new DateField
18551 * @param {Object} config The config object
18554 Roo.bootstrap.DateField = function(config){
18555 Roo.bootstrap.DateField.superclass.constructor.call(this, config);
18559 * Fires when this field show.
18560 * @param {Roo.bootstrap.DateField} this
18561 * @param {Mixed} date The date value
18566 * Fires when this field hide.
18567 * @param {Roo.bootstrap.DateField} this
18568 * @param {Mixed} date The date value
18573 * Fires when select a date.
18574 * @param {Roo.bootstrap.DateField} this
18575 * @param {Mixed} date The date value
18579 * @event beforeselect
18580 * Fires when before select a date.
18581 * @param {Roo.bootstrap.DateField} this
18582 * @param {Mixed} date The date value
18584 beforeselect : true
18588 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, {
18591 * @cfg {String} format
18592 * The default date format string which can be overriden for localization support. The format must be
18593 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18597 * @cfg {String} altFormats
18598 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18599 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18601 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
18609 todayHighlight : false,
18615 keyboardNavigation: true,
18617 calendarWeeks: false,
18619 startDate: -Infinity,
18623 daysOfWeekDisabled: [],
18627 singleMode : false,
18629 UTCDate: function()
18631 return new Date(Date.UTC.apply(Date, arguments));
18634 UTCToday: function()
18636 var today = new Date();
18637 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
18640 getDate: function() {
18641 var d = this.getUTCDate();
18642 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
18645 getUTCDate: function() {
18649 setDate: function(d) {
18650 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
18653 setUTCDate: function(d) {
18655 this.setValue(this.formatDate(this.date));
18658 onRender: function(ct, position)
18661 Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
18663 this.language = this.language || 'en';
18664 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
18665 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
18667 this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
18668 this.format = this.format || 'm/d/y';
18669 this.isInline = false;
18670 this.isInput = true;
18671 this.component = this.el.select('.add-on', true).first() || false;
18672 this.component = (this.component && this.component.length === 0) ? false : this.component;
18673 this.hasInput = this.component && this.inputEl().length;
18675 if (typeof(this.minViewMode === 'string')) {
18676 switch (this.minViewMode) {
18678 this.minViewMode = 1;
18681 this.minViewMode = 2;
18684 this.minViewMode = 0;
18689 if (typeof(this.viewMode === 'string')) {
18690 switch (this.viewMode) {
18703 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
18705 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
18707 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18709 this.picker().on('mousedown', this.onMousedown, this);
18710 this.picker().on('click', this.onClick, this);
18712 this.picker().addClass('datepicker-dropdown');
18714 this.startViewMode = this.viewMode;
18716 if(this.singleMode){
18717 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
18718 v.setVisibilityMode(Roo.Element.DISPLAY);
18722 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18723 v.setStyle('width', '189px');
18727 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
18728 if(!this.calendarWeeks){
18733 v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18734 v.attr('colspan', function(i, val){
18735 return parseInt(val) + 1;
18740 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
18742 this.setStartDate(this.startDate);
18743 this.setEndDate(this.endDate);
18745 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
18752 if(this.isInline) {
18757 picker : function()
18759 return this.pickerEl;
18760 // return this.el.select('.datepicker', true).first();
18763 fillDow: function()
18765 var dowCnt = this.weekStart;
18774 if(this.calendarWeeks){
18782 while (dowCnt < this.weekStart + 7) {
18786 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
18790 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
18793 fillMonths: function()
18796 var months = this.picker().select('>.datepicker-months td', true).first();
18798 months.dom.innerHTML = '';
18804 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
18807 months.createChild(month);
18814 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;
18816 if (this.date < this.startDate) {
18817 this.viewDate = new Date(this.startDate);
18818 } else if (this.date > this.endDate) {
18819 this.viewDate = new Date(this.endDate);
18821 this.viewDate = new Date(this.date);
18829 var d = new Date(this.viewDate),
18830 year = d.getUTCFullYear(),
18831 month = d.getUTCMonth(),
18832 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
18833 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
18834 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
18835 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
18836 currentDate = this.date && this.date.valueOf(),
18837 today = this.UTCToday();
18839 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
18841 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18843 // this.picker.select('>tfoot th.today').
18844 // .text(dates[this.language].today)
18845 // .toggle(this.todayBtn !== false);
18847 this.updateNavArrows();
18850 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
18852 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
18854 prevMonth.setUTCDate(day);
18856 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
18858 var nextMonth = new Date(prevMonth);
18860 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
18862 nextMonth = nextMonth.valueOf();
18864 var fillMonths = false;
18866 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
18868 while(prevMonth.valueOf() <= nextMonth) {
18871 if (prevMonth.getUTCDay() === this.weekStart) {
18873 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
18881 if(this.calendarWeeks){
18882 // ISO 8601: First week contains first thursday.
18883 // ISO also states week starts on Monday, but we can be more abstract here.
18885 // Start of current week: based on weekstart/current date
18886 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
18887 // Thursday of this week
18888 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
18889 // First Thursday of year, year from thursday
18890 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
18891 // Calendar week: ms between thursdays, div ms per day, div 7 days
18892 calWeek = (th - yth) / 864e5 / 7 + 1;
18894 fillMonths.cn.push({
18902 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
18904 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
18907 if (this.todayHighlight &&
18908 prevMonth.getUTCFullYear() == today.getFullYear() &&
18909 prevMonth.getUTCMonth() == today.getMonth() &&
18910 prevMonth.getUTCDate() == today.getDate()) {
18911 clsName += ' today';
18914 if (currentDate && prevMonth.valueOf() === currentDate) {
18915 clsName += ' active';
18918 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
18919 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
18920 clsName += ' disabled';
18923 fillMonths.cn.push({
18925 cls: 'day ' + clsName,
18926 html: prevMonth.getDate()
18929 prevMonth.setDate(prevMonth.getDate()+1);
18932 var currentYear = this.date && this.date.getUTCFullYear();
18933 var currentMonth = this.date && this.date.getUTCMonth();
18935 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
18937 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
18938 v.removeClass('active');
18940 if(currentYear === year && k === currentMonth){
18941 v.addClass('active');
18944 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
18945 v.addClass('disabled');
18951 year = parseInt(year/10, 10) * 10;
18953 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
18955 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
18958 for (var i = -1; i < 11; i++) {
18959 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
18961 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
18969 showMode: function(dir)
18972 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
18975 Roo.each(this.picker().select('>div',true).elements, function(v){
18976 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18979 this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
18984 if(this.isInline) {
18988 this.picker().removeClass(['bottom', 'top']);
18990 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
18992 * place to the top of element!
18996 this.picker().addClass('top');
18997 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
19002 this.picker().addClass('bottom');
19004 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
19007 parseDate : function(value)
19009 if(!value || value instanceof Date){
19012 var v = Date.parseDate(value, this.format);
19013 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
19014 v = Date.parseDate(value, 'Y-m-d');
19016 if(!v && this.altFormats){
19017 if(!this.altFormatsArray){
19018 this.altFormatsArray = this.altFormats.split("|");
19020 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
19021 v = Date.parseDate(value, this.altFormatsArray[i]);
19027 formatDate : function(date, fmt)
19029 return (!date || !(date instanceof Date)) ?
19030 date : date.dateFormat(fmt || this.format);
19033 onFocus : function()
19035 Roo.bootstrap.DateField.superclass.onFocus.call(this);
19039 onBlur : function()
19041 Roo.bootstrap.DateField.superclass.onBlur.call(this);
19043 var d = this.inputEl().getValue();
19050 showPopup : function()
19052 this.picker().show();
19056 this.fireEvent('showpopup', this, this.date);
19059 hidePopup : function()
19061 if(this.isInline) {
19064 this.picker().hide();
19065 this.viewMode = this.startViewMode;
19068 this.fireEvent('hidepopup', this, this.date);
19072 onMousedown: function(e)
19074 e.stopPropagation();
19075 e.preventDefault();
19080 Roo.bootstrap.DateField.superclass.keyup.call(this);
19084 setValue: function(v)
19086 if(this.fireEvent('beforeselect', this, v) !== false){
19087 var d = new Date(this.parseDate(v) ).clearTime();
19089 if(isNaN(d.getTime())){
19090 this.date = this.viewDate = '';
19091 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
19095 v = this.formatDate(d);
19097 Roo.bootstrap.DateField.superclass.setValue.call(this, v);
19099 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
19103 this.fireEvent('select', this, this.date);
19107 getValue: function()
19109 return this.formatDate(this.date);
19112 fireKey: function(e)
19114 if (!this.picker().isVisible()){
19115 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19121 var dateChanged = false,
19123 newDate, newViewDate;
19128 e.preventDefault();
19132 if (!this.keyboardNavigation) {
19135 dir = e.keyCode == 37 ? -1 : 1;
19138 newDate = this.moveYear(this.date, dir);
19139 newViewDate = this.moveYear(this.viewDate, dir);
19140 } else if (e.shiftKey){
19141 newDate = this.moveMonth(this.date, dir);
19142 newViewDate = this.moveMonth(this.viewDate, dir);
19144 newDate = new Date(this.date);
19145 newDate.setUTCDate(this.date.getUTCDate() + dir);
19146 newViewDate = new Date(this.viewDate);
19147 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
19149 if (this.dateWithinRange(newDate)){
19150 this.date = newDate;
19151 this.viewDate = newViewDate;
19152 this.setValue(this.formatDate(this.date));
19154 e.preventDefault();
19155 dateChanged = true;
19160 if (!this.keyboardNavigation) {
19163 dir = e.keyCode == 38 ? -1 : 1;
19165 newDate = this.moveYear(this.date, dir);
19166 newViewDate = this.moveYear(this.viewDate, dir);
19167 } else if (e.shiftKey){
19168 newDate = this.moveMonth(this.date, dir);
19169 newViewDate = this.moveMonth(this.viewDate, dir);
19171 newDate = new Date(this.date);
19172 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
19173 newViewDate = new Date(this.viewDate);
19174 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
19176 if (this.dateWithinRange(newDate)){
19177 this.date = newDate;
19178 this.viewDate = newViewDate;
19179 this.setValue(this.formatDate(this.date));
19181 e.preventDefault();
19182 dateChanged = true;
19186 this.setValue(this.formatDate(this.date));
19188 e.preventDefault();
19191 this.setValue(this.formatDate(this.date));
19205 onClick: function(e)
19207 e.stopPropagation();
19208 e.preventDefault();
19210 var target = e.getTarget();
19212 if(target.nodeName.toLowerCase() === 'i'){
19213 target = Roo.get(target).dom.parentNode;
19216 var nodeName = target.nodeName;
19217 var className = target.className;
19218 var html = target.innerHTML;
19219 //Roo.log(nodeName);
19221 switch(nodeName.toLowerCase()) {
19223 switch(className) {
19229 var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
19230 switch(this.viewMode){
19232 this.viewDate = this.moveMonth(this.viewDate, dir);
19236 this.viewDate = this.moveYear(this.viewDate, dir);
19242 var date = new Date();
19243 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
19245 this.setValue(this.formatDate(this.date));
19252 if (className.indexOf('disabled') < 0) {
19253 this.viewDate.setUTCDate(1);
19254 if (className.indexOf('month') > -1) {
19255 this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
19257 var year = parseInt(html, 10) || 0;
19258 this.viewDate.setUTCFullYear(year);
19262 if(this.singleMode){
19263 this.setValue(this.formatDate(this.viewDate));
19274 //Roo.log(className);
19275 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
19276 var day = parseInt(html, 10) || 1;
19277 var year = this.viewDate.getUTCFullYear(),
19278 month = this.viewDate.getUTCMonth();
19280 if (className.indexOf('old') > -1) {
19287 } else if (className.indexOf('new') > -1) {
19295 //Roo.log([year,month,day]);
19296 this.date = this.UTCDate(year, month, day,0,0,0,0);
19297 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
19299 //Roo.log(this.formatDate(this.date));
19300 this.setValue(this.formatDate(this.date));
19307 setStartDate: function(startDate)
19309 this.startDate = startDate || -Infinity;
19310 if (this.startDate !== -Infinity) {
19311 this.startDate = this.parseDate(this.startDate);
19314 this.updateNavArrows();
19317 setEndDate: function(endDate)
19319 this.endDate = endDate || Infinity;
19320 if (this.endDate !== Infinity) {
19321 this.endDate = this.parseDate(this.endDate);
19324 this.updateNavArrows();
19327 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
19329 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
19330 if (typeof(this.daysOfWeekDisabled) !== 'object') {
19331 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
19333 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
19334 return parseInt(d, 10);
19337 this.updateNavArrows();
19340 updateNavArrows: function()
19342 if(this.singleMode){
19346 var d = new Date(this.viewDate),
19347 year = d.getUTCFullYear(),
19348 month = d.getUTCMonth();
19350 Roo.each(this.picker().select('.prev', true).elements, function(v){
19352 switch (this.viewMode) {
19355 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
19361 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
19368 Roo.each(this.picker().select('.next', true).elements, function(v){
19370 switch (this.viewMode) {
19373 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
19379 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
19387 moveMonth: function(date, dir)
19392 var new_date = new Date(date.valueOf()),
19393 day = new_date.getUTCDate(),
19394 month = new_date.getUTCMonth(),
19395 mag = Math.abs(dir),
19397 dir = dir > 0 ? 1 : -1;
19400 // If going back one month, make sure month is not current month
19401 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
19403 return new_date.getUTCMonth() == month;
19405 // If going forward one month, make sure month is as expected
19406 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
19408 return new_date.getUTCMonth() != new_month;
19410 new_month = month + dir;
19411 new_date.setUTCMonth(new_month);
19412 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
19413 if (new_month < 0 || new_month > 11) {
19414 new_month = (new_month + 12) % 12;
19417 // For magnitudes >1, move one month at a time...
19418 for (var i=0; i<mag; i++) {
19419 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
19420 new_date = this.moveMonth(new_date, dir);
19422 // ...then reset the day, keeping it in the new month
19423 new_month = new_date.getUTCMonth();
19424 new_date.setUTCDate(day);
19426 return new_month != new_date.getUTCMonth();
19429 // Common date-resetting loop -- if date is beyond end of month, make it
19432 new_date.setUTCDate(--day);
19433 new_date.setUTCMonth(new_month);
19438 moveYear: function(date, dir)
19440 return this.moveMonth(date, dir*12);
19443 dateWithinRange: function(date)
19445 return date >= this.startDate && date <= this.endDate;
19451 this.picker().remove();
19454 validateValue : function(value)
19456 if(this.getVisibilityEl().hasClass('hidden')){
19460 if(value.length < 1) {
19461 if(this.allowBlank){
19467 if(value.length < this.minLength){
19470 if(value.length > this.maxLength){
19474 var vt = Roo.form.VTypes;
19475 if(!vt[this.vtype](value, this)){
19479 if(typeof this.validator == "function"){
19480 var msg = this.validator(value);
19486 if(this.regex && !this.regex.test(value)){
19490 if(typeof(this.parseDate(value)) == 'undefined'){
19494 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
19498 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
19508 this.date = this.viewDate = '';
19510 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
19515 Roo.apply(Roo.bootstrap.DateField, {
19526 html: '<i class="fa fa-arrow-left"/>'
19536 html: '<i class="fa fa-arrow-right"/>'
19578 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
19579 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
19580 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
19581 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19582 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
19595 navFnc: 'FullYear',
19600 navFnc: 'FullYear',
19605 Roo.apply(Roo.bootstrap.DateField, {
19609 cls: 'datepicker dropdown-menu roo-dynamic',
19613 cls: 'datepicker-days',
19617 cls: 'table-condensed',
19619 Roo.bootstrap.DateField.head,
19623 Roo.bootstrap.DateField.footer
19630 cls: 'datepicker-months',
19634 cls: 'table-condensed',
19636 Roo.bootstrap.DateField.head,
19637 Roo.bootstrap.DateField.content,
19638 Roo.bootstrap.DateField.footer
19645 cls: 'datepicker-years',
19649 cls: 'table-condensed',
19651 Roo.bootstrap.DateField.head,
19652 Roo.bootstrap.DateField.content,
19653 Roo.bootstrap.DateField.footer
19672 * @class Roo.bootstrap.TimeField
19673 * @extends Roo.bootstrap.Input
19674 * Bootstrap DateField class
19678 * Create a new TimeField
19679 * @param {Object} config The config object
19682 Roo.bootstrap.TimeField = function(config){
19683 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
19687 * Fires when this field show.
19688 * @param {Roo.bootstrap.DateField} thisthis
19689 * @param {Mixed} date The date value
19694 * Fires when this field hide.
19695 * @param {Roo.bootstrap.DateField} this
19696 * @param {Mixed} date The date value
19701 * Fires when select a date.
19702 * @param {Roo.bootstrap.DateField} this
19703 * @param {Mixed} date The date value
19709 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
19712 * @cfg {String} format
19713 * The default time format string which can be overriden for localization support. The format must be
19714 * valid according to {@link Date#parseDate} (defaults to 'H:i').
19718 onRender: function(ct, position)
19721 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
19723 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
19725 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19727 this.pop = this.picker().select('>.datepicker-time',true).first();
19728 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19730 this.picker().on('mousedown', this.onMousedown, this);
19731 this.picker().on('click', this.onClick, this);
19733 this.picker().addClass('datepicker-dropdown');
19738 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
19739 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
19740 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
19741 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
19742 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
19743 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
19747 fireKey: function(e){
19748 if (!this.picker().isVisible()){
19749 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19755 e.preventDefault();
19763 this.onTogglePeriod();
19766 this.onIncrementMinutes();
19769 this.onDecrementMinutes();
19778 onClick: function(e) {
19779 e.stopPropagation();
19780 e.preventDefault();
19783 picker : function()
19785 return this.el.select('.datepicker', true).first();
19788 fillTime: function()
19790 var time = this.pop.select('tbody', true).first();
19792 time.dom.innerHTML = '';
19807 cls: 'hours-up glyphicon glyphicon-chevron-up'
19827 cls: 'minutes-up glyphicon glyphicon-chevron-up'
19848 cls: 'timepicker-hour',
19863 cls: 'timepicker-minute',
19878 cls: 'btn btn-primary period',
19900 cls: 'hours-down glyphicon glyphicon-chevron-down'
19920 cls: 'minutes-down glyphicon glyphicon-chevron-down'
19938 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
19945 var hours = this.time.getHours();
19946 var minutes = this.time.getMinutes();
19959 hours = hours - 12;
19963 hours = '0' + hours;
19967 minutes = '0' + minutes;
19970 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
19971 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
19972 this.pop.select('button', true).first().dom.innerHTML = period;
19978 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
19980 var cls = ['bottom'];
19982 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
19989 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
19994 this.picker().addClass(cls.join('-'));
19998 Roo.each(cls, function(c){
20000 _this.picker().setTop(_this.inputEl().getHeight());
20004 _this.picker().setTop(0 - _this.picker().getHeight());
20009 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
20013 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
20020 onFocus : function()
20022 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
20026 onBlur : function()
20028 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
20034 this.picker().show();
20039 this.fireEvent('show', this, this.date);
20044 this.picker().hide();
20047 this.fireEvent('hide', this, this.date);
20050 setTime : function()
20053 this.setValue(this.time.format(this.format));
20055 this.fireEvent('select', this, this.date);
20060 onMousedown: function(e){
20061 e.stopPropagation();
20062 e.preventDefault();
20065 onIncrementHours: function()
20067 Roo.log('onIncrementHours');
20068 this.time = this.time.add(Date.HOUR, 1);
20073 onDecrementHours: function()
20075 Roo.log('onDecrementHours');
20076 this.time = this.time.add(Date.HOUR, -1);
20080 onIncrementMinutes: function()
20082 Roo.log('onIncrementMinutes');
20083 this.time = this.time.add(Date.MINUTE, 1);
20087 onDecrementMinutes: function()
20089 Roo.log('onDecrementMinutes');
20090 this.time = this.time.add(Date.MINUTE, -1);
20094 onTogglePeriod: function()
20096 Roo.log('onTogglePeriod');
20097 this.time = this.time.add(Date.HOUR, 12);
20104 Roo.apply(Roo.bootstrap.TimeField, {
20134 cls: 'btn btn-info ok',
20146 Roo.apply(Roo.bootstrap.TimeField, {
20150 cls: 'datepicker dropdown-menu',
20154 cls: 'datepicker-time',
20158 cls: 'table-condensed',
20160 Roo.bootstrap.TimeField.content,
20161 Roo.bootstrap.TimeField.footer
20180 * @class Roo.bootstrap.MonthField
20181 * @extends Roo.bootstrap.Input
20182 * Bootstrap MonthField class
20184 * @cfg {String} language default en
20187 * Create a new MonthField
20188 * @param {Object} config The config object
20191 Roo.bootstrap.MonthField = function(config){
20192 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
20197 * Fires when this field show.
20198 * @param {Roo.bootstrap.MonthField} this
20199 * @param {Mixed} date The date value
20204 * Fires when this field hide.
20205 * @param {Roo.bootstrap.MonthField} this
20206 * @param {Mixed} date The date value
20211 * Fires when select a date.
20212 * @param {Roo.bootstrap.MonthField} this
20213 * @param {String} oldvalue The old value
20214 * @param {String} newvalue The new value
20220 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
20222 onRender: function(ct, position)
20225 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
20227 this.language = this.language || 'en';
20228 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
20229 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
20231 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
20232 this.isInline = false;
20233 this.isInput = true;
20234 this.component = this.el.select('.add-on', true).first() || false;
20235 this.component = (this.component && this.component.length === 0) ? false : this.component;
20236 this.hasInput = this.component && this.inputEL().length;
20238 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
20240 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
20242 this.picker().on('mousedown', this.onMousedown, this);
20243 this.picker().on('click', this.onClick, this);
20245 this.picker().addClass('datepicker-dropdown');
20247 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
20248 v.setStyle('width', '189px');
20255 if(this.isInline) {
20261 setValue: function(v, suppressEvent)
20263 var o = this.getValue();
20265 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
20269 if(suppressEvent !== true){
20270 this.fireEvent('select', this, o, v);
20275 getValue: function()
20280 onClick: function(e)
20282 e.stopPropagation();
20283 e.preventDefault();
20285 var target = e.getTarget();
20287 if(target.nodeName.toLowerCase() === 'i'){
20288 target = Roo.get(target).dom.parentNode;
20291 var nodeName = target.nodeName;
20292 var className = target.className;
20293 var html = target.innerHTML;
20295 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
20299 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
20301 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20307 picker : function()
20309 return this.pickerEl;
20312 fillMonths: function()
20315 var months = this.picker().select('>.datepicker-months td', true).first();
20317 months.dom.innerHTML = '';
20323 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
20326 months.createChild(month);
20335 if(typeof(this.vIndex) == 'undefined' && this.value.length){
20336 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
20339 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
20340 e.removeClass('active');
20342 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
20343 e.addClass('active');
20350 if(this.isInline) {
20354 this.picker().removeClass(['bottom', 'top']);
20356 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
20358 * place to the top of element!
20362 this.picker().addClass('top');
20363 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
20368 this.picker().addClass('bottom');
20370 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
20373 onFocus : function()
20375 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
20379 onBlur : function()
20381 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
20383 var d = this.inputEl().getValue();
20392 this.picker().show();
20393 this.picker().select('>.datepicker-months', true).first().show();
20397 this.fireEvent('show', this, this.date);
20402 if(this.isInline) {
20405 this.picker().hide();
20406 this.fireEvent('hide', this, this.date);
20410 onMousedown: function(e)
20412 e.stopPropagation();
20413 e.preventDefault();
20418 Roo.bootstrap.MonthField.superclass.keyup.call(this);
20422 fireKey: function(e)
20424 if (!this.picker().isVisible()){
20425 if (e.keyCode == 27) {// allow escape to hide and re-show picker
20436 e.preventDefault();
20440 dir = e.keyCode == 37 ? -1 : 1;
20442 this.vIndex = this.vIndex + dir;
20444 if(this.vIndex < 0){
20448 if(this.vIndex > 11){
20452 if(isNaN(this.vIndex)){
20456 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20462 dir = e.keyCode == 38 ? -1 : 1;
20464 this.vIndex = this.vIndex + dir * 4;
20466 if(this.vIndex < 0){
20470 if(this.vIndex > 11){
20474 if(isNaN(this.vIndex)){
20478 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20483 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20484 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20488 e.preventDefault();
20491 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20492 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20508 this.picker().remove();
20513 Roo.apply(Roo.bootstrap.MonthField, {
20532 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
20533 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
20538 Roo.apply(Roo.bootstrap.MonthField, {
20542 cls: 'datepicker dropdown-menu roo-dynamic',
20546 cls: 'datepicker-months',
20550 cls: 'table-condensed',
20552 Roo.bootstrap.DateField.content
20572 * @class Roo.bootstrap.CheckBox
20573 * @extends Roo.bootstrap.Input
20574 * Bootstrap CheckBox class
20576 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20577 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
20578 * @cfg {String} boxLabel The text that appears beside the checkbox
20579 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
20580 * @cfg {Boolean} checked initnal the element
20581 * @cfg {Boolean} inline inline the element (default false)
20582 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
20583 * @cfg {String} tooltip label tooltip
20586 * Create a new CheckBox
20587 * @param {Object} config The config object
20590 Roo.bootstrap.CheckBox = function(config){
20591 Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
20596 * Fires when the element is checked or unchecked.
20597 * @param {Roo.bootstrap.CheckBox} this This input
20598 * @param {Boolean} checked The new checked value
20603 * Fires when the element is click.
20604 * @param {Roo.bootstrap.CheckBox} this This input
20611 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input, {
20613 inputType: 'checkbox',
20622 getAutoCreate : function()
20624 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
20630 cfg.cls = 'form-group ' + this.inputType; //input-group
20633 cfg.cls += ' ' + this.inputType + '-inline';
20639 type : this.inputType,
20640 value : this.inputValue,
20641 cls : 'roo-' + this.inputType, //'form-box',
20642 placeholder : this.placeholder || ''
20646 if(this.inputType != 'radio'){
20650 cls : 'roo-hidden-value',
20651 value : this.checked ? this.inputValue : this.valueOff
20656 if (this.weight) { // Validity check?
20657 cfg.cls += " " + this.inputType + "-" + this.weight;
20660 if (this.disabled) {
20661 input.disabled=true;
20665 input.checked = this.checked;
20670 input.name = this.name;
20672 if(this.inputType != 'radio'){
20673 hidden.name = this.name;
20674 input.name = '_hidden_' + this.name;
20679 input.cls += ' input-' + this.size;
20684 ['xs','sm','md','lg'].map(function(size){
20685 if (settings[size]) {
20686 cfg.cls += ' col-' + size + '-' + settings[size];
20690 var inputblock = input;
20692 if (this.before || this.after) {
20695 cls : 'input-group',
20700 inputblock.cn.push({
20702 cls : 'input-group-addon',
20707 inputblock.cn.push(input);
20709 if(this.inputType != 'radio'){
20710 inputblock.cn.push(hidden);
20714 inputblock.cn.push({
20716 cls : 'input-group-addon',
20723 if (align ==='left' && this.fieldLabel.length) {
20724 // Roo.log("left and has label");
20729 cls : 'control-label',
20730 html : this.fieldLabel
20740 if(this.labelWidth > 12){
20741 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
20744 if(this.labelWidth < 13 && this.labelmd == 0){
20745 this.labelmd = this.labelWidth;
20748 if(this.labellg > 0){
20749 cfg.cn[0].cls += ' col-lg-' + this.labellg;
20750 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
20753 if(this.labelmd > 0){
20754 cfg.cn[0].cls += ' col-md-' + this.labelmd;
20755 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
20758 if(this.labelsm > 0){
20759 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
20760 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
20763 if(this.labelxs > 0){
20764 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
20765 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
20768 } else if ( this.fieldLabel.length) {
20769 // Roo.log(" label");
20773 tag: this.boxLabel ? 'span' : 'label',
20775 cls: 'control-label box-input-label',
20776 //cls : 'input-group-addon',
20777 html : this.fieldLabel
20786 // Roo.log(" no label && no align");
20787 cfg.cn = [ inputblock ] ;
20793 var boxLabelCfg = {
20795 //'for': id, // box label is handled by onclick - so no for...
20797 html: this.boxLabel
20801 boxLabelCfg.tooltip = this.tooltip;
20804 cfg.cn.push(boxLabelCfg);
20807 if(this.inputType != 'radio'){
20808 cfg.cn.push(hidden);
20816 * return the real input element.
20818 inputEl: function ()
20820 return this.el.select('input.roo-' + this.inputType,true).first();
20822 hiddenEl: function ()
20824 return this.el.select('input.roo-hidden-value',true).first();
20827 labelEl: function()
20829 return this.el.select('label.control-label',true).first();
20831 /* depricated... */
20835 return this.labelEl();
20838 boxLabelEl: function()
20840 return this.el.select('label.box-label',true).first();
20843 initEvents : function()
20845 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
20847 this.inputEl().on('click', this.onClick, this);
20849 if (this.boxLabel) {
20850 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
20853 this.startValue = this.getValue();
20856 Roo.bootstrap.CheckBox.register(this);
20860 onClick : function(e)
20862 if(this.fireEvent('click', this, e) !== false){
20863 this.setChecked(!this.checked);
20868 setChecked : function(state,suppressEvent)
20870 this.startValue = this.getValue();
20872 if(this.inputType == 'radio'){
20874 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20875 e.dom.checked = false;
20878 this.inputEl().dom.checked = true;
20880 this.inputEl().dom.value = this.inputValue;
20882 if(suppressEvent !== true){
20883 this.fireEvent('check', this, true);
20891 this.checked = state;
20893 this.inputEl().dom.checked = state;
20896 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
20898 if(suppressEvent !== true){
20899 this.fireEvent('check', this, state);
20905 getValue : function()
20907 if(this.inputType == 'radio'){
20908 return this.getGroupValue();
20911 return this.hiddenEl().dom.value;
20915 getGroupValue : function()
20917 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
20921 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
20924 setValue : function(v,suppressEvent)
20926 if(this.inputType == 'radio'){
20927 this.setGroupValue(v, suppressEvent);
20931 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
20936 setGroupValue : function(v, suppressEvent)
20938 this.startValue = this.getValue();
20940 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20941 e.dom.checked = false;
20943 if(e.dom.value == v){
20944 e.dom.checked = true;
20948 if(suppressEvent !== true){
20949 this.fireEvent('check', this, true);
20957 validate : function()
20959 if(this.getVisibilityEl().hasClass('hidden')){
20965 (this.inputType == 'radio' && this.validateRadio()) ||
20966 (this.inputType == 'checkbox' && this.validateCheckbox())
20972 this.markInvalid();
20976 validateRadio : function()
20978 if(this.getVisibilityEl().hasClass('hidden')){
20982 if(this.allowBlank){
20988 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20989 if(!e.dom.checked){
21001 validateCheckbox : function()
21004 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
21005 //return (this.getValue() == this.inputValue) ? true : false;
21008 var group = Roo.bootstrap.CheckBox.get(this.groupId);
21016 for(var i in group){
21017 if(group[i].el.isVisible(true)){
21025 for(var i in group){
21030 r = (group[i].getValue() == group[i].inputValue) ? true : false;
21037 * Mark this field as valid
21039 markValid : function()
21043 this.fireEvent('valid', this);
21045 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21048 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
21055 if(this.inputType == 'radio'){
21056 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21057 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
21058 e.findParent('.form-group', false, true).addClass(_this.validClass);
21065 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21066 this.el.findParent('.form-group', false, true).addClass(this.validClass);
21070 var group = Roo.bootstrap.CheckBox.get(this.groupId);
21076 for(var i in group){
21077 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21078 group[i].el.findParent('.form-group', false, true).addClass(this.validClass);
21083 * Mark this field as invalid
21084 * @param {String} msg The validation message
21086 markInvalid : function(msg)
21088 if(this.allowBlank){
21094 this.fireEvent('invalid', this, msg);
21096 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21099 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
21103 label.markInvalid();
21106 if(this.inputType == 'radio'){
21107 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21108 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
21109 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
21116 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21117 this.el.findParent('.form-group', false, true).addClass(this.invalidClass);
21121 var group = Roo.bootstrap.CheckBox.get(this.groupId);
21127 for(var i in group){
21128 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21129 group[i].el.findParent('.form-group', false, true).addClass(this.invalidClass);
21134 clearInvalid : function()
21136 Roo.bootstrap.Input.prototype.clearInvalid.call(this);
21138 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21140 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21142 if (label && label.iconEl) {
21143 label.iconEl.removeClass(label.validClass);
21144 label.iconEl.removeClass(label.invalidClass);
21148 disable : function()
21150 if(this.inputType != 'radio'){
21151 Roo.bootstrap.CheckBox.superclass.disable.call(this);
21158 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21159 _this.getActionEl().addClass(this.disabledClass);
21160 e.dom.disabled = true;
21164 this.disabled = true;
21165 this.fireEvent("disable", this);
21169 enable : function()
21171 if(this.inputType != 'radio'){
21172 Roo.bootstrap.CheckBox.superclass.enable.call(this);
21179 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21180 _this.getActionEl().removeClass(this.disabledClass);
21181 e.dom.disabled = false;
21185 this.disabled = false;
21186 this.fireEvent("enable", this);
21190 setBoxLabel : function(v)
21195 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21201 Roo.apply(Roo.bootstrap.CheckBox, {
21206 * register a CheckBox Group
21207 * @param {Roo.bootstrap.CheckBox} the CheckBox to add
21209 register : function(checkbox)
21211 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
21212 this.groups[checkbox.groupId] = {};
21215 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
21219 this.groups[checkbox.groupId][checkbox.name] = checkbox;
21223 * fetch a CheckBox Group based on the group ID
21224 * @param {string} the group ID
21225 * @returns {Roo.bootstrap.CheckBox} the CheckBox group
21227 get: function(groupId) {
21228 if (typeof(this.groups[groupId]) == 'undefined') {
21232 return this.groups[groupId] ;
21245 * @class Roo.bootstrap.Radio
21246 * @extends Roo.bootstrap.Component
21247 * Bootstrap Radio class
21248 * @cfg {String} boxLabel - the label associated
21249 * @cfg {String} value - the value of radio
21252 * Create a new Radio
21253 * @param {Object} config The config object
21255 Roo.bootstrap.Radio = function(config){
21256 Roo.bootstrap.Radio.superclass.constructor.call(this, config);
21260 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.Component, {
21266 getAutoCreate : function()
21270 cls : 'form-group radio',
21275 html : this.boxLabel
21283 initEvents : function()
21285 this.parent().register(this);
21287 this.el.on('click', this.onClick, this);
21291 onClick : function(e)
21293 if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
21294 this.setChecked(true);
21298 setChecked : function(state, suppressEvent)
21300 this.parent().setValue(this.value, suppressEvent);
21304 setBoxLabel : function(v)
21309 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21324 * @class Roo.bootstrap.SecurePass
21325 * @extends Roo.bootstrap.Input
21326 * Bootstrap SecurePass class
21330 * Create a new SecurePass
21331 * @param {Object} config The config object
21334 Roo.bootstrap.SecurePass = function (config) {
21335 // these go here, so the translation tool can replace them..
21337 PwdEmpty: "Please type a password, and then retype it to confirm.",
21338 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21339 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21340 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21341 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21342 FNInPwd: "Your password can't contain your first name. Please type a different password.",
21343 LNInPwd: "Your password can't contain your last name. Please type a different password.",
21344 TooWeak: "Your password is Too Weak."
21346 this.meterLabel = "Password strength:";
21347 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
21348 this.meterClass = [
21349 "roo-password-meter-tooweak",
21350 "roo-password-meter-weak",
21351 "roo-password-meter-medium",
21352 "roo-password-meter-strong",
21353 "roo-password-meter-grey"
21358 Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
21361 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
21363 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
21365 * PwdEmpty: "Please type a password, and then retype it to confirm.",
21366 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21367 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21368 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21369 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21370 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
21371 * LNInPwd: "Your password can't contain your last name. Please type a different password."
21381 * @cfg {String/Object} Label for the strength meter (defaults to
21382 * 'Password strength:')
21387 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
21388 * ['Weak', 'Medium', 'Strong'])
21391 pwdStrengths: false,
21404 initEvents: function ()
21406 Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
21408 if (this.el.is('input[type=password]') && Roo.isSafari) {
21409 this.el.on('keydown', this.SafariOnKeyDown, this);
21412 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
21415 onRender: function (ct, position)
21417 Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
21418 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
21419 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
21421 this.trigger.createChild({
21426 cls: 'roo-password-meter-grey col-xs-12',
21429 //width: this.meterWidth + 'px'
21433 cls: 'roo-password-meter-text'
21439 if (this.hideTrigger) {
21440 this.trigger.setDisplayed(false);
21442 this.setSize(this.width || '', this.height || '');
21445 onDestroy: function ()
21447 if (this.trigger) {
21448 this.trigger.removeAllListeners();
21449 this.trigger.remove();
21452 this.wrap.remove();
21454 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
21457 checkStrength: function ()
21459 var pwd = this.inputEl().getValue();
21460 if (pwd == this._lastPwd) {
21465 if (this.ClientSideStrongPassword(pwd)) {
21467 } else if (this.ClientSideMediumPassword(pwd)) {
21469 } else if (this.ClientSideWeakPassword(pwd)) {
21475 Roo.log('strength1: ' + strength);
21477 //var pm = this.trigger.child('div/div/div').dom;
21478 var pm = this.trigger.child('div/div');
21479 pm.removeClass(this.meterClass);
21480 pm.addClass(this.meterClass[strength]);
21483 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21485 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21487 this._lastPwd = pwd;
21491 Roo.bootstrap.SecurePass.superclass.reset.call(this);
21493 this._lastPwd = '';
21495 var pm = this.trigger.child('div/div');
21496 pm.removeClass(this.meterClass);
21497 pm.addClass('roo-password-meter-grey');
21500 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21503 this.inputEl().dom.type='password';
21506 validateValue: function (value)
21509 if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
21512 if (value.length == 0) {
21513 if (this.allowBlank) {
21514 this.clearInvalid();
21518 this.markInvalid(this.errors.PwdEmpty);
21519 this.errorMsg = this.errors.PwdEmpty;
21527 if ('[\x21-\x7e]*'.match(value)) {
21528 this.markInvalid(this.errors.PwdBadChar);
21529 this.errorMsg = this.errors.PwdBadChar;
21532 if (value.length < 6) {
21533 this.markInvalid(this.errors.PwdShort);
21534 this.errorMsg = this.errors.PwdShort;
21537 if (value.length > 16) {
21538 this.markInvalid(this.errors.PwdLong);
21539 this.errorMsg = this.errors.PwdLong;
21543 if (this.ClientSideStrongPassword(value)) {
21545 } else if (this.ClientSideMediumPassword(value)) {
21547 } else if (this.ClientSideWeakPassword(value)) {
21554 if (strength < 2) {
21555 //this.markInvalid(this.errors.TooWeak);
21556 this.errorMsg = this.errors.TooWeak;
21561 console.log('strength2: ' + strength);
21563 //var pm = this.trigger.child('div/div/div').dom;
21565 var pm = this.trigger.child('div/div');
21566 pm.removeClass(this.meterClass);
21567 pm.addClass(this.meterClass[strength]);
21569 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21571 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21573 this.errorMsg = '';
21577 CharacterSetChecks: function (type)
21580 this.fResult = false;
21583 isctype: function (character, type)
21586 case this.kCapitalLetter:
21587 if (character >= 'A' && character <= 'Z') {
21592 case this.kSmallLetter:
21593 if (character >= 'a' && character <= 'z') {
21599 if (character >= '0' && character <= '9') {
21604 case this.kPunctuation:
21605 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
21616 IsLongEnough: function (pwd, size)
21618 return !(pwd == null || isNaN(size) || pwd.length < size);
21621 SpansEnoughCharacterSets: function (word, nb)
21623 if (!this.IsLongEnough(word, nb))
21628 var characterSetChecks = new Array(
21629 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
21630 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
21633 for (var index = 0; index < word.length; ++index) {
21634 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21635 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
21636 characterSetChecks[nCharSet].fResult = true;
21643 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21644 if (characterSetChecks[nCharSet].fResult) {
21649 if (nCharSets < nb) {
21655 ClientSideStrongPassword: function (pwd)
21657 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
21660 ClientSideMediumPassword: function (pwd)
21662 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
21665 ClientSideWeakPassword: function (pwd)
21667 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
21670 })//<script type="text/javascript">
21673 * Based Ext JS Library 1.1.1
21674 * Copyright(c) 2006-2007, Ext JS, LLC.
21680 * @class Roo.HtmlEditorCore
21681 * @extends Roo.Component
21682 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
21684 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
21687 Roo.HtmlEditorCore = function(config){
21690 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
21695 * @event initialize
21696 * Fires when the editor is fully initialized (including the iframe)
21697 * @param {Roo.HtmlEditorCore} this
21702 * Fires when the editor is first receives the focus. Any insertion must wait
21703 * until after this event.
21704 * @param {Roo.HtmlEditorCore} this
21708 * @event beforesync
21709 * Fires before the textarea is updated with content from the editor iframe. Return false
21710 * to cancel the sync.
21711 * @param {Roo.HtmlEditorCore} this
21712 * @param {String} html
21716 * @event beforepush
21717 * Fires before the iframe editor is updated with content from the textarea. Return false
21718 * to cancel the push.
21719 * @param {Roo.HtmlEditorCore} this
21720 * @param {String} html
21725 * Fires when the textarea is updated with content from the editor iframe.
21726 * @param {Roo.HtmlEditorCore} this
21727 * @param {String} html
21732 * Fires when the iframe editor is updated with content from the textarea.
21733 * @param {Roo.HtmlEditorCore} this
21734 * @param {String} html
21739 * @event editorevent
21740 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21741 * @param {Roo.HtmlEditorCore} this
21747 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
21749 // defaults : white / black...
21750 this.applyBlacklists();
21757 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
21761 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
21767 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
21772 * @cfg {Number} height (in pixels)
21776 * @cfg {Number} width (in pixels)
21781 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21784 stylesheets: false,
21789 // private properties
21790 validationEvent : false,
21792 initialized : false,
21794 sourceEditMode : false,
21795 onFocus : Roo.emptyFn,
21797 hideMode:'offsets',
21801 // blacklist + whitelisted elements..
21808 * Protected method that will not generally be called directly. It
21809 * is called when the editor initializes the iframe with HTML contents. Override this method if you
21810 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
21812 getDocMarkup : function(){
21816 // inherit styels from page...??
21817 if (this.stylesheets === false) {
21819 Roo.get(document.head).select('style').each(function(node) {
21820 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21823 Roo.get(document.head).select('link').each(function(node) {
21824 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21827 } else if (!this.stylesheets.length) {
21829 st = '<style type="text/css">' +
21830 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21833 st = '<style type="text/css">' +
21838 st += '<style type="text/css">' +
21839 'IMG { cursor: pointer } ' +
21842 var cls = 'roo-htmleditor-body';
21844 if(this.bodyCls.length){
21845 cls += ' ' + this.bodyCls;
21848 return '<html><head>' + st +
21849 //<style type="text/css">' +
21850 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21852 ' </head><body class="' + cls + '"></body></html>';
21856 onRender : function(ct, position)
21859 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
21860 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
21863 this.el.dom.style.border = '0 none';
21864 this.el.dom.setAttribute('tabIndex', -1);
21865 this.el.addClass('x-hidden hide');
21869 if(Roo.isIE){ // fix IE 1px bogus margin
21870 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
21874 this.frameId = Roo.id();
21878 var iframe = this.owner.wrap.createChild({
21880 cls: 'form-control', // bootstrap..
21882 name: this.frameId,
21883 frameBorder : 'no',
21884 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
21889 this.iframe = iframe.dom;
21891 this.assignDocWin();
21893 this.doc.designMode = 'on';
21896 this.doc.write(this.getDocMarkup());
21900 var task = { // must defer to wait for browser to be ready
21902 //console.log("run task?" + this.doc.readyState);
21903 this.assignDocWin();
21904 if(this.doc.body || this.doc.readyState == 'complete'){
21906 this.doc.designMode="on";
21910 Roo.TaskMgr.stop(task);
21911 this.initEditor.defer(10, this);
21918 Roo.TaskMgr.start(task);
21923 onResize : function(w, h)
21925 Roo.log('resize: ' +w + ',' + h );
21926 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
21930 if(typeof w == 'number'){
21932 this.iframe.style.width = w + 'px';
21934 if(typeof h == 'number'){
21936 this.iframe.style.height = h + 'px';
21938 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
21945 * Toggles the editor between standard and source edit mode.
21946 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21948 toggleSourceEdit : function(sourceEditMode){
21950 this.sourceEditMode = sourceEditMode === true;
21952 if(this.sourceEditMode){
21954 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
21957 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
21958 //this.iframe.className = '';
21961 //this.setSize(this.owner.wrap.getSize());
21962 //this.fireEvent('editmodechange', this, this.sourceEditMode);
21969 * Protected method that will not generally be called directly. If you need/want
21970 * custom HTML cleanup, this is the method you should override.
21971 * @param {String} html The HTML to be cleaned
21972 * return {String} The cleaned HTML
21974 cleanHtml : function(html){
21975 html = String(html);
21976 if(html.length > 5){
21977 if(Roo.isSafari){ // strip safari nonsense
21978 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
21981 if(html == ' '){
21988 * HTML Editor -> Textarea
21989 * Protected method that will not generally be called directly. Syncs the contents
21990 * of the editor iframe with the textarea.
21992 syncValue : function(){
21993 if(this.initialized){
21994 var bd = (this.doc.body || this.doc.documentElement);
21995 //this.cleanUpPaste(); -- this is done else where and causes havoc..
21996 var html = bd.innerHTML;
21998 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
21999 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
22001 html = '<div style="'+m[0]+'">' + html + '</div>';
22004 html = this.cleanHtml(html);
22005 // fix up the special chars.. normaly like back quotes in word...
22006 // however we do not want to do this with chinese..
22007 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
22008 var cc = b.charCodeAt();
22010 (cc >= 0x4E00 && cc < 0xA000 ) ||
22011 (cc >= 0x3400 && cc < 0x4E00 ) ||
22012 (cc >= 0xf900 && cc < 0xfb00 )
22018 if(this.owner.fireEvent('beforesync', this, html) !== false){
22019 this.el.dom.value = html;
22020 this.owner.fireEvent('sync', this, html);
22026 * Protected method that will not generally be called directly. Pushes the value of the textarea
22027 * into the iframe editor.
22029 pushValue : function(){
22030 if(this.initialized){
22031 var v = this.el.dom.value.trim();
22033 // if(v.length < 1){
22037 if(this.owner.fireEvent('beforepush', this, v) !== false){
22038 var d = (this.doc.body || this.doc.documentElement);
22040 this.cleanUpPaste();
22041 this.el.dom.value = d.innerHTML;
22042 this.owner.fireEvent('push', this, v);
22048 deferFocus : function(){
22049 this.focus.defer(10, this);
22053 focus : function(){
22054 if(this.win && !this.sourceEditMode){
22061 assignDocWin: function()
22063 var iframe = this.iframe;
22066 this.doc = iframe.contentWindow.document;
22067 this.win = iframe.contentWindow;
22069 // if (!Roo.get(this.frameId)) {
22072 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
22073 // this.win = Roo.get(this.frameId).dom.contentWindow;
22075 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
22079 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
22080 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
22085 initEditor : function(){
22086 //console.log("INIT EDITOR");
22087 this.assignDocWin();
22091 this.doc.designMode="on";
22093 this.doc.write(this.getDocMarkup());
22096 var dbody = (this.doc.body || this.doc.documentElement);
22097 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
22098 // this copies styles from the containing element into thsi one..
22099 // not sure why we need all of this..
22100 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
22102 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
22103 //ss['background-attachment'] = 'fixed'; // w3c
22104 dbody.bgProperties = 'fixed'; // ie
22105 //Roo.DomHelper.applyStyles(dbody, ss);
22106 Roo.EventManager.on(this.doc, {
22107 //'mousedown': this.onEditorEvent,
22108 'mouseup': this.onEditorEvent,
22109 'dblclick': this.onEditorEvent,
22110 'click': this.onEditorEvent,
22111 'keyup': this.onEditorEvent,
22116 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
22118 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
22119 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
22121 this.initialized = true;
22123 this.owner.fireEvent('initialize', this);
22128 onDestroy : function(){
22134 //for (var i =0; i < this.toolbars.length;i++) {
22135 // // fixme - ask toolbars for heights?
22136 // this.toolbars[i].onDestroy();
22139 //this.wrap.dom.innerHTML = '';
22140 //this.wrap.remove();
22145 onFirstFocus : function(){
22147 this.assignDocWin();
22150 this.activated = true;
22153 if(Roo.isGecko){ // prevent silly gecko errors
22155 var s = this.win.getSelection();
22156 if(!s.focusNode || s.focusNode.nodeType != 3){
22157 var r = s.getRangeAt(0);
22158 r.selectNodeContents((this.doc.body || this.doc.documentElement));
22163 this.execCmd('useCSS', true);
22164 this.execCmd('styleWithCSS', false);
22167 this.owner.fireEvent('activate', this);
22171 adjustFont: function(btn){
22172 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
22173 //if(Roo.isSafari){ // safari
22176 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
22177 if(Roo.isSafari){ // safari
22178 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
22179 v = (v < 10) ? 10 : v;
22180 v = (v > 48) ? 48 : v;
22181 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
22186 v = Math.max(1, v+adjust);
22188 this.execCmd('FontSize', v );
22191 onEditorEvent : function(e)
22193 this.owner.fireEvent('editorevent', this, e);
22194 // this.updateToolbar();
22195 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
22198 insertTag : function(tg)
22200 // could be a bit smarter... -> wrap the current selected tRoo..
22201 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
22203 range = this.createRange(this.getSelection());
22204 var wrappingNode = this.doc.createElement(tg.toLowerCase());
22205 wrappingNode.appendChild(range.extractContents());
22206 range.insertNode(wrappingNode);
22213 this.execCmd("formatblock", tg);
22217 insertText : function(txt)
22221 var range = this.createRange();
22222 range.deleteContents();
22223 //alert(Sender.getAttribute('label'));
22225 range.insertNode(this.doc.createTextNode(txt));
22231 * Executes a Midas editor command on the editor document and performs necessary focus and
22232 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
22233 * @param {String} cmd The Midas command
22234 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22236 relayCmd : function(cmd, value){
22238 this.execCmd(cmd, value);
22239 this.owner.fireEvent('editorevent', this);
22240 //this.updateToolbar();
22241 this.owner.deferFocus();
22245 * Executes a Midas editor command directly on the editor document.
22246 * For visual commands, you should use {@link #relayCmd} instead.
22247 * <b>This should only be called after the editor is initialized.</b>
22248 * @param {String} cmd The Midas command
22249 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22251 execCmd : function(cmd, value){
22252 this.doc.execCommand(cmd, false, value === undefined ? null : value);
22259 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
22261 * @param {String} text | dom node..
22263 insertAtCursor : function(text)
22266 if(!this.activated){
22272 var r = this.doc.selection.createRange();
22283 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
22287 // from jquery ui (MIT licenced)
22289 var win = this.win;
22291 if (win.getSelection && win.getSelection().getRangeAt) {
22292 range = win.getSelection().getRangeAt(0);
22293 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
22294 range.insertNode(node);
22295 } else if (win.document.selection && win.document.selection.createRange) {
22296 // no firefox support
22297 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22298 win.document.selection.createRange().pasteHTML(txt);
22300 // no firefox support
22301 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22302 this.execCmd('InsertHTML', txt);
22311 mozKeyPress : function(e){
22313 var c = e.getCharCode(), cmd;
22316 c = String.fromCharCode(c).toLowerCase();
22330 this.cleanUpPaste.defer(100, this);
22338 e.preventDefault();
22346 fixKeys : function(){ // load time branching for fastest keydown performance
22348 return function(e){
22349 var k = e.getKey(), r;
22352 r = this.doc.selection.createRange();
22355 r.pasteHTML('    ');
22362 r = this.doc.selection.createRange();
22364 var target = r.parentElement();
22365 if(!target || target.tagName.toLowerCase() != 'li'){
22367 r.pasteHTML('<br />');
22373 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22374 this.cleanUpPaste.defer(100, this);
22380 }else if(Roo.isOpera){
22381 return function(e){
22382 var k = e.getKey();
22386 this.execCmd('InsertHTML','    ');
22389 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22390 this.cleanUpPaste.defer(100, this);
22395 }else if(Roo.isSafari){
22396 return function(e){
22397 var k = e.getKey();
22401 this.execCmd('InsertText','\t');
22405 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22406 this.cleanUpPaste.defer(100, this);
22414 getAllAncestors: function()
22416 var p = this.getSelectedNode();
22419 a.push(p); // push blank onto stack..
22420 p = this.getParentElement();
22424 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
22428 a.push(this.doc.body);
22432 lastSelNode : false,
22435 getSelection : function()
22437 this.assignDocWin();
22438 return Roo.isIE ? this.doc.selection : this.win.getSelection();
22441 getSelectedNode: function()
22443 // this may only work on Gecko!!!
22445 // should we cache this!!!!
22450 var range = this.createRange(this.getSelection()).cloneRange();
22453 var parent = range.parentElement();
22455 var testRange = range.duplicate();
22456 testRange.moveToElementText(parent);
22457 if (testRange.inRange(range)) {
22460 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
22463 parent = parent.parentElement;
22468 // is ancestor a text element.
22469 var ac = range.commonAncestorContainer;
22470 if (ac.nodeType == 3) {
22471 ac = ac.parentNode;
22474 var ar = ac.childNodes;
22477 var other_nodes = [];
22478 var has_other_nodes = false;
22479 for (var i=0;i<ar.length;i++) {
22480 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
22483 // fullly contained node.
22485 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
22490 // probably selected..
22491 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
22492 other_nodes.push(ar[i]);
22496 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
22501 has_other_nodes = true;
22503 if (!nodes.length && other_nodes.length) {
22504 nodes= other_nodes;
22506 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
22512 createRange: function(sel)
22514 // this has strange effects when using with
22515 // top toolbar - not sure if it's a great idea.
22516 //this.editor.contentWindow.focus();
22517 if (typeof sel != "undefined") {
22519 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
22521 return this.doc.createRange();
22524 return this.doc.createRange();
22527 getParentElement: function()
22530 this.assignDocWin();
22531 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
22533 var range = this.createRange(sel);
22536 var p = range.commonAncestorContainer;
22537 while (p.nodeType == 3) { // text node
22548 * Range intersection.. the hard stuff...
22552 * [ -- selected range --- ]
22556 * if end is before start or hits it. fail.
22557 * if start is after end or hits it fail.
22559 * if either hits (but other is outside. - then it's not
22565 // @see http://www.thismuchiknow.co.uk/?p=64.
22566 rangeIntersectsNode : function(range, node)
22568 var nodeRange = node.ownerDocument.createRange();
22570 nodeRange.selectNode(node);
22572 nodeRange.selectNodeContents(node);
22575 var rangeStartRange = range.cloneRange();
22576 rangeStartRange.collapse(true);
22578 var rangeEndRange = range.cloneRange();
22579 rangeEndRange.collapse(false);
22581 var nodeStartRange = nodeRange.cloneRange();
22582 nodeStartRange.collapse(true);
22584 var nodeEndRange = nodeRange.cloneRange();
22585 nodeEndRange.collapse(false);
22587 return rangeStartRange.compareBoundaryPoints(
22588 Range.START_TO_START, nodeEndRange) == -1 &&
22589 rangeEndRange.compareBoundaryPoints(
22590 Range.START_TO_START, nodeStartRange) == 1;
22594 rangeCompareNode : function(range, node)
22596 var nodeRange = node.ownerDocument.createRange();
22598 nodeRange.selectNode(node);
22600 nodeRange.selectNodeContents(node);
22604 range.collapse(true);
22606 nodeRange.collapse(true);
22608 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
22609 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
22611 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
22613 var nodeIsBefore = ss == 1;
22614 var nodeIsAfter = ee == -1;
22616 if (nodeIsBefore && nodeIsAfter) {
22619 if (!nodeIsBefore && nodeIsAfter) {
22620 return 1; //right trailed.
22623 if (nodeIsBefore && !nodeIsAfter) {
22624 return 2; // left trailed.
22630 // private? - in a new class?
22631 cleanUpPaste : function()
22633 // cleans up the whole document..
22634 Roo.log('cleanuppaste');
22636 this.cleanUpChildren(this.doc.body);
22637 var clean = this.cleanWordChars(this.doc.body.innerHTML);
22638 if (clean != this.doc.body.innerHTML) {
22639 this.doc.body.innerHTML = clean;
22644 cleanWordChars : function(input) {// change the chars to hex code
22645 var he = Roo.HtmlEditorCore;
22647 var output = input;
22648 Roo.each(he.swapCodes, function(sw) {
22649 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
22651 output = output.replace(swapper, sw[1]);
22658 cleanUpChildren : function (n)
22660 if (!n.childNodes.length) {
22663 for (var i = n.childNodes.length-1; i > -1 ; i--) {
22664 this.cleanUpChild(n.childNodes[i]);
22671 cleanUpChild : function (node)
22674 //console.log(node);
22675 if (node.nodeName == "#text") {
22676 // clean up silly Windows -- stuff?
22679 if (node.nodeName == "#comment") {
22680 node.parentNode.removeChild(node);
22681 // clean up silly Windows -- stuff?
22684 var lcname = node.tagName.toLowerCase();
22685 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
22686 // whitelist of tags..
22688 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
22690 node.parentNode.removeChild(node);
22695 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
22697 // remove <a name=....> as rendering on yahoo mailer is borked with this.
22698 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
22700 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
22701 // remove_keep_children = true;
22704 if (remove_keep_children) {
22705 this.cleanUpChildren(node);
22706 // inserts everything just before this node...
22707 while (node.childNodes.length) {
22708 var cn = node.childNodes[0];
22709 node.removeChild(cn);
22710 node.parentNode.insertBefore(cn, node);
22712 node.parentNode.removeChild(node);
22716 if (!node.attributes || !node.attributes.length) {
22717 this.cleanUpChildren(node);
22721 function cleanAttr(n,v)
22724 if (v.match(/^\./) || v.match(/^\//)) {
22727 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/) || v.match(/^ftp:/)) {
22730 if (v.match(/^#/)) {
22733 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
22734 node.removeAttribute(n);
22738 var cwhite = this.cwhite;
22739 var cblack = this.cblack;
22741 function cleanStyle(n,v)
22743 if (v.match(/expression/)) { //XSS?? should we even bother..
22744 node.removeAttribute(n);
22748 var parts = v.split(/;/);
22751 Roo.each(parts, function(p) {
22752 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
22756 var l = p.split(':').shift().replace(/\s+/g,'');
22757 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
22759 if ( cwhite.length && cblack.indexOf(l) > -1) {
22760 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22761 //node.removeAttribute(n);
22765 // only allow 'c whitelisted system attributes'
22766 if ( cwhite.length && cwhite.indexOf(l) < 0) {
22767 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22768 //node.removeAttribute(n);
22778 if (clean.length) {
22779 node.setAttribute(n, clean.join(';'));
22781 node.removeAttribute(n);
22787 for (var i = node.attributes.length-1; i > -1 ; i--) {
22788 var a = node.attributes[i];
22791 if (a.name.toLowerCase().substr(0,2)=='on') {
22792 node.removeAttribute(a.name);
22795 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
22796 node.removeAttribute(a.name);
22799 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
22800 cleanAttr(a.name,a.value); // fixme..
22803 if (a.name == 'style') {
22804 cleanStyle(a.name,a.value);
22807 /// clean up MS crap..
22808 // tecnically this should be a list of valid class'es..
22811 if (a.name == 'class') {
22812 if (a.value.match(/^Mso/)) {
22813 node.className = '';
22816 if (a.value.match(/^body$/)) {
22817 node.className = '';
22828 this.cleanUpChildren(node);
22834 * Clean up MS wordisms...
22836 cleanWord : function(node)
22841 this.cleanWord(this.doc.body);
22844 if (node.nodeName == "#text") {
22845 // clean up silly Windows -- stuff?
22848 if (node.nodeName == "#comment") {
22849 node.parentNode.removeChild(node);
22850 // clean up silly Windows -- stuff?
22854 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
22855 node.parentNode.removeChild(node);
22859 // remove - but keep children..
22860 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
22861 while (node.childNodes.length) {
22862 var cn = node.childNodes[0];
22863 node.removeChild(cn);
22864 node.parentNode.insertBefore(cn, node);
22866 node.parentNode.removeChild(node);
22867 this.iterateChildren(node, this.cleanWord);
22871 if (node.className.length) {
22873 var cn = node.className.split(/\W+/);
22875 Roo.each(cn, function(cls) {
22876 if (cls.match(/Mso[a-zA-Z]+/)) {
22881 node.className = cna.length ? cna.join(' ') : '';
22883 node.removeAttribute("class");
22887 if (node.hasAttribute("lang")) {
22888 node.removeAttribute("lang");
22891 if (node.hasAttribute("style")) {
22893 var styles = node.getAttribute("style").split(";");
22895 Roo.each(styles, function(s) {
22896 if (!s.match(/:/)) {
22899 var kv = s.split(":");
22900 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
22903 // what ever is left... we allow.
22906 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22907 if (!nstyle.length) {
22908 node.removeAttribute('style');
22911 this.iterateChildren(node, this.cleanWord);
22917 * iterateChildren of a Node, calling fn each time, using this as the scole..
22918 * @param {DomNode} node node to iterate children of.
22919 * @param {Function} fn method of this class to call on each item.
22921 iterateChildren : function(node, fn)
22923 if (!node.childNodes.length) {
22926 for (var i = node.childNodes.length-1; i > -1 ; i--) {
22927 fn.call(this, node.childNodes[i])
22933 * cleanTableWidths.
22935 * Quite often pasting from word etc.. results in tables with column and widths.
22936 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
22939 cleanTableWidths : function(node)
22944 this.cleanTableWidths(this.doc.body);
22949 if (node.nodeName == "#text" || node.nodeName == "#comment") {
22952 Roo.log(node.tagName);
22953 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
22954 this.iterateChildren(node, this.cleanTableWidths);
22957 if (node.hasAttribute('width')) {
22958 node.removeAttribute('width');
22962 if (node.hasAttribute("style")) {
22965 var styles = node.getAttribute("style").split(";");
22967 Roo.each(styles, function(s) {
22968 if (!s.match(/:/)) {
22971 var kv = s.split(":");
22972 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
22975 // what ever is left... we allow.
22978 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22979 if (!nstyle.length) {
22980 node.removeAttribute('style');
22984 this.iterateChildren(node, this.cleanTableWidths);
22992 domToHTML : function(currentElement, depth, nopadtext) {
22994 depth = depth || 0;
22995 nopadtext = nopadtext || false;
22997 if (!currentElement) {
22998 return this.domToHTML(this.doc.body);
23001 //Roo.log(currentElement);
23003 var allText = false;
23004 var nodeName = currentElement.nodeName;
23005 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
23007 if (nodeName == '#text') {
23009 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
23014 if (nodeName != 'BODY') {
23017 // Prints the node tagName, such as <A>, <IMG>, etc
23020 for(i = 0; i < currentElement.attributes.length;i++) {
23022 var aname = currentElement.attributes.item(i).name;
23023 if (!currentElement.attributes.item(i).value.length) {
23026 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
23029 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
23038 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
23041 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
23046 // Traverse the tree
23048 var currentElementChild = currentElement.childNodes.item(i);
23049 var allText = true;
23050 var innerHTML = '';
23052 while (currentElementChild) {
23053 // Formatting code (indent the tree so it looks nice on the screen)
23054 var nopad = nopadtext;
23055 if (lastnode == 'SPAN') {
23059 if (currentElementChild.nodeName == '#text') {
23060 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
23061 toadd = nopadtext ? toadd : toadd.trim();
23062 if (!nopad && toadd.length > 80) {
23063 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
23065 innerHTML += toadd;
23068 currentElementChild = currentElement.childNodes.item(i);
23074 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
23076 // Recursively traverse the tree structure of the child node
23077 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
23078 lastnode = currentElementChild.nodeName;
23080 currentElementChild=currentElement.childNodes.item(i);
23086 // The remaining code is mostly for formatting the tree
23087 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
23092 ret+= "</"+tagName+">";
23098 applyBlacklists : function()
23100 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
23101 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
23105 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
23106 if (b.indexOf(tag) > -1) {
23109 this.white.push(tag);
23113 Roo.each(w, function(tag) {
23114 if (b.indexOf(tag) > -1) {
23117 if (this.white.indexOf(tag) > -1) {
23120 this.white.push(tag);
23125 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
23126 if (w.indexOf(tag) > -1) {
23129 this.black.push(tag);
23133 Roo.each(b, function(tag) {
23134 if (w.indexOf(tag) > -1) {
23137 if (this.black.indexOf(tag) > -1) {
23140 this.black.push(tag);
23145 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
23146 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
23150 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
23151 if (b.indexOf(tag) > -1) {
23154 this.cwhite.push(tag);
23158 Roo.each(w, function(tag) {
23159 if (b.indexOf(tag) > -1) {
23162 if (this.cwhite.indexOf(tag) > -1) {
23165 this.cwhite.push(tag);
23170 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
23171 if (w.indexOf(tag) > -1) {
23174 this.cblack.push(tag);
23178 Roo.each(b, function(tag) {
23179 if (w.indexOf(tag) > -1) {
23182 if (this.cblack.indexOf(tag) > -1) {
23185 this.cblack.push(tag);
23190 setStylesheets : function(stylesheets)
23192 if(typeof(stylesheets) == 'string'){
23193 Roo.get(this.iframe.contentDocument.head).createChild({
23195 rel : 'stylesheet',
23204 Roo.each(stylesheets, function(s) {
23209 Roo.get(_this.iframe.contentDocument.head).createChild({
23211 rel : 'stylesheet',
23220 removeStylesheets : function()
23224 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
23229 setStyle : function(style)
23231 Roo.get(this.iframe.contentDocument.head).createChild({
23240 // hide stuff that is not compatible
23254 * @event specialkey
23258 * @cfg {String} fieldClass @hide
23261 * @cfg {String} focusClass @hide
23264 * @cfg {String} autoCreate @hide
23267 * @cfg {String} inputType @hide
23270 * @cfg {String} invalidClass @hide
23273 * @cfg {String} invalidText @hide
23276 * @cfg {String} msgFx @hide
23279 * @cfg {String} validateOnBlur @hide
23283 Roo.HtmlEditorCore.white = [
23284 'area', 'br', 'img', 'input', 'hr', 'wbr',
23286 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
23287 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
23288 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
23289 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
23290 'table', 'ul', 'xmp',
23292 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
23295 'dir', 'menu', 'ol', 'ul', 'dl',
23301 Roo.HtmlEditorCore.black = [
23302 // 'embed', 'object', // enable - backend responsiblity to clean thiese
23304 'base', 'basefont', 'bgsound', 'blink', 'body',
23305 'frame', 'frameset', 'head', 'html', 'ilayer',
23306 'iframe', 'layer', 'link', 'meta', 'object',
23307 'script', 'style' ,'title', 'xml' // clean later..
23309 Roo.HtmlEditorCore.clean = [
23310 'script', 'style', 'title', 'xml'
23312 Roo.HtmlEditorCore.remove = [
23317 Roo.HtmlEditorCore.ablack = [
23321 Roo.HtmlEditorCore.aclean = [
23322 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
23326 Roo.HtmlEditorCore.pwhite= [
23327 'http', 'https', 'mailto'
23330 // white listed style attributes.
23331 Roo.HtmlEditorCore.cwhite= [
23332 // 'text-align', /// default is to allow most things..
23338 // black listed style attributes.
23339 Roo.HtmlEditorCore.cblack= [
23340 // 'font-size' -- this can be set by the project
23344 Roo.HtmlEditorCore.swapCodes =[
23363 * @class Roo.bootstrap.HtmlEditor
23364 * @extends Roo.bootstrap.TextArea
23365 * Bootstrap HtmlEditor class
23368 * Create a new HtmlEditor
23369 * @param {Object} config The config object
23372 Roo.bootstrap.HtmlEditor = function(config){
23373 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
23374 if (!this.toolbars) {
23375 this.toolbars = [];
23378 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
23381 * @event initialize
23382 * Fires when the editor is fully initialized (including the iframe)
23383 * @param {HtmlEditor} this
23388 * Fires when the editor is first receives the focus. Any insertion must wait
23389 * until after this event.
23390 * @param {HtmlEditor} this
23394 * @event beforesync
23395 * Fires before the textarea is updated with content from the editor iframe. Return false
23396 * to cancel the sync.
23397 * @param {HtmlEditor} this
23398 * @param {String} html
23402 * @event beforepush
23403 * Fires before the iframe editor is updated with content from the textarea. Return false
23404 * to cancel the push.
23405 * @param {HtmlEditor} this
23406 * @param {String} html
23411 * Fires when the textarea is updated with content from the editor iframe.
23412 * @param {HtmlEditor} this
23413 * @param {String} html
23418 * Fires when the iframe editor is updated with content from the textarea.
23419 * @param {HtmlEditor} this
23420 * @param {String} html
23424 * @event editmodechange
23425 * Fires when the editor switches edit modes
23426 * @param {HtmlEditor} this
23427 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
23429 editmodechange: true,
23431 * @event editorevent
23432 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
23433 * @param {HtmlEditor} this
23437 * @event firstfocus
23438 * Fires when on first focus - needed by toolbars..
23439 * @param {HtmlEditor} this
23444 * Auto save the htmlEditor value as a file into Events
23445 * @param {HtmlEditor} this
23449 * @event savedpreview
23450 * preview the saved version of htmlEditor
23451 * @param {HtmlEditor} this
23458 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
23462 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
23467 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
23472 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
23477 * @cfg {Number} height (in pixels)
23481 * @cfg {Number} width (in pixels)
23486 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
23489 stylesheets: false,
23494 // private properties
23495 validationEvent : false,
23497 initialized : false,
23500 onFocus : Roo.emptyFn,
23502 hideMode:'offsets',
23504 tbContainer : false,
23508 toolbarContainer :function() {
23509 return this.wrap.select('.x-html-editor-tb',true).first();
23513 * Protected method that will not generally be called directly. It
23514 * is called when the editor creates its toolbar. Override this method if you need to
23515 * add custom toolbar buttons.
23516 * @param {HtmlEditor} editor
23518 createToolbar : function(){
23519 Roo.log('renewing');
23520 Roo.log("create toolbars");
23522 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
23523 this.toolbars[0].render(this.toolbarContainer());
23527 // if (!editor.toolbars || !editor.toolbars.length) {
23528 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
23531 // for (var i =0 ; i < editor.toolbars.length;i++) {
23532 // editor.toolbars[i] = Roo.factory(
23533 // typeof(editor.toolbars[i]) == 'string' ?
23534 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
23535 // Roo.bootstrap.HtmlEditor);
23536 // editor.toolbars[i].init(editor);
23542 onRender : function(ct, position)
23544 // Roo.log("Call onRender: " + this.xtype);
23546 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
23548 this.wrap = this.inputEl().wrap({
23549 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
23552 this.editorcore.onRender(ct, position);
23554 if (this.resizable) {
23555 this.resizeEl = new Roo.Resizable(this.wrap, {
23559 minHeight : this.height,
23560 height: this.height,
23561 handles : this.resizable,
23564 resize : function(r, w, h) {
23565 _t.onResize(w,h); // -something
23571 this.createToolbar(this);
23574 if(!this.width && this.resizable){
23575 this.setSize(this.wrap.getSize());
23577 if (this.resizeEl) {
23578 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
23579 // should trigger onReize..
23585 onResize : function(w, h)
23587 Roo.log('resize: ' +w + ',' + h );
23588 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
23592 if(this.inputEl() ){
23593 if(typeof w == 'number'){
23594 var aw = w - this.wrap.getFrameWidth('lr');
23595 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
23598 if(typeof h == 'number'){
23599 var tbh = -11; // fixme it needs to tool bar size!
23600 for (var i =0; i < this.toolbars.length;i++) {
23601 // fixme - ask toolbars for heights?
23602 tbh += this.toolbars[i].el.getHeight();
23603 //if (this.toolbars[i].footer) {
23604 // tbh += this.toolbars[i].footer.el.getHeight();
23612 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23613 ah -= 5; // knock a few pixes off for look..
23614 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
23618 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23619 this.editorcore.onResize(ew,eh);
23624 * Toggles the editor between standard and source edit mode.
23625 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23627 toggleSourceEdit : function(sourceEditMode)
23629 this.editorcore.toggleSourceEdit(sourceEditMode);
23631 if(this.editorcore.sourceEditMode){
23632 Roo.log('editor - showing textarea');
23635 // Roo.log(this.syncValue());
23637 this.inputEl().removeClass(['hide', 'x-hidden']);
23638 this.inputEl().dom.removeAttribute('tabIndex');
23639 this.inputEl().focus();
23641 Roo.log('editor - hiding textarea');
23643 // Roo.log(this.pushValue());
23646 this.inputEl().addClass(['hide', 'x-hidden']);
23647 this.inputEl().dom.setAttribute('tabIndex', -1);
23648 //this.deferFocus();
23651 if(this.resizable){
23652 this.setSize(this.wrap.getSize());
23655 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23658 // private (for BoxComponent)
23659 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23661 // private (for BoxComponent)
23662 getResizeEl : function(){
23666 // private (for BoxComponent)
23667 getPositionEl : function(){
23672 initEvents : function(){
23673 this.originalValue = this.getValue();
23677 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23680 // markInvalid : Roo.emptyFn,
23682 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23685 // clearInvalid : Roo.emptyFn,
23687 setValue : function(v){
23688 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
23689 this.editorcore.pushValue();
23694 deferFocus : function(){
23695 this.focus.defer(10, this);
23699 focus : function(){
23700 this.editorcore.focus();
23706 onDestroy : function(){
23712 for (var i =0; i < this.toolbars.length;i++) {
23713 // fixme - ask toolbars for heights?
23714 this.toolbars[i].onDestroy();
23717 this.wrap.dom.innerHTML = '';
23718 this.wrap.remove();
23723 onFirstFocus : function(){
23724 //Roo.log("onFirstFocus");
23725 this.editorcore.onFirstFocus();
23726 for (var i =0; i < this.toolbars.length;i++) {
23727 this.toolbars[i].onFirstFocus();
23733 syncValue : function()
23735 this.editorcore.syncValue();
23738 pushValue : function()
23740 this.editorcore.pushValue();
23744 // hide stuff that is not compatible
23758 * @event specialkey
23762 * @cfg {String} fieldClass @hide
23765 * @cfg {String} focusClass @hide
23768 * @cfg {String} autoCreate @hide
23771 * @cfg {String} inputType @hide
23774 * @cfg {String} invalidClass @hide
23777 * @cfg {String} invalidText @hide
23780 * @cfg {String} msgFx @hide
23783 * @cfg {String} validateOnBlur @hide
23792 Roo.namespace('Roo.bootstrap.htmleditor');
23794 * @class Roo.bootstrap.HtmlEditorToolbar1
23799 new Roo.bootstrap.HtmlEditor({
23802 new Roo.bootstrap.HtmlEditorToolbar1({
23803 disable : { fonts: 1 , format: 1, ..., ... , ...],
23809 * @cfg {Object} disable List of elements to disable..
23810 * @cfg {Array} btns List of additional buttons.
23814 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
23817 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
23820 Roo.apply(this, config);
23822 // default disabled, based on 'good practice'..
23823 this.disable = this.disable || {};
23824 Roo.applyIf(this.disable, {
23827 specialElements : true
23829 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
23831 this.editor = config.editor;
23832 this.editorcore = config.editor.editorcore;
23834 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
23836 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23837 // dont call parent... till later.
23839 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
23844 editorcore : false,
23849 "h1","h2","h3","h4","h5","h6",
23851 "abbr", "acronym", "address", "cite", "samp", "var",
23855 onRender : function(ct, position)
23857 // Roo.log("Call onRender: " + this.xtype);
23859 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
23861 this.el.dom.style.marginBottom = '0';
23863 var editorcore = this.editorcore;
23864 var editor= this.editor;
23867 var btn = function(id,cmd , toggle, handler, html){
23869 var event = toggle ? 'toggle' : 'click';
23874 xns: Roo.bootstrap,
23877 enableToggle:toggle !== false,
23879 pressed : toggle ? false : null,
23882 a.listeners[toggle ? 'toggle' : 'click'] = function() {
23883 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
23889 // var cb_box = function...
23894 xns: Roo.bootstrap,
23895 glyphicon : 'font',
23899 xns: Roo.bootstrap,
23903 Roo.each(this.formats, function(f) {
23904 style.menu.items.push({
23906 xns: Roo.bootstrap,
23907 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
23912 editorcore.insertTag(this.tagname);
23919 children.push(style);
23921 btn('bold',false,true);
23922 btn('italic',false,true);
23923 btn('align-left', 'justifyleft',true);
23924 btn('align-center', 'justifycenter',true);
23925 btn('align-right' , 'justifyright',true);
23926 btn('link', false, false, function(btn) {
23927 //Roo.log("create link?");
23928 var url = prompt(this.createLinkText, this.defaultLinkValue);
23929 if(url && url != 'http:/'+'/'){
23930 this.editorcore.relayCmd('createlink', url);
23933 btn('list','insertunorderedlist',true);
23934 btn('pencil', false,true, function(btn){
23936 this.toggleSourceEdit(btn.pressed);
23939 if (this.editor.btns.length > 0) {
23940 for (var i = 0; i<this.editor.btns.length; i++) {
23941 children.push(this.editor.btns[i]);
23949 xns: Roo.bootstrap,
23954 xns: Roo.bootstrap,
23959 cog.menu.items.push({
23961 xns: Roo.bootstrap,
23962 html : Clean styles,
23967 editorcore.insertTag(this.tagname);
23976 this.xtype = 'NavSimplebar';
23978 for(var i=0;i< children.length;i++) {
23980 this.buttons.add(this.addxtypeChild(children[i]));
23984 editor.on('editorevent', this.updateToolbar, this);
23986 onBtnClick : function(id)
23988 this.editorcore.relayCmd(id);
23989 this.editorcore.focus();
23993 * Protected method that will not generally be called directly. It triggers
23994 * a toolbar update by reading the markup state of the current selection in the editor.
23996 updateToolbar: function(){
23998 if(!this.editorcore.activated){
23999 this.editor.onFirstFocus(); // is this neeed?
24003 var btns = this.buttons;
24004 var doc = this.editorcore.doc;
24005 btns.get('bold').setActive(doc.queryCommandState('bold'));
24006 btns.get('italic').setActive(doc.queryCommandState('italic'));
24007 //btns.get('underline').setActive(doc.queryCommandState('underline'));
24009 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
24010 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
24011 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
24013 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
24014 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
24017 var ans = this.editorcore.getAllAncestors();
24018 if (this.formatCombo) {
24021 var store = this.formatCombo.store;
24022 this.formatCombo.setValue("");
24023 for (var i =0; i < ans.length;i++) {
24024 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
24026 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
24034 // hides menus... - so this cant be on a menu...
24035 Roo.bootstrap.MenuMgr.hideAll();
24037 Roo.bootstrap.MenuMgr.hideAll();
24038 //this.editorsyncValue();
24040 onFirstFocus: function() {
24041 this.buttons.each(function(item){
24045 toggleSourceEdit : function(sourceEditMode){
24048 if(sourceEditMode){
24049 Roo.log("disabling buttons");
24050 this.buttons.each( function(item){
24051 if(item.cmd != 'pencil'){
24057 Roo.log("enabling buttons");
24058 if(this.editorcore.initialized){
24059 this.buttons.each( function(item){
24065 Roo.log("calling toggole on editor");
24066 // tell the editor that it's been pressed..
24067 this.editor.toggleSourceEdit(sourceEditMode);
24077 * @class Roo.bootstrap.Table.AbstractSelectionModel
24078 * @extends Roo.util.Observable
24079 * Abstract base class for grid SelectionModels. It provides the interface that should be
24080 * implemented by descendant classes. This class should not be directly instantiated.
24083 Roo.bootstrap.Table.AbstractSelectionModel = function(){
24084 this.locked = false;
24085 Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
24089 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable, {
24090 /** @ignore Called by the grid automatically. Do not call directly. */
24091 init : function(grid){
24097 * Locks the selections.
24100 this.locked = true;
24104 * Unlocks the selections.
24106 unlock : function(){
24107 this.locked = false;
24111 * Returns true if the selections are locked.
24112 * @return {Boolean}
24114 isLocked : function(){
24115 return this.locked;
24119 * @extends Roo.bootstrap.Table.AbstractSelectionModel
24120 * @class Roo.bootstrap.Table.RowSelectionModel
24121 * The default SelectionModel used by {@link Roo.bootstrap.Table}.
24122 * It supports multiple selections and keyboard selection/navigation.
24124 * @param {Object} config
24127 Roo.bootstrap.Table.RowSelectionModel = function(config){
24128 Roo.apply(this, config);
24129 this.selections = new Roo.util.MixedCollection(false, function(o){
24134 this.lastActive = false;
24138 * @event selectionchange
24139 * Fires when the selection changes
24140 * @param {SelectionModel} this
24142 "selectionchange" : true,
24144 * @event afterselectionchange
24145 * Fires after the selection changes (eg. by key press or clicking)
24146 * @param {SelectionModel} this
24148 "afterselectionchange" : true,
24150 * @event beforerowselect
24151 * Fires when a row is selected being selected, return false to cancel.
24152 * @param {SelectionModel} this
24153 * @param {Number} rowIndex The selected index
24154 * @param {Boolean} keepExisting False if other selections will be cleared
24156 "beforerowselect" : true,
24159 * Fires when a row is selected.
24160 * @param {SelectionModel} this
24161 * @param {Number} rowIndex The selected index
24162 * @param {Roo.data.Record} r The record
24164 "rowselect" : true,
24166 * @event rowdeselect
24167 * Fires when a row is deselected.
24168 * @param {SelectionModel} this
24169 * @param {Number} rowIndex The selected index
24171 "rowdeselect" : true
24173 Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
24174 this.locked = false;
24177 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel, {
24179 * @cfg {Boolean} singleSelect
24180 * True to allow selection of only one row at a time (defaults to false)
24182 singleSelect : false,
24185 initEvents : function()
24188 //if(!this.grid.enableDragDrop && !this.grid.enableDrag){
24189 // this.growclickrid.on("mousedown", this.handleMouseDown, this);
24190 //}else{ // allow click to work like normal
24191 // this.grid.on("rowclick", this.handleDragableRowClick, this);
24193 //this.grid.on("rowdblclick", this.handleMouseDBClick, this);
24194 this.grid.on("rowclick", this.handleMouseDown, this);
24196 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
24197 "up" : function(e){
24199 this.selectPrevious(e.shiftKey);
24200 }else if(this.last !== false && this.lastActive !== false){
24201 var last = this.last;
24202 this.selectRange(this.last, this.lastActive-1);
24203 this.grid.getView().focusRow(this.lastActive);
24204 if(last !== false){
24208 this.selectFirstRow();
24210 this.fireEvent("afterselectionchange", this);
24212 "down" : function(e){
24214 this.selectNext(e.shiftKey);
24215 }else if(this.last !== false && this.lastActive !== false){
24216 var last = this.last;
24217 this.selectRange(this.last, this.lastActive+1);
24218 this.grid.getView().focusRow(this.lastActive);
24219 if(last !== false){
24223 this.selectFirstRow();
24225 this.fireEvent("afterselectionchange", this);
24229 this.grid.store.on('load', function(){
24230 this.selections.clear();
24233 var view = this.grid.view;
24234 view.on("refresh", this.onRefresh, this);
24235 view.on("rowupdated", this.onRowUpdated, this);
24236 view.on("rowremoved", this.onRemove, this);
24241 onRefresh : function()
24243 var ds = this.grid.store, i, v = this.grid.view;
24244 var s = this.selections;
24245 s.each(function(r){
24246 if((i = ds.indexOfId(r.id)) != -1){
24255 onRemove : function(v, index, r){
24256 this.selections.remove(r);
24260 onRowUpdated : function(v, index, r){
24261 if(this.isSelected(r)){
24262 v.onRowSelect(index);
24268 * @param {Array} records The records to select
24269 * @param {Boolean} keepExisting (optional) True to keep existing selections
24271 selectRecords : function(records, keepExisting)
24274 this.clearSelections();
24276 var ds = this.grid.store;
24277 for(var i = 0, len = records.length; i < len; i++){
24278 this.selectRow(ds.indexOf(records[i]), true);
24283 * Gets the number of selected rows.
24286 getCount : function(){
24287 return this.selections.length;
24291 * Selects the first row in the grid.
24293 selectFirstRow : function(){
24298 * Select the last row.
24299 * @param {Boolean} keepExisting (optional) True to keep existing selections
24301 selectLastRow : function(keepExisting){
24302 //this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
24303 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
24307 * Selects the row immediately following the last selected row.
24308 * @param {Boolean} keepExisting (optional) True to keep existing selections
24310 selectNext : function(keepExisting)
24312 if(this.last !== false && (this.last+1) < this.grid.store.getCount()){
24313 this.selectRow(this.last+1, keepExisting);
24314 this.grid.getView().focusRow(this.last);
24319 * Selects the row that precedes the last selected row.
24320 * @param {Boolean} keepExisting (optional) True to keep existing selections
24322 selectPrevious : function(keepExisting){
24324 this.selectRow(this.last-1, keepExisting);
24325 this.grid.getView().focusRow(this.last);
24330 * Returns the selected records
24331 * @return {Array} Array of selected records
24333 getSelections : function(){
24334 return [].concat(this.selections.items);
24338 * Returns the first selected record.
24341 getSelected : function(){
24342 return this.selections.itemAt(0);
24347 * Clears all selections.
24349 clearSelections : function(fast)
24355 var ds = this.grid.store;
24356 var s = this.selections;
24357 s.each(function(r){
24358 this.deselectRow(ds.indexOfId(r.id));
24362 this.selections.clear();
24369 * Selects all rows.
24371 selectAll : function(){
24375 this.selections.clear();
24376 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
24377 this.selectRow(i, true);
24382 * Returns True if there is a selection.
24383 * @return {Boolean}
24385 hasSelection : function(){
24386 return this.selections.length > 0;
24390 * Returns True if the specified row is selected.
24391 * @param {Number/Record} record The record or index of the record to check
24392 * @return {Boolean}
24394 isSelected : function(index){
24395 var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
24396 return (r && this.selections.key(r.id) ? true : false);
24400 * Returns True if the specified record id is selected.
24401 * @param {String} id The id of record to check
24402 * @return {Boolean}
24404 isIdSelected : function(id){
24405 return (this.selections.key(id) ? true : false);
24410 handleMouseDBClick : function(e, t){
24414 handleMouseDown : function(e, t)
24416 var rowIndex = this.grid.headerShow ? t.dom.rowIndex - 1 : t.dom.rowIndex ; // first row is header???
24417 if(this.isLocked() || rowIndex < 0 ){
24420 if(e.shiftKey && this.last !== false){
24421 var last = this.last;
24422 this.selectRange(last, rowIndex, e.ctrlKey);
24423 this.last = last; // reset the last
24427 var isSelected = this.isSelected(rowIndex);
24428 //Roo.log("select row:" + rowIndex);
24430 this.deselectRow(rowIndex);
24432 this.selectRow(rowIndex, true);
24436 if(e.button !== 0 && isSelected){
24437 alert('rowIndex 2: ' + rowIndex);
24438 view.focusRow(rowIndex);
24439 }else if(e.ctrlKey && isSelected){
24440 this.deselectRow(rowIndex);
24441 }else if(!isSelected){
24442 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
24443 view.focusRow(rowIndex);
24447 this.fireEvent("afterselectionchange", this);
24450 handleDragableRowClick : function(grid, rowIndex, e)
24452 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
24453 this.selectRow(rowIndex, false);
24454 grid.view.focusRow(rowIndex);
24455 this.fireEvent("afterselectionchange", this);
24460 * Selects multiple rows.
24461 * @param {Array} rows Array of the indexes of the row to select
24462 * @param {Boolean} keepExisting (optional) True to keep existing selections
24464 selectRows : function(rows, keepExisting){
24466 this.clearSelections();
24468 for(var i = 0, len = rows.length; i < len; i++){
24469 this.selectRow(rows[i], true);
24474 * Selects a range of rows. All rows in between startRow and endRow are also selected.
24475 * @param {Number} startRow The index of the first row in the range
24476 * @param {Number} endRow The index of the last row in the range
24477 * @param {Boolean} keepExisting (optional) True to retain existing selections
24479 selectRange : function(startRow, endRow, keepExisting){
24484 this.clearSelections();
24486 if(startRow <= endRow){
24487 for(var i = startRow; i <= endRow; i++){
24488 this.selectRow(i, true);
24491 for(var i = startRow; i >= endRow; i--){
24492 this.selectRow(i, true);
24498 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
24499 * @param {Number} startRow The index of the first row in the range
24500 * @param {Number} endRow The index of the last row in the range
24502 deselectRange : function(startRow, endRow, preventViewNotify){
24506 for(var i = startRow; i <= endRow; i++){
24507 this.deselectRow(i, preventViewNotify);
24513 * @param {Number} row The index of the row to select
24514 * @param {Boolean} keepExisting (optional) True to keep existing selections
24516 selectRow : function(index, keepExisting, preventViewNotify)
24518 if(this.locked || (index < 0 || index > this.grid.store.getCount())) {
24521 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
24522 if(!keepExisting || this.singleSelect){
24523 this.clearSelections();
24526 var r = this.grid.store.getAt(index);
24527 //console.log('selectRow - record id :' + r.id);
24529 this.selections.add(r);
24530 this.last = this.lastActive = index;
24531 if(!preventViewNotify){
24532 var proxy = new Roo.Element(
24533 this.grid.getRowDom(index)
24535 proxy.addClass('bg-info info');
24537 this.fireEvent("rowselect", this, index, r);
24538 this.fireEvent("selectionchange", this);
24544 * @param {Number} row The index of the row to deselect
24546 deselectRow : function(index, preventViewNotify)
24551 if(this.last == index){
24554 if(this.lastActive == index){
24555 this.lastActive = false;
24558 var r = this.grid.store.getAt(index);
24563 this.selections.remove(r);
24564 //.console.log('deselectRow - record id :' + r.id);
24565 if(!preventViewNotify){
24567 var proxy = new Roo.Element(
24568 this.grid.getRowDom(index)
24570 proxy.removeClass('bg-info info');
24572 this.fireEvent("rowdeselect", this, index);
24573 this.fireEvent("selectionchange", this);
24577 restoreLast : function(){
24579 this.last = this._last;
24584 acceptsNav : function(row, col, cm){
24585 return !cm.isHidden(col) && cm.isCellEditable(col, row);
24589 onEditorKey : function(field, e){
24590 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
24595 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
24597 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
24599 }else if(k == e.ENTER && !e.ctrlKey){
24603 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
24605 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
24607 }else if(k == e.ESC){
24611 g.startEditing(newCell[0], newCell[1]);
24617 * Ext JS Library 1.1.1
24618 * Copyright(c) 2006-2007, Ext JS, LLC.
24620 * Originally Released Under LGPL - original licence link has changed is not relivant.
24623 * <script type="text/javascript">
24627 * @class Roo.bootstrap.PagingToolbar
24628 * @extends Roo.bootstrap.NavSimplebar
24629 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
24631 * Create a new PagingToolbar
24632 * @param {Object} config The config object
24633 * @param {Roo.data.Store} store
24635 Roo.bootstrap.PagingToolbar = function(config)
24637 // old args format still supported... - xtype is prefered..
24638 // created from xtype...
24640 this.ds = config.dataSource;
24642 if (config.store && !this.ds) {
24643 this.store= Roo.factory(config.store, Roo.data);
24644 this.ds = this.store;
24645 this.ds.xmodule = this.xmodule || false;
24648 this.toolbarItems = [];
24649 if (config.items) {
24650 this.toolbarItems = config.items;
24653 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
24658 this.bind(this.ds);
24661 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
24665 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
24667 * @cfg {Roo.data.Store} dataSource
24668 * The underlying data store providing the paged data
24671 * @cfg {String/HTMLElement/Element} container
24672 * container The id or element that will contain the toolbar
24675 * @cfg {Boolean} displayInfo
24676 * True to display the displayMsg (defaults to false)
24679 * @cfg {Number} pageSize
24680 * The number of records to display per page (defaults to 20)
24684 * @cfg {String} displayMsg
24685 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
24687 displayMsg : 'Displaying {0} - {1} of {2}',
24689 * @cfg {String} emptyMsg
24690 * The message to display when no records are found (defaults to "No data to display")
24692 emptyMsg : 'No data to display',
24694 * Customizable piece of the default paging text (defaults to "Page")
24697 beforePageText : "Page",
24699 * Customizable piece of the default paging text (defaults to "of %0")
24702 afterPageText : "of {0}",
24704 * Customizable piece of the default paging text (defaults to "First Page")
24707 firstText : "First Page",
24709 * Customizable piece of the default paging text (defaults to "Previous Page")
24712 prevText : "Previous Page",
24714 * Customizable piece of the default paging text (defaults to "Next Page")
24717 nextText : "Next Page",
24719 * Customizable piece of the default paging text (defaults to "Last Page")
24722 lastText : "Last Page",
24724 * Customizable piece of the default paging text (defaults to "Refresh")
24727 refreshText : "Refresh",
24731 onRender : function(ct, position)
24733 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
24734 this.navgroup.parentId = this.id;
24735 this.navgroup.onRender(this.el, null);
24736 // add the buttons to the navgroup
24738 if(this.displayInfo){
24739 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
24740 this.displayEl = this.el.select('.x-paging-info', true).first();
24741 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
24742 // this.displayEl = navel.el.select('span',true).first();
24748 Roo.each(_this.buttons, function(e){ // this might need to use render????
24749 Roo.factory(e).render(_this.el);
24753 Roo.each(_this.toolbarItems, function(e) {
24754 _this.navgroup.addItem(e);
24758 this.first = this.navgroup.addItem({
24759 tooltip: this.firstText,
24761 icon : 'fa fa-step-backward',
24763 preventDefault: true,
24764 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
24767 this.prev = this.navgroup.addItem({
24768 tooltip: this.prevText,
24770 icon : 'fa fa-backward',
24772 preventDefault: true,
24773 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
24775 //this.addSeparator();
24778 var field = this.navgroup.addItem( {
24780 cls : 'x-paging-position',
24782 html : this.beforePageText +
24783 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
24784 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
24787 this.field = field.el.select('input', true).first();
24788 this.field.on("keydown", this.onPagingKeydown, this);
24789 this.field.on("focus", function(){this.dom.select();});
24792 this.afterTextEl = field.el.select('.x-paging-after',true).first();
24793 //this.field.setHeight(18);
24794 //this.addSeparator();
24795 this.next = this.navgroup.addItem({
24796 tooltip: this.nextText,
24798 html : ' <i class="fa fa-forward">',
24800 preventDefault: true,
24801 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
24803 this.last = this.navgroup.addItem({
24804 tooltip: this.lastText,
24805 icon : 'fa fa-step-forward',
24808 preventDefault: true,
24809 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
24811 //this.addSeparator();
24812 this.loading = this.navgroup.addItem({
24813 tooltip: this.refreshText,
24814 icon: 'fa fa-refresh',
24815 preventDefault: true,
24816 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
24822 updateInfo : function(){
24823 if(this.displayEl){
24824 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
24825 var msg = count == 0 ?
24829 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
24831 this.displayEl.update(msg);
24836 onLoad : function(ds, r, o)
24838 this.cursor = o.params.start ? o.params.start : 0;
24840 var d = this.getPageData(),
24845 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
24846 this.field.dom.value = ap;
24847 this.first.setDisabled(ap == 1);
24848 this.prev.setDisabled(ap == 1);
24849 this.next.setDisabled(ap == ps);
24850 this.last.setDisabled(ap == ps);
24851 this.loading.enable();
24856 getPageData : function(){
24857 var total = this.ds.getTotalCount();
24860 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
24861 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
24866 onLoadError : function(){
24867 this.loading.enable();
24871 onPagingKeydown : function(e){
24872 var k = e.getKey();
24873 var d = this.getPageData();
24875 var v = this.field.dom.value, pageNum;
24876 if(!v || isNaN(pageNum = parseInt(v, 10))){
24877 this.field.dom.value = d.activePage;
24880 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
24881 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24884 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))
24886 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
24887 this.field.dom.value = pageNum;
24888 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
24891 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
24893 var v = this.field.dom.value, pageNum;
24894 var increment = (e.shiftKey) ? 10 : 1;
24895 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
24898 if(!v || isNaN(pageNum = parseInt(v, 10))) {
24899 this.field.dom.value = d.activePage;
24902 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
24904 this.field.dom.value = parseInt(v, 10) + increment;
24905 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
24906 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24913 beforeLoad : function(){
24915 this.loading.disable();
24920 onClick : function(which){
24929 ds.load({params:{start: 0, limit: this.pageSize}});
24932 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
24935 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
24938 var total = ds.getTotalCount();
24939 var extra = total % this.pageSize;
24940 var lastStart = extra ? (total - extra) : total-this.pageSize;
24941 ds.load({params:{start: lastStart, limit: this.pageSize}});
24944 ds.load({params:{start: this.cursor, limit: this.pageSize}});
24950 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
24951 * @param {Roo.data.Store} store The data store to unbind
24953 unbind : function(ds){
24954 ds.un("beforeload", this.beforeLoad, this);
24955 ds.un("load", this.onLoad, this);
24956 ds.un("loadexception", this.onLoadError, this);
24957 ds.un("remove", this.updateInfo, this);
24958 ds.un("add", this.updateInfo, this);
24959 this.ds = undefined;
24963 * Binds the paging toolbar to the specified {@link Roo.data.Store}
24964 * @param {Roo.data.Store} store The data store to bind
24966 bind : function(ds){
24967 ds.on("beforeload", this.beforeLoad, this);
24968 ds.on("load", this.onLoad, this);
24969 ds.on("loadexception", this.onLoadError, this);
24970 ds.on("remove", this.updateInfo, this);
24971 ds.on("add", this.updateInfo, this);
24982 * @class Roo.bootstrap.MessageBar
24983 * @extends Roo.bootstrap.Component
24984 * Bootstrap MessageBar class
24985 * @cfg {String} html contents of the MessageBar
24986 * @cfg {String} weight (info | success | warning | danger) default info
24987 * @cfg {String} beforeClass insert the bar before the given class
24988 * @cfg {Boolean} closable (true | false) default false
24989 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
24992 * Create a new Element
24993 * @param {Object} config The config object
24996 Roo.bootstrap.MessageBar = function(config){
24997 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
25000 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
25006 beforeClass: 'bootstrap-sticky-wrap',
25008 getAutoCreate : function(){
25012 cls: 'alert alert-dismissable alert-' + this.weight,
25017 html: this.html || ''
25023 cfg.cls += ' alert-messages-fixed';
25037 onRender : function(ct, position)
25039 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
25042 var cfg = Roo.apply({}, this.getAutoCreate());
25046 cfg.cls += ' ' + this.cls;
25049 cfg.style = this.style;
25051 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
25053 this.el.setVisibilityMode(Roo.Element.DISPLAY);
25056 this.el.select('>button.close').on('click', this.hide, this);
25062 if (!this.rendered) {
25068 this.fireEvent('show', this);
25074 if (!this.rendered) {
25080 this.fireEvent('hide', this);
25083 update : function()
25085 // var e = this.el.dom.firstChild;
25087 // if(this.closable){
25088 // e = e.nextSibling;
25091 // e.data = this.html || '';
25093 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
25109 * @class Roo.bootstrap.Graph
25110 * @extends Roo.bootstrap.Component
25111 * Bootstrap Graph class
25115 @cfg {String} graphtype bar | vbar | pie
25116 @cfg {number} g_x coodinator | centre x (pie)
25117 @cfg {number} g_y coodinator | centre y (pie)
25118 @cfg {number} g_r radius (pie)
25119 @cfg {number} g_height height of the chart (respected by all elements in the set)
25120 @cfg {number} g_width width of the chart (respected by all elements in the set)
25121 @cfg {Object} title The title of the chart
25124 -opts (object) options for the chart
25126 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
25127 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
25129 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.
25130 o stacked (boolean) whether or not to tread values as in a stacked bar chart
25132 o stretch (boolean)
25134 -opts (object) options for the pie
25137 o startAngle (number)
25138 o endAngle (number)
25142 * Create a new Input
25143 * @param {Object} config The config object
25146 Roo.bootstrap.Graph = function(config){
25147 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
25153 * The img click event for the img.
25154 * @param {Roo.EventObject} e
25160 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
25171 //g_colors: this.colors,
25178 getAutoCreate : function(){
25189 onRender : function(ct,position){
25192 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
25194 if (typeof(Raphael) == 'undefined') {
25195 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
25199 this.raphael = Raphael(this.el.dom);
25201 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25202 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25203 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25204 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
25206 r.text(160, 10, "Single Series Chart").attr(txtattr);
25207 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
25208 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
25209 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
25211 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
25212 r.barchart(330, 10, 300, 220, data1);
25213 r.barchart(10, 250, 300, 220, data2, {stacked: true});
25214 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
25217 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25218 // r.barchart(30, 30, 560, 250, xdata, {
25219 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
25220 // axis : "0 0 1 1",
25221 // axisxlabels : xdata
25222 // //yvalues : cols,
25225 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25227 // this.load(null,xdata,{
25228 // axis : "0 0 1 1",
25229 // axisxlabels : xdata
25234 load : function(graphtype,xdata,opts)
25236 this.raphael.clear();
25238 graphtype = this.graphtype;
25243 var r = this.raphael,
25244 fin = function () {
25245 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
25247 fout = function () {
25248 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
25250 pfin = function() {
25251 this.sector.stop();
25252 this.sector.scale(1.1, 1.1, this.cx, this.cy);
25255 this.label[0].stop();
25256 this.label[0].attr({ r: 7.5 });
25257 this.label[1].attr({ "font-weight": 800 });
25260 pfout = function() {
25261 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
25264 this.label[0].animate({ r: 5 }, 500, "bounce");
25265 this.label[1].attr({ "font-weight": 400 });
25271 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25274 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25277 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
25278 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
25280 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
25287 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
25292 setTitle: function(o)
25297 initEvents: function() {
25300 this.el.on('click', this.onClick, this);
25304 onClick : function(e)
25306 Roo.log('img onclick');
25307 this.fireEvent('click', this, e);
25319 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25322 * @class Roo.bootstrap.dash.NumberBox
25323 * @extends Roo.bootstrap.Component
25324 * Bootstrap NumberBox class
25325 * @cfg {String} headline Box headline
25326 * @cfg {String} content Box content
25327 * @cfg {String} icon Box icon
25328 * @cfg {String} footer Footer text
25329 * @cfg {String} fhref Footer href
25332 * Create a new NumberBox
25333 * @param {Object} config The config object
25337 Roo.bootstrap.dash.NumberBox = function(config){
25338 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
25342 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
25351 getAutoCreate : function(){
25355 cls : 'small-box ',
25363 cls : 'roo-headline',
25364 html : this.headline
25368 cls : 'roo-content',
25369 html : this.content
25383 cls : 'ion ' + this.icon
25392 cls : 'small-box-footer',
25393 href : this.fhref || '#',
25397 cfg.cn.push(footer);
25404 onRender : function(ct,position){
25405 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
25412 setHeadline: function (value)
25414 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
25417 setFooter: function (value, href)
25419 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
25422 this.el.select('a.small-box-footer',true).first().attr('href', href);
25427 setContent: function (value)
25429 this.el.select('.roo-content',true).first().dom.innerHTML = value;
25432 initEvents: function()
25446 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25449 * @class Roo.bootstrap.dash.TabBox
25450 * @extends Roo.bootstrap.Component
25451 * Bootstrap TabBox class
25452 * @cfg {String} title Title of the TabBox
25453 * @cfg {String} icon Icon of the TabBox
25454 * @cfg {Boolean} showtabs (true|false) show the tabs default true
25455 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
25458 * Create a new TabBox
25459 * @param {Object} config The config object
25463 Roo.bootstrap.dash.TabBox = function(config){
25464 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
25469 * When a pane is added
25470 * @param {Roo.bootstrap.dash.TabPane} pane
25474 * @event activatepane
25475 * When a pane is activated
25476 * @param {Roo.bootstrap.dash.TabPane} pane
25478 "activatepane" : true
25486 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
25491 tabScrollable : false,
25493 getChildContainer : function()
25495 return this.el.select('.tab-content', true).first();
25498 getAutoCreate : function(){
25502 cls: 'pull-left header',
25510 cls: 'fa ' + this.icon
25516 cls: 'nav nav-tabs pull-right',
25522 if(this.tabScrollable){
25529 cls: 'nav nav-tabs pull-right',
25540 cls: 'nav-tabs-custom',
25545 cls: 'tab-content no-padding',
25553 initEvents : function()
25555 //Roo.log('add add pane handler');
25556 this.on('addpane', this.onAddPane, this);
25559 * Updates the box title
25560 * @param {String} html to set the title to.
25562 setTitle : function(value)
25564 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
25566 onAddPane : function(pane)
25568 this.panes.push(pane);
25569 //Roo.log('addpane');
25571 // tabs are rendere left to right..
25572 if(!this.showtabs){
25576 var ctr = this.el.select('.nav-tabs', true).first();
25579 var existing = ctr.select('.nav-tab',true);
25580 var qty = existing.getCount();;
25583 var tab = ctr.createChild({
25585 cls : 'nav-tab' + (qty ? '' : ' active'),
25593 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
25596 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
25598 pane.el.addClass('active');
25603 onTabClick : function(ev,un,ob,pane)
25605 //Roo.log('tab - prev default');
25606 ev.preventDefault();
25609 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
25610 pane.tab.addClass('active');
25611 //Roo.log(pane.title);
25612 this.getChildContainer().select('.tab-pane',true).removeClass('active');
25613 // technically we should have a deactivate event.. but maybe add later.
25614 // and it should not de-activate the selected tab...
25615 this.fireEvent('activatepane', pane);
25616 pane.el.addClass('active');
25617 pane.fireEvent('activate');
25622 getActivePane : function()
25625 Roo.each(this.panes, function(p) {
25626 if(p.el.hasClass('active')){
25647 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25649 * @class Roo.bootstrap.TabPane
25650 * @extends Roo.bootstrap.Component
25651 * Bootstrap TabPane class
25652 * @cfg {Boolean} active (false | true) Default false
25653 * @cfg {String} title title of panel
25657 * Create a new TabPane
25658 * @param {Object} config The config object
25661 Roo.bootstrap.dash.TabPane = function(config){
25662 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
25668 * When a pane is activated
25669 * @param {Roo.bootstrap.dash.TabPane} pane
25676 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
25681 // the tabBox that this is attached to.
25684 getAutoCreate : function()
25692 cfg.cls += ' active';
25697 initEvents : function()
25699 //Roo.log('trigger add pane handler');
25700 this.parent().fireEvent('addpane', this)
25704 * Updates the tab title
25705 * @param {String} html to set the title to.
25707 setTitle: function(str)
25713 this.tab.select('a', true).first().dom.innerHTML = str;
25730 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25733 * @class Roo.bootstrap.menu.Menu
25734 * @extends Roo.bootstrap.Component
25735 * Bootstrap Menu class - container for Menu
25736 * @cfg {String} html Text of the menu
25737 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
25738 * @cfg {String} icon Font awesome icon
25739 * @cfg {String} pos Menu align to (top | bottom) default bottom
25743 * Create a new Menu
25744 * @param {Object} config The config object
25748 Roo.bootstrap.menu.Menu = function(config){
25749 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
25753 * @event beforeshow
25754 * Fires before this menu is displayed
25755 * @param {Roo.bootstrap.menu.Menu} this
25759 * @event beforehide
25760 * Fires before this menu is hidden
25761 * @param {Roo.bootstrap.menu.Menu} this
25766 * Fires after this menu is displayed
25767 * @param {Roo.bootstrap.menu.Menu} this
25772 * Fires after this menu is hidden
25773 * @param {Roo.bootstrap.menu.Menu} this
25778 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
25779 * @param {Roo.bootstrap.menu.Menu} this
25780 * @param {Roo.EventObject} e
25787 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
25791 weight : 'default',
25796 getChildContainer : function() {
25797 if(this.isSubMenu){
25801 return this.el.select('ul.dropdown-menu', true).first();
25804 getAutoCreate : function()
25809 cls : 'roo-menu-text',
25817 cls : 'fa ' + this.icon
25828 cls : 'dropdown-button btn btn-' + this.weight,
25833 cls : 'dropdown-toggle btn btn-' + this.weight,
25843 cls : 'dropdown-menu'
25849 if(this.pos == 'top'){
25850 cfg.cls += ' dropup';
25853 if(this.isSubMenu){
25856 cls : 'dropdown-menu'
25863 onRender : function(ct, position)
25865 this.isSubMenu = ct.hasClass('dropdown-submenu');
25867 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
25870 initEvents : function()
25872 if(this.isSubMenu){
25876 this.hidden = true;
25878 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
25879 this.triggerEl.on('click', this.onTriggerPress, this);
25881 this.buttonEl = this.el.select('button.dropdown-button', true).first();
25882 this.buttonEl.on('click', this.onClick, this);
25888 if(this.isSubMenu){
25892 return this.el.select('ul.dropdown-menu', true).first();
25895 onClick : function(e)
25897 this.fireEvent("click", this, e);
25900 onTriggerPress : function(e)
25902 if (this.isVisible()) {
25909 isVisible : function(){
25910 return !this.hidden;
25915 this.fireEvent("beforeshow", this);
25917 this.hidden = false;
25918 this.el.addClass('open');
25920 Roo.get(document).on("mouseup", this.onMouseUp, this);
25922 this.fireEvent("show", this);
25929 this.fireEvent("beforehide", this);
25931 this.hidden = true;
25932 this.el.removeClass('open');
25934 Roo.get(document).un("mouseup", this.onMouseUp);
25936 this.fireEvent("hide", this);
25939 onMouseUp : function()
25953 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25956 * @class Roo.bootstrap.menu.Item
25957 * @extends Roo.bootstrap.Component
25958 * Bootstrap MenuItem class
25959 * @cfg {Boolean} submenu (true | false) default false
25960 * @cfg {String} html text of the item
25961 * @cfg {String} href the link
25962 * @cfg {Boolean} disable (true | false) default false
25963 * @cfg {Boolean} preventDefault (true | false) default true
25964 * @cfg {String} icon Font awesome icon
25965 * @cfg {String} pos Submenu align to (left | right) default right
25969 * Create a new Item
25970 * @param {Object} config The config object
25974 Roo.bootstrap.menu.Item = function(config){
25975 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
25979 * Fires when the mouse is hovering over this menu
25980 * @param {Roo.bootstrap.menu.Item} this
25981 * @param {Roo.EventObject} e
25986 * Fires when the mouse exits this menu
25987 * @param {Roo.bootstrap.menu.Item} this
25988 * @param {Roo.EventObject} e
25994 * The raw click event for the entire grid.
25995 * @param {Roo.EventObject} e
26001 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
26006 preventDefault: true,
26011 getAutoCreate : function()
26016 cls : 'roo-menu-item-text',
26024 cls : 'fa ' + this.icon
26033 href : this.href || '#',
26040 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
26044 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
26046 if(this.pos == 'left'){
26047 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
26054 initEvents : function()
26056 this.el.on('mouseover', this.onMouseOver, this);
26057 this.el.on('mouseout', this.onMouseOut, this);
26059 this.el.select('a', true).first().on('click', this.onClick, this);
26063 onClick : function(e)
26065 if(this.preventDefault){
26066 e.preventDefault();
26069 this.fireEvent("click", this, e);
26072 onMouseOver : function(e)
26074 if(this.submenu && this.pos == 'left'){
26075 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
26078 this.fireEvent("mouseover", this, e);
26081 onMouseOut : function(e)
26083 this.fireEvent("mouseout", this, e);
26095 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
26098 * @class Roo.bootstrap.menu.Separator
26099 * @extends Roo.bootstrap.Component
26100 * Bootstrap Separator class
26103 * Create a new Separator
26104 * @param {Object} config The config object
26108 Roo.bootstrap.menu.Separator = function(config){
26109 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
26112 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
26114 getAutoCreate : function(){
26135 * @class Roo.bootstrap.Tooltip
26136 * Bootstrap Tooltip class
26137 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
26138 * to determine which dom element triggers the tooltip.
26140 * It needs to add support for additional attributes like tooltip-position
26143 * Create a new Toolti
26144 * @param {Object} config The config object
26147 Roo.bootstrap.Tooltip = function(config){
26148 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
26150 this.alignment = Roo.bootstrap.Tooltip.alignment;
26152 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
26153 this.alignment = config.alignment;
26158 Roo.apply(Roo.bootstrap.Tooltip, {
26160 * @function init initialize tooltip monitoring.
26164 currentTip : false,
26165 currentRegion : false,
26171 Roo.get(document).on('mouseover', this.enter ,this);
26172 Roo.get(document).on('mouseout', this.leave, this);
26175 this.currentTip = new Roo.bootstrap.Tooltip();
26178 enter : function(ev)
26180 var dom = ev.getTarget();
26182 //Roo.log(['enter',dom]);
26183 var el = Roo.fly(dom);
26184 if (this.currentEl) {
26186 //Roo.log(this.currentEl);
26187 //Roo.log(this.currentEl.contains(dom));
26188 if (this.currentEl == el) {
26191 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
26197 if (this.currentTip.el) {
26198 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
26202 if(!el || el.dom == document){
26208 // you can not look for children, as if el is the body.. then everythign is the child..
26209 if (!el.attr('tooltip')) { //
26210 if (!el.select("[tooltip]").elements.length) {
26213 // is the mouse over this child...?
26214 bindEl = el.select("[tooltip]").first();
26215 var xy = ev.getXY();
26216 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
26217 //Roo.log("not in region.");
26220 //Roo.log("child element over..");
26223 this.currentEl = bindEl;
26224 this.currentTip.bind(bindEl);
26225 this.currentRegion = Roo.lib.Region.getRegion(dom);
26226 this.currentTip.enter();
26229 leave : function(ev)
26231 var dom = ev.getTarget();
26232 //Roo.log(['leave',dom]);
26233 if (!this.currentEl) {
26238 if (dom != this.currentEl.dom) {
26241 var xy = ev.getXY();
26242 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
26245 // only activate leave if mouse cursor is outside... bounding box..
26250 if (this.currentTip) {
26251 this.currentTip.leave();
26253 //Roo.log('clear currentEl');
26254 this.currentEl = false;
26259 'left' : ['r-l', [-2,0], 'right'],
26260 'right' : ['l-r', [2,0], 'left'],
26261 'bottom' : ['t-b', [0,2], 'top'],
26262 'top' : [ 'b-t', [0,-2], 'bottom']
26268 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
26273 delay : null, // can be { show : 300 , hide: 500}
26277 hoverState : null, //???
26279 placement : 'bottom',
26283 getAutoCreate : function(){
26290 cls : 'tooltip-arrow'
26293 cls : 'tooltip-inner'
26300 bind : function(el)
26306 enter : function () {
26308 if (this.timeout != null) {
26309 clearTimeout(this.timeout);
26312 this.hoverState = 'in';
26313 //Roo.log("enter - show");
26314 if (!this.delay || !this.delay.show) {
26319 this.timeout = setTimeout(function () {
26320 if (_t.hoverState == 'in') {
26323 }, this.delay.show);
26327 clearTimeout(this.timeout);
26329 this.hoverState = 'out';
26330 if (!this.delay || !this.delay.hide) {
26336 this.timeout = setTimeout(function () {
26337 //Roo.log("leave - timeout");
26339 if (_t.hoverState == 'out') {
26341 Roo.bootstrap.Tooltip.currentEl = false;
26346 show : function (msg)
26349 this.render(document.body);
26352 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
26354 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
26356 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
26358 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
26360 var placement = typeof this.placement == 'function' ?
26361 this.placement.call(this, this.el, on_el) :
26364 var autoToken = /\s?auto?\s?/i;
26365 var autoPlace = autoToken.test(placement);
26367 placement = placement.replace(autoToken, '') || 'top';
26371 //this.el.setXY([0,0]);
26373 //this.el.dom.style.display='block';
26375 //this.el.appendTo(on_el);
26377 var p = this.getPosition();
26378 var box = this.el.getBox();
26384 var align = this.alignment[placement];
26386 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
26388 if(placement == 'top' || placement == 'bottom'){
26390 placement = 'right';
26393 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
26394 placement = 'left';
26397 var scroll = Roo.select('body', true).first().getScroll();
26399 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
26403 align = this.alignment[placement];
26406 this.el.alignTo(this.bindEl, align[0],align[1]);
26407 //var arrow = this.el.select('.arrow',true).first();
26408 //arrow.set(align[2],
26410 this.el.addClass(placement);
26412 this.el.addClass('in fade');
26414 this.hoverState = null;
26416 if (this.el.hasClass('fade')) {
26427 //this.el.setXY([0,0]);
26428 this.el.removeClass('in');
26444 * @class Roo.bootstrap.LocationPicker
26445 * @extends Roo.bootstrap.Component
26446 * Bootstrap LocationPicker class
26447 * @cfg {Number} latitude Position when init default 0
26448 * @cfg {Number} longitude Position when init default 0
26449 * @cfg {Number} zoom default 15
26450 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
26451 * @cfg {Boolean} mapTypeControl default false
26452 * @cfg {Boolean} disableDoubleClickZoom default false
26453 * @cfg {Boolean} scrollwheel default true
26454 * @cfg {Boolean} streetViewControl default false
26455 * @cfg {Number} radius default 0
26456 * @cfg {String} locationName
26457 * @cfg {Boolean} draggable default true
26458 * @cfg {Boolean} enableAutocomplete default false
26459 * @cfg {Boolean} enableReverseGeocode default true
26460 * @cfg {String} markerTitle
26463 * Create a new LocationPicker
26464 * @param {Object} config The config object
26468 Roo.bootstrap.LocationPicker = function(config){
26470 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
26475 * Fires when the picker initialized.
26476 * @param {Roo.bootstrap.LocationPicker} this
26477 * @param {Google Location} location
26481 * @event positionchanged
26482 * Fires when the picker position changed.
26483 * @param {Roo.bootstrap.LocationPicker} this
26484 * @param {Google Location} location
26486 positionchanged : true,
26489 * Fires when the map resize.
26490 * @param {Roo.bootstrap.LocationPicker} this
26495 * Fires when the map show.
26496 * @param {Roo.bootstrap.LocationPicker} this
26501 * Fires when the map hide.
26502 * @param {Roo.bootstrap.LocationPicker} this
26507 * Fires when click the map.
26508 * @param {Roo.bootstrap.LocationPicker} this
26509 * @param {Map event} e
26513 * @event mapRightClick
26514 * Fires when right click the map.
26515 * @param {Roo.bootstrap.LocationPicker} this
26516 * @param {Map event} e
26518 mapRightClick : true,
26520 * @event markerClick
26521 * Fires when click the marker.
26522 * @param {Roo.bootstrap.LocationPicker} this
26523 * @param {Map event} e
26525 markerClick : true,
26527 * @event markerRightClick
26528 * Fires when right click the marker.
26529 * @param {Roo.bootstrap.LocationPicker} this
26530 * @param {Map event} e
26532 markerRightClick : true,
26534 * @event OverlayViewDraw
26535 * Fires when OverlayView Draw
26536 * @param {Roo.bootstrap.LocationPicker} this
26538 OverlayViewDraw : true,
26540 * @event OverlayViewOnAdd
26541 * Fires when OverlayView Draw
26542 * @param {Roo.bootstrap.LocationPicker} this
26544 OverlayViewOnAdd : true,
26546 * @event OverlayViewOnRemove
26547 * Fires when OverlayView Draw
26548 * @param {Roo.bootstrap.LocationPicker} this
26550 OverlayViewOnRemove : true,
26552 * @event OverlayViewShow
26553 * Fires when OverlayView Draw
26554 * @param {Roo.bootstrap.LocationPicker} this
26555 * @param {Pixel} cpx
26557 OverlayViewShow : true,
26559 * @event OverlayViewHide
26560 * Fires when OverlayView Draw
26561 * @param {Roo.bootstrap.LocationPicker} this
26563 OverlayViewHide : true,
26565 * @event loadexception
26566 * Fires when load google lib failed.
26567 * @param {Roo.bootstrap.LocationPicker} this
26569 loadexception : true
26574 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
26576 gMapContext: false,
26582 mapTypeControl: false,
26583 disableDoubleClickZoom: false,
26585 streetViewControl: false,
26589 enableAutocomplete: false,
26590 enableReverseGeocode: true,
26593 getAutoCreate: function()
26598 cls: 'roo-location-picker'
26604 initEvents: function(ct, position)
26606 if(!this.el.getWidth() || this.isApplied()){
26610 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26615 initial: function()
26617 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
26618 this.fireEvent('loadexception', this);
26622 if(!this.mapTypeId){
26623 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
26626 this.gMapContext = this.GMapContext();
26628 this.initOverlayView();
26630 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
26634 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
26635 _this.setPosition(_this.gMapContext.marker.position);
26638 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
26639 _this.fireEvent('mapClick', this, event);
26643 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
26644 _this.fireEvent('mapRightClick', this, event);
26648 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
26649 _this.fireEvent('markerClick', this, event);
26653 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
26654 _this.fireEvent('markerRightClick', this, event);
26658 this.setPosition(this.gMapContext.location);
26660 this.fireEvent('initial', this, this.gMapContext.location);
26663 initOverlayView: function()
26667 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
26671 _this.fireEvent('OverlayViewDraw', _this);
26676 _this.fireEvent('OverlayViewOnAdd', _this);
26679 onRemove: function()
26681 _this.fireEvent('OverlayViewOnRemove', _this);
26684 show: function(cpx)
26686 _this.fireEvent('OverlayViewShow', _this, cpx);
26691 _this.fireEvent('OverlayViewHide', _this);
26697 fromLatLngToContainerPixel: function(event)
26699 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
26702 isApplied: function()
26704 return this.getGmapContext() == false ? false : true;
26707 getGmapContext: function()
26709 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
26712 GMapContext: function()
26714 var position = new google.maps.LatLng(this.latitude, this.longitude);
26716 var _map = new google.maps.Map(this.el.dom, {
26719 mapTypeId: this.mapTypeId,
26720 mapTypeControl: this.mapTypeControl,
26721 disableDoubleClickZoom: this.disableDoubleClickZoom,
26722 scrollwheel: this.scrollwheel,
26723 streetViewControl: this.streetViewControl,
26724 locationName: this.locationName,
26725 draggable: this.draggable,
26726 enableAutocomplete: this.enableAutocomplete,
26727 enableReverseGeocode: this.enableReverseGeocode
26730 var _marker = new google.maps.Marker({
26731 position: position,
26733 title: this.markerTitle,
26734 draggable: this.draggable
26741 location: position,
26742 radius: this.radius,
26743 locationName: this.locationName,
26744 addressComponents: {
26745 formatted_address: null,
26746 addressLine1: null,
26747 addressLine2: null,
26749 streetNumber: null,
26753 stateOrProvince: null
26756 domContainer: this.el.dom,
26757 geodecoder: new google.maps.Geocoder()
26761 drawCircle: function(center, radius, options)
26763 if (this.gMapContext.circle != null) {
26764 this.gMapContext.circle.setMap(null);
26768 options = Roo.apply({}, options, {
26769 strokeColor: "#0000FF",
26770 strokeOpacity: .35,
26772 fillColor: "#0000FF",
26776 options.map = this.gMapContext.map;
26777 options.radius = radius;
26778 options.center = center;
26779 this.gMapContext.circle = new google.maps.Circle(options);
26780 return this.gMapContext.circle;
26786 setPosition: function(location)
26788 this.gMapContext.location = location;
26789 this.gMapContext.marker.setPosition(location);
26790 this.gMapContext.map.panTo(location);
26791 this.drawCircle(location, this.gMapContext.radius, {});
26795 if (this.gMapContext.settings.enableReverseGeocode) {
26796 this.gMapContext.geodecoder.geocode({
26797 latLng: this.gMapContext.location
26798 }, function(results, status) {
26800 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
26801 _this.gMapContext.locationName = results[0].formatted_address;
26802 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
26804 _this.fireEvent('positionchanged', this, location);
26811 this.fireEvent('positionchanged', this, location);
26816 google.maps.event.trigger(this.gMapContext.map, "resize");
26818 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
26820 this.fireEvent('resize', this);
26823 setPositionByLatLng: function(latitude, longitude)
26825 this.setPosition(new google.maps.LatLng(latitude, longitude));
26828 getCurrentPosition: function()
26831 latitude: this.gMapContext.location.lat(),
26832 longitude: this.gMapContext.location.lng()
26836 getAddressName: function()
26838 return this.gMapContext.locationName;
26841 getAddressComponents: function()
26843 return this.gMapContext.addressComponents;
26846 address_component_from_google_geocode: function(address_components)
26850 for (var i = 0; i < address_components.length; i++) {
26851 var component = address_components[i];
26852 if (component.types.indexOf("postal_code") >= 0) {
26853 result.postalCode = component.short_name;
26854 } else if (component.types.indexOf("street_number") >= 0) {
26855 result.streetNumber = component.short_name;
26856 } else if (component.types.indexOf("route") >= 0) {
26857 result.streetName = component.short_name;
26858 } else if (component.types.indexOf("neighborhood") >= 0) {
26859 result.city = component.short_name;
26860 } else if (component.types.indexOf("locality") >= 0) {
26861 result.city = component.short_name;
26862 } else if (component.types.indexOf("sublocality") >= 0) {
26863 result.district = component.short_name;
26864 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
26865 result.stateOrProvince = component.short_name;
26866 } else if (component.types.indexOf("country") >= 0) {
26867 result.country = component.short_name;
26871 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
26872 result.addressLine2 = "";
26876 setZoomLevel: function(zoom)
26878 this.gMapContext.map.setZoom(zoom);
26891 this.fireEvent('show', this);
26902 this.fireEvent('hide', this);
26907 Roo.apply(Roo.bootstrap.LocationPicker, {
26909 OverlayView : function(map, options)
26911 options = options || {};
26925 * @class Roo.bootstrap.Alert
26926 * @extends Roo.bootstrap.Component
26927 * Bootstrap Alert class
26928 * @cfg {String} title The title of alert
26929 * @cfg {String} html The content of alert
26930 * @cfg {String} weight ( success | info | warning | danger )
26931 * @cfg {String} faicon font-awesomeicon
26934 * Create a new alert
26935 * @param {Object} config The config object
26939 Roo.bootstrap.Alert = function(config){
26940 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
26944 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
26951 getAutoCreate : function()
26960 cls : 'roo-alert-icon'
26965 cls : 'roo-alert-title',
26970 cls : 'roo-alert-text',
26977 cfg.cn[0].cls += ' fa ' + this.faicon;
26981 cfg.cls += ' alert-' + this.weight;
26987 initEvents: function()
26989 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26992 setTitle : function(str)
26994 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
26997 setText : function(str)
26999 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
27002 setWeight : function(weight)
27005 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
27008 this.weight = weight;
27010 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
27013 setIcon : function(icon)
27016 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
27019 this.faicon = icon;
27021 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
27042 * @class Roo.bootstrap.UploadCropbox
27043 * @extends Roo.bootstrap.Component
27044 * Bootstrap UploadCropbox class
27045 * @cfg {String} emptyText show when image has been loaded
27046 * @cfg {String} rotateNotify show when image too small to rotate
27047 * @cfg {Number} errorTimeout default 3000
27048 * @cfg {Number} minWidth default 300
27049 * @cfg {Number} minHeight default 300
27050 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
27051 * @cfg {Boolean} isDocument (true|false) default false
27052 * @cfg {String} url action url
27053 * @cfg {String} paramName default 'imageUpload'
27054 * @cfg {String} method default POST
27055 * @cfg {Boolean} loadMask (true|false) default true
27056 * @cfg {Boolean} loadingText default 'Loading...'
27059 * Create a new UploadCropbox
27060 * @param {Object} config The config object
27063 Roo.bootstrap.UploadCropbox = function(config){
27064 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
27068 * @event beforeselectfile
27069 * Fire before select file
27070 * @param {Roo.bootstrap.UploadCropbox} this
27072 "beforeselectfile" : true,
27075 * Fire after initEvent
27076 * @param {Roo.bootstrap.UploadCropbox} this
27081 * Fire after initEvent
27082 * @param {Roo.bootstrap.UploadCropbox} this
27083 * @param {String} data
27088 * Fire when preparing the file data
27089 * @param {Roo.bootstrap.UploadCropbox} this
27090 * @param {Object} file
27095 * Fire when get exception
27096 * @param {Roo.bootstrap.UploadCropbox} this
27097 * @param {XMLHttpRequest} xhr
27099 "exception" : true,
27101 * @event beforeloadcanvas
27102 * Fire before load the canvas
27103 * @param {Roo.bootstrap.UploadCropbox} this
27104 * @param {String} src
27106 "beforeloadcanvas" : true,
27109 * Fire when trash image
27110 * @param {Roo.bootstrap.UploadCropbox} this
27115 * Fire when download the image
27116 * @param {Roo.bootstrap.UploadCropbox} this
27120 * @event footerbuttonclick
27121 * Fire when footerbuttonclick
27122 * @param {Roo.bootstrap.UploadCropbox} this
27123 * @param {String} type
27125 "footerbuttonclick" : true,
27129 * @param {Roo.bootstrap.UploadCropbox} this
27134 * Fire when rotate the image
27135 * @param {Roo.bootstrap.UploadCropbox} this
27136 * @param {String} pos
27141 * Fire when inspect the file
27142 * @param {Roo.bootstrap.UploadCropbox} this
27143 * @param {Object} file
27148 * Fire when xhr upload the file
27149 * @param {Roo.bootstrap.UploadCropbox} this
27150 * @param {Object} data
27155 * Fire when arrange the file data
27156 * @param {Roo.bootstrap.UploadCropbox} this
27157 * @param {Object} formData
27162 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
27165 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
27167 emptyText : 'Click to upload image',
27168 rotateNotify : 'Image is too small to rotate',
27169 errorTimeout : 3000,
27183 cropType : 'image/jpeg',
27185 canvasLoaded : false,
27186 isDocument : false,
27188 paramName : 'imageUpload',
27190 loadingText : 'Loading...',
27193 getAutoCreate : function()
27197 cls : 'roo-upload-cropbox',
27201 cls : 'roo-upload-cropbox-selector',
27206 cls : 'roo-upload-cropbox-body',
27207 style : 'cursor:pointer',
27211 cls : 'roo-upload-cropbox-preview'
27215 cls : 'roo-upload-cropbox-thumb'
27219 cls : 'roo-upload-cropbox-empty-notify',
27220 html : this.emptyText
27224 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
27225 html : this.rotateNotify
27231 cls : 'roo-upload-cropbox-footer',
27234 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
27244 onRender : function(ct, position)
27246 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
27248 if (this.buttons.length) {
27250 Roo.each(this.buttons, function(bb) {
27252 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
27254 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
27260 this.maskEl = this.el;
27264 initEvents : function()
27266 this.urlAPI = (window.createObjectURL && window) ||
27267 (window.URL && URL.revokeObjectURL && URL) ||
27268 (window.webkitURL && webkitURL);
27270 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
27271 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27273 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
27274 this.selectorEl.hide();
27276 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
27277 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27279 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
27280 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27281 this.thumbEl.hide();
27283 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
27284 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27286 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
27287 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27288 this.errorEl.hide();
27290 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
27291 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27292 this.footerEl.hide();
27294 this.setThumbBoxSize();
27300 this.fireEvent('initial', this);
27307 window.addEventListener("resize", function() { _this.resize(); } );
27309 this.bodyEl.on('click', this.beforeSelectFile, this);
27312 this.bodyEl.on('touchstart', this.onTouchStart, this);
27313 this.bodyEl.on('touchmove', this.onTouchMove, this);
27314 this.bodyEl.on('touchend', this.onTouchEnd, this);
27318 this.bodyEl.on('mousedown', this.onMouseDown, this);
27319 this.bodyEl.on('mousemove', this.onMouseMove, this);
27320 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
27321 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
27322 Roo.get(document).on('mouseup', this.onMouseUp, this);
27325 this.selectorEl.on('change', this.onFileSelected, this);
27331 this.baseScale = 1;
27333 this.baseRotate = 1;
27334 this.dragable = false;
27335 this.pinching = false;
27338 this.cropData = false;
27339 this.notifyEl.dom.innerHTML = this.emptyText;
27341 this.selectorEl.dom.value = '';
27345 resize : function()
27347 if(this.fireEvent('resize', this) != false){
27348 this.setThumbBoxPosition();
27349 this.setCanvasPosition();
27353 onFooterButtonClick : function(e, el, o, type)
27356 case 'rotate-left' :
27357 this.onRotateLeft(e);
27359 case 'rotate-right' :
27360 this.onRotateRight(e);
27363 this.beforeSelectFile(e);
27378 this.fireEvent('footerbuttonclick', this, type);
27381 beforeSelectFile : function(e)
27383 e.preventDefault();
27385 if(this.fireEvent('beforeselectfile', this) != false){
27386 this.selectorEl.dom.click();
27390 onFileSelected : function(e)
27392 e.preventDefault();
27394 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
27398 var file = this.selectorEl.dom.files[0];
27400 if(this.fireEvent('inspect', this, file) != false){
27401 this.prepare(file);
27406 trash : function(e)
27408 this.fireEvent('trash', this);
27411 download : function(e)
27413 this.fireEvent('download', this);
27416 loadCanvas : function(src)
27418 if(this.fireEvent('beforeloadcanvas', this, src) != false){
27422 this.imageEl = document.createElement('img');
27426 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
27428 this.imageEl.src = src;
27432 onLoadCanvas : function()
27434 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
27435 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
27437 this.bodyEl.un('click', this.beforeSelectFile, this);
27439 this.notifyEl.hide();
27440 this.thumbEl.show();
27441 this.footerEl.show();
27443 this.baseRotateLevel();
27445 if(this.isDocument){
27446 this.setThumbBoxSize();
27449 this.setThumbBoxPosition();
27451 this.baseScaleLevel();
27457 this.canvasLoaded = true;
27460 this.maskEl.unmask();
27465 setCanvasPosition : function()
27467 if(!this.canvasEl){
27471 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
27472 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
27474 this.previewEl.setLeft(pw);
27475 this.previewEl.setTop(ph);
27479 onMouseDown : function(e)
27483 this.dragable = true;
27484 this.pinching = false;
27486 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
27487 this.dragable = false;
27491 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27492 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27496 onMouseMove : function(e)
27500 if(!this.canvasLoaded){
27504 if (!this.dragable){
27508 var minX = Math.ceil(this.thumbEl.getLeft(true));
27509 var minY = Math.ceil(this.thumbEl.getTop(true));
27511 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
27512 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
27514 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27515 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27517 x = x - this.mouseX;
27518 y = y - this.mouseY;
27520 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
27521 var bgY = Math.ceil(y + this.previewEl.getTop(true));
27523 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
27524 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
27526 this.previewEl.setLeft(bgX);
27527 this.previewEl.setTop(bgY);
27529 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27530 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27533 onMouseUp : function(e)
27537 this.dragable = false;
27540 onMouseWheel : function(e)
27544 this.startScale = this.scale;
27546 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
27548 if(!this.zoomable()){
27549 this.scale = this.startScale;
27558 zoomable : function()
27560 var minScale = this.thumbEl.getWidth() / this.minWidth;
27562 if(this.minWidth < this.minHeight){
27563 minScale = this.thumbEl.getHeight() / this.minHeight;
27566 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
27567 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
27571 (this.rotate == 0 || this.rotate == 180) &&
27573 width > this.imageEl.OriginWidth ||
27574 height > this.imageEl.OriginHeight ||
27575 (width < this.minWidth && height < this.minHeight)
27583 (this.rotate == 90 || this.rotate == 270) &&
27585 width > this.imageEl.OriginWidth ||
27586 height > this.imageEl.OriginHeight ||
27587 (width < this.minHeight && height < this.minWidth)
27594 !this.isDocument &&
27595 (this.rotate == 0 || this.rotate == 180) &&
27597 width < this.minWidth ||
27598 width > this.imageEl.OriginWidth ||
27599 height < this.minHeight ||
27600 height > this.imageEl.OriginHeight
27607 !this.isDocument &&
27608 (this.rotate == 90 || this.rotate == 270) &&
27610 width < this.minHeight ||
27611 width > this.imageEl.OriginWidth ||
27612 height < this.minWidth ||
27613 height > this.imageEl.OriginHeight
27623 onRotateLeft : function(e)
27625 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27627 var minScale = this.thumbEl.getWidth() / this.minWidth;
27629 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27630 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27632 this.startScale = this.scale;
27634 while (this.getScaleLevel() < minScale){
27636 this.scale = this.scale + 1;
27638 if(!this.zoomable()){
27643 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27644 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27649 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27656 this.scale = this.startScale;
27658 this.onRotateFail();
27663 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27665 if(this.isDocument){
27666 this.setThumbBoxSize();
27667 this.setThumbBoxPosition();
27668 this.setCanvasPosition();
27673 this.fireEvent('rotate', this, 'left');
27677 onRotateRight : function(e)
27679 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27681 var minScale = this.thumbEl.getWidth() / this.minWidth;
27683 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27684 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27686 this.startScale = this.scale;
27688 while (this.getScaleLevel() < minScale){
27690 this.scale = this.scale + 1;
27692 if(!this.zoomable()){
27697 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27698 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27703 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27710 this.scale = this.startScale;
27712 this.onRotateFail();
27717 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27719 if(this.isDocument){
27720 this.setThumbBoxSize();
27721 this.setThumbBoxPosition();
27722 this.setCanvasPosition();
27727 this.fireEvent('rotate', this, 'right');
27730 onRotateFail : function()
27732 this.errorEl.show(true);
27736 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
27741 this.previewEl.dom.innerHTML = '';
27743 var canvasEl = document.createElement("canvas");
27745 var contextEl = canvasEl.getContext("2d");
27747 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27748 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27749 var center = this.imageEl.OriginWidth / 2;
27751 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
27752 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27753 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27754 center = this.imageEl.OriginHeight / 2;
27757 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
27759 contextEl.translate(center, center);
27760 contextEl.rotate(this.rotate * Math.PI / 180);
27762 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27764 this.canvasEl = document.createElement("canvas");
27766 this.contextEl = this.canvasEl.getContext("2d");
27768 switch (this.rotate) {
27771 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27772 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27774 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27779 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27780 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27782 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27783 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);
27787 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27792 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27793 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27795 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27796 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);
27800 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);
27805 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27806 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27808 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27809 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27813 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);
27820 this.previewEl.appendChild(this.canvasEl);
27822 this.setCanvasPosition();
27827 if(!this.canvasLoaded){
27831 var imageCanvas = document.createElement("canvas");
27833 var imageContext = imageCanvas.getContext("2d");
27835 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27836 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27838 var center = imageCanvas.width / 2;
27840 imageContext.translate(center, center);
27842 imageContext.rotate(this.rotate * Math.PI / 180);
27844 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27846 var canvas = document.createElement("canvas");
27848 var context = canvas.getContext("2d");
27850 canvas.width = this.minWidth;
27851 canvas.height = this.minHeight;
27853 switch (this.rotate) {
27856 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27857 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27859 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27860 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27862 var targetWidth = this.minWidth - 2 * x;
27863 var targetHeight = this.minHeight - 2 * y;
27867 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27868 scale = targetWidth / width;
27871 if(x > 0 && y == 0){
27872 scale = targetHeight / height;
27875 if(x > 0 && y > 0){
27876 scale = targetWidth / width;
27878 if(width < height){
27879 scale = targetHeight / height;
27883 context.scale(scale, scale);
27885 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27886 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27888 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27889 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27891 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27896 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27897 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27899 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27900 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27902 var targetWidth = this.minWidth - 2 * x;
27903 var targetHeight = this.minHeight - 2 * y;
27907 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27908 scale = targetWidth / width;
27911 if(x > 0 && y == 0){
27912 scale = targetHeight / height;
27915 if(x > 0 && y > 0){
27916 scale = targetWidth / width;
27918 if(width < height){
27919 scale = targetHeight / height;
27923 context.scale(scale, scale);
27925 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27926 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27928 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27929 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27931 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27933 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27938 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27939 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27941 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27942 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27944 var targetWidth = this.minWidth - 2 * x;
27945 var targetHeight = this.minHeight - 2 * y;
27949 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27950 scale = targetWidth / width;
27953 if(x > 0 && y == 0){
27954 scale = targetHeight / height;
27957 if(x > 0 && y > 0){
27958 scale = targetWidth / width;
27960 if(width < height){
27961 scale = targetHeight / height;
27965 context.scale(scale, scale);
27967 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27968 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27970 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27971 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27973 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27974 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27976 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27981 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27982 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27984 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27985 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27987 var targetWidth = this.minWidth - 2 * x;
27988 var targetHeight = this.minHeight - 2 * y;
27992 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27993 scale = targetWidth / width;
27996 if(x > 0 && y == 0){
27997 scale = targetHeight / height;
28000 if(x > 0 && y > 0){
28001 scale = targetWidth / width;
28003 if(width < height){
28004 scale = targetHeight / height;
28008 context.scale(scale, scale);
28010 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
28011 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
28013 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
28014 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
28016 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
28018 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
28025 this.cropData = canvas.toDataURL(this.cropType);
28027 if(this.fireEvent('crop', this, this.cropData) !== false){
28028 this.process(this.file, this.cropData);
28035 setThumbBoxSize : function()
28039 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
28040 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
28041 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
28043 this.minWidth = width;
28044 this.minHeight = height;
28046 if(this.rotate == 90 || this.rotate == 270){
28047 this.minWidth = height;
28048 this.minHeight = width;
28053 width = Math.ceil(this.minWidth * height / this.minHeight);
28055 if(this.minWidth > this.minHeight){
28057 height = Math.ceil(this.minHeight * width / this.minWidth);
28060 this.thumbEl.setStyle({
28061 width : width + 'px',
28062 height : height + 'px'
28069 setThumbBoxPosition : function()
28071 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
28072 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
28074 this.thumbEl.setLeft(x);
28075 this.thumbEl.setTop(y);
28079 baseRotateLevel : function()
28081 this.baseRotate = 1;
28084 typeof(this.exif) != 'undefined' &&
28085 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
28086 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
28088 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
28091 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
28095 baseScaleLevel : function()
28099 if(this.isDocument){
28101 if(this.baseRotate == 6 || this.baseRotate == 8){
28103 height = this.thumbEl.getHeight();
28104 this.baseScale = height / this.imageEl.OriginWidth;
28106 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
28107 width = this.thumbEl.getWidth();
28108 this.baseScale = width / this.imageEl.OriginHeight;
28114 height = this.thumbEl.getHeight();
28115 this.baseScale = height / this.imageEl.OriginHeight;
28117 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
28118 width = this.thumbEl.getWidth();
28119 this.baseScale = width / this.imageEl.OriginWidth;
28125 if(this.baseRotate == 6 || this.baseRotate == 8){
28127 width = this.thumbEl.getHeight();
28128 this.baseScale = width / this.imageEl.OriginHeight;
28130 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
28131 height = this.thumbEl.getWidth();
28132 this.baseScale = height / this.imageEl.OriginHeight;
28135 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28136 height = this.thumbEl.getWidth();
28137 this.baseScale = height / this.imageEl.OriginHeight;
28139 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
28140 width = this.thumbEl.getHeight();
28141 this.baseScale = width / this.imageEl.OriginWidth;
28148 width = this.thumbEl.getWidth();
28149 this.baseScale = width / this.imageEl.OriginWidth;
28151 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
28152 height = this.thumbEl.getHeight();
28153 this.baseScale = height / this.imageEl.OriginHeight;
28156 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28158 height = this.thumbEl.getHeight();
28159 this.baseScale = height / this.imageEl.OriginHeight;
28161 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
28162 width = this.thumbEl.getWidth();
28163 this.baseScale = width / this.imageEl.OriginWidth;
28171 getScaleLevel : function()
28173 return this.baseScale * Math.pow(1.1, this.scale);
28176 onTouchStart : function(e)
28178 if(!this.canvasLoaded){
28179 this.beforeSelectFile(e);
28183 var touches = e.browserEvent.touches;
28189 if(touches.length == 1){
28190 this.onMouseDown(e);
28194 if(touches.length != 2){
28200 for(var i = 0, finger; finger = touches[i]; i++){
28201 coords.push(finger.pageX, finger.pageY);
28204 var x = Math.pow(coords[0] - coords[2], 2);
28205 var y = Math.pow(coords[1] - coords[3], 2);
28207 this.startDistance = Math.sqrt(x + y);
28209 this.startScale = this.scale;
28211 this.pinching = true;
28212 this.dragable = false;
28216 onTouchMove : function(e)
28218 if(!this.pinching && !this.dragable){
28222 var touches = e.browserEvent.touches;
28229 this.onMouseMove(e);
28235 for(var i = 0, finger; finger = touches[i]; i++){
28236 coords.push(finger.pageX, finger.pageY);
28239 var x = Math.pow(coords[0] - coords[2], 2);
28240 var y = Math.pow(coords[1] - coords[3], 2);
28242 this.endDistance = Math.sqrt(x + y);
28244 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
28246 if(!this.zoomable()){
28247 this.scale = this.startScale;
28255 onTouchEnd : function(e)
28257 this.pinching = false;
28258 this.dragable = false;
28262 process : function(file, crop)
28265 this.maskEl.mask(this.loadingText);
28268 this.xhr = new XMLHttpRequest();
28270 file.xhr = this.xhr;
28272 this.xhr.open(this.method, this.url, true);
28275 "Accept": "application/json",
28276 "Cache-Control": "no-cache",
28277 "X-Requested-With": "XMLHttpRequest"
28280 for (var headerName in headers) {
28281 var headerValue = headers[headerName];
28283 this.xhr.setRequestHeader(headerName, headerValue);
28289 this.xhr.onload = function()
28291 _this.xhrOnLoad(_this.xhr);
28294 this.xhr.onerror = function()
28296 _this.xhrOnError(_this.xhr);
28299 var formData = new FormData();
28301 formData.append('returnHTML', 'NO');
28304 formData.append('crop', crop);
28307 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
28308 formData.append(this.paramName, file, file.name);
28311 if(typeof(file.filename) != 'undefined'){
28312 formData.append('filename', file.filename);
28315 if(typeof(file.mimetype) != 'undefined'){
28316 formData.append('mimetype', file.mimetype);
28319 if(this.fireEvent('arrange', this, formData) != false){
28320 this.xhr.send(formData);
28324 xhrOnLoad : function(xhr)
28327 this.maskEl.unmask();
28330 if (xhr.readyState !== 4) {
28331 this.fireEvent('exception', this, xhr);
28335 var response = Roo.decode(xhr.responseText);
28337 if(!response.success){
28338 this.fireEvent('exception', this, xhr);
28342 var response = Roo.decode(xhr.responseText);
28344 this.fireEvent('upload', this, response);
28348 xhrOnError : function()
28351 this.maskEl.unmask();
28354 Roo.log('xhr on error');
28356 var response = Roo.decode(xhr.responseText);
28362 prepare : function(file)
28365 this.maskEl.mask(this.loadingText);
28371 if(typeof(file) === 'string'){
28372 this.loadCanvas(file);
28376 if(!file || !this.urlAPI){
28381 this.cropType = file.type;
28385 if(this.fireEvent('prepare', this, this.file) != false){
28387 var reader = new FileReader();
28389 reader.onload = function (e) {
28390 if (e.target.error) {
28391 Roo.log(e.target.error);
28395 var buffer = e.target.result,
28396 dataView = new DataView(buffer),
28398 maxOffset = dataView.byteLength - 4,
28402 if (dataView.getUint16(0) === 0xffd8) {
28403 while (offset < maxOffset) {
28404 markerBytes = dataView.getUint16(offset);
28406 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
28407 markerLength = dataView.getUint16(offset + 2) + 2;
28408 if (offset + markerLength > dataView.byteLength) {
28409 Roo.log('Invalid meta data: Invalid segment size.');
28413 if(markerBytes == 0xffe1){
28414 _this.parseExifData(
28421 offset += markerLength;
28431 var url = _this.urlAPI.createObjectURL(_this.file);
28433 _this.loadCanvas(url);
28438 reader.readAsArrayBuffer(this.file);
28444 parseExifData : function(dataView, offset, length)
28446 var tiffOffset = offset + 10,
28450 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28451 // No Exif data, might be XMP data instead
28455 // Check for the ASCII code for "Exif" (0x45786966):
28456 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28457 // No Exif data, might be XMP data instead
28460 if (tiffOffset + 8 > dataView.byteLength) {
28461 Roo.log('Invalid Exif data: Invalid segment size.');
28464 // Check for the two null bytes:
28465 if (dataView.getUint16(offset + 8) !== 0x0000) {
28466 Roo.log('Invalid Exif data: Missing byte alignment offset.');
28469 // Check the byte alignment:
28470 switch (dataView.getUint16(tiffOffset)) {
28472 littleEndian = true;
28475 littleEndian = false;
28478 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
28481 // Check for the TIFF tag marker (0x002A):
28482 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
28483 Roo.log('Invalid Exif data: Missing TIFF marker.');
28486 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
28487 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
28489 this.parseExifTags(
28492 tiffOffset + dirOffset,
28497 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
28502 if (dirOffset + 6 > dataView.byteLength) {
28503 Roo.log('Invalid Exif data: Invalid directory offset.');
28506 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
28507 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
28508 if (dirEndOffset + 4 > dataView.byteLength) {
28509 Roo.log('Invalid Exif data: Invalid directory size.');
28512 for (i = 0; i < tagsNumber; i += 1) {
28516 dirOffset + 2 + 12 * i, // tag offset
28520 // Return the offset to the next directory:
28521 return dataView.getUint32(dirEndOffset, littleEndian);
28524 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
28526 var tag = dataView.getUint16(offset, littleEndian);
28528 this.exif[tag] = this.getExifValue(
28532 dataView.getUint16(offset + 2, littleEndian), // tag type
28533 dataView.getUint32(offset + 4, littleEndian), // tag length
28538 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
28540 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
28549 Roo.log('Invalid Exif data: Invalid tag type.');
28553 tagSize = tagType.size * length;
28554 // Determine if the value is contained in the dataOffset bytes,
28555 // or if the value at the dataOffset is a pointer to the actual data:
28556 dataOffset = tagSize > 4 ?
28557 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
28558 if (dataOffset + tagSize > dataView.byteLength) {
28559 Roo.log('Invalid Exif data: Invalid data offset.');
28562 if (length === 1) {
28563 return tagType.getValue(dataView, dataOffset, littleEndian);
28566 for (i = 0; i < length; i += 1) {
28567 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
28570 if (tagType.ascii) {
28572 // Concatenate the chars:
28573 for (i = 0; i < values.length; i += 1) {
28575 // Ignore the terminating NULL byte(s):
28576 if (c === '\u0000') {
28588 Roo.apply(Roo.bootstrap.UploadCropbox, {
28590 'Orientation': 0x0112
28594 1: 0, //'top-left',
28596 3: 180, //'bottom-right',
28597 // 4: 'bottom-left',
28599 6: 90, //'right-top',
28600 // 7: 'right-bottom',
28601 8: 270 //'left-bottom'
28605 // byte, 8-bit unsigned int:
28607 getValue: function (dataView, dataOffset) {
28608 return dataView.getUint8(dataOffset);
28612 // ascii, 8-bit byte:
28614 getValue: function (dataView, dataOffset) {
28615 return String.fromCharCode(dataView.getUint8(dataOffset));
28620 // short, 16 bit int:
28622 getValue: function (dataView, dataOffset, littleEndian) {
28623 return dataView.getUint16(dataOffset, littleEndian);
28627 // long, 32 bit int:
28629 getValue: function (dataView, dataOffset, littleEndian) {
28630 return dataView.getUint32(dataOffset, littleEndian);
28634 // rational = two long values, first is numerator, second is denominator:
28636 getValue: function (dataView, dataOffset, littleEndian) {
28637 return dataView.getUint32(dataOffset, littleEndian) /
28638 dataView.getUint32(dataOffset + 4, littleEndian);
28642 // slong, 32 bit signed int:
28644 getValue: function (dataView, dataOffset, littleEndian) {
28645 return dataView.getInt32(dataOffset, littleEndian);
28649 // srational, two slongs, first is numerator, second is denominator:
28651 getValue: function (dataView, dataOffset, littleEndian) {
28652 return dataView.getInt32(dataOffset, littleEndian) /
28653 dataView.getInt32(dataOffset + 4, littleEndian);
28663 cls : 'btn-group roo-upload-cropbox-rotate-left',
28664 action : 'rotate-left',
28668 cls : 'btn btn-default',
28669 html : '<i class="fa fa-undo"></i>'
28675 cls : 'btn-group roo-upload-cropbox-picture',
28676 action : 'picture',
28680 cls : 'btn btn-default',
28681 html : '<i class="fa fa-picture-o"></i>'
28687 cls : 'btn-group roo-upload-cropbox-rotate-right',
28688 action : 'rotate-right',
28692 cls : 'btn btn-default',
28693 html : '<i class="fa fa-repeat"></i>'
28701 cls : 'btn-group roo-upload-cropbox-rotate-left',
28702 action : 'rotate-left',
28706 cls : 'btn btn-default',
28707 html : '<i class="fa fa-undo"></i>'
28713 cls : 'btn-group roo-upload-cropbox-download',
28714 action : 'download',
28718 cls : 'btn btn-default',
28719 html : '<i class="fa fa-download"></i>'
28725 cls : 'btn-group roo-upload-cropbox-crop',
28730 cls : 'btn btn-default',
28731 html : '<i class="fa fa-crop"></i>'
28737 cls : 'btn-group roo-upload-cropbox-trash',
28742 cls : 'btn btn-default',
28743 html : '<i class="fa fa-trash"></i>'
28749 cls : 'btn-group roo-upload-cropbox-rotate-right',
28750 action : 'rotate-right',
28754 cls : 'btn btn-default',
28755 html : '<i class="fa fa-repeat"></i>'
28763 cls : 'btn-group roo-upload-cropbox-rotate-left',
28764 action : 'rotate-left',
28768 cls : 'btn btn-default',
28769 html : '<i class="fa fa-undo"></i>'
28775 cls : 'btn-group roo-upload-cropbox-rotate-right',
28776 action : 'rotate-right',
28780 cls : 'btn btn-default',
28781 html : '<i class="fa fa-repeat"></i>'
28794 * @class Roo.bootstrap.DocumentManager
28795 * @extends Roo.bootstrap.Component
28796 * Bootstrap DocumentManager class
28797 * @cfg {String} paramName default 'imageUpload'
28798 * @cfg {String} toolTipName default 'filename'
28799 * @cfg {String} method default POST
28800 * @cfg {String} url action url
28801 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
28802 * @cfg {Boolean} multiple multiple upload default true
28803 * @cfg {Number} thumbSize default 300
28804 * @cfg {String} fieldLabel
28805 * @cfg {Number} labelWidth default 4
28806 * @cfg {String} labelAlign (left|top) default left
28807 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
28808 * @cfg {Number} labellg set the width of label (1-12)
28809 * @cfg {Number} labelmd set the width of label (1-12)
28810 * @cfg {Number} labelsm set the width of label (1-12)
28811 * @cfg {Number} labelxs set the width of label (1-12)
28814 * Create a new DocumentManager
28815 * @param {Object} config The config object
28818 Roo.bootstrap.DocumentManager = function(config){
28819 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
28822 this.delegates = [];
28827 * Fire when initial the DocumentManager
28828 * @param {Roo.bootstrap.DocumentManager} this
28833 * inspect selected file
28834 * @param {Roo.bootstrap.DocumentManager} this
28835 * @param {File} file
28840 * Fire when xhr load exception
28841 * @param {Roo.bootstrap.DocumentManager} this
28842 * @param {XMLHttpRequest} xhr
28844 "exception" : true,
28846 * @event afterupload
28847 * Fire when xhr load exception
28848 * @param {Roo.bootstrap.DocumentManager} this
28849 * @param {XMLHttpRequest} xhr
28851 "afterupload" : true,
28854 * prepare the form data
28855 * @param {Roo.bootstrap.DocumentManager} this
28856 * @param {Object} formData
28861 * Fire when remove the file
28862 * @param {Roo.bootstrap.DocumentManager} this
28863 * @param {Object} file
28868 * Fire after refresh the file
28869 * @param {Roo.bootstrap.DocumentManager} this
28874 * Fire after click the image
28875 * @param {Roo.bootstrap.DocumentManager} this
28876 * @param {Object} file
28881 * Fire when upload a image and editable set to true
28882 * @param {Roo.bootstrap.DocumentManager} this
28883 * @param {Object} file
28887 * @event beforeselectfile
28888 * Fire before select file
28889 * @param {Roo.bootstrap.DocumentManager} this
28891 "beforeselectfile" : true,
28894 * Fire before process file
28895 * @param {Roo.bootstrap.DocumentManager} this
28896 * @param {Object} file
28900 * @event previewrendered
28901 * Fire when preview rendered
28902 * @param {Roo.bootstrap.DocumentManager} this
28903 * @param {Object} file
28905 "previewrendered" : true,
28908 "previewResize" : true
28913 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
28922 paramName : 'imageUpload',
28923 toolTipName : 'filename',
28926 labelAlign : 'left',
28936 getAutoCreate : function()
28938 var managerWidget = {
28940 cls : 'roo-document-manager',
28944 cls : 'roo-document-manager-selector',
28949 cls : 'roo-document-manager-uploader',
28953 cls : 'roo-document-manager-upload-btn',
28954 html : '<i class="fa fa-plus"></i>'
28965 cls : 'column col-md-12',
28970 if(this.fieldLabel.length){
28975 cls : 'column col-md-12',
28976 html : this.fieldLabel
28980 cls : 'column col-md-12',
28985 if(this.labelAlign == 'left'){
28990 html : this.fieldLabel
28999 if(this.labelWidth > 12){
29000 content[0].style = "width: " + this.labelWidth + 'px';
29003 if(this.labelWidth < 13 && this.labelmd == 0){
29004 this.labelmd = this.labelWidth;
29007 if(this.labellg > 0){
29008 content[0].cls += ' col-lg-' + this.labellg;
29009 content[1].cls += ' col-lg-' + (12 - this.labellg);
29012 if(this.labelmd > 0){
29013 content[0].cls += ' col-md-' + this.labelmd;
29014 content[1].cls += ' col-md-' + (12 - this.labelmd);
29017 if(this.labelsm > 0){
29018 content[0].cls += ' col-sm-' + this.labelsm;
29019 content[1].cls += ' col-sm-' + (12 - this.labelsm);
29022 if(this.labelxs > 0){
29023 content[0].cls += ' col-xs-' + this.labelxs;
29024 content[1].cls += ' col-xs-' + (12 - this.labelxs);
29032 cls : 'row clearfix',
29040 initEvents : function()
29042 this.managerEl = this.el.select('.roo-document-manager', true).first();
29043 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29045 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
29046 this.selectorEl.hide();
29049 this.selectorEl.attr('multiple', 'multiple');
29052 this.selectorEl.on('change', this.onFileSelected, this);
29054 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
29055 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29057 this.uploader.on('click', this.onUploaderClick, this);
29059 this.renderProgressDialog();
29063 window.addEventListener("resize", function() { _this.refresh(); } );
29065 this.fireEvent('initial', this);
29068 renderProgressDialog : function()
29072 this.progressDialog = new Roo.bootstrap.Modal({
29073 cls : 'roo-document-manager-progress-dialog',
29074 allow_close : false,
29084 btnclick : function() {
29085 _this.uploadCancel();
29091 this.progressDialog.render(Roo.get(document.body));
29093 this.progress = new Roo.bootstrap.Progress({
29094 cls : 'roo-document-manager-progress',
29099 this.progress.render(this.progressDialog.getChildContainer());
29101 this.progressBar = new Roo.bootstrap.ProgressBar({
29102 cls : 'roo-document-manager-progress-bar',
29105 aria_valuemax : 12,
29109 this.progressBar.render(this.progress.getChildContainer());
29112 onUploaderClick : function(e)
29114 e.preventDefault();
29116 if(this.fireEvent('beforeselectfile', this) != false){
29117 this.selectorEl.dom.click();
29122 onFileSelected : function(e)
29124 e.preventDefault();
29126 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
29130 Roo.each(this.selectorEl.dom.files, function(file){
29131 if(this.fireEvent('inspect', this, file) != false){
29132 this.files.push(file);
29142 this.selectorEl.dom.value = '';
29144 if(!this.files || !this.files.length){
29148 if(this.boxes > 0 && this.files.length > this.boxes){
29149 this.files = this.files.slice(0, this.boxes);
29152 this.uploader.show();
29154 if(this.boxes > 0 && this.files.length > this.boxes - 1){
29155 this.uploader.hide();
29164 Roo.each(this.files, function(file){
29166 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29167 var f = this.renderPreview(file);
29172 if(file.type.indexOf('image') != -1){
29173 this.delegates.push(
29175 _this.process(file);
29176 }).createDelegate(this)
29184 _this.process(file);
29185 }).createDelegate(this)
29190 this.files = files;
29192 this.delegates = this.delegates.concat(docs);
29194 if(!this.delegates.length){
29199 this.progressBar.aria_valuemax = this.delegates.length;
29206 arrange : function()
29208 if(!this.delegates.length){
29209 this.progressDialog.hide();
29214 var delegate = this.delegates.shift();
29216 this.progressDialog.show();
29218 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
29220 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
29225 refresh : function()
29227 this.uploader.show();
29229 if(this.boxes > 0 && this.files.length > this.boxes - 1){
29230 this.uploader.hide();
29233 Roo.isTouch ? this.closable(false) : this.closable(true);
29235 this.fireEvent('refresh', this);
29238 onRemove : function(e, el, o)
29240 e.preventDefault();
29242 this.fireEvent('remove', this, o);
29246 remove : function(o)
29250 Roo.each(this.files, function(file){
29251 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
29260 this.files = files;
29267 Roo.each(this.files, function(file){
29272 file.target.remove();
29281 onClick : function(e, el, o)
29283 e.preventDefault();
29285 this.fireEvent('click', this, o);
29289 closable : function(closable)
29291 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
29293 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29305 xhrOnLoad : function(xhr)
29307 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29311 if (xhr.readyState !== 4) {
29313 this.fireEvent('exception', this, xhr);
29317 var response = Roo.decode(xhr.responseText);
29319 if(!response.success){
29321 this.fireEvent('exception', this, xhr);
29325 var file = this.renderPreview(response.data);
29327 this.files.push(file);
29331 this.fireEvent('afterupload', this, xhr);
29335 xhrOnError : function(xhr)
29337 Roo.log('xhr on error');
29339 var response = Roo.decode(xhr.responseText);
29346 process : function(file)
29348 if(this.fireEvent('process', this, file) !== false){
29349 if(this.editable && file.type.indexOf('image') != -1){
29350 this.fireEvent('edit', this, file);
29354 this.uploadStart(file, false);
29361 uploadStart : function(file, crop)
29363 this.xhr = new XMLHttpRequest();
29365 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29370 file.xhr = this.xhr;
29372 this.managerEl.createChild({
29374 cls : 'roo-document-manager-loading',
29378 tooltip : file.name,
29379 cls : 'roo-document-manager-thumb',
29380 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29386 this.xhr.open(this.method, this.url, true);
29389 "Accept": "application/json",
29390 "Cache-Control": "no-cache",
29391 "X-Requested-With": "XMLHttpRequest"
29394 for (var headerName in headers) {
29395 var headerValue = headers[headerName];
29397 this.xhr.setRequestHeader(headerName, headerValue);
29403 this.xhr.onload = function()
29405 _this.xhrOnLoad(_this.xhr);
29408 this.xhr.onerror = function()
29410 _this.xhrOnError(_this.xhr);
29413 var formData = new FormData();
29415 formData.append('returnHTML', 'NO');
29418 formData.append('crop', crop);
29421 formData.append(this.paramName, file, file.name);
29428 if(this.fireEvent('prepare', this, formData, options) != false){
29430 if(options.manually){
29434 this.xhr.send(formData);
29438 this.uploadCancel();
29441 uploadCancel : function()
29447 this.delegates = [];
29449 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29456 renderPreview : function(file)
29458 if(typeof(file.target) != 'undefined' && file.target){
29462 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
29464 var previewEl = this.managerEl.createChild({
29466 cls : 'roo-document-manager-preview',
29470 tooltip : file[this.toolTipName],
29471 cls : 'roo-document-manager-thumb',
29472 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
29477 html : '<i class="fa fa-times-circle"></i>'
29482 var close = previewEl.select('button.close', true).first();
29484 close.on('click', this.onRemove, this, file);
29486 file.target = previewEl;
29488 var image = previewEl.select('img', true).first();
29492 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
29494 image.on('click', this.onClick, this, file);
29496 this.fireEvent('previewrendered', this, file);
29502 onPreviewLoad : function(file, image)
29504 if(typeof(file.target) == 'undefined' || !file.target){
29508 var width = image.dom.naturalWidth || image.dom.width;
29509 var height = image.dom.naturalHeight || image.dom.height;
29511 if(!this.previewResize) {
29515 if(width > height){
29516 file.target.addClass('wide');
29520 file.target.addClass('tall');
29525 uploadFromSource : function(file, crop)
29527 this.xhr = new XMLHttpRequest();
29529 this.managerEl.createChild({
29531 cls : 'roo-document-manager-loading',
29535 tooltip : file.name,
29536 cls : 'roo-document-manager-thumb',
29537 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29543 this.xhr.open(this.method, this.url, true);
29546 "Accept": "application/json",
29547 "Cache-Control": "no-cache",
29548 "X-Requested-With": "XMLHttpRequest"
29551 for (var headerName in headers) {
29552 var headerValue = headers[headerName];
29554 this.xhr.setRequestHeader(headerName, headerValue);
29560 this.xhr.onload = function()
29562 _this.xhrOnLoad(_this.xhr);
29565 this.xhr.onerror = function()
29567 _this.xhrOnError(_this.xhr);
29570 var formData = new FormData();
29572 formData.append('returnHTML', 'NO');
29574 formData.append('crop', crop);
29576 if(typeof(file.filename) != 'undefined'){
29577 formData.append('filename', file.filename);
29580 if(typeof(file.mimetype) != 'undefined'){
29581 formData.append('mimetype', file.mimetype);
29586 if(this.fireEvent('prepare', this, formData) != false){
29587 this.xhr.send(formData);
29597 * @class Roo.bootstrap.DocumentViewer
29598 * @extends Roo.bootstrap.Component
29599 * Bootstrap DocumentViewer class
29600 * @cfg {Boolean} showDownload (true|false) show download button (default true)
29601 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
29604 * Create a new DocumentViewer
29605 * @param {Object} config The config object
29608 Roo.bootstrap.DocumentViewer = function(config){
29609 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
29614 * Fire after initEvent
29615 * @param {Roo.bootstrap.DocumentViewer} this
29621 * @param {Roo.bootstrap.DocumentViewer} this
29626 * Fire after download button
29627 * @param {Roo.bootstrap.DocumentViewer} this
29632 * Fire after trash button
29633 * @param {Roo.bootstrap.DocumentViewer} this
29640 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
29642 showDownload : true,
29646 getAutoCreate : function()
29650 cls : 'roo-document-viewer',
29654 cls : 'roo-document-viewer-body',
29658 cls : 'roo-document-viewer-thumb',
29662 cls : 'roo-document-viewer-image'
29670 cls : 'roo-document-viewer-footer',
29673 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
29677 cls : 'btn-group roo-document-viewer-download',
29681 cls : 'btn btn-default',
29682 html : '<i class="fa fa-download"></i>'
29688 cls : 'btn-group roo-document-viewer-trash',
29692 cls : 'btn btn-default',
29693 html : '<i class="fa fa-trash"></i>'
29706 initEvents : function()
29708 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
29709 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
29711 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
29712 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
29714 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
29715 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
29717 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
29718 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
29720 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
29721 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
29723 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
29724 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
29726 this.bodyEl.on('click', this.onClick, this);
29727 this.downloadBtn.on('click', this.onDownload, this);
29728 this.trashBtn.on('click', this.onTrash, this);
29730 this.downloadBtn.hide();
29731 this.trashBtn.hide();
29733 if(this.showDownload){
29734 this.downloadBtn.show();
29737 if(this.showTrash){
29738 this.trashBtn.show();
29741 if(!this.showDownload && !this.showTrash) {
29742 this.footerEl.hide();
29747 initial : function()
29749 this.fireEvent('initial', this);
29753 onClick : function(e)
29755 e.preventDefault();
29757 this.fireEvent('click', this);
29760 onDownload : function(e)
29762 e.preventDefault();
29764 this.fireEvent('download', this);
29767 onTrash : function(e)
29769 e.preventDefault();
29771 this.fireEvent('trash', this);
29783 * @class Roo.bootstrap.NavProgressBar
29784 * @extends Roo.bootstrap.Component
29785 * Bootstrap NavProgressBar class
29788 * Create a new nav progress bar
29789 * @param {Object} config The config object
29792 Roo.bootstrap.NavProgressBar = function(config){
29793 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
29795 this.bullets = this.bullets || [];
29797 // Roo.bootstrap.NavProgressBar.register(this);
29801 * Fires when the active item changes
29802 * @param {Roo.bootstrap.NavProgressBar} this
29803 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
29804 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
29811 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
29816 getAutoCreate : function()
29818 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
29822 cls : 'roo-navigation-bar-group',
29826 cls : 'roo-navigation-top-bar'
29830 cls : 'roo-navigation-bullets-bar',
29834 cls : 'roo-navigation-bar'
29841 cls : 'roo-navigation-bottom-bar'
29851 initEvents: function()
29856 onRender : function(ct, position)
29858 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
29860 if(this.bullets.length){
29861 Roo.each(this.bullets, function(b){
29870 addItem : function(cfg)
29872 var item = new Roo.bootstrap.NavProgressItem(cfg);
29874 item.parentId = this.id;
29875 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
29878 var top = new Roo.bootstrap.Element({
29880 cls : 'roo-navigation-bar-text'
29883 var bottom = new Roo.bootstrap.Element({
29885 cls : 'roo-navigation-bar-text'
29888 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
29889 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
29891 var topText = new Roo.bootstrap.Element({
29893 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
29896 var bottomText = new Roo.bootstrap.Element({
29898 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
29901 topText.onRender(top.el, null);
29902 bottomText.onRender(bottom.el, null);
29905 item.bottomEl = bottom;
29908 this.barItems.push(item);
29913 getActive : function()
29915 var active = false;
29917 Roo.each(this.barItems, function(v){
29919 if (!v.isActive()) {
29931 setActiveItem : function(item)
29935 Roo.each(this.barItems, function(v){
29936 if (v.rid == item.rid) {
29940 if (v.isActive()) {
29941 v.setActive(false);
29946 item.setActive(true);
29948 this.fireEvent('changed', this, item, prev);
29951 getBarItem: function(rid)
29955 Roo.each(this.barItems, function(e) {
29956 if (e.rid != rid) {
29967 indexOfItem : function(item)
29971 Roo.each(this.barItems, function(v, i){
29973 if (v.rid != item.rid) {
29984 setActiveNext : function()
29986 var i = this.indexOfItem(this.getActive());
29988 if (i > this.barItems.length) {
29992 this.setActiveItem(this.barItems[i+1]);
29995 setActivePrev : function()
29997 var i = this.indexOfItem(this.getActive());
30003 this.setActiveItem(this.barItems[i-1]);
30006 format : function()
30008 if(!this.barItems.length){
30012 var width = 100 / this.barItems.length;
30014 Roo.each(this.barItems, function(i){
30015 i.el.setStyle('width', width + '%');
30016 i.topEl.el.setStyle('width', width + '%');
30017 i.bottomEl.el.setStyle('width', width + '%');
30026 * Nav Progress Item
30031 * @class Roo.bootstrap.NavProgressItem
30032 * @extends Roo.bootstrap.Component
30033 * Bootstrap NavProgressItem class
30034 * @cfg {String} rid the reference id
30035 * @cfg {Boolean} active (true|false) Is item active default false
30036 * @cfg {Boolean} disabled (true|false) Is item active default false
30037 * @cfg {String} html
30038 * @cfg {String} position (top|bottom) text position default bottom
30039 * @cfg {String} icon show icon instead of number
30042 * Create a new NavProgressItem
30043 * @param {Object} config The config object
30045 Roo.bootstrap.NavProgressItem = function(config){
30046 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
30051 * The raw click event for the entire grid.
30052 * @param {Roo.bootstrap.NavProgressItem} this
30053 * @param {Roo.EventObject} e
30060 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
30066 position : 'bottom',
30069 getAutoCreate : function()
30071 var iconCls = 'roo-navigation-bar-item-icon';
30073 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
30077 cls: 'roo-navigation-bar-item',
30087 cfg.cls += ' active';
30090 cfg.cls += ' disabled';
30096 disable : function()
30098 this.setDisabled(true);
30101 enable : function()
30103 this.setDisabled(false);
30106 initEvents: function()
30108 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
30110 this.iconEl.on('click', this.onClick, this);
30113 onClick : function(e)
30115 e.preventDefault();
30121 if(this.fireEvent('click', this, e) === false){
30125 this.parent().setActiveItem(this);
30128 isActive: function ()
30130 return this.active;
30133 setActive : function(state)
30135 if(this.active == state){
30139 this.active = state;
30142 this.el.addClass('active');
30146 this.el.removeClass('active');
30151 setDisabled : function(state)
30153 if(this.disabled == state){
30157 this.disabled = state;
30160 this.el.addClass('disabled');
30164 this.el.removeClass('disabled');
30167 tooltipEl : function()
30169 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
30182 * @class Roo.bootstrap.FieldLabel
30183 * @extends Roo.bootstrap.Component
30184 * Bootstrap FieldLabel class
30185 * @cfg {String} html contents of the element
30186 * @cfg {String} tag tag of the element default label
30187 * @cfg {String} cls class of the element
30188 * @cfg {String} target label target
30189 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
30190 * @cfg {String} invalidClass default "text-warning"
30191 * @cfg {String} validClass default "text-success"
30192 * @cfg {String} iconTooltip default "This field is required"
30193 * @cfg {String} indicatorpos (left|right) default left
30196 * Create a new FieldLabel
30197 * @param {Object} config The config object
30200 Roo.bootstrap.FieldLabel = function(config){
30201 Roo.bootstrap.Element.superclass.constructor.call(this, config);
30206 * Fires after the field has been marked as invalid.
30207 * @param {Roo.form.FieldLabel} this
30208 * @param {String} msg The validation message
30213 * Fires after the field has been validated with no errors.
30214 * @param {Roo.form.FieldLabel} this
30220 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
30227 invalidClass : 'has-warning',
30228 validClass : 'has-success',
30229 iconTooltip : 'This field is required',
30230 indicatorpos : 'left',
30232 getAutoCreate : function(){
30235 if (!this.allowBlank) {
30241 cls : 'roo-bootstrap-field-label ' + this.cls,
30246 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
30247 tooltip : this.iconTooltip
30256 if(this.indicatorpos == 'right'){
30259 cls : 'roo-bootstrap-field-label ' + this.cls,
30268 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
30269 tooltip : this.iconTooltip
30278 initEvents: function()
30280 Roo.bootstrap.Element.superclass.initEvents.call(this);
30282 this.indicator = this.indicatorEl();
30284 if(this.indicator){
30285 this.indicator.removeClass('visible');
30286 this.indicator.addClass('invisible');
30289 Roo.bootstrap.FieldLabel.register(this);
30292 indicatorEl : function()
30294 var indicator = this.el.select('i.roo-required-indicator',true).first();
30305 * Mark this field as valid
30307 markValid : function()
30309 if(this.indicator){
30310 this.indicator.removeClass('visible');
30311 this.indicator.addClass('invisible');
30314 this.el.removeClass(this.invalidClass);
30316 this.el.addClass(this.validClass);
30318 this.fireEvent('valid', this);
30322 * Mark this field as invalid
30323 * @param {String} msg The validation message
30325 markInvalid : function(msg)
30327 if(this.indicator){
30328 this.indicator.removeClass('invisible');
30329 this.indicator.addClass('visible');
30332 this.el.removeClass(this.validClass);
30334 this.el.addClass(this.invalidClass);
30336 this.fireEvent('invalid', this, msg);
30342 Roo.apply(Roo.bootstrap.FieldLabel, {
30347 * register a FieldLabel Group
30348 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
30350 register : function(label)
30352 if(this.groups.hasOwnProperty(label.target)){
30356 this.groups[label.target] = label;
30360 * fetch a FieldLabel Group based on the target
30361 * @param {string} target
30362 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
30364 get: function(target) {
30365 if (typeof(this.groups[target]) == 'undefined') {
30369 return this.groups[target] ;
30378 * page DateSplitField.
30384 * @class Roo.bootstrap.DateSplitField
30385 * @extends Roo.bootstrap.Component
30386 * Bootstrap DateSplitField class
30387 * @cfg {string} fieldLabel - the label associated
30388 * @cfg {Number} labelWidth set the width of label (0-12)
30389 * @cfg {String} labelAlign (top|left)
30390 * @cfg {Boolean} dayAllowBlank (true|false) default false
30391 * @cfg {Boolean} monthAllowBlank (true|false) default false
30392 * @cfg {Boolean} yearAllowBlank (true|false) default false
30393 * @cfg {string} dayPlaceholder
30394 * @cfg {string} monthPlaceholder
30395 * @cfg {string} yearPlaceholder
30396 * @cfg {string} dayFormat default 'd'
30397 * @cfg {string} monthFormat default 'm'
30398 * @cfg {string} yearFormat default 'Y'
30399 * @cfg {Number} labellg set the width of label (1-12)
30400 * @cfg {Number} labelmd set the width of label (1-12)
30401 * @cfg {Number} labelsm set the width of label (1-12)
30402 * @cfg {Number} labelxs set the width of label (1-12)
30406 * Create a new DateSplitField
30407 * @param {Object} config The config object
30410 Roo.bootstrap.DateSplitField = function(config){
30411 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
30417 * getting the data of years
30418 * @param {Roo.bootstrap.DateSplitField} this
30419 * @param {Object} years
30424 * getting the data of days
30425 * @param {Roo.bootstrap.DateSplitField} this
30426 * @param {Object} days
30431 * Fires after the field has been marked as invalid.
30432 * @param {Roo.form.Field} this
30433 * @param {String} msg The validation message
30438 * Fires after the field has been validated with no errors.
30439 * @param {Roo.form.Field} this
30445 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
30448 labelAlign : 'top',
30450 dayAllowBlank : false,
30451 monthAllowBlank : false,
30452 yearAllowBlank : false,
30453 dayPlaceholder : '',
30454 monthPlaceholder : '',
30455 yearPlaceholder : '',
30459 isFormField : true,
30465 getAutoCreate : function()
30469 cls : 'row roo-date-split-field-group',
30474 cls : 'form-hidden-field roo-date-split-field-group-value',
30480 var labelCls = 'col-md-12';
30481 var contentCls = 'col-md-4';
30483 if(this.fieldLabel){
30487 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
30491 html : this.fieldLabel
30496 if(this.labelAlign == 'left'){
30498 if(this.labelWidth > 12){
30499 label.style = "width: " + this.labelWidth + 'px';
30502 if(this.labelWidth < 13 && this.labelmd == 0){
30503 this.labelmd = this.labelWidth;
30506 if(this.labellg > 0){
30507 labelCls = ' col-lg-' + this.labellg;
30508 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
30511 if(this.labelmd > 0){
30512 labelCls = ' col-md-' + this.labelmd;
30513 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
30516 if(this.labelsm > 0){
30517 labelCls = ' col-sm-' + this.labelsm;
30518 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
30521 if(this.labelxs > 0){
30522 labelCls = ' col-xs-' + this.labelxs;
30523 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
30527 label.cls += ' ' + labelCls;
30529 cfg.cn.push(label);
30532 Roo.each(['day', 'month', 'year'], function(t){
30535 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
30542 inputEl: function ()
30544 return this.el.select('.roo-date-split-field-group-value', true).first();
30547 onRender : function(ct, position)
30551 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
30553 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
30555 this.dayField = new Roo.bootstrap.ComboBox({
30556 allowBlank : this.dayAllowBlank,
30557 alwaysQuery : true,
30558 displayField : 'value',
30561 forceSelection : true,
30563 placeholder : this.dayPlaceholder,
30564 selectOnFocus : true,
30565 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30566 triggerAction : 'all',
30568 valueField : 'value',
30569 store : new Roo.data.SimpleStore({
30570 data : (function() {
30572 _this.fireEvent('days', _this, days);
30575 fields : [ 'value' ]
30578 select : function (_self, record, index)
30580 _this.setValue(_this.getValue());
30585 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
30587 this.monthField = new Roo.bootstrap.MonthField({
30588 after : '<i class=\"fa fa-calendar\"></i>',
30589 allowBlank : this.monthAllowBlank,
30590 placeholder : this.monthPlaceholder,
30593 render : function (_self)
30595 this.el.select('span.input-group-addon', true).first().on('click', function(e){
30596 e.preventDefault();
30600 select : function (_self, oldvalue, newvalue)
30602 _this.setValue(_this.getValue());
30607 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
30609 this.yearField = new Roo.bootstrap.ComboBox({
30610 allowBlank : this.yearAllowBlank,
30611 alwaysQuery : true,
30612 displayField : 'value',
30615 forceSelection : true,
30617 placeholder : this.yearPlaceholder,
30618 selectOnFocus : true,
30619 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30620 triggerAction : 'all',
30622 valueField : 'value',
30623 store : new Roo.data.SimpleStore({
30624 data : (function() {
30626 _this.fireEvent('years', _this, years);
30629 fields : [ 'value' ]
30632 select : function (_self, record, index)
30634 _this.setValue(_this.getValue());
30639 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
30642 setValue : function(v, format)
30644 this.inputEl.dom.value = v;
30646 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
30648 var d = Date.parseDate(v, f);
30655 this.setDay(d.format(this.dayFormat));
30656 this.setMonth(d.format(this.monthFormat));
30657 this.setYear(d.format(this.yearFormat));
30664 setDay : function(v)
30666 this.dayField.setValue(v);
30667 this.inputEl.dom.value = this.getValue();
30672 setMonth : function(v)
30674 this.monthField.setValue(v, true);
30675 this.inputEl.dom.value = this.getValue();
30680 setYear : function(v)
30682 this.yearField.setValue(v);
30683 this.inputEl.dom.value = this.getValue();
30688 getDay : function()
30690 return this.dayField.getValue();
30693 getMonth : function()
30695 return this.monthField.getValue();
30698 getYear : function()
30700 return this.yearField.getValue();
30703 getValue : function()
30705 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
30707 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
30717 this.inputEl.dom.value = '';
30722 validate : function()
30724 var d = this.dayField.validate();
30725 var m = this.monthField.validate();
30726 var y = this.yearField.validate();
30731 (!this.dayAllowBlank && !d) ||
30732 (!this.monthAllowBlank && !m) ||
30733 (!this.yearAllowBlank && !y)
30738 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
30747 this.markInvalid();
30752 markValid : function()
30755 var label = this.el.select('label', true).first();
30756 var icon = this.el.select('i.fa-star', true).first();
30762 this.fireEvent('valid', this);
30766 * Mark this field as invalid
30767 * @param {String} msg The validation message
30769 markInvalid : function(msg)
30772 var label = this.el.select('label', true).first();
30773 var icon = this.el.select('i.fa-star', true).first();
30775 if(label && !icon){
30776 this.el.select('.roo-date-split-field-label', true).createChild({
30778 cls : 'text-danger fa fa-lg fa-star',
30779 tooltip : 'This field is required',
30780 style : 'margin-right:5px;'
30784 this.fireEvent('invalid', this, msg);
30787 clearInvalid : function()
30789 var label = this.el.select('label', true).first();
30790 var icon = this.el.select('i.fa-star', true).first();
30796 this.fireEvent('valid', this);
30799 getName: function()
30809 * http://masonry.desandro.com
30811 * The idea is to render all the bricks based on vertical width...
30813 * The original code extends 'outlayer' - we might need to use that....
30819 * @class Roo.bootstrap.LayoutMasonry
30820 * @extends Roo.bootstrap.Component
30821 * Bootstrap Layout Masonry class
30824 * Create a new Element
30825 * @param {Object} config The config object
30828 Roo.bootstrap.LayoutMasonry = function(config){
30830 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
30834 Roo.bootstrap.LayoutMasonry.register(this);
30840 * Fire after layout the items
30841 * @param {Roo.bootstrap.LayoutMasonry} this
30842 * @param {Roo.EventObject} e
30849 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
30852 * @cfg {Boolean} isLayoutInstant = no animation?
30854 isLayoutInstant : false, // needed?
30857 * @cfg {Number} boxWidth width of the columns
30862 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
30867 * @cfg {Number} padWidth padding below box..
30872 * @cfg {Number} gutter gutter width..
30877 * @cfg {Number} maxCols maximum number of columns
30883 * @cfg {Boolean} isAutoInitial defalut true
30885 isAutoInitial : true,
30890 * @cfg {Boolean} isHorizontal defalut false
30892 isHorizontal : false,
30894 currentSize : null,
30900 bricks: null, //CompositeElement
30904 _isLayoutInited : false,
30906 // isAlternative : false, // only use for vertical layout...
30909 * @cfg {Number} alternativePadWidth padding below box..
30911 alternativePadWidth : 50,
30913 selectedBrick : [],
30915 getAutoCreate : function(){
30917 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
30921 cls: 'blog-masonary-wrapper ' + this.cls,
30923 cls : 'mas-boxes masonary'
30930 getChildContainer: function( )
30932 if (this.boxesEl) {
30933 return this.boxesEl;
30936 this.boxesEl = this.el.select('.mas-boxes').first();
30938 return this.boxesEl;
30942 initEvents : function()
30946 if(this.isAutoInitial){
30947 Roo.log('hook children rendered');
30948 this.on('childrenrendered', function() {
30949 Roo.log('children rendered');
30955 initial : function()
30957 this.selectedBrick = [];
30959 this.currentSize = this.el.getBox(true);
30961 Roo.EventManager.onWindowResize(this.resize, this);
30963 if(!this.isAutoInitial){
30971 //this.layout.defer(500,this);
30975 resize : function()
30977 var cs = this.el.getBox(true);
30980 this.currentSize.width == cs.width &&
30981 this.currentSize.x == cs.x &&
30982 this.currentSize.height == cs.height &&
30983 this.currentSize.y == cs.y
30985 Roo.log("no change in with or X or Y");
30989 this.currentSize = cs;
30995 layout : function()
30997 this._resetLayout();
30999 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
31001 this.layoutItems( isInstant );
31003 this._isLayoutInited = true;
31005 this.fireEvent('layout', this);
31009 _resetLayout : function()
31011 if(this.isHorizontal){
31012 this.horizontalMeasureColumns();
31016 this.verticalMeasureColumns();
31020 verticalMeasureColumns : function()
31022 this.getContainerWidth();
31024 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
31025 // this.colWidth = Math.floor(this.containerWidth * 0.8);
31029 var boxWidth = this.boxWidth + this.padWidth;
31031 if(this.containerWidth < this.boxWidth){
31032 boxWidth = this.containerWidth
31035 var containerWidth = this.containerWidth;
31037 var cols = Math.floor(containerWidth / boxWidth);
31039 this.cols = Math.max( cols, 1 );
31041 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
31043 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
31045 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
31047 this.colWidth = boxWidth + avail - this.padWidth;
31049 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
31050 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
31053 horizontalMeasureColumns : function()
31055 this.getContainerWidth();
31057 var boxWidth = this.boxWidth;
31059 if(this.containerWidth < boxWidth){
31060 boxWidth = this.containerWidth;
31063 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
31065 this.el.setHeight(boxWidth);
31069 getContainerWidth : function()
31071 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
31074 layoutItems : function( isInstant )
31076 Roo.log(this.bricks);
31078 var items = Roo.apply([], this.bricks);
31080 if(this.isHorizontal){
31081 this._horizontalLayoutItems( items , isInstant );
31085 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
31086 // this._verticalAlternativeLayoutItems( items , isInstant );
31090 this._verticalLayoutItems( items , isInstant );
31094 _verticalLayoutItems : function ( items , isInstant)
31096 if ( !items || !items.length ) {
31101 ['xs', 'xs', 'xs', 'tall'],
31102 ['xs', 'xs', 'tall'],
31103 ['xs', 'xs', 'sm'],
31104 ['xs', 'xs', 'xs'],
31110 ['sm', 'xs', 'xs'],
31114 ['tall', 'xs', 'xs', 'xs'],
31115 ['tall', 'xs', 'xs'],
31127 Roo.each(items, function(item, k){
31129 switch (item.size) {
31130 // these layouts take up a full box,
31141 boxes.push([item]);
31164 var filterPattern = function(box, length)
31172 var pattern = box.slice(0, length);
31176 Roo.each(pattern, function(i){
31177 format.push(i.size);
31180 Roo.each(standard, function(s){
31182 if(String(s) != String(format)){
31191 if(!match && length == 1){
31196 filterPattern(box, length - 1);
31200 queue.push(pattern);
31202 box = box.slice(length, box.length);
31204 filterPattern(box, 4);
31210 Roo.each(boxes, function(box, k){
31216 if(box.length == 1){
31221 filterPattern(box, 4);
31225 this._processVerticalLayoutQueue( queue, isInstant );
31229 // _verticalAlternativeLayoutItems : function( items , isInstant )
31231 // if ( !items || !items.length ) {
31235 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
31239 _horizontalLayoutItems : function ( items , isInstant)
31241 if ( !items || !items.length || items.length < 3) {
31247 var eItems = items.slice(0, 3);
31249 items = items.slice(3, items.length);
31252 ['xs', 'xs', 'xs', 'wide'],
31253 ['xs', 'xs', 'wide'],
31254 ['xs', 'xs', 'sm'],
31255 ['xs', 'xs', 'xs'],
31261 ['sm', 'xs', 'xs'],
31265 ['wide', 'xs', 'xs', 'xs'],
31266 ['wide', 'xs', 'xs'],
31279 Roo.each(items, function(item, k){
31281 switch (item.size) {
31292 boxes.push([item]);
31316 var filterPattern = function(box, length)
31324 var pattern = box.slice(0, length);
31328 Roo.each(pattern, function(i){
31329 format.push(i.size);
31332 Roo.each(standard, function(s){
31334 if(String(s) != String(format)){
31343 if(!match && length == 1){
31348 filterPattern(box, length - 1);
31352 queue.push(pattern);
31354 box = box.slice(length, box.length);
31356 filterPattern(box, 4);
31362 Roo.each(boxes, function(box, k){
31368 if(box.length == 1){
31373 filterPattern(box, 4);
31380 var pos = this.el.getBox(true);
31384 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31386 var hit_end = false;
31388 Roo.each(queue, function(box){
31392 Roo.each(box, function(b){
31394 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31404 Roo.each(box, function(b){
31406 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31409 mx = Math.max(mx, b.x);
31413 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
31417 Roo.each(box, function(b){
31419 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31433 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
31436 /** Sets position of item in DOM
31437 * @param {Element} item
31438 * @param {Number} x - horizontal position
31439 * @param {Number} y - vertical position
31440 * @param {Boolean} isInstant - disables transitions
31442 _processVerticalLayoutQueue : function( queue, isInstant )
31444 var pos = this.el.getBox(true);
31449 for (var i = 0; i < this.cols; i++){
31453 Roo.each(queue, function(box, k){
31455 var col = k % this.cols;
31457 Roo.each(box, function(b,kk){
31459 b.el.position('absolute');
31461 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31462 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31464 if(b.size == 'md-left' || b.size == 'md-right'){
31465 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31466 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31469 b.el.setWidth(width);
31470 b.el.setHeight(height);
31472 b.el.select('iframe',true).setSize(width,height);
31476 for (var i = 0; i < this.cols; i++){
31478 if(maxY[i] < maxY[col]){
31483 col = Math.min(col, i);
31487 x = pos.x + col * (this.colWidth + this.padWidth);
31491 var positions = [];
31493 switch (box.length){
31495 positions = this.getVerticalOneBoxColPositions(x, y, box);
31498 positions = this.getVerticalTwoBoxColPositions(x, y, box);
31501 positions = this.getVerticalThreeBoxColPositions(x, y, box);
31504 positions = this.getVerticalFourBoxColPositions(x, y, box);
31510 Roo.each(box, function(b,kk){
31512 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31514 var sz = b.el.getSize();
31516 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
31524 for (var i = 0; i < this.cols; i++){
31525 mY = Math.max(mY, maxY[i]);
31528 this.el.setHeight(mY - pos.y);
31532 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
31534 // var pos = this.el.getBox(true);
31537 // var maxX = pos.right;
31539 // var maxHeight = 0;
31541 // Roo.each(items, function(item, k){
31545 // item.el.position('absolute');
31547 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
31549 // item.el.setWidth(width);
31551 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
31553 // item.el.setHeight(height);
31556 // item.el.setXY([x, y], isInstant ? false : true);
31558 // item.el.setXY([maxX - width, y], isInstant ? false : true);
31561 // y = y + height + this.alternativePadWidth;
31563 // maxHeight = maxHeight + height + this.alternativePadWidth;
31567 // this.el.setHeight(maxHeight);
31571 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
31573 var pos = this.el.getBox(true);
31578 var maxX = pos.right;
31580 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
31582 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31584 Roo.each(queue, function(box, k){
31586 Roo.each(box, function(b, kk){
31588 b.el.position('absolute');
31590 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31591 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31593 if(b.size == 'md-left' || b.size == 'md-right'){
31594 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31595 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31598 b.el.setWidth(width);
31599 b.el.setHeight(height);
31607 var positions = [];
31609 switch (box.length){
31611 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
31614 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
31617 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
31620 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
31626 Roo.each(box, function(b,kk){
31628 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31630 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
31638 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
31640 Roo.each(eItems, function(b,k){
31642 b.size = (k == 0) ? 'sm' : 'xs';
31643 b.x = (k == 0) ? 2 : 1;
31644 b.y = (k == 0) ? 2 : 1;
31646 b.el.position('absolute');
31648 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31650 b.el.setWidth(width);
31652 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31654 b.el.setHeight(height);
31658 var positions = [];
31661 x : maxX - this.unitWidth * 2 - this.gutter,
31666 x : maxX - this.unitWidth,
31667 y : minY + (this.unitWidth + this.gutter) * 2
31671 x : maxX - this.unitWidth * 3 - this.gutter * 2,
31675 Roo.each(eItems, function(b,k){
31677 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
31683 getVerticalOneBoxColPositions : function(x, y, box)
31687 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
31689 if(box[0].size == 'md-left'){
31693 if(box[0].size == 'md-right'){
31698 x : x + (this.unitWidth + this.gutter) * rand,
31705 getVerticalTwoBoxColPositions : function(x, y, box)
31709 if(box[0].size == 'xs'){
31713 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
31717 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
31731 x : x + (this.unitWidth + this.gutter) * 2,
31732 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
31739 getVerticalThreeBoxColPositions : function(x, y, box)
31743 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31751 x : x + (this.unitWidth + this.gutter) * 1,
31756 x : x + (this.unitWidth + this.gutter) * 2,
31764 if(box[0].size == 'xs' && box[1].size == 'xs'){
31773 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
31777 x : x + (this.unitWidth + this.gutter) * 1,
31791 x : x + (this.unitWidth + this.gutter) * 2,
31796 x : x + (this.unitWidth + this.gutter) * 2,
31797 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
31804 getVerticalFourBoxColPositions : function(x, y, box)
31808 if(box[0].size == 'xs'){
31817 y : y + (this.unitHeight + this.gutter) * 1
31822 y : y + (this.unitHeight + this.gutter) * 2
31826 x : x + (this.unitWidth + this.gutter) * 1,
31840 x : x + (this.unitWidth + this.gutter) * 2,
31845 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
31846 y : y + (this.unitHeight + this.gutter) * 1
31850 x : x + (this.unitWidth + this.gutter) * 2,
31851 y : y + (this.unitWidth + this.gutter) * 2
31858 getHorizontalOneBoxColPositions : function(maxX, minY, box)
31862 if(box[0].size == 'md-left'){
31864 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31871 if(box[0].size == 'md-right'){
31873 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31874 y : minY + (this.unitWidth + this.gutter) * 1
31880 var rand = Math.floor(Math.random() * (4 - box[0].y));
31883 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31884 y : minY + (this.unitWidth + this.gutter) * rand
31891 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
31895 if(box[0].size == 'xs'){
31898 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31903 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31904 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
31912 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31917 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31918 y : minY + (this.unitWidth + this.gutter) * 2
31925 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
31929 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31932 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31937 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31938 y : minY + (this.unitWidth + this.gutter) * 1
31942 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31943 y : minY + (this.unitWidth + this.gutter) * 2
31950 if(box[0].size == 'xs' && box[1].size == 'xs'){
31953 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31958 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31963 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31964 y : minY + (this.unitWidth + this.gutter) * 1
31972 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31977 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31978 y : minY + (this.unitWidth + this.gutter) * 2
31982 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31983 y : minY + (this.unitWidth + this.gutter) * 2
31990 getHorizontalFourBoxColPositions : function(maxX, minY, box)
31994 if(box[0].size == 'xs'){
31997 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32002 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
32007 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),
32012 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
32013 y : minY + (this.unitWidth + this.gutter) * 1
32021 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32026 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
32027 y : minY + (this.unitWidth + this.gutter) * 2
32031 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
32032 y : minY + (this.unitWidth + this.gutter) * 2
32036 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),
32037 y : minY + (this.unitWidth + this.gutter) * 2
32045 * remove a Masonry Brick
32046 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
32048 removeBrick : function(brick_id)
32054 for (var i = 0; i<this.bricks.length; i++) {
32055 if (this.bricks[i].id == brick_id) {
32056 this.bricks.splice(i,1);
32057 this.el.dom.removeChild(Roo.get(brick_id).dom);
32064 * adds a Masonry Brick
32065 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32067 addBrick : function(cfg)
32069 var cn = new Roo.bootstrap.MasonryBrick(cfg);
32070 //this.register(cn);
32071 cn.parentId = this.id;
32072 cn.render(this.el);
32077 * register a Masonry Brick
32078 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32081 register : function(brick)
32083 this.bricks.push(brick);
32084 brick.masonryId = this.id;
32088 * clear all the Masonry Brick
32090 clearAll : function()
32093 //this.getChildContainer().dom.innerHTML = "";
32094 this.el.dom.innerHTML = '';
32097 getSelected : function()
32099 if (!this.selectedBrick) {
32103 return this.selectedBrick;
32107 Roo.apply(Roo.bootstrap.LayoutMasonry, {
32111 * register a Masonry Layout
32112 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
32115 register : function(layout)
32117 this.groups[layout.id] = layout;
32120 * fetch a Masonry Layout based on the masonry layout ID
32121 * @param {string} the masonry layout to add
32122 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
32125 get: function(layout_id) {
32126 if (typeof(this.groups[layout_id]) == 'undefined') {
32129 return this.groups[layout_id] ;
32141 * http://masonry.desandro.com
32143 * The idea is to render all the bricks based on vertical width...
32145 * The original code extends 'outlayer' - we might need to use that....
32151 * @class Roo.bootstrap.LayoutMasonryAuto
32152 * @extends Roo.bootstrap.Component
32153 * Bootstrap Layout Masonry class
32156 * Create a new Element
32157 * @param {Object} config The config object
32160 Roo.bootstrap.LayoutMasonryAuto = function(config){
32161 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
32164 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
32167 * @cfg {Boolean} isFitWidth - resize the width..
32169 isFitWidth : false, // options..
32171 * @cfg {Boolean} isOriginLeft = left align?
32173 isOriginLeft : true,
32175 * @cfg {Boolean} isOriginTop = top align?
32177 isOriginTop : false,
32179 * @cfg {Boolean} isLayoutInstant = no animation?
32181 isLayoutInstant : false, // needed?
32183 * @cfg {Boolean} isResizingContainer = not sure if this is used..
32185 isResizingContainer : true,
32187 * @cfg {Number} columnWidth width of the columns
32193 * @cfg {Number} maxCols maximum number of columns
32198 * @cfg {Number} padHeight padding below box..
32204 * @cfg {Boolean} isAutoInitial defalut true
32207 isAutoInitial : true,
32213 initialColumnWidth : 0,
32214 currentSize : null,
32216 colYs : null, // array.
32223 bricks: null, //CompositeElement
32224 cols : 0, // array?
32225 // element : null, // wrapped now this.el
32226 _isLayoutInited : null,
32229 getAutoCreate : function(){
32233 cls: 'blog-masonary-wrapper ' + this.cls,
32235 cls : 'mas-boxes masonary'
32242 getChildContainer: function( )
32244 if (this.boxesEl) {
32245 return this.boxesEl;
32248 this.boxesEl = this.el.select('.mas-boxes').first();
32250 return this.boxesEl;
32254 initEvents : function()
32258 if(this.isAutoInitial){
32259 Roo.log('hook children rendered');
32260 this.on('childrenrendered', function() {
32261 Roo.log('children rendered');
32268 initial : function()
32270 this.reloadItems();
32272 this.currentSize = this.el.getBox(true);
32274 /// was window resize... - let's see if this works..
32275 Roo.EventManager.onWindowResize(this.resize, this);
32277 if(!this.isAutoInitial){
32282 this.layout.defer(500,this);
32285 reloadItems: function()
32287 this.bricks = this.el.select('.masonry-brick', true);
32289 this.bricks.each(function(b) {
32290 //Roo.log(b.getSize());
32291 if (!b.attr('originalwidth')) {
32292 b.attr('originalwidth', b.getSize().width);
32297 Roo.log(this.bricks.elements.length);
32300 resize : function()
32303 var cs = this.el.getBox(true);
32305 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
32306 Roo.log("no change in with or X");
32309 this.currentSize = cs;
32313 layout : function()
32316 this._resetLayout();
32317 //this._manageStamps();
32319 // don't animate first layout
32320 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
32321 this.layoutItems( isInstant );
32323 // flag for initalized
32324 this._isLayoutInited = true;
32327 layoutItems : function( isInstant )
32329 //var items = this._getItemsForLayout( this.items );
32330 // original code supports filtering layout items.. we just ignore it..
32332 this._layoutItems( this.bricks , isInstant );
32334 this._postLayout();
32336 _layoutItems : function ( items , isInstant)
32338 //this.fireEvent( 'layout', this, items );
32341 if ( !items || !items.elements.length ) {
32342 // no items, emit event with empty array
32347 items.each(function(item) {
32348 Roo.log("layout item");
32350 // get x/y object from method
32351 var position = this._getItemLayoutPosition( item );
32353 position.item = item;
32354 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
32355 queue.push( position );
32358 this._processLayoutQueue( queue );
32360 /** Sets position of item in DOM
32361 * @param {Element} item
32362 * @param {Number} x - horizontal position
32363 * @param {Number} y - vertical position
32364 * @param {Boolean} isInstant - disables transitions
32366 _processLayoutQueue : function( queue )
32368 for ( var i=0, len = queue.length; i < len; i++ ) {
32369 var obj = queue[i];
32370 obj.item.position('absolute');
32371 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
32377 * Any logic you want to do after each layout,
32378 * i.e. size the container
32380 _postLayout : function()
32382 this.resizeContainer();
32385 resizeContainer : function()
32387 if ( !this.isResizingContainer ) {
32390 var size = this._getContainerSize();
32392 this.el.setSize(size.width,size.height);
32393 this.boxesEl.setSize(size.width,size.height);
32399 _resetLayout : function()
32401 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
32402 this.colWidth = this.el.getWidth();
32403 //this.gutter = this.el.getWidth();
32405 this.measureColumns();
32411 this.colYs.push( 0 );
32417 measureColumns : function()
32419 this.getContainerWidth();
32420 // if columnWidth is 0, default to outerWidth of first item
32421 if ( !this.columnWidth ) {
32422 var firstItem = this.bricks.first();
32423 Roo.log(firstItem);
32424 this.columnWidth = this.containerWidth;
32425 if (firstItem && firstItem.attr('originalwidth') ) {
32426 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
32428 // columnWidth fall back to item of first element
32429 Roo.log("set column width?");
32430 this.initialColumnWidth = this.columnWidth ;
32432 // if first elem has no width, default to size of container
32437 if (this.initialColumnWidth) {
32438 this.columnWidth = this.initialColumnWidth;
32443 // column width is fixed at the top - however if container width get's smaller we should
32446 // this bit calcs how man columns..
32448 var columnWidth = this.columnWidth += this.gutter;
32450 // calculate columns
32451 var containerWidth = this.containerWidth + this.gutter;
32453 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
32454 // fix rounding errors, typically with gutters
32455 var excess = columnWidth - containerWidth % columnWidth;
32458 // if overshoot is less than a pixel, round up, otherwise floor it
32459 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
32460 cols = Math[ mathMethod ]( cols );
32461 this.cols = Math.max( cols, 1 );
32462 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
32464 // padding positioning..
32465 var totalColWidth = this.cols * this.columnWidth;
32466 var padavail = this.containerWidth - totalColWidth;
32467 // so for 2 columns - we need 3 'pads'
32469 var padNeeded = (1+this.cols) * this.padWidth;
32471 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
32473 this.columnWidth += padExtra
32474 //this.padWidth = Math.floor(padavail / ( this.cols));
32476 // adjust colum width so that padding is fixed??
32478 // we have 3 columns ... total = width * 3
32479 // we have X left over... that should be used by
32481 //if (this.expandC) {
32489 getContainerWidth : function()
32491 /* // container is parent if fit width
32492 var container = this.isFitWidth ? this.element.parentNode : this.element;
32493 // check that this.size and size are there
32494 // IE8 triggers resize on body size change, so they might not be
32496 var size = getSize( container ); //FIXME
32497 this.containerWidth = size && size.innerWidth; //FIXME
32500 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
32504 _getItemLayoutPosition : function( item ) // what is item?
32506 // we resize the item to our columnWidth..
32508 item.setWidth(this.columnWidth);
32509 item.autoBoxAdjust = false;
32511 var sz = item.getSize();
32513 // how many columns does this brick span
32514 var remainder = this.containerWidth % this.columnWidth;
32516 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
32517 // round if off by 1 pixel, otherwise use ceil
32518 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
32519 colSpan = Math.min( colSpan, this.cols );
32521 // normally this should be '1' as we dont' currently allow multi width columns..
32523 var colGroup = this._getColGroup( colSpan );
32524 // get the minimum Y value from the columns
32525 var minimumY = Math.min.apply( Math, colGroup );
32526 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32528 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
32530 // position the brick
32532 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
32533 y: this.currentSize.y + minimumY + this.padHeight
32537 // apply setHeight to necessary columns
32538 var setHeight = minimumY + sz.height + this.padHeight;
32539 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32541 var setSpan = this.cols + 1 - colGroup.length;
32542 for ( var i = 0; i < setSpan; i++ ) {
32543 this.colYs[ shortColIndex + i ] = setHeight ;
32550 * @param {Number} colSpan - number of columns the element spans
32551 * @returns {Array} colGroup
32553 _getColGroup : function( colSpan )
32555 if ( colSpan < 2 ) {
32556 // if brick spans only one column, use all the column Ys
32561 // how many different places could this brick fit horizontally
32562 var groupCount = this.cols + 1 - colSpan;
32563 // for each group potential horizontal position
32564 for ( var i = 0; i < groupCount; i++ ) {
32565 // make an array of colY values for that one group
32566 var groupColYs = this.colYs.slice( i, i + colSpan );
32567 // and get the max value of the array
32568 colGroup[i] = Math.max.apply( Math, groupColYs );
32573 _manageStamp : function( stamp )
32575 var stampSize = stamp.getSize();
32576 var offset = stamp.getBox();
32577 // get the columns that this stamp affects
32578 var firstX = this.isOriginLeft ? offset.x : offset.right;
32579 var lastX = firstX + stampSize.width;
32580 var firstCol = Math.floor( firstX / this.columnWidth );
32581 firstCol = Math.max( 0, firstCol );
32583 var lastCol = Math.floor( lastX / this.columnWidth );
32584 // lastCol should not go over if multiple of columnWidth #425
32585 lastCol -= lastX % this.columnWidth ? 0 : 1;
32586 lastCol = Math.min( this.cols - 1, lastCol );
32588 // set colYs to bottom of the stamp
32589 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
32592 for ( var i = firstCol; i <= lastCol; i++ ) {
32593 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
32598 _getContainerSize : function()
32600 this.maxY = Math.max.apply( Math, this.colYs );
32605 if ( this.isFitWidth ) {
32606 size.width = this._getContainerFitWidth();
32612 _getContainerFitWidth : function()
32614 var unusedCols = 0;
32615 // count unused columns
32618 if ( this.colYs[i] !== 0 ) {
32623 // fit container to columns that have been used
32624 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
32627 needsResizeLayout : function()
32629 var previousWidth = this.containerWidth;
32630 this.getContainerWidth();
32631 return previousWidth !== this.containerWidth;
32646 * @class Roo.bootstrap.MasonryBrick
32647 * @extends Roo.bootstrap.Component
32648 * Bootstrap MasonryBrick class
32651 * Create a new MasonryBrick
32652 * @param {Object} config The config object
32655 Roo.bootstrap.MasonryBrick = function(config){
32657 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
32659 Roo.bootstrap.MasonryBrick.register(this);
32665 * When a MasonryBrick is clcik
32666 * @param {Roo.bootstrap.MasonryBrick} this
32667 * @param {Roo.EventObject} e
32673 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
32676 * @cfg {String} title
32680 * @cfg {String} html
32684 * @cfg {String} bgimage
32688 * @cfg {String} videourl
32692 * @cfg {String} cls
32696 * @cfg {String} href
32700 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
32705 * @cfg {String} placetitle (center|bottom)
32710 * @cfg {Boolean} isFitContainer defalut true
32712 isFitContainer : true,
32715 * @cfg {Boolean} preventDefault defalut false
32717 preventDefault : false,
32720 * @cfg {Boolean} inverse defalut false
32722 maskInverse : false,
32724 getAutoCreate : function()
32726 if(!this.isFitContainer){
32727 return this.getSplitAutoCreate();
32730 var cls = 'masonry-brick masonry-brick-full';
32732 if(this.href.length){
32733 cls += ' masonry-brick-link';
32736 if(this.bgimage.length){
32737 cls += ' masonry-brick-image';
32740 if(this.maskInverse){
32741 cls += ' mask-inverse';
32744 if(!this.html.length && !this.maskInverse && !this.videourl.length){
32745 cls += ' enable-mask';
32749 cls += ' masonry-' + this.size + '-brick';
32752 if(this.placetitle.length){
32754 switch (this.placetitle) {
32756 cls += ' masonry-center-title';
32759 cls += ' masonry-bottom-title';
32766 if(!this.html.length && !this.bgimage.length){
32767 cls += ' masonry-center-title';
32770 if(!this.html.length && this.bgimage.length){
32771 cls += ' masonry-bottom-title';
32776 cls += ' ' + this.cls;
32780 tag: (this.href.length) ? 'a' : 'div',
32785 cls: 'masonry-brick-mask'
32789 cls: 'masonry-brick-paragraph',
32795 if(this.href.length){
32796 cfg.href = this.href;
32799 var cn = cfg.cn[1].cn;
32801 if(this.title.length){
32804 cls: 'masonry-brick-title',
32809 if(this.html.length){
32812 cls: 'masonry-brick-text',
32817 if (!this.title.length && !this.html.length) {
32818 cfg.cn[1].cls += ' hide';
32821 if(this.bgimage.length){
32824 cls: 'masonry-brick-image-view',
32829 if(this.videourl.length){
32830 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32831 // youtube support only?
32834 cls: 'masonry-brick-image-view',
32837 allowfullscreen : true
32845 getSplitAutoCreate : function()
32847 var cls = 'masonry-brick masonry-brick-split';
32849 if(this.href.length){
32850 cls += ' masonry-brick-link';
32853 if(this.bgimage.length){
32854 cls += ' masonry-brick-image';
32858 cls += ' masonry-' + this.size + '-brick';
32861 switch (this.placetitle) {
32863 cls += ' masonry-center-title';
32866 cls += ' masonry-bottom-title';
32869 if(!this.bgimage.length){
32870 cls += ' masonry-center-title';
32873 if(this.bgimage.length){
32874 cls += ' masonry-bottom-title';
32880 cls += ' ' + this.cls;
32884 tag: (this.href.length) ? 'a' : 'div',
32889 cls: 'masonry-brick-split-head',
32893 cls: 'masonry-brick-paragraph',
32900 cls: 'masonry-brick-split-body',
32906 if(this.href.length){
32907 cfg.href = this.href;
32910 if(this.title.length){
32911 cfg.cn[0].cn[0].cn.push({
32913 cls: 'masonry-brick-title',
32918 if(this.html.length){
32919 cfg.cn[1].cn.push({
32921 cls: 'masonry-brick-text',
32926 if(this.bgimage.length){
32927 cfg.cn[0].cn.push({
32929 cls: 'masonry-brick-image-view',
32934 if(this.videourl.length){
32935 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32936 // youtube support only?
32937 cfg.cn[0].cn.cn.push({
32939 cls: 'masonry-brick-image-view',
32942 allowfullscreen : true
32949 initEvents: function()
32951 switch (this.size) {
32984 this.el.on('touchstart', this.onTouchStart, this);
32985 this.el.on('touchmove', this.onTouchMove, this);
32986 this.el.on('touchend', this.onTouchEnd, this);
32987 this.el.on('contextmenu', this.onContextMenu, this);
32989 this.el.on('mouseenter' ,this.enter, this);
32990 this.el.on('mouseleave', this.leave, this);
32991 this.el.on('click', this.onClick, this);
32994 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
32995 this.parent().bricks.push(this);
33000 onClick: function(e, el)
33002 var time = this.endTimer - this.startTimer;
33003 // Roo.log(e.preventDefault());
33006 e.preventDefault();
33011 if(!this.preventDefault){
33015 e.preventDefault();
33017 if (this.activeClass != '') {
33018 this.selectBrick();
33021 this.fireEvent('click', this, e);
33024 enter: function(e, el)
33026 e.preventDefault();
33028 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
33032 if(this.bgimage.length && this.html.length){
33033 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
33037 leave: function(e, el)
33039 e.preventDefault();
33041 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
33045 if(this.bgimage.length && this.html.length){
33046 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
33050 onTouchStart: function(e, el)
33052 // e.preventDefault();
33054 this.touchmoved = false;
33056 if(!this.isFitContainer){
33060 if(!this.bgimage.length || !this.html.length){
33064 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
33066 this.timer = new Date().getTime();
33070 onTouchMove: function(e, el)
33072 this.touchmoved = true;
33075 onContextMenu : function(e,el)
33077 e.preventDefault();
33078 e.stopPropagation();
33082 onTouchEnd: function(e, el)
33084 // e.preventDefault();
33086 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
33093 if(!this.bgimage.length || !this.html.length){
33095 if(this.href.length){
33096 window.location.href = this.href;
33102 if(!this.isFitContainer){
33106 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
33108 window.location.href = this.href;
33111 //selection on single brick only
33112 selectBrick : function() {
33114 if (!this.parentId) {
33118 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
33119 var index = m.selectedBrick.indexOf(this.id);
33122 m.selectedBrick.splice(index,1);
33123 this.el.removeClass(this.activeClass);
33127 for(var i = 0; i < m.selectedBrick.length; i++) {
33128 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
33129 b.el.removeClass(b.activeClass);
33132 m.selectedBrick = [];
33134 m.selectedBrick.push(this.id);
33135 this.el.addClass(this.activeClass);
33139 isSelected : function(){
33140 return this.el.hasClass(this.activeClass);
33145 Roo.apply(Roo.bootstrap.MasonryBrick, {
33148 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
33150 * register a Masonry Brick
33151 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
33154 register : function(brick)
33156 //this.groups[brick.id] = brick;
33157 this.groups.add(brick.id, brick);
33160 * fetch a masonry brick based on the masonry brick ID
33161 * @param {string} the masonry brick to add
33162 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
33165 get: function(brick_id)
33167 // if (typeof(this.groups[brick_id]) == 'undefined') {
33170 // return this.groups[brick_id] ;
33172 if(this.groups.key(brick_id)) {
33173 return this.groups.key(brick_id);
33191 * @class Roo.bootstrap.Brick
33192 * @extends Roo.bootstrap.Component
33193 * Bootstrap Brick class
33196 * Create a new Brick
33197 * @param {Object} config The config object
33200 Roo.bootstrap.Brick = function(config){
33201 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
33207 * When a Brick is click
33208 * @param {Roo.bootstrap.Brick} this
33209 * @param {Roo.EventObject} e
33215 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
33218 * @cfg {String} title
33222 * @cfg {String} html
33226 * @cfg {String} bgimage
33230 * @cfg {String} cls
33234 * @cfg {String} href
33238 * @cfg {String} video
33242 * @cfg {Boolean} square
33246 getAutoCreate : function()
33248 var cls = 'roo-brick';
33250 if(this.href.length){
33251 cls += ' roo-brick-link';
33254 if(this.bgimage.length){
33255 cls += ' roo-brick-image';
33258 if(!this.html.length && !this.bgimage.length){
33259 cls += ' roo-brick-center-title';
33262 if(!this.html.length && this.bgimage.length){
33263 cls += ' roo-brick-bottom-title';
33267 cls += ' ' + this.cls;
33271 tag: (this.href.length) ? 'a' : 'div',
33276 cls: 'roo-brick-paragraph',
33282 if(this.href.length){
33283 cfg.href = this.href;
33286 var cn = cfg.cn[0].cn;
33288 if(this.title.length){
33291 cls: 'roo-brick-title',
33296 if(this.html.length){
33299 cls: 'roo-brick-text',
33306 if(this.bgimage.length){
33309 cls: 'roo-brick-image-view',
33317 initEvents: function()
33319 if(this.title.length || this.html.length){
33320 this.el.on('mouseenter' ,this.enter, this);
33321 this.el.on('mouseleave', this.leave, this);
33324 Roo.EventManager.onWindowResize(this.resize, this);
33326 if(this.bgimage.length){
33327 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
33328 this.imageEl.on('load', this.onImageLoad, this);
33335 onImageLoad : function()
33340 resize : function()
33342 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
33344 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
33346 if(this.bgimage.length){
33347 var image = this.el.select('.roo-brick-image-view', true).first();
33349 image.setWidth(paragraph.getWidth());
33352 image.setHeight(paragraph.getWidth());
33355 this.el.setHeight(image.getHeight());
33356 paragraph.setHeight(image.getHeight());
33362 enter: function(e, el)
33364 e.preventDefault();
33366 if(this.bgimage.length){
33367 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
33368 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
33372 leave: function(e, el)
33374 e.preventDefault();
33376 if(this.bgimage.length){
33377 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
33378 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
33393 * @class Roo.bootstrap.NumberField
33394 * @extends Roo.bootstrap.Input
33395 * Bootstrap NumberField class
33401 * Create a new NumberField
33402 * @param {Object} config The config object
33405 Roo.bootstrap.NumberField = function(config){
33406 Roo.bootstrap.NumberField.superclass.constructor.call(this, config);
33409 Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
33412 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
33414 allowDecimals : true,
33416 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
33418 decimalSeparator : ".",
33420 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
33422 decimalPrecision : 2,
33424 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
33426 allowNegative : true,
33429 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
33433 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
33435 minValue : Number.NEGATIVE_INFINITY,
33437 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
33439 maxValue : Number.MAX_VALUE,
33441 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
33443 minText : "The minimum value for this field is {0}",
33445 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
33447 maxText : "The maximum value for this field is {0}",
33449 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
33450 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
33452 nanText : "{0} is not a valid number",
33454 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
33456 thousandsDelimiter : false,
33458 * @cfg {String} valueAlign alignment of value
33460 valueAlign : "left",
33462 getAutoCreate : function()
33464 var hiddenInput = {
33468 cls: 'hidden-number-input'
33472 hiddenInput.name = this.name;
33477 var cfg = Roo.bootstrap.NumberField.superclass.getAutoCreate.call(this);
33479 this.name = hiddenInput.name;
33481 if(cfg.cn.length > 0) {
33482 cfg.cn.push(hiddenInput);
33489 initEvents : function()
33491 Roo.bootstrap.NumberField.superclass.initEvents.call(this);
33493 var allowed = "0123456789";
33495 if(this.allowDecimals){
33496 allowed += this.decimalSeparator;
33499 if(this.allowNegative){
33503 if(this.thousandsDelimiter) {
33507 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
33509 var keyPress = function(e){
33511 var k = e.getKey();
33513 var c = e.getCharCode();
33516 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
33517 allowed.indexOf(String.fromCharCode(c)) === -1
33523 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
33527 if(allowed.indexOf(String.fromCharCode(c)) === -1){
33532 this.el.on("keypress", keyPress, this);
33535 validateValue : function(value)
33538 if(!Roo.bootstrap.NumberField.superclass.validateValue.call(this, value)){
33542 var num = this.parseValue(value);
33545 this.markInvalid(String.format(this.nanText, value));
33549 if(num < this.minValue){
33550 this.markInvalid(String.format(this.minText, this.minValue));
33554 if(num > this.maxValue){
33555 this.markInvalid(String.format(this.maxText, this.maxValue));
33562 getValue : function()
33564 var v = this.hiddenEl().getValue();
33566 return this.fixPrecision(this.parseValue(v));
33569 parseValue : function(value)
33571 if(this.thousandsDelimiter) {
33573 r = new RegExp(",", "g");
33574 value = value.replace(r, "");
33577 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
33578 return isNaN(value) ? '' : value;
33581 fixPrecision : function(value)
33583 if(this.thousandsDelimiter) {
33585 r = new RegExp(",", "g");
33586 value = value.replace(r, "");
33589 var nan = isNaN(value);
33591 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
33592 return nan ? '' : value;
33594 return parseFloat(value).toFixed(this.decimalPrecision);
33597 setValue : function(v)
33599 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
33605 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
33607 this.inputEl().dom.value = (v == '') ? '' :
33608 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
33610 if(!this.allowZero && v === '0') {
33611 this.hiddenEl().dom.value = '';
33612 this.inputEl().dom.value = '';
33619 decimalPrecisionFcn : function(v)
33621 return Math.floor(v);
33624 beforeBlur : function()
33626 var v = this.parseValue(this.getRawValue());
33628 if(v || v === 0 || v === ''){
33633 hiddenEl : function()
33635 return this.el.select('input.hidden-number-input',true).first();
33647 * @class Roo.bootstrap.DocumentSlider
33648 * @extends Roo.bootstrap.Component
33649 * Bootstrap DocumentSlider class
33652 * Create a new DocumentViewer
33653 * @param {Object} config The config object
33656 Roo.bootstrap.DocumentSlider = function(config){
33657 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
33664 * Fire after initEvent
33665 * @param {Roo.bootstrap.DocumentSlider} this
33670 * Fire after update
33671 * @param {Roo.bootstrap.DocumentSlider} this
33677 * @param {Roo.bootstrap.DocumentSlider} this
33683 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
33689 getAutoCreate : function()
33693 cls : 'roo-document-slider',
33697 cls : 'roo-document-slider-header',
33701 cls : 'roo-document-slider-header-title'
33707 cls : 'roo-document-slider-body',
33711 cls : 'roo-document-slider-prev',
33715 cls : 'fa fa-chevron-left'
33721 cls : 'roo-document-slider-thumb',
33725 cls : 'roo-document-slider-image'
33731 cls : 'roo-document-slider-next',
33735 cls : 'fa fa-chevron-right'
33747 initEvents : function()
33749 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
33750 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
33752 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
33753 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
33755 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
33756 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
33758 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
33759 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
33761 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
33762 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
33764 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
33765 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33767 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
33768 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33770 this.thumbEl.on('click', this.onClick, this);
33772 this.prevIndicator.on('click', this.prev, this);
33774 this.nextIndicator.on('click', this.next, this);
33778 initial : function()
33780 if(this.files.length){
33781 this.indicator = 1;
33785 this.fireEvent('initial', this);
33788 update : function()
33790 this.imageEl.attr('src', this.files[this.indicator - 1]);
33792 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
33794 this.prevIndicator.show();
33796 if(this.indicator == 1){
33797 this.prevIndicator.hide();
33800 this.nextIndicator.show();
33802 if(this.indicator == this.files.length){
33803 this.nextIndicator.hide();
33806 this.thumbEl.scrollTo('top');
33808 this.fireEvent('update', this);
33811 onClick : function(e)
33813 e.preventDefault();
33815 this.fireEvent('click', this);
33820 e.preventDefault();
33822 this.indicator = Math.max(1, this.indicator - 1);
33829 e.preventDefault();
33831 this.indicator = Math.min(this.files.length, this.indicator + 1);
33845 * @class Roo.bootstrap.RadioSet
33846 * @extends Roo.bootstrap.Input
33847 * Bootstrap RadioSet class
33848 * @cfg {String} indicatorpos (left|right) default left
33849 * @cfg {Boolean} inline (true|false) inline the element (default true)
33850 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
33852 * Create a new RadioSet
33853 * @param {Object} config The config object
33856 Roo.bootstrap.RadioSet = function(config){
33858 Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
33862 Roo.bootstrap.RadioSet.register(this);
33867 * Fires when the element is checked or unchecked.
33868 * @param {Roo.bootstrap.RadioSet} this This radio
33869 * @param {Roo.bootstrap.Radio} item The checked item
33874 * Fires when the element is click.
33875 * @param {Roo.bootstrap.RadioSet} this This radio set
33876 * @param {Roo.bootstrap.Radio} item The checked item
33877 * @param {Roo.EventObject} e The event object
33884 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
33892 indicatorpos : 'left',
33894 getAutoCreate : function()
33898 cls : 'roo-radio-set-label',
33902 html : this.fieldLabel
33907 if(this.indicatorpos == 'left'){
33910 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
33911 tooltip : 'This field is required'
33916 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
33917 tooltip : 'This field is required'
33923 cls : 'roo-radio-set-items'
33926 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
33928 if (align === 'left' && this.fieldLabel.length) {
33931 cls : "roo-radio-set-right",
33937 if(this.labelWidth > 12){
33938 label.style = "width: " + this.labelWidth + 'px';
33941 if(this.labelWidth < 13 && this.labelmd == 0){
33942 this.labelmd = this.labelWidth;
33945 if(this.labellg > 0){
33946 label.cls += ' col-lg-' + this.labellg;
33947 items.cls += ' col-lg-' + (12 - this.labellg);
33950 if(this.labelmd > 0){
33951 label.cls += ' col-md-' + this.labelmd;
33952 items.cls += ' col-md-' + (12 - this.labelmd);
33955 if(this.labelsm > 0){
33956 label.cls += ' col-sm-' + this.labelsm;
33957 items.cls += ' col-sm-' + (12 - this.labelsm);
33960 if(this.labelxs > 0){
33961 label.cls += ' col-xs-' + this.labelxs;
33962 items.cls += ' col-xs-' + (12 - this.labelxs);
33968 cls : 'roo-radio-set',
33972 cls : 'roo-radio-set-input',
33975 value : this.value ? this.value : ''
33982 if(this.weight.length){
33983 cfg.cls += ' roo-radio-' + this.weight;
33987 cfg.cls += ' roo-radio-set-inline';
33991 ['xs','sm','md','lg'].map(function(size){
33992 if (settings[size]) {
33993 cfg.cls += ' col-' + size + '-' + settings[size];
34001 initEvents : function()
34003 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
34004 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
34006 if(!this.fieldLabel.length){
34007 this.labelEl.hide();
34010 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
34011 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
34013 this.indicator = this.indicatorEl();
34015 if(this.indicator){
34016 this.indicator.addClass('invisible');
34019 this.originalValue = this.getValue();
34023 inputEl: function ()
34025 return this.el.select('.roo-radio-set-input', true).first();
34028 getChildContainer : function()
34030 return this.itemsEl;
34033 register : function(item)
34035 this.radioes.push(item);
34039 validate : function()
34041 if(this.getVisibilityEl().hasClass('hidden')){
34047 Roo.each(this.radioes, function(i){
34056 if(this.allowBlank) {
34060 if(this.disabled || valid){
34065 this.markInvalid();
34070 markValid : function()
34072 if(this.labelEl.isVisible(true)){
34073 this.indicatorEl().removeClass('visible');
34074 this.indicatorEl().addClass('invisible');
34077 this.el.removeClass([this.invalidClass, this.validClass]);
34078 this.el.addClass(this.validClass);
34080 this.fireEvent('valid', this);
34083 markInvalid : function(msg)
34085 if(this.allowBlank || this.disabled){
34089 if(this.labelEl.isVisible(true)){
34090 this.indicatorEl().removeClass('invisible');
34091 this.indicatorEl().addClass('visible');
34094 this.el.removeClass([this.invalidClass, this.validClass]);
34095 this.el.addClass(this.invalidClass);
34097 this.fireEvent('invalid', this, msg);
34101 setValue : function(v, suppressEvent)
34103 if(this.value === v){
34110 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
34113 Roo.each(this.radioes, function(i){
34115 i.el.removeClass('checked');
34118 Roo.each(this.radioes, function(i){
34120 if(i.value === v || i.value.toString() === v.toString()){
34122 i.el.addClass('checked');
34124 if(suppressEvent !== true){
34125 this.fireEvent('check', this, i);
34136 clearInvalid : function(){
34138 if(!this.el || this.preventMark){
34142 this.el.removeClass([this.invalidClass]);
34144 this.fireEvent('valid', this);
34149 Roo.apply(Roo.bootstrap.RadioSet, {
34153 register : function(set)
34155 this.groups[set.name] = set;
34158 get: function(name)
34160 if (typeof(this.groups[name]) == 'undefined') {
34164 return this.groups[name] ;
34170 * Ext JS Library 1.1.1
34171 * Copyright(c) 2006-2007, Ext JS, LLC.
34173 * Originally Released Under LGPL - original licence link has changed is not relivant.
34176 * <script type="text/javascript">
34181 * @class Roo.bootstrap.SplitBar
34182 * @extends Roo.util.Observable
34183 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
34187 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
34188 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
34189 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
34190 split.minSize = 100;
34191 split.maxSize = 600;
34192 split.animate = true;
34193 split.on('moved', splitterMoved);
34196 * Create a new SplitBar
34197 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
34198 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
34199 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34200 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
34201 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
34202 position of the SplitBar).
34204 Roo.bootstrap.SplitBar = function(cfg){
34209 // dragElement : elm
34210 // resizingElement: el,
34212 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
34213 // placement : Roo.bootstrap.SplitBar.LEFT ,
34214 // existingProxy ???
34217 this.el = Roo.get(cfg.dragElement, true);
34218 this.el.dom.unselectable = "on";
34220 this.resizingEl = Roo.get(cfg.resizingElement, true);
34224 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34225 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
34228 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
34231 * The minimum size of the resizing element. (Defaults to 0)
34237 * The maximum size of the resizing element. (Defaults to 2000)
34240 this.maxSize = 2000;
34243 * Whether to animate the transition to the new size
34246 this.animate = false;
34249 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
34252 this.useShim = false;
34257 if(!cfg.existingProxy){
34259 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
34261 this.proxy = Roo.get(cfg.existingProxy).dom;
34264 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
34267 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
34270 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
34273 this.dragSpecs = {};
34276 * @private The adapter to use to positon and resize elements
34278 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34279 this.adapter.init(this);
34281 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34283 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
34284 this.el.addClass("roo-splitbar-h");
34287 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
34288 this.el.addClass("roo-splitbar-v");
34294 * Fires when the splitter is moved (alias for {@link #event-moved})
34295 * @param {Roo.bootstrap.SplitBar} this
34296 * @param {Number} newSize the new width or height
34301 * Fires when the splitter is moved
34302 * @param {Roo.bootstrap.SplitBar} this
34303 * @param {Number} newSize the new width or height
34307 * @event beforeresize
34308 * Fires before the splitter is dragged
34309 * @param {Roo.bootstrap.SplitBar} this
34311 "beforeresize" : true,
34313 "beforeapply" : true
34316 Roo.util.Observable.call(this);
34319 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
34320 onStartProxyDrag : function(x, y){
34321 this.fireEvent("beforeresize", this);
34323 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
34325 o.enableDisplayMode("block");
34326 // all splitbars share the same overlay
34327 Roo.bootstrap.SplitBar.prototype.overlay = o;
34329 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
34330 this.overlay.show();
34331 Roo.get(this.proxy).setDisplayed("block");
34332 var size = this.adapter.getElementSize(this);
34333 this.activeMinSize = this.getMinimumSize();;
34334 this.activeMaxSize = this.getMaximumSize();;
34335 var c1 = size - this.activeMinSize;
34336 var c2 = Math.max(this.activeMaxSize - size, 0);
34337 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34338 this.dd.resetConstraints();
34339 this.dd.setXConstraint(
34340 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
34341 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
34343 this.dd.setYConstraint(0, 0);
34345 this.dd.resetConstraints();
34346 this.dd.setXConstraint(0, 0);
34347 this.dd.setYConstraint(
34348 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
34349 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
34352 this.dragSpecs.startSize = size;
34353 this.dragSpecs.startPoint = [x, y];
34354 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
34358 * @private Called after the drag operation by the DDProxy
34360 onEndProxyDrag : function(e){
34361 Roo.get(this.proxy).setDisplayed(false);
34362 var endPoint = Roo.lib.Event.getXY(e);
34364 this.overlay.hide();
34367 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34368 newSize = this.dragSpecs.startSize +
34369 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
34370 endPoint[0] - this.dragSpecs.startPoint[0] :
34371 this.dragSpecs.startPoint[0] - endPoint[0]
34374 newSize = this.dragSpecs.startSize +
34375 (this.placement == Roo.bootstrap.SplitBar.TOP ?
34376 endPoint[1] - this.dragSpecs.startPoint[1] :
34377 this.dragSpecs.startPoint[1] - endPoint[1]
34380 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
34381 if(newSize != this.dragSpecs.startSize){
34382 if(this.fireEvent('beforeapply', this, newSize) !== false){
34383 this.adapter.setElementSize(this, newSize);
34384 this.fireEvent("moved", this, newSize);
34385 this.fireEvent("resize", this, newSize);
34391 * Get the adapter this SplitBar uses
34392 * @return The adapter object
34394 getAdapter : function(){
34395 return this.adapter;
34399 * Set the adapter this SplitBar uses
34400 * @param {Object} adapter A SplitBar adapter object
34402 setAdapter : function(adapter){
34403 this.adapter = adapter;
34404 this.adapter.init(this);
34408 * Gets the minimum size for the resizing element
34409 * @return {Number} The minimum size
34411 getMinimumSize : function(){
34412 return this.minSize;
34416 * Sets the minimum size for the resizing element
34417 * @param {Number} minSize The minimum size
34419 setMinimumSize : function(minSize){
34420 this.minSize = minSize;
34424 * Gets the maximum size for the resizing element
34425 * @return {Number} The maximum size
34427 getMaximumSize : function(){
34428 return this.maxSize;
34432 * Sets the maximum size for the resizing element
34433 * @param {Number} maxSize The maximum size
34435 setMaximumSize : function(maxSize){
34436 this.maxSize = maxSize;
34440 * Sets the initialize size for the resizing element
34441 * @param {Number} size The initial size
34443 setCurrentSize : function(size){
34444 var oldAnimate = this.animate;
34445 this.animate = false;
34446 this.adapter.setElementSize(this, size);
34447 this.animate = oldAnimate;
34451 * Destroy this splitbar.
34452 * @param {Boolean} removeEl True to remove the element
34454 destroy : function(removeEl){
34456 this.shim.remove();
34459 this.proxy.parentNode.removeChild(this.proxy);
34467 * @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.
34469 Roo.bootstrap.SplitBar.createProxy = function(dir){
34470 var proxy = new Roo.Element(document.createElement("div"));
34471 proxy.unselectable();
34472 var cls = 'roo-splitbar-proxy';
34473 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
34474 document.body.appendChild(proxy.dom);
34479 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
34480 * Default Adapter. It assumes the splitter and resizing element are not positioned
34481 * elements and only gets/sets the width of the element. Generally used for table based layouts.
34483 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
34486 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
34487 // do nothing for now
34488 init : function(s){
34492 * Called before drag operations to get the current size of the resizing element.
34493 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34495 getElementSize : function(s){
34496 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34497 return s.resizingEl.getWidth();
34499 return s.resizingEl.getHeight();
34504 * Called after drag operations to set the size of the resizing element.
34505 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34506 * @param {Number} newSize The new size to set
34507 * @param {Function} onComplete A function to be invoked when resizing is complete
34509 setElementSize : function(s, newSize, onComplete){
34510 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34512 s.resizingEl.setWidth(newSize);
34514 onComplete(s, newSize);
34517 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
34522 s.resizingEl.setHeight(newSize);
34524 onComplete(s, newSize);
34527 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
34534 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
34535 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
34536 * Adapter that moves the splitter element to align with the resized sizing element.
34537 * Used with an absolute positioned SplitBar.
34538 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
34539 * document.body, make sure you assign an id to the body element.
34541 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
34542 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34543 this.container = Roo.get(container);
34546 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
34547 init : function(s){
34548 this.basic.init(s);
34551 getElementSize : function(s){
34552 return this.basic.getElementSize(s);
34555 setElementSize : function(s, newSize, onComplete){
34556 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
34559 moveSplitter : function(s){
34560 var yes = Roo.bootstrap.SplitBar;
34561 switch(s.placement){
34563 s.el.setX(s.resizingEl.getRight());
34566 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
34569 s.el.setY(s.resizingEl.getBottom());
34572 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
34579 * Orientation constant - Create a vertical SplitBar
34583 Roo.bootstrap.SplitBar.VERTICAL = 1;
34586 * Orientation constant - Create a horizontal SplitBar
34590 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
34593 * Placement constant - The resizing element is to the left of the splitter element
34597 Roo.bootstrap.SplitBar.LEFT = 1;
34600 * Placement constant - The resizing element is to the right of the splitter element
34604 Roo.bootstrap.SplitBar.RIGHT = 2;
34607 * Placement constant - The resizing element is positioned above the splitter element
34611 Roo.bootstrap.SplitBar.TOP = 3;
34614 * Placement constant - The resizing element is positioned under splitter element
34618 Roo.bootstrap.SplitBar.BOTTOM = 4;
34619 Roo.namespace("Roo.bootstrap.layout");/*
34621 * Ext JS Library 1.1.1
34622 * Copyright(c) 2006-2007, Ext JS, LLC.
34624 * Originally Released Under LGPL - original licence link has changed is not relivant.
34627 * <script type="text/javascript">
34631 * @class Roo.bootstrap.layout.Manager
34632 * @extends Roo.bootstrap.Component
34633 * Base class for layout managers.
34635 Roo.bootstrap.layout.Manager = function(config)
34637 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
34643 /** false to disable window resize monitoring @type Boolean */
34644 this.monitorWindowResize = true;
34649 * Fires when a layout is performed.
34650 * @param {Roo.LayoutManager} this
34654 * @event regionresized
34655 * Fires when the user resizes a region.
34656 * @param {Roo.LayoutRegion} region The resized region
34657 * @param {Number} newSize The new size (width for east/west, height for north/south)
34659 "regionresized" : true,
34661 * @event regioncollapsed
34662 * Fires when a region is collapsed.
34663 * @param {Roo.LayoutRegion} region The collapsed region
34665 "regioncollapsed" : true,
34667 * @event regionexpanded
34668 * Fires when a region is expanded.
34669 * @param {Roo.LayoutRegion} region The expanded region
34671 "regionexpanded" : true
34673 this.updating = false;
34676 this.el = Roo.get(config.el);
34682 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
34687 monitorWindowResize : true,
34693 onRender : function(ct, position)
34696 this.el = Roo.get(ct);
34699 //this.fireEvent('render',this);
34703 initEvents: function()
34707 // ie scrollbar fix
34708 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
34709 document.body.scroll = "no";
34710 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
34711 this.el.position('relative');
34713 this.id = this.el.id;
34714 this.el.addClass("roo-layout-container");
34715 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34716 if(this.el.dom != document.body ) {
34717 this.el.on('resize', this.layout,this);
34718 this.el.on('show', this.layout,this);
34724 * Returns true if this layout is currently being updated
34725 * @return {Boolean}
34727 isUpdating : function(){
34728 return this.updating;
34732 * Suspend the LayoutManager from doing auto-layouts while
34733 * making multiple add or remove calls
34735 beginUpdate : function(){
34736 this.updating = true;
34740 * Restore auto-layouts and optionally disable the manager from performing a layout
34741 * @param {Boolean} noLayout true to disable a layout update
34743 endUpdate : function(noLayout){
34744 this.updating = false;
34750 layout: function(){
34754 onRegionResized : function(region, newSize){
34755 this.fireEvent("regionresized", region, newSize);
34759 onRegionCollapsed : function(region){
34760 this.fireEvent("regioncollapsed", region);
34763 onRegionExpanded : function(region){
34764 this.fireEvent("regionexpanded", region);
34768 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
34769 * performs box-model adjustments.
34770 * @return {Object} The size as an object {width: (the width), height: (the height)}
34772 getViewSize : function()
34775 if(this.el.dom != document.body){
34776 size = this.el.getSize();
34778 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
34780 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
34781 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34786 * Returns the Element this layout is bound to.
34787 * @return {Roo.Element}
34789 getEl : function(){
34794 * Returns the specified region.
34795 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
34796 * @return {Roo.LayoutRegion}
34798 getRegion : function(target){
34799 return this.regions[target.toLowerCase()];
34802 onWindowResize : function(){
34803 if(this.monitorWindowResize){
34810 * Ext JS Library 1.1.1
34811 * Copyright(c) 2006-2007, Ext JS, LLC.
34813 * Originally Released Under LGPL - original licence link has changed is not relivant.
34816 * <script type="text/javascript">
34819 * @class Roo.bootstrap.layout.Border
34820 * @extends Roo.bootstrap.layout.Manager
34821 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
34822 * please see: examples/bootstrap/nested.html<br><br>
34824 <b>The container the layout is rendered into can be either the body element or any other element.
34825 If it is not the body element, the container needs to either be an absolute positioned element,
34826 or you will need to add "position:relative" to the css of the container. You will also need to specify
34827 the container size if it is not the body element.</b>
34830 * Create a new Border
34831 * @param {Object} config Configuration options
34833 Roo.bootstrap.layout.Border = function(config){
34834 config = config || {};
34835 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
34839 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34840 if(config[region]){
34841 config[region].region = region;
34842 this.addRegion(config[region]);
34848 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
34850 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
34852 * Creates and adds a new region if it doesn't already exist.
34853 * @param {String} target The target region key (north, south, east, west or center).
34854 * @param {Object} config The regions config object
34855 * @return {BorderLayoutRegion} The new region
34857 addRegion : function(config)
34859 if(!this.regions[config.region]){
34860 var r = this.factory(config);
34861 this.bindRegion(r);
34863 return this.regions[config.region];
34867 bindRegion : function(r){
34868 this.regions[r.config.region] = r;
34870 r.on("visibilitychange", this.layout, this);
34871 r.on("paneladded", this.layout, this);
34872 r.on("panelremoved", this.layout, this);
34873 r.on("invalidated", this.layout, this);
34874 r.on("resized", this.onRegionResized, this);
34875 r.on("collapsed", this.onRegionCollapsed, this);
34876 r.on("expanded", this.onRegionExpanded, this);
34880 * Performs a layout update.
34882 layout : function()
34884 if(this.updating) {
34888 // render all the rebions if they have not been done alreayd?
34889 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34890 if(this.regions[region] && !this.regions[region].bodyEl){
34891 this.regions[region].onRender(this.el)
34895 var size = this.getViewSize();
34896 var w = size.width;
34897 var h = size.height;
34902 //var x = 0, y = 0;
34904 var rs = this.regions;
34905 var north = rs["north"];
34906 var south = rs["south"];
34907 var west = rs["west"];
34908 var east = rs["east"];
34909 var center = rs["center"];
34910 //if(this.hideOnLayout){ // not supported anymore
34911 //c.el.setStyle("display", "none");
34913 if(north && north.isVisible()){
34914 var b = north.getBox();
34915 var m = north.getMargins();
34916 b.width = w - (m.left+m.right);
34919 centerY = b.height + b.y + m.bottom;
34920 centerH -= centerY;
34921 north.updateBox(this.safeBox(b));
34923 if(south && south.isVisible()){
34924 var b = south.getBox();
34925 var m = south.getMargins();
34926 b.width = w - (m.left+m.right);
34928 var totalHeight = (b.height + m.top + m.bottom);
34929 b.y = h - totalHeight + m.top;
34930 centerH -= totalHeight;
34931 south.updateBox(this.safeBox(b));
34933 if(west && west.isVisible()){
34934 var b = west.getBox();
34935 var m = west.getMargins();
34936 b.height = centerH - (m.top+m.bottom);
34938 b.y = centerY + m.top;
34939 var totalWidth = (b.width + m.left + m.right);
34940 centerX += totalWidth;
34941 centerW -= totalWidth;
34942 west.updateBox(this.safeBox(b));
34944 if(east && east.isVisible()){
34945 var b = east.getBox();
34946 var m = east.getMargins();
34947 b.height = centerH - (m.top+m.bottom);
34948 var totalWidth = (b.width + m.left + m.right);
34949 b.x = w - totalWidth + m.left;
34950 b.y = centerY + m.top;
34951 centerW -= totalWidth;
34952 east.updateBox(this.safeBox(b));
34955 var m = center.getMargins();
34957 x: centerX + m.left,
34958 y: centerY + m.top,
34959 width: centerW - (m.left+m.right),
34960 height: centerH - (m.top+m.bottom)
34962 //if(this.hideOnLayout){
34963 //center.el.setStyle("display", "block");
34965 center.updateBox(this.safeBox(centerBox));
34968 this.fireEvent("layout", this);
34972 safeBox : function(box){
34973 box.width = Math.max(0, box.width);
34974 box.height = Math.max(0, box.height);
34979 * Adds a ContentPanel (or subclass) to this layout.
34980 * @param {String} target The target region key (north, south, east, west or center).
34981 * @param {Roo.ContentPanel} panel The panel to add
34982 * @return {Roo.ContentPanel} The added panel
34984 add : function(target, panel){
34986 target = target.toLowerCase();
34987 return this.regions[target].add(panel);
34991 * Remove a ContentPanel (or subclass) to this layout.
34992 * @param {String} target The target region key (north, south, east, west or center).
34993 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
34994 * @return {Roo.ContentPanel} The removed panel
34996 remove : function(target, panel){
34997 target = target.toLowerCase();
34998 return this.regions[target].remove(panel);
35002 * Searches all regions for a panel with the specified id
35003 * @param {String} panelId
35004 * @return {Roo.ContentPanel} The panel or null if it wasn't found
35006 findPanel : function(panelId){
35007 var rs = this.regions;
35008 for(var target in rs){
35009 if(typeof rs[target] != "function"){
35010 var p = rs[target].getPanel(panelId);
35020 * Searches all regions for a panel with the specified id and activates (shows) it.
35021 * @param {String/ContentPanel} panelId The panels id or the panel itself
35022 * @return {Roo.ContentPanel} The shown panel or null
35024 showPanel : function(panelId) {
35025 var rs = this.regions;
35026 for(var target in rs){
35027 var r = rs[target];
35028 if(typeof r != "function"){
35029 if(r.hasPanel(panelId)){
35030 return r.showPanel(panelId);
35038 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
35039 * @param {Roo.state.Provider} provider (optional) An alternate state provider
35042 restoreState : function(provider){
35044 provider = Roo.state.Manager;
35046 var sm = new Roo.LayoutStateManager();
35047 sm.init(this, provider);
35053 * Adds a xtype elements to the layout.
35057 xtype : 'ContentPanel',
35064 xtype : 'NestedLayoutPanel',
35070 items : [ ... list of content panels or nested layout panels.. ]
35074 * @param {Object} cfg Xtype definition of item to add.
35076 addxtype : function(cfg)
35078 // basically accepts a pannel...
35079 // can accept a layout region..!?!?
35080 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
35083 // theory? children can only be panels??
35085 //if (!cfg.xtype.match(/Panel$/)) {
35090 if (typeof(cfg.region) == 'undefined') {
35091 Roo.log("Failed to add Panel, region was not set");
35095 var region = cfg.region;
35101 xitems = cfg.items;
35108 case 'Content': // ContentPanel (el, cfg)
35109 case 'Scroll': // ContentPanel (el, cfg)
35111 cfg.autoCreate = true;
35112 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35114 // var el = this.el.createChild();
35115 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
35118 this.add(region, ret);
35122 case 'TreePanel': // our new panel!
35123 cfg.el = this.el.createChild();
35124 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35125 this.add(region, ret);
35130 // create a new Layout (which is a Border Layout...
35132 var clayout = cfg.layout;
35133 clayout.el = this.el.createChild();
35134 clayout.items = clayout.items || [];
35138 // replace this exitems with the clayout ones..
35139 xitems = clayout.items;
35141 // force background off if it's in center...
35142 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
35143 cfg.background = false;
35145 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
35148 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35149 //console.log('adding nested layout panel ' + cfg.toSource());
35150 this.add(region, ret);
35151 nb = {}; /// find first...
35156 // needs grid and region
35158 //var el = this.getRegion(region).el.createChild();
35160 *var el = this.el.createChild();
35161 // create the grid first...
35162 cfg.grid.container = el;
35163 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
35166 if (region == 'center' && this.active ) {
35167 cfg.background = false;
35170 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35172 this.add(region, ret);
35174 if (cfg.background) {
35175 // render grid on panel activation (if panel background)
35176 ret.on('activate', function(gp) {
35177 if (!gp.grid.rendered) {
35178 // gp.grid.render(el);
35182 // cfg.grid.render(el);
35188 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
35189 // it was the old xcomponent building that caused this before.
35190 // espeically if border is the top element in the tree.
35200 if (typeof(Roo[cfg.xtype]) != 'undefined') {
35202 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35203 this.add(region, ret);
35207 throw "Can not add '" + cfg.xtype + "' to Border";
35213 this.beginUpdate();
35217 Roo.each(xitems, function(i) {
35218 region = nb && i.region ? i.region : false;
35220 var add = ret.addxtype(i);
35223 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
35224 if (!i.background) {
35225 abn[region] = nb[region] ;
35232 // make the last non-background panel active..
35233 //if (nb) { Roo.log(abn); }
35236 for(var r in abn) {
35237 region = this.getRegion(r);
35239 // tried using nb[r], but it does not work..
35241 region.showPanel(abn[r]);
35252 factory : function(cfg)
35255 var validRegions = Roo.bootstrap.layout.Border.regions;
35257 var target = cfg.region;
35260 var r = Roo.bootstrap.layout;
35264 return new r.North(cfg);
35266 return new r.South(cfg);
35268 return new r.East(cfg);
35270 return new r.West(cfg);
35272 return new r.Center(cfg);
35274 throw 'Layout region "'+target+'" not supported.';
35281 * Ext JS Library 1.1.1
35282 * Copyright(c) 2006-2007, Ext JS, LLC.
35284 * Originally Released Under LGPL - original licence link has changed is not relivant.
35287 * <script type="text/javascript">
35291 * @class Roo.bootstrap.layout.Basic
35292 * @extends Roo.util.Observable
35293 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
35294 * and does not have a titlebar, tabs or any other features. All it does is size and position
35295 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
35296 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35297 * @cfg {string} region the region that it inhabits..
35298 * @cfg {bool} skipConfig skip config?
35302 Roo.bootstrap.layout.Basic = function(config){
35304 this.mgr = config.mgr;
35306 this.position = config.region;
35308 var skipConfig = config.skipConfig;
35312 * @scope Roo.BasicLayoutRegion
35316 * @event beforeremove
35317 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
35318 * @param {Roo.LayoutRegion} this
35319 * @param {Roo.ContentPanel} panel The panel
35320 * @param {Object} e The cancel event object
35322 "beforeremove" : true,
35324 * @event invalidated
35325 * Fires when the layout for this region is changed.
35326 * @param {Roo.LayoutRegion} this
35328 "invalidated" : true,
35330 * @event visibilitychange
35331 * Fires when this region is shown or hidden
35332 * @param {Roo.LayoutRegion} this
35333 * @param {Boolean} visibility true or false
35335 "visibilitychange" : true,
35337 * @event paneladded
35338 * Fires when a panel is added.
35339 * @param {Roo.LayoutRegion} this
35340 * @param {Roo.ContentPanel} panel The panel
35342 "paneladded" : true,
35344 * @event panelremoved
35345 * Fires when a panel is removed.
35346 * @param {Roo.LayoutRegion} this
35347 * @param {Roo.ContentPanel} panel The panel
35349 "panelremoved" : true,
35351 * @event beforecollapse
35352 * Fires when this region before collapse.
35353 * @param {Roo.LayoutRegion} this
35355 "beforecollapse" : true,
35358 * Fires when this region is collapsed.
35359 * @param {Roo.LayoutRegion} this
35361 "collapsed" : true,
35364 * Fires when this region is expanded.
35365 * @param {Roo.LayoutRegion} this
35370 * Fires when this region is slid into view.
35371 * @param {Roo.LayoutRegion} this
35373 "slideshow" : true,
35376 * Fires when this region slides out of view.
35377 * @param {Roo.LayoutRegion} this
35379 "slidehide" : true,
35381 * @event panelactivated
35382 * Fires when a panel is activated.
35383 * @param {Roo.LayoutRegion} this
35384 * @param {Roo.ContentPanel} panel The activated panel
35386 "panelactivated" : true,
35389 * Fires when the user resizes this region.
35390 * @param {Roo.LayoutRegion} this
35391 * @param {Number} newSize The new size (width for east/west, height for north/south)
35395 /** A collection of panels in this region. @type Roo.util.MixedCollection */
35396 this.panels = new Roo.util.MixedCollection();
35397 this.panels.getKey = this.getPanelId.createDelegate(this);
35399 this.activePanel = null;
35400 // ensure listeners are added...
35402 if (config.listeners || config.events) {
35403 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
35404 listeners : config.listeners || {},
35405 events : config.events || {}
35409 if(skipConfig !== true){
35410 this.applyConfig(config);
35414 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
35416 getPanelId : function(p){
35420 applyConfig : function(config){
35421 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35422 this.config = config;
35427 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
35428 * the width, for horizontal (north, south) the height.
35429 * @param {Number} newSize The new width or height
35431 resizeTo : function(newSize){
35432 var el = this.el ? this.el :
35433 (this.activePanel ? this.activePanel.getEl() : null);
35435 switch(this.position){
35438 el.setWidth(newSize);
35439 this.fireEvent("resized", this, newSize);
35443 el.setHeight(newSize);
35444 this.fireEvent("resized", this, newSize);
35450 getBox : function(){
35451 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
35454 getMargins : function(){
35455 return this.margins;
35458 updateBox : function(box){
35460 var el = this.activePanel.getEl();
35461 el.dom.style.left = box.x + "px";
35462 el.dom.style.top = box.y + "px";
35463 this.activePanel.setSize(box.width, box.height);
35467 * Returns the container element for this region.
35468 * @return {Roo.Element}
35470 getEl : function(){
35471 return this.activePanel;
35475 * Returns true if this region is currently visible.
35476 * @return {Boolean}
35478 isVisible : function(){
35479 return this.activePanel ? true : false;
35482 setActivePanel : function(panel){
35483 panel = this.getPanel(panel);
35484 if(this.activePanel && this.activePanel != panel){
35485 this.activePanel.setActiveState(false);
35486 this.activePanel.getEl().setLeftTop(-10000,-10000);
35488 this.activePanel = panel;
35489 panel.setActiveState(true);
35491 panel.setSize(this.box.width, this.box.height);
35493 this.fireEvent("panelactivated", this, panel);
35494 this.fireEvent("invalidated");
35498 * Show the specified panel.
35499 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
35500 * @return {Roo.ContentPanel} The shown panel or null
35502 showPanel : function(panel){
35503 panel = this.getPanel(panel);
35505 this.setActivePanel(panel);
35511 * Get the active panel for this region.
35512 * @return {Roo.ContentPanel} The active panel or null
35514 getActivePanel : function(){
35515 return this.activePanel;
35519 * Add the passed ContentPanel(s)
35520 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35521 * @return {Roo.ContentPanel} The panel added (if only one was added)
35523 add : function(panel){
35524 if(arguments.length > 1){
35525 for(var i = 0, len = arguments.length; i < len; i++) {
35526 this.add(arguments[i]);
35530 if(this.hasPanel(panel)){
35531 this.showPanel(panel);
35534 var el = panel.getEl();
35535 if(el.dom.parentNode != this.mgr.el.dom){
35536 this.mgr.el.dom.appendChild(el.dom);
35538 if(panel.setRegion){
35539 panel.setRegion(this);
35541 this.panels.add(panel);
35542 el.setStyle("position", "absolute");
35543 if(!panel.background){
35544 this.setActivePanel(panel);
35545 if(this.config.initialSize && this.panels.getCount()==1){
35546 this.resizeTo(this.config.initialSize);
35549 this.fireEvent("paneladded", this, panel);
35554 * Returns true if the panel is in this region.
35555 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35556 * @return {Boolean}
35558 hasPanel : function(panel){
35559 if(typeof panel == "object"){ // must be panel obj
35560 panel = panel.getId();
35562 return this.getPanel(panel) ? true : false;
35566 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35567 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35568 * @param {Boolean} preservePanel Overrides the config preservePanel option
35569 * @return {Roo.ContentPanel} The panel that was removed
35571 remove : function(panel, preservePanel){
35572 panel = this.getPanel(panel);
35577 this.fireEvent("beforeremove", this, panel, e);
35578 if(e.cancel === true){
35581 var panelId = panel.getId();
35582 this.panels.removeKey(panelId);
35587 * Returns the panel specified or null if it's not in this region.
35588 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35589 * @return {Roo.ContentPanel}
35591 getPanel : function(id){
35592 if(typeof id == "object"){ // must be panel obj
35595 return this.panels.get(id);
35599 * Returns this regions position (north/south/east/west/center).
35602 getPosition: function(){
35603 return this.position;
35607 * Ext JS Library 1.1.1
35608 * Copyright(c) 2006-2007, Ext JS, LLC.
35610 * Originally Released Under LGPL - original licence link has changed is not relivant.
35613 * <script type="text/javascript">
35617 * @class Roo.bootstrap.layout.Region
35618 * @extends Roo.bootstrap.layout.Basic
35619 * This class represents a region in a layout manager.
35621 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
35622 * @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})
35623 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
35624 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
35625 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
35626 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
35627 * @cfg {String} title The title for the region (overrides panel titles)
35628 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
35629 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
35630 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
35631 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
35632 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
35633 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
35634 * the space available, similar to FireFox 1.5 tabs (defaults to false)
35635 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
35636 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
35637 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
35639 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
35640 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
35641 * @cfg {Boolean} disableTabTips True to disable tab tooltips
35642 * @cfg {Number} width For East/West panels
35643 * @cfg {Number} height For North/South panels
35644 * @cfg {Boolean} split To show the splitter
35645 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
35647 * @cfg {string} cls Extra CSS classes to add to region
35649 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35650 * @cfg {string} region the region that it inhabits..
35653 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
35654 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
35656 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
35657 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
35658 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
35660 Roo.bootstrap.layout.Region = function(config)
35662 this.applyConfig(config);
35664 var mgr = config.mgr;
35665 var pos = config.region;
35666 config.skipConfig = true;
35667 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
35670 this.onRender(mgr.el);
35673 this.visible = true;
35674 this.collapsed = false;
35675 this.unrendered_panels = [];
35678 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
35680 position: '', // set by wrapper (eg. north/south etc..)
35681 unrendered_panels : null, // unrendered panels.
35682 createBody : function(){
35683 /** This region's body element
35684 * @type Roo.Element */
35685 this.bodyEl = this.el.createChild({
35687 cls: "roo-layout-panel-body tab-content" // bootstrap added...
35691 onRender: function(ctr, pos)
35693 var dh = Roo.DomHelper;
35694 /** This region's container element
35695 * @type Roo.Element */
35696 this.el = dh.append(ctr.dom, {
35698 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
35700 /** This region's title element
35701 * @type Roo.Element */
35703 this.titleEl = dh.append(this.el.dom,
35706 unselectable: "on",
35707 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
35709 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
35710 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
35713 this.titleEl.enableDisplayMode();
35714 /** This region's title text element
35715 * @type HTMLElement */
35716 this.titleTextEl = this.titleEl.dom.firstChild;
35717 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
35719 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
35720 this.closeBtn.enableDisplayMode();
35721 this.closeBtn.on("click", this.closeClicked, this);
35722 this.closeBtn.hide();
35724 this.createBody(this.config);
35725 if(this.config.hideWhenEmpty){
35727 this.on("paneladded", this.validateVisibility, this);
35728 this.on("panelremoved", this.validateVisibility, this);
35730 if(this.autoScroll){
35731 this.bodyEl.setStyle("overflow", "auto");
35733 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
35735 //if(c.titlebar !== false){
35736 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
35737 this.titleEl.hide();
35739 this.titleEl.show();
35740 if(this.config.title){
35741 this.titleTextEl.innerHTML = this.config.title;
35745 if(this.config.collapsed){
35746 this.collapse(true);
35748 if(this.config.hidden){
35752 if (this.unrendered_panels && this.unrendered_panels.length) {
35753 for (var i =0;i< this.unrendered_panels.length; i++) {
35754 this.add(this.unrendered_panels[i]);
35756 this.unrendered_panels = null;
35762 applyConfig : function(c)
35765 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
35766 var dh = Roo.DomHelper;
35767 if(c.titlebar !== false){
35768 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
35769 this.collapseBtn.on("click", this.collapse, this);
35770 this.collapseBtn.enableDisplayMode();
35772 if(c.showPin === true || this.showPin){
35773 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
35774 this.stickBtn.enableDisplayMode();
35775 this.stickBtn.on("click", this.expand, this);
35776 this.stickBtn.hide();
35781 /** This region's collapsed element
35782 * @type Roo.Element */
35785 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
35786 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
35789 if(c.floatable !== false){
35790 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
35791 this.collapsedEl.on("click", this.collapseClick, this);
35794 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
35795 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
35796 id: "message", unselectable: "on", style:{"float":"left"}});
35797 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
35799 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
35800 this.expandBtn.on("click", this.expand, this);
35804 if(this.collapseBtn){
35805 this.collapseBtn.setVisible(c.collapsible == true);
35808 this.cmargins = c.cmargins || this.cmargins ||
35809 (this.position == "west" || this.position == "east" ?
35810 {top: 0, left: 2, right:2, bottom: 0} :
35811 {top: 2, left: 0, right:0, bottom: 2});
35813 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35816 this.bottomTabs = c.tabPosition != "top";
35818 this.autoScroll = c.autoScroll || false;
35823 this.duration = c.duration || .30;
35824 this.slideDuration = c.slideDuration || .45;
35829 * Returns true if this region is currently visible.
35830 * @return {Boolean}
35832 isVisible : function(){
35833 return this.visible;
35837 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
35838 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
35840 //setCollapsedTitle : function(title){
35841 // title = title || " ";
35842 // if(this.collapsedTitleTextEl){
35843 // this.collapsedTitleTextEl.innerHTML = title;
35847 getBox : function(){
35849 // if(!this.collapsed){
35850 b = this.el.getBox(false, true);
35852 // b = this.collapsedEl.getBox(false, true);
35857 getMargins : function(){
35858 return this.margins;
35859 //return this.collapsed ? this.cmargins : this.margins;
35862 highlight : function(){
35863 this.el.addClass("x-layout-panel-dragover");
35866 unhighlight : function(){
35867 this.el.removeClass("x-layout-panel-dragover");
35870 updateBox : function(box)
35872 if (!this.bodyEl) {
35873 return; // not rendered yet..
35877 if(!this.collapsed){
35878 this.el.dom.style.left = box.x + "px";
35879 this.el.dom.style.top = box.y + "px";
35880 this.updateBody(box.width, box.height);
35882 this.collapsedEl.dom.style.left = box.x + "px";
35883 this.collapsedEl.dom.style.top = box.y + "px";
35884 this.collapsedEl.setSize(box.width, box.height);
35887 this.tabs.autoSizeTabs();
35891 updateBody : function(w, h)
35894 this.el.setWidth(w);
35895 w -= this.el.getBorderWidth("rl");
35896 if(this.config.adjustments){
35897 w += this.config.adjustments[0];
35900 if(h !== null && h > 0){
35901 this.el.setHeight(h);
35902 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
35903 h -= this.el.getBorderWidth("tb");
35904 if(this.config.adjustments){
35905 h += this.config.adjustments[1];
35907 this.bodyEl.setHeight(h);
35909 h = this.tabs.syncHeight(h);
35912 if(this.panelSize){
35913 w = w !== null ? w : this.panelSize.width;
35914 h = h !== null ? h : this.panelSize.height;
35916 if(this.activePanel){
35917 var el = this.activePanel.getEl();
35918 w = w !== null ? w : el.getWidth();
35919 h = h !== null ? h : el.getHeight();
35920 this.panelSize = {width: w, height: h};
35921 this.activePanel.setSize(w, h);
35923 if(Roo.isIE && this.tabs){
35924 this.tabs.el.repaint();
35929 * Returns the container element for this region.
35930 * @return {Roo.Element}
35932 getEl : function(){
35937 * Hides this region.
35940 //if(!this.collapsed){
35941 this.el.dom.style.left = "-2000px";
35944 // this.collapsedEl.dom.style.left = "-2000px";
35945 // this.collapsedEl.hide();
35947 this.visible = false;
35948 this.fireEvent("visibilitychange", this, false);
35952 * Shows this region if it was previously hidden.
35955 //if(!this.collapsed){
35958 // this.collapsedEl.show();
35960 this.visible = true;
35961 this.fireEvent("visibilitychange", this, true);
35964 closeClicked : function(){
35965 if(this.activePanel){
35966 this.remove(this.activePanel);
35970 collapseClick : function(e){
35972 e.stopPropagation();
35975 e.stopPropagation();
35981 * Collapses this region.
35982 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
35985 collapse : function(skipAnim, skipCheck = false){
35986 if(this.collapsed) {
35990 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
35992 this.collapsed = true;
35994 this.split.el.hide();
35996 if(this.config.animate && skipAnim !== true){
35997 this.fireEvent("invalidated", this);
35998 this.animateCollapse();
36000 this.el.setLocation(-20000,-20000);
36002 this.collapsedEl.show();
36003 this.fireEvent("collapsed", this);
36004 this.fireEvent("invalidated", this);
36010 animateCollapse : function(){
36015 * Expands this region if it was previously collapsed.
36016 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
36017 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
36020 expand : function(e, skipAnim){
36022 e.stopPropagation();
36024 if(!this.collapsed || this.el.hasActiveFx()) {
36028 this.afterSlideIn();
36031 this.collapsed = false;
36032 if(this.config.animate && skipAnim !== true){
36033 this.animateExpand();
36037 this.split.el.show();
36039 this.collapsedEl.setLocation(-2000,-2000);
36040 this.collapsedEl.hide();
36041 this.fireEvent("invalidated", this);
36042 this.fireEvent("expanded", this);
36046 animateExpand : function(){
36050 initTabs : function()
36052 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
36054 var ts = new Roo.bootstrap.panel.Tabs({
36055 el: this.bodyEl.dom,
36056 tabPosition: this.bottomTabs ? 'bottom' : 'top',
36057 disableTooltips: this.config.disableTabTips,
36058 toolbar : this.config.toolbar
36061 if(this.config.hideTabs){
36062 ts.stripWrap.setDisplayed(false);
36065 ts.resizeTabs = this.config.resizeTabs === true;
36066 ts.minTabWidth = this.config.minTabWidth || 40;
36067 ts.maxTabWidth = this.config.maxTabWidth || 250;
36068 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
36069 ts.monitorResize = false;
36070 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
36071 ts.bodyEl.addClass('roo-layout-tabs-body');
36072 this.panels.each(this.initPanelAsTab, this);
36075 initPanelAsTab : function(panel){
36076 var ti = this.tabs.addTab(
36080 this.config.closeOnTab && panel.isClosable(),
36083 if(panel.tabTip !== undefined){
36084 ti.setTooltip(panel.tabTip);
36086 ti.on("activate", function(){
36087 this.setActivePanel(panel);
36090 if(this.config.closeOnTab){
36091 ti.on("beforeclose", function(t, e){
36093 this.remove(panel);
36097 panel.tabItem = ti;
36102 updatePanelTitle : function(panel, title)
36104 if(this.activePanel == panel){
36105 this.updateTitle(title);
36108 var ti = this.tabs.getTab(panel.getEl().id);
36110 if(panel.tabTip !== undefined){
36111 ti.setTooltip(panel.tabTip);
36116 updateTitle : function(title){
36117 if(this.titleTextEl && !this.config.title){
36118 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
36122 setActivePanel : function(panel)
36124 panel = this.getPanel(panel);
36125 if(this.activePanel && this.activePanel != panel){
36126 if(this.activePanel.setActiveState(false) === false){
36130 this.activePanel = panel;
36131 panel.setActiveState(true);
36132 if(this.panelSize){
36133 panel.setSize(this.panelSize.width, this.panelSize.height);
36136 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
36138 this.updateTitle(panel.getTitle());
36140 this.fireEvent("invalidated", this);
36142 this.fireEvent("panelactivated", this, panel);
36146 * Shows the specified panel.
36147 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
36148 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
36150 showPanel : function(panel)
36152 panel = this.getPanel(panel);
36155 var tab = this.tabs.getTab(panel.getEl().id);
36156 if(tab.isHidden()){
36157 this.tabs.unhideTab(tab.id);
36161 this.setActivePanel(panel);
36168 * Get the active panel for this region.
36169 * @return {Roo.ContentPanel} The active panel or null
36171 getActivePanel : function(){
36172 return this.activePanel;
36175 validateVisibility : function(){
36176 if(this.panels.getCount() < 1){
36177 this.updateTitle(" ");
36178 this.closeBtn.hide();
36181 if(!this.isVisible()){
36188 * Adds the passed ContentPanel(s) to this region.
36189 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
36190 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
36192 add : function(panel)
36194 if(arguments.length > 1){
36195 for(var i = 0, len = arguments.length; i < len; i++) {
36196 this.add(arguments[i]);
36201 // if we have not been rendered yet, then we can not really do much of this..
36202 if (!this.bodyEl) {
36203 this.unrendered_panels.push(panel);
36210 if(this.hasPanel(panel)){
36211 this.showPanel(panel);
36214 panel.setRegion(this);
36215 this.panels.add(panel);
36216 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
36217 // sinle panel - no tab...?? would it not be better to render it with the tabs,
36218 // and hide them... ???
36219 this.bodyEl.dom.appendChild(panel.getEl().dom);
36220 if(panel.background !== true){
36221 this.setActivePanel(panel);
36223 this.fireEvent("paneladded", this, panel);
36230 this.initPanelAsTab(panel);
36234 if(panel.background !== true){
36235 this.tabs.activate(panel.getEl().id);
36237 this.fireEvent("paneladded", this, panel);
36242 * Hides the tab for the specified panel.
36243 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36245 hidePanel : function(panel){
36246 if(this.tabs && (panel = this.getPanel(panel))){
36247 this.tabs.hideTab(panel.getEl().id);
36252 * Unhides the tab for a previously hidden panel.
36253 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36255 unhidePanel : function(panel){
36256 if(this.tabs && (panel = this.getPanel(panel))){
36257 this.tabs.unhideTab(panel.getEl().id);
36261 clearPanels : function(){
36262 while(this.panels.getCount() > 0){
36263 this.remove(this.panels.first());
36268 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
36269 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36270 * @param {Boolean} preservePanel Overrides the config preservePanel option
36271 * @return {Roo.ContentPanel} The panel that was removed
36273 remove : function(panel, preservePanel)
36275 panel = this.getPanel(panel);
36280 this.fireEvent("beforeremove", this, panel, e);
36281 if(e.cancel === true){
36284 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
36285 var panelId = panel.getId();
36286 this.panels.removeKey(panelId);
36288 document.body.appendChild(panel.getEl().dom);
36291 this.tabs.removeTab(panel.getEl().id);
36292 }else if (!preservePanel){
36293 this.bodyEl.dom.removeChild(panel.getEl().dom);
36295 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
36296 var p = this.panels.first();
36297 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
36298 tempEl.appendChild(p.getEl().dom);
36299 this.bodyEl.update("");
36300 this.bodyEl.dom.appendChild(p.getEl().dom);
36302 this.updateTitle(p.getTitle());
36304 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
36305 this.setActivePanel(p);
36307 panel.setRegion(null);
36308 if(this.activePanel == panel){
36309 this.activePanel = null;
36311 if(this.config.autoDestroy !== false && preservePanel !== true){
36312 try{panel.destroy();}catch(e){}
36314 this.fireEvent("panelremoved", this, panel);
36319 * Returns the TabPanel component used by this region
36320 * @return {Roo.TabPanel}
36322 getTabs : function(){
36326 createTool : function(parentEl, className){
36327 var btn = Roo.DomHelper.append(parentEl, {
36329 cls: "x-layout-tools-button",
36332 cls: "roo-layout-tools-button-inner " + className,
36336 btn.addClassOnOver("roo-layout-tools-button-over");
36341 * Ext JS Library 1.1.1
36342 * Copyright(c) 2006-2007, Ext JS, LLC.
36344 * Originally Released Under LGPL - original licence link has changed is not relivant.
36347 * <script type="text/javascript">
36353 * @class Roo.SplitLayoutRegion
36354 * @extends Roo.LayoutRegion
36355 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
36357 Roo.bootstrap.layout.Split = function(config){
36358 this.cursor = config.cursor;
36359 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
36362 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
36364 splitTip : "Drag to resize.",
36365 collapsibleSplitTip : "Drag to resize. Double click to hide.",
36366 useSplitTips : false,
36368 applyConfig : function(config){
36369 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
36372 onRender : function(ctr,pos) {
36374 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
36375 if(!this.config.split){
36380 var splitEl = Roo.DomHelper.append(ctr.dom, {
36382 id: this.el.id + "-split",
36383 cls: "roo-layout-split roo-layout-split-"+this.position,
36386 /** The SplitBar for this region
36387 * @type Roo.SplitBar */
36388 // does not exist yet...
36389 Roo.log([this.position, this.orientation]);
36391 this.split = new Roo.bootstrap.SplitBar({
36392 dragElement : splitEl,
36393 resizingElement: this.el,
36394 orientation : this.orientation
36397 this.split.on("moved", this.onSplitMove, this);
36398 this.split.useShim = this.config.useShim === true;
36399 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
36400 if(this.useSplitTips){
36401 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
36403 //if(config.collapsible){
36404 // this.split.el.on("dblclick", this.collapse, this);
36407 if(typeof this.config.minSize != "undefined"){
36408 this.split.minSize = this.config.minSize;
36410 if(typeof this.config.maxSize != "undefined"){
36411 this.split.maxSize = this.config.maxSize;
36413 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
36414 this.hideSplitter();
36419 getHMaxSize : function(){
36420 var cmax = this.config.maxSize || 10000;
36421 var center = this.mgr.getRegion("center");
36422 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
36425 getVMaxSize : function(){
36426 var cmax = this.config.maxSize || 10000;
36427 var center = this.mgr.getRegion("center");
36428 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
36431 onSplitMove : function(split, newSize){
36432 this.fireEvent("resized", this, newSize);
36436 * Returns the {@link Roo.SplitBar} for this region.
36437 * @return {Roo.SplitBar}
36439 getSplitBar : function(){
36444 this.hideSplitter();
36445 Roo.bootstrap.layout.Split.superclass.hide.call(this);
36448 hideSplitter : function(){
36450 this.split.el.setLocation(-2000,-2000);
36451 this.split.el.hide();
36457 this.split.el.show();
36459 Roo.bootstrap.layout.Split.superclass.show.call(this);
36462 beforeSlide: function(){
36463 if(Roo.isGecko){// firefox overflow auto bug workaround
36464 this.bodyEl.clip();
36466 this.tabs.bodyEl.clip();
36468 if(this.activePanel){
36469 this.activePanel.getEl().clip();
36471 if(this.activePanel.beforeSlide){
36472 this.activePanel.beforeSlide();
36478 afterSlide : function(){
36479 if(Roo.isGecko){// firefox overflow auto bug workaround
36480 this.bodyEl.unclip();
36482 this.tabs.bodyEl.unclip();
36484 if(this.activePanel){
36485 this.activePanel.getEl().unclip();
36486 if(this.activePanel.afterSlide){
36487 this.activePanel.afterSlide();
36493 initAutoHide : function(){
36494 if(this.autoHide !== false){
36495 if(!this.autoHideHd){
36496 var st = new Roo.util.DelayedTask(this.slideIn, this);
36497 this.autoHideHd = {
36498 "mouseout": function(e){
36499 if(!e.within(this.el, true)){
36503 "mouseover" : function(e){
36509 this.el.on(this.autoHideHd);
36513 clearAutoHide : function(){
36514 if(this.autoHide !== false){
36515 this.el.un("mouseout", this.autoHideHd.mouseout);
36516 this.el.un("mouseover", this.autoHideHd.mouseover);
36520 clearMonitor : function(){
36521 Roo.get(document).un("click", this.slideInIf, this);
36524 // these names are backwards but not changed for compat
36525 slideOut : function(){
36526 if(this.isSlid || this.el.hasActiveFx()){
36529 this.isSlid = true;
36530 if(this.collapseBtn){
36531 this.collapseBtn.hide();
36533 this.closeBtnState = this.closeBtn.getStyle('display');
36534 this.closeBtn.hide();
36536 this.stickBtn.show();
36539 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
36540 this.beforeSlide();
36541 this.el.setStyle("z-index", 10001);
36542 this.el.slideIn(this.getSlideAnchor(), {
36543 callback: function(){
36545 this.initAutoHide();
36546 Roo.get(document).on("click", this.slideInIf, this);
36547 this.fireEvent("slideshow", this);
36554 afterSlideIn : function(){
36555 this.clearAutoHide();
36556 this.isSlid = false;
36557 this.clearMonitor();
36558 this.el.setStyle("z-index", "");
36559 if(this.collapseBtn){
36560 this.collapseBtn.show();
36562 this.closeBtn.setStyle('display', this.closeBtnState);
36564 this.stickBtn.hide();
36566 this.fireEvent("slidehide", this);
36569 slideIn : function(cb){
36570 if(!this.isSlid || this.el.hasActiveFx()){
36574 this.isSlid = false;
36575 this.beforeSlide();
36576 this.el.slideOut(this.getSlideAnchor(), {
36577 callback: function(){
36578 this.el.setLeftTop(-10000, -10000);
36580 this.afterSlideIn();
36588 slideInIf : function(e){
36589 if(!e.within(this.el)){
36594 animateCollapse : function(){
36595 this.beforeSlide();
36596 this.el.setStyle("z-index", 20000);
36597 var anchor = this.getSlideAnchor();
36598 this.el.slideOut(anchor, {
36599 callback : function(){
36600 this.el.setStyle("z-index", "");
36601 this.collapsedEl.slideIn(anchor, {duration:.3});
36603 this.el.setLocation(-10000,-10000);
36605 this.fireEvent("collapsed", this);
36612 animateExpand : function(){
36613 this.beforeSlide();
36614 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
36615 this.el.setStyle("z-index", 20000);
36616 this.collapsedEl.hide({
36619 this.el.slideIn(this.getSlideAnchor(), {
36620 callback : function(){
36621 this.el.setStyle("z-index", "");
36624 this.split.el.show();
36626 this.fireEvent("invalidated", this);
36627 this.fireEvent("expanded", this);
36655 getAnchor : function(){
36656 return this.anchors[this.position];
36659 getCollapseAnchor : function(){
36660 return this.canchors[this.position];
36663 getSlideAnchor : function(){
36664 return this.sanchors[this.position];
36667 getAlignAdj : function(){
36668 var cm = this.cmargins;
36669 switch(this.position){
36685 getExpandAdj : function(){
36686 var c = this.collapsedEl, cm = this.cmargins;
36687 switch(this.position){
36689 return [-(cm.right+c.getWidth()+cm.left), 0];
36692 return [cm.right+c.getWidth()+cm.left, 0];
36695 return [0, -(cm.top+cm.bottom+c.getHeight())];
36698 return [0, cm.top+cm.bottom+c.getHeight()];
36704 * Ext JS Library 1.1.1
36705 * Copyright(c) 2006-2007, Ext JS, LLC.
36707 * Originally Released Under LGPL - original licence link has changed is not relivant.
36710 * <script type="text/javascript">
36713 * These classes are private internal classes
36715 Roo.bootstrap.layout.Center = function(config){
36716 config.region = "center";
36717 Roo.bootstrap.layout.Region.call(this, config);
36718 this.visible = true;
36719 this.minWidth = config.minWidth || 20;
36720 this.minHeight = config.minHeight || 20;
36723 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
36725 // center panel can't be hidden
36729 // center panel can't be hidden
36732 getMinWidth: function(){
36733 return this.minWidth;
36736 getMinHeight: function(){
36737 return this.minHeight;
36750 Roo.bootstrap.layout.North = function(config)
36752 config.region = 'north';
36753 config.cursor = 'n-resize';
36755 Roo.bootstrap.layout.Split.call(this, config);
36759 this.split.placement = Roo.bootstrap.SplitBar.TOP;
36760 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36761 this.split.el.addClass("roo-layout-split-v");
36763 var size = config.initialSize || config.height;
36764 if(typeof size != "undefined"){
36765 this.el.setHeight(size);
36768 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
36770 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36774 getBox : function(){
36775 if(this.collapsed){
36776 return this.collapsedEl.getBox();
36778 var box = this.el.getBox();
36780 box.height += this.split.el.getHeight();
36785 updateBox : function(box){
36786 if(this.split && !this.collapsed){
36787 box.height -= this.split.el.getHeight();
36788 this.split.el.setLeft(box.x);
36789 this.split.el.setTop(box.y+box.height);
36790 this.split.el.setWidth(box.width);
36792 if(this.collapsed){
36793 this.updateBody(box.width, null);
36795 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36803 Roo.bootstrap.layout.South = function(config){
36804 config.region = 'south';
36805 config.cursor = 's-resize';
36806 Roo.bootstrap.layout.Split.call(this, config);
36808 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
36809 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36810 this.split.el.addClass("roo-layout-split-v");
36812 var size = config.initialSize || config.height;
36813 if(typeof size != "undefined"){
36814 this.el.setHeight(size);
36818 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
36819 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36820 getBox : function(){
36821 if(this.collapsed){
36822 return this.collapsedEl.getBox();
36824 var box = this.el.getBox();
36826 var sh = this.split.el.getHeight();
36833 updateBox : function(box){
36834 if(this.split && !this.collapsed){
36835 var sh = this.split.el.getHeight();
36838 this.split.el.setLeft(box.x);
36839 this.split.el.setTop(box.y-sh);
36840 this.split.el.setWidth(box.width);
36842 if(this.collapsed){
36843 this.updateBody(box.width, null);
36845 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36849 Roo.bootstrap.layout.East = function(config){
36850 config.region = "east";
36851 config.cursor = "e-resize";
36852 Roo.bootstrap.layout.Split.call(this, config);
36854 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
36855 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36856 this.split.el.addClass("roo-layout-split-h");
36858 var size = config.initialSize || config.width;
36859 if(typeof size != "undefined"){
36860 this.el.setWidth(size);
36863 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
36864 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36865 getBox : function(){
36866 if(this.collapsed){
36867 return this.collapsedEl.getBox();
36869 var box = this.el.getBox();
36871 var sw = this.split.el.getWidth();
36878 updateBox : function(box){
36879 if(this.split && !this.collapsed){
36880 var sw = this.split.el.getWidth();
36882 this.split.el.setLeft(box.x);
36883 this.split.el.setTop(box.y);
36884 this.split.el.setHeight(box.height);
36887 if(this.collapsed){
36888 this.updateBody(null, box.height);
36890 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36894 Roo.bootstrap.layout.West = function(config){
36895 config.region = "west";
36896 config.cursor = "w-resize";
36898 Roo.bootstrap.layout.Split.call(this, config);
36900 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
36901 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36902 this.split.el.addClass("roo-layout-split-h");
36906 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
36907 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36909 onRender: function(ctr, pos)
36911 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
36912 var size = this.config.initialSize || this.config.width;
36913 if(typeof size != "undefined"){
36914 this.el.setWidth(size);
36918 getBox : function(){
36919 if(this.collapsed){
36920 return this.collapsedEl.getBox();
36922 var box = this.el.getBox();
36924 box.width += this.split.el.getWidth();
36929 updateBox : function(box){
36930 if(this.split && !this.collapsed){
36931 var sw = this.split.el.getWidth();
36933 this.split.el.setLeft(box.x+box.width);
36934 this.split.el.setTop(box.y);
36935 this.split.el.setHeight(box.height);
36937 if(this.collapsed){
36938 this.updateBody(null, box.height);
36940 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36943 Roo.namespace("Roo.bootstrap.panel");/*
36945 * Ext JS Library 1.1.1
36946 * Copyright(c) 2006-2007, Ext JS, LLC.
36948 * Originally Released Under LGPL - original licence link has changed is not relivant.
36951 * <script type="text/javascript">
36954 * @class Roo.ContentPanel
36955 * @extends Roo.util.Observable
36956 * A basic ContentPanel element.
36957 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
36958 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
36959 * @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
36960 * @cfg {Boolean} closable True if the panel can be closed/removed
36961 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
36962 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
36963 * @cfg {Toolbar} toolbar A toolbar for this panel
36964 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
36965 * @cfg {String} title The title for this panel
36966 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
36967 * @cfg {String} url Calls {@link #setUrl} with this value
36968 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
36969 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
36970 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
36971 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
36972 * @cfg {Boolean} badges render the badges
36975 * Create a new ContentPanel.
36976 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
36977 * @param {String/Object} config A string to set only the title or a config object
36978 * @param {String} content (optional) Set the HTML content for this panel
36979 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
36981 Roo.bootstrap.panel.Content = function( config){
36983 this.tpl = config.tpl || false;
36985 var el = config.el;
36986 var content = config.content;
36988 if(config.autoCreate){ // xtype is available if this is called from factory
36991 this.el = Roo.get(el);
36992 if(!this.el && config && config.autoCreate){
36993 if(typeof config.autoCreate == "object"){
36994 if(!config.autoCreate.id){
36995 config.autoCreate.id = config.id||el;
36997 this.el = Roo.DomHelper.append(document.body,
36998 config.autoCreate, true);
37000 var elcfg = { tag: "div",
37001 cls: "roo-layout-inactive-content",
37005 elcfg.html = config.html;
37009 this.el = Roo.DomHelper.append(document.body, elcfg , true);
37012 this.closable = false;
37013 this.loaded = false;
37014 this.active = false;
37017 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
37019 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
37021 this.wrapEl = this.el; //this.el.wrap();
37023 if (config.toolbar.items) {
37024 ti = config.toolbar.items ;
37025 delete config.toolbar.items ;
37029 this.toolbar.render(this.wrapEl, 'before');
37030 for(var i =0;i < ti.length;i++) {
37031 // Roo.log(['add child', items[i]]);
37032 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37034 this.toolbar.items = nitems;
37035 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
37036 delete config.toolbar;
37040 // xtype created footer. - not sure if will work as we normally have to render first..
37041 if (this.footer && !this.footer.el && this.footer.xtype) {
37042 if (!this.wrapEl) {
37043 this.wrapEl = this.el.wrap();
37046 this.footer.container = this.wrapEl.createChild();
37048 this.footer = Roo.factory(this.footer, Roo);
37053 if(typeof config == "string"){
37054 this.title = config;
37056 Roo.apply(this, config);
37060 this.resizeEl = Roo.get(this.resizeEl, true);
37062 this.resizeEl = this.el;
37064 // handle view.xtype
37072 * Fires when this panel is activated.
37073 * @param {Roo.ContentPanel} this
37077 * @event deactivate
37078 * Fires when this panel is activated.
37079 * @param {Roo.ContentPanel} this
37081 "deactivate" : true,
37085 * Fires when this panel is resized if fitToFrame is true.
37086 * @param {Roo.ContentPanel} this
37087 * @param {Number} width The width after any component adjustments
37088 * @param {Number} height The height after any component adjustments
37094 * Fires when this tab is created
37095 * @param {Roo.ContentPanel} this
37106 if(this.autoScroll){
37107 this.resizeEl.setStyle("overflow", "auto");
37109 // fix randome scrolling
37110 //this.el.on('scroll', function() {
37111 // Roo.log('fix random scolling');
37112 // this.scrollTo('top',0);
37115 content = content || this.content;
37117 this.setContent(content);
37119 if(config && config.url){
37120 this.setUrl(this.url, this.params, this.loadOnce);
37125 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
37127 if (this.view && typeof(this.view.xtype) != 'undefined') {
37128 this.view.el = this.el.appendChild(document.createElement("div"));
37129 this.view = Roo.factory(this.view);
37130 this.view.render && this.view.render(false, '');
37134 this.fireEvent('render', this);
37137 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
37141 setRegion : function(region){
37142 this.region = region;
37143 this.setActiveClass(region && !this.background);
37147 setActiveClass: function(state)
37150 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
37151 this.el.setStyle('position','relative');
37153 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
37154 this.el.setStyle('position', 'absolute');
37159 * Returns the toolbar for this Panel if one was configured.
37160 * @return {Roo.Toolbar}
37162 getToolbar : function(){
37163 return this.toolbar;
37166 setActiveState : function(active)
37168 this.active = active;
37169 this.setActiveClass(active);
37171 if(this.fireEvent("deactivate", this) === false){
37176 this.fireEvent("activate", this);
37180 * Updates this panel's element
37181 * @param {String} content The new content
37182 * @param {Boolean} loadScripts (optional) true to look for and process scripts
37184 setContent : function(content, loadScripts){
37185 this.el.update(content, loadScripts);
37188 ignoreResize : function(w, h){
37189 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
37192 this.lastSize = {width: w, height: h};
37197 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
37198 * @return {Roo.UpdateManager} The UpdateManager
37200 getUpdateManager : function(){
37201 return this.el.getUpdateManager();
37204 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
37205 * @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:
37208 url: "your-url.php",
37209 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
37210 callback: yourFunction,
37211 scope: yourObject, //(optional scope)
37214 text: "Loading...",
37219 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
37220 * 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.
37221 * @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}
37222 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
37223 * @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.
37224 * @return {Roo.ContentPanel} this
37227 var um = this.el.getUpdateManager();
37228 um.update.apply(um, arguments);
37234 * 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.
37235 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
37236 * @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)
37237 * @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)
37238 * @return {Roo.UpdateManager} The UpdateManager
37240 setUrl : function(url, params, loadOnce){
37241 if(this.refreshDelegate){
37242 this.removeListener("activate", this.refreshDelegate);
37244 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
37245 this.on("activate", this.refreshDelegate);
37246 return this.el.getUpdateManager();
37249 _handleRefresh : function(url, params, loadOnce){
37250 if(!loadOnce || !this.loaded){
37251 var updater = this.el.getUpdateManager();
37252 updater.update(url, params, this._setLoaded.createDelegate(this));
37256 _setLoaded : function(){
37257 this.loaded = true;
37261 * Returns this panel's id
37264 getId : function(){
37269 * Returns this panel's element - used by regiosn to add.
37270 * @return {Roo.Element}
37272 getEl : function(){
37273 return this.wrapEl || this.el;
37278 adjustForComponents : function(width, height)
37280 //Roo.log('adjustForComponents ');
37281 if(this.resizeEl != this.el){
37282 width -= this.el.getFrameWidth('lr');
37283 height -= this.el.getFrameWidth('tb');
37286 var te = this.toolbar.getEl();
37287 te.setWidth(width);
37288 height -= te.getHeight();
37291 var te = this.footer.getEl();
37292 te.setWidth(width);
37293 height -= te.getHeight();
37297 if(this.adjustments){
37298 width += this.adjustments[0];
37299 height += this.adjustments[1];
37301 return {"width": width, "height": height};
37304 setSize : function(width, height){
37305 if(this.fitToFrame && !this.ignoreResize(width, height)){
37306 if(this.fitContainer && this.resizeEl != this.el){
37307 this.el.setSize(width, height);
37309 var size = this.adjustForComponents(width, height);
37310 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
37311 this.fireEvent('resize', this, size.width, size.height);
37316 * Returns this panel's title
37319 getTitle : function(){
37321 if (typeof(this.title) != 'object') {
37326 for (var k in this.title) {
37327 if (!this.title.hasOwnProperty(k)) {
37331 if (k.indexOf('-') >= 0) {
37332 var s = k.split('-');
37333 for (var i = 0; i<s.length; i++) {
37334 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
37337 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
37344 * Set this panel's title
37345 * @param {String} title
37347 setTitle : function(title){
37348 this.title = title;
37350 this.region.updatePanelTitle(this, title);
37355 * Returns true is this panel was configured to be closable
37356 * @return {Boolean}
37358 isClosable : function(){
37359 return this.closable;
37362 beforeSlide : function(){
37364 this.resizeEl.clip();
37367 afterSlide : function(){
37369 this.resizeEl.unclip();
37373 * Force a content refresh from the URL specified in the {@link #setUrl} method.
37374 * Will fail silently if the {@link #setUrl} method has not been called.
37375 * This does not activate the panel, just updates its content.
37377 refresh : function(){
37378 if(this.refreshDelegate){
37379 this.loaded = false;
37380 this.refreshDelegate();
37385 * Destroys this panel
37387 destroy : function(){
37388 this.el.removeAllListeners();
37389 var tempEl = document.createElement("span");
37390 tempEl.appendChild(this.el.dom);
37391 tempEl.innerHTML = "";
37397 * form - if the content panel contains a form - this is a reference to it.
37398 * @type {Roo.form.Form}
37402 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
37403 * This contains a reference to it.
37409 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
37419 * @param {Object} cfg Xtype definition of item to add.
37423 getChildContainer: function () {
37424 return this.getEl();
37429 var ret = new Roo.factory(cfg);
37434 if (cfg.xtype.match(/^Form$/)) {
37437 //if (this.footer) {
37438 // el = this.footer.container.insertSibling(false, 'before');
37440 el = this.el.createChild();
37443 this.form = new Roo.form.Form(cfg);
37446 if ( this.form.allItems.length) {
37447 this.form.render(el.dom);
37451 // should only have one of theses..
37452 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
37453 // views.. should not be just added - used named prop 'view''
37455 cfg.el = this.el.appendChild(document.createElement("div"));
37458 var ret = new Roo.factory(cfg);
37460 ret.render && ret.render(false, ''); // render blank..
37470 * @class Roo.bootstrap.panel.Grid
37471 * @extends Roo.bootstrap.panel.Content
37473 * Create a new GridPanel.
37474 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
37475 * @param {Object} config A the config object
37481 Roo.bootstrap.panel.Grid = function(config)
37485 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
37486 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
37488 config.el = this.wrapper;
37489 //this.el = this.wrapper;
37491 if (config.container) {
37492 // ctor'ed from a Border/panel.grid
37495 this.wrapper.setStyle("overflow", "hidden");
37496 this.wrapper.addClass('roo-grid-container');
37501 if(config.toolbar){
37502 var tool_el = this.wrapper.createChild();
37503 this.toolbar = Roo.factory(config.toolbar);
37505 if (config.toolbar.items) {
37506 ti = config.toolbar.items ;
37507 delete config.toolbar.items ;
37511 this.toolbar.render(tool_el);
37512 for(var i =0;i < ti.length;i++) {
37513 // Roo.log(['add child', items[i]]);
37514 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37516 this.toolbar.items = nitems;
37518 delete config.toolbar;
37521 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
37522 config.grid.scrollBody = true;;
37523 config.grid.monitorWindowResize = false; // turn off autosizing
37524 config.grid.autoHeight = false;
37525 config.grid.autoWidth = false;
37527 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
37529 if (config.background) {
37530 // render grid on panel activation (if panel background)
37531 this.on('activate', function(gp) {
37532 if (!gp.grid.rendered) {
37533 gp.grid.render(this.wrapper);
37534 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37539 this.grid.render(this.wrapper);
37540 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37543 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
37544 // ??? needed ??? config.el = this.wrapper;
37549 // xtype created footer. - not sure if will work as we normally have to render first..
37550 if (this.footer && !this.footer.el && this.footer.xtype) {
37552 var ctr = this.grid.getView().getFooterPanel(true);
37553 this.footer.dataSource = this.grid.dataSource;
37554 this.footer = Roo.factory(this.footer, Roo);
37555 this.footer.render(ctr);
37565 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
37566 getId : function(){
37567 return this.grid.id;
37571 * Returns the grid for this panel
37572 * @return {Roo.bootstrap.Table}
37574 getGrid : function(){
37578 setSize : function(width, height){
37579 if(!this.ignoreResize(width, height)){
37580 var grid = this.grid;
37581 var size = this.adjustForComponents(width, height);
37582 var gridel = grid.getGridEl();
37583 gridel.setSize(size.width, size.height);
37585 var thd = grid.getGridEl().select('thead',true).first();
37586 var tbd = grid.getGridEl().select('tbody', true).first();
37588 tbd.setSize(width, height - thd.getHeight());
37597 beforeSlide : function(){
37598 this.grid.getView().scroller.clip();
37601 afterSlide : function(){
37602 this.grid.getView().scroller.unclip();
37605 destroy : function(){
37606 this.grid.destroy();
37608 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
37613 * @class Roo.bootstrap.panel.Nest
37614 * @extends Roo.bootstrap.panel.Content
37616 * Create a new Panel, that can contain a layout.Border.
37619 * @param {Roo.BorderLayout} layout The layout for this panel
37620 * @param {String/Object} config A string to set only the title or a config object
37622 Roo.bootstrap.panel.Nest = function(config)
37624 // construct with only one argument..
37625 /* FIXME - implement nicer consturctors
37626 if (layout.layout) {
37628 layout = config.layout;
37629 delete config.layout;
37631 if (layout.xtype && !layout.getEl) {
37632 // then layout needs constructing..
37633 layout = Roo.factory(layout, Roo);
37637 config.el = config.layout.getEl();
37639 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
37641 config.layout.monitorWindowResize = false; // turn off autosizing
37642 this.layout = config.layout;
37643 this.layout.getEl().addClass("roo-layout-nested-layout");
37650 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
37652 setSize : function(width, height){
37653 if(!this.ignoreResize(width, height)){
37654 var size = this.adjustForComponents(width, height);
37655 var el = this.layout.getEl();
37656 if (size.height < 1) {
37657 el.setWidth(size.width);
37659 el.setSize(size.width, size.height);
37661 var touch = el.dom.offsetWidth;
37662 this.layout.layout();
37663 // ie requires a double layout on the first pass
37664 if(Roo.isIE && !this.initialized){
37665 this.initialized = true;
37666 this.layout.layout();
37671 // activate all subpanels if not currently active..
37673 setActiveState : function(active){
37674 this.active = active;
37675 this.setActiveClass(active);
37678 this.fireEvent("deactivate", this);
37682 this.fireEvent("activate", this);
37683 // not sure if this should happen before or after..
37684 if (!this.layout) {
37685 return; // should not happen..
37688 for (var r in this.layout.regions) {
37689 reg = this.layout.getRegion(r);
37690 if (reg.getActivePanel()) {
37691 //reg.showPanel(reg.getActivePanel()); // force it to activate..
37692 reg.setActivePanel(reg.getActivePanel());
37695 if (!reg.panels.length) {
37698 reg.showPanel(reg.getPanel(0));
37707 * Returns the nested BorderLayout for this panel
37708 * @return {Roo.BorderLayout}
37710 getLayout : function(){
37711 return this.layout;
37715 * Adds a xtype elements to the layout of the nested panel
37719 xtype : 'ContentPanel',
37726 xtype : 'NestedLayoutPanel',
37732 items : [ ... list of content panels or nested layout panels.. ]
37736 * @param {Object} cfg Xtype definition of item to add.
37738 addxtype : function(cfg) {
37739 return this.layout.addxtype(cfg);
37744 * Ext JS Library 1.1.1
37745 * Copyright(c) 2006-2007, Ext JS, LLC.
37747 * Originally Released Under LGPL - original licence link has changed is not relivant.
37750 * <script type="text/javascript">
37753 * @class Roo.TabPanel
37754 * @extends Roo.util.Observable
37755 * A lightweight tab container.
37759 // basic tabs 1, built from existing content
37760 var tabs = new Roo.TabPanel("tabs1");
37761 tabs.addTab("script", "View Script");
37762 tabs.addTab("markup", "View Markup");
37763 tabs.activate("script");
37765 // more advanced tabs, built from javascript
37766 var jtabs = new Roo.TabPanel("jtabs");
37767 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
37769 // set up the UpdateManager
37770 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
37771 var updater = tab2.getUpdateManager();
37772 updater.setDefaultUrl("ajax1.htm");
37773 tab2.on('activate', updater.refresh, updater, true);
37775 // Use setUrl for Ajax loading
37776 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
37777 tab3.setUrl("ajax2.htm", null, true);
37780 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
37783 jtabs.activate("jtabs-1");
37786 * Create a new TabPanel.
37787 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
37788 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
37790 Roo.bootstrap.panel.Tabs = function(config){
37792 * The container element for this TabPanel.
37793 * @type Roo.Element
37795 this.el = Roo.get(config.el);
37798 if(typeof config == "boolean"){
37799 this.tabPosition = config ? "bottom" : "top";
37801 Roo.apply(this, config);
37805 if(this.tabPosition == "bottom"){
37806 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37807 this.el.addClass("roo-tabs-bottom");
37809 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
37810 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
37811 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
37813 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
37815 if(this.tabPosition != "bottom"){
37816 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
37817 * @type Roo.Element
37819 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37820 this.el.addClass("roo-tabs-top");
37824 this.bodyEl.setStyle("position", "relative");
37826 this.active = null;
37827 this.activateDelegate = this.activate.createDelegate(this);
37832 * Fires when the active tab changes
37833 * @param {Roo.TabPanel} this
37834 * @param {Roo.TabPanelItem} activePanel The new active tab
37838 * @event beforetabchange
37839 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
37840 * @param {Roo.TabPanel} this
37841 * @param {Object} e Set cancel to true on this object to cancel the tab change
37842 * @param {Roo.TabPanelItem} tab The tab being changed to
37844 "beforetabchange" : true
37847 Roo.EventManager.onWindowResize(this.onResize, this);
37848 this.cpad = this.el.getPadding("lr");
37849 this.hiddenCount = 0;
37852 // toolbar on the tabbar support...
37853 if (this.toolbar) {
37854 alert("no toolbar support yet");
37855 this.toolbar = false;
37857 var tcfg = this.toolbar;
37858 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
37859 this.toolbar = new Roo.Toolbar(tcfg);
37860 if (Roo.isSafari) {
37861 var tbl = tcfg.container.child('table', true);
37862 tbl.setAttribute('width', '100%');
37870 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
37873 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
37875 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
37877 tabPosition : "top",
37879 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
37881 currentTabWidth : 0,
37883 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
37887 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
37891 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
37893 preferredTabWidth : 175,
37895 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
37897 resizeTabs : false,
37899 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
37901 monitorResize : true,
37903 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
37908 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
37909 * @param {String} id The id of the div to use <b>or create</b>
37910 * @param {String} text The text for the tab
37911 * @param {String} content (optional) Content to put in the TabPanelItem body
37912 * @param {Boolean} closable (optional) True to create a close icon on the tab
37913 * @return {Roo.TabPanelItem} The created TabPanelItem
37915 addTab : function(id, text, content, closable, tpl)
37917 var item = new Roo.bootstrap.panel.TabItem({
37921 closable : closable,
37924 this.addTabItem(item);
37926 item.setContent(content);
37932 * Returns the {@link Roo.TabPanelItem} with the specified id/index
37933 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
37934 * @return {Roo.TabPanelItem}
37936 getTab : function(id){
37937 return this.items[id];
37941 * Hides the {@link Roo.TabPanelItem} with the specified id/index
37942 * @param {String/Number} id The id or index of the TabPanelItem to hide.
37944 hideTab : function(id){
37945 var t = this.items[id];
37948 this.hiddenCount++;
37949 this.autoSizeTabs();
37954 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
37955 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
37957 unhideTab : function(id){
37958 var t = this.items[id];
37960 t.setHidden(false);
37961 this.hiddenCount--;
37962 this.autoSizeTabs();
37967 * Adds an existing {@link Roo.TabPanelItem}.
37968 * @param {Roo.TabPanelItem} item The TabPanelItem to add
37970 addTabItem : function(item){
37971 this.items[item.id] = item;
37972 this.items.push(item);
37973 // if(this.resizeTabs){
37974 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
37975 // this.autoSizeTabs();
37977 // item.autoSize();
37982 * Removes a {@link Roo.TabPanelItem}.
37983 * @param {String/Number} id The id or index of the TabPanelItem to remove.
37985 removeTab : function(id){
37986 var items = this.items;
37987 var tab = items[id];
37988 if(!tab) { return; }
37989 var index = items.indexOf(tab);
37990 if(this.active == tab && items.length > 1){
37991 var newTab = this.getNextAvailable(index);
37996 this.stripEl.dom.removeChild(tab.pnode.dom);
37997 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
37998 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
38000 items.splice(index, 1);
38001 delete this.items[tab.id];
38002 tab.fireEvent("close", tab);
38003 tab.purgeListeners();
38004 this.autoSizeTabs();
38007 getNextAvailable : function(start){
38008 var items = this.items;
38010 // look for a next tab that will slide over to
38011 // replace the one being removed
38012 while(index < items.length){
38013 var item = items[++index];
38014 if(item && !item.isHidden()){
38018 // if one isn't found select the previous tab (on the left)
38021 var item = items[--index];
38022 if(item && !item.isHidden()){
38030 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
38031 * @param {String/Number} id The id or index of the TabPanelItem to disable.
38033 disableTab : function(id){
38034 var tab = this.items[id];
38035 if(tab && this.active != tab){
38041 * Enables a {@link Roo.TabPanelItem} that is disabled.
38042 * @param {String/Number} id The id or index of the TabPanelItem to enable.
38044 enableTab : function(id){
38045 var tab = this.items[id];
38050 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
38051 * @param {String/Number} id The id or index of the TabPanelItem to activate.
38052 * @return {Roo.TabPanelItem} The TabPanelItem.
38054 activate : function(id){
38055 var tab = this.items[id];
38059 if(tab == this.active || tab.disabled){
38063 this.fireEvent("beforetabchange", this, e, tab);
38064 if(e.cancel !== true && !tab.disabled){
38066 this.active.hide();
38068 this.active = this.items[id];
38069 this.active.show();
38070 this.fireEvent("tabchange", this, this.active);
38076 * Gets the active {@link Roo.TabPanelItem}.
38077 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
38079 getActiveTab : function(){
38080 return this.active;
38084 * Updates the tab body element to fit the height of the container element
38085 * for overflow scrolling
38086 * @param {Number} targetHeight (optional) Override the starting height from the elements height
38088 syncHeight : function(targetHeight){
38089 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
38090 var bm = this.bodyEl.getMargins();
38091 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
38092 this.bodyEl.setHeight(newHeight);
38096 onResize : function(){
38097 if(this.monitorResize){
38098 this.autoSizeTabs();
38103 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
38105 beginUpdate : function(){
38106 this.updating = true;
38110 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
38112 endUpdate : function(){
38113 this.updating = false;
38114 this.autoSizeTabs();
38118 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
38120 autoSizeTabs : function(){
38121 var count = this.items.length;
38122 var vcount = count - this.hiddenCount;
38123 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
38126 var w = Math.max(this.el.getWidth() - this.cpad, 10);
38127 var availWidth = Math.floor(w / vcount);
38128 var b = this.stripBody;
38129 if(b.getWidth() > w){
38130 var tabs = this.items;
38131 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
38132 if(availWidth < this.minTabWidth){
38133 /*if(!this.sleft){ // incomplete scrolling code
38134 this.createScrollButtons();
38137 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
38140 if(this.currentTabWidth < this.preferredTabWidth){
38141 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
38147 * Returns the number of tabs in this TabPanel.
38150 getCount : function(){
38151 return this.items.length;
38155 * Resizes all the tabs to the passed width
38156 * @param {Number} The new width
38158 setTabWidth : function(width){
38159 this.currentTabWidth = width;
38160 for(var i = 0, len = this.items.length; i < len; i++) {
38161 if(!this.items[i].isHidden()) {
38162 this.items[i].setWidth(width);
38168 * Destroys this TabPanel
38169 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
38171 destroy : function(removeEl){
38172 Roo.EventManager.removeResizeListener(this.onResize, this);
38173 for(var i = 0, len = this.items.length; i < len; i++){
38174 this.items[i].purgeListeners();
38176 if(removeEl === true){
38177 this.el.update("");
38182 createStrip : function(container)
38184 var strip = document.createElement("nav");
38185 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
38186 container.appendChild(strip);
38190 createStripList : function(strip)
38192 // div wrapper for retard IE
38193 // returns the "tr" element.
38194 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
38195 //'<div class="x-tabs-strip-wrap">'+
38196 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
38197 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
38198 return strip.firstChild; //.firstChild.firstChild.firstChild;
38200 createBody : function(container)
38202 var body = document.createElement("div");
38203 Roo.id(body, "tab-body");
38204 //Roo.fly(body).addClass("x-tabs-body");
38205 Roo.fly(body).addClass("tab-content");
38206 container.appendChild(body);
38209 createItemBody :function(bodyEl, id){
38210 var body = Roo.getDom(id);
38212 body = document.createElement("div");
38215 //Roo.fly(body).addClass("x-tabs-item-body");
38216 Roo.fly(body).addClass("tab-pane");
38217 bodyEl.insertBefore(body, bodyEl.firstChild);
38221 createStripElements : function(stripEl, text, closable, tpl)
38223 var td = document.createElement("li"); // was td..
38226 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
38229 stripEl.appendChild(td);
38231 td.className = "x-tabs-closable";
38232 if(!this.closeTpl){
38233 this.closeTpl = new Roo.Template(
38234 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38235 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
38236 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
38239 var el = this.closeTpl.overwrite(td, {"text": text});
38240 var close = el.getElementsByTagName("div")[0];
38241 var inner = el.getElementsByTagName("em")[0];
38242 return {"el": el, "close": close, "inner": inner};
38245 // not sure what this is..
38246 // if(!this.tabTpl){
38247 //this.tabTpl = new Roo.Template(
38248 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38249 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
38251 // this.tabTpl = new Roo.Template(
38252 // '<a href="#">' +
38253 // '<span unselectable="on"' +
38254 // (this.disableTooltips ? '' : ' title="{text}"') +
38255 // ' >{text}</span></a>'
38261 var template = tpl || this.tabTpl || false;
38265 template = new Roo.Template(
38267 '<span unselectable="on"' +
38268 (this.disableTooltips ? '' : ' title="{text}"') +
38269 ' >{text}</span></a>'
38273 switch (typeof(template)) {
38277 template = new Roo.Template(template);
38283 var el = template.overwrite(td, {"text": text});
38285 var inner = el.getElementsByTagName("span")[0];
38287 return {"el": el, "inner": inner};
38295 * @class Roo.TabPanelItem
38296 * @extends Roo.util.Observable
38297 * Represents an individual item (tab plus body) in a TabPanel.
38298 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
38299 * @param {String} id The id of this TabPanelItem
38300 * @param {String} text The text for the tab of this TabPanelItem
38301 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
38303 Roo.bootstrap.panel.TabItem = function(config){
38305 * The {@link Roo.TabPanel} this TabPanelItem belongs to
38306 * @type Roo.TabPanel
38308 this.tabPanel = config.panel;
38310 * The id for this TabPanelItem
38313 this.id = config.id;
38315 this.disabled = false;
38317 this.text = config.text;
38319 this.loaded = false;
38320 this.closable = config.closable;
38323 * The body element for this TabPanelItem.
38324 * @type Roo.Element
38326 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
38327 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
38328 this.bodyEl.setStyle("display", "block");
38329 this.bodyEl.setStyle("zoom", "1");
38330 //this.hideAction();
38332 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
38334 this.el = Roo.get(els.el);
38335 this.inner = Roo.get(els.inner, true);
38336 this.textEl = Roo.get(this.el.dom.firstChild, true);
38337 this.pnode = Roo.get(els.el.parentNode, true);
38338 // this.el.on("mousedown", this.onTabMouseDown, this);
38339 this.el.on("click", this.onTabClick, this);
38341 if(config.closable){
38342 var c = Roo.get(els.close, true);
38343 c.dom.title = this.closeText;
38344 c.addClassOnOver("close-over");
38345 c.on("click", this.closeClick, this);
38351 * Fires when this tab becomes the active tab.
38352 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38353 * @param {Roo.TabPanelItem} this
38357 * @event beforeclose
38358 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
38359 * @param {Roo.TabPanelItem} this
38360 * @param {Object} e Set cancel to true on this object to cancel the close.
38362 "beforeclose": true,
38365 * Fires when this tab is closed.
38366 * @param {Roo.TabPanelItem} this
38370 * @event deactivate
38371 * Fires when this tab is no longer the active tab.
38372 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38373 * @param {Roo.TabPanelItem} this
38375 "deactivate" : true
38377 this.hidden = false;
38379 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
38382 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
38384 purgeListeners : function(){
38385 Roo.util.Observable.prototype.purgeListeners.call(this);
38386 this.el.removeAllListeners();
38389 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
38392 this.pnode.addClass("active");
38395 this.tabPanel.stripWrap.repaint();
38397 this.fireEvent("activate", this.tabPanel, this);
38401 * Returns true if this tab is the active tab.
38402 * @return {Boolean}
38404 isActive : function(){
38405 return this.tabPanel.getActiveTab() == this;
38409 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
38412 this.pnode.removeClass("active");
38414 this.fireEvent("deactivate", this.tabPanel, this);
38417 hideAction : function(){
38418 this.bodyEl.hide();
38419 this.bodyEl.setStyle("position", "absolute");
38420 this.bodyEl.setLeft("-20000px");
38421 this.bodyEl.setTop("-20000px");
38424 showAction : function(){
38425 this.bodyEl.setStyle("position", "relative");
38426 this.bodyEl.setTop("");
38427 this.bodyEl.setLeft("");
38428 this.bodyEl.show();
38432 * Set the tooltip for the tab.
38433 * @param {String} tooltip The tab's tooltip
38435 setTooltip : function(text){
38436 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
38437 this.textEl.dom.qtip = text;
38438 this.textEl.dom.removeAttribute('title');
38440 this.textEl.dom.title = text;
38444 onTabClick : function(e){
38445 e.preventDefault();
38446 this.tabPanel.activate(this.id);
38449 onTabMouseDown : function(e){
38450 e.preventDefault();
38451 this.tabPanel.activate(this.id);
38454 getWidth : function(){
38455 return this.inner.getWidth();
38458 setWidth : function(width){
38459 var iwidth = width - this.pnode.getPadding("lr");
38460 this.inner.setWidth(iwidth);
38461 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
38462 this.pnode.setWidth(width);
38466 * Show or hide the tab
38467 * @param {Boolean} hidden True to hide or false to show.
38469 setHidden : function(hidden){
38470 this.hidden = hidden;
38471 this.pnode.setStyle("display", hidden ? "none" : "");
38475 * Returns true if this tab is "hidden"
38476 * @return {Boolean}
38478 isHidden : function(){
38479 return this.hidden;
38483 * Returns the text for this tab
38486 getText : function(){
38490 autoSize : function(){
38491 //this.el.beginMeasure();
38492 this.textEl.setWidth(1);
38494 * #2804 [new] Tabs in Roojs
38495 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
38497 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
38498 //this.el.endMeasure();
38502 * Sets the text for the tab (Note: this also sets the tooltip text)
38503 * @param {String} text The tab's text and tooltip
38505 setText : function(text){
38507 this.textEl.update(text);
38508 this.setTooltip(text);
38509 //if(!this.tabPanel.resizeTabs){
38510 // this.autoSize();
38514 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
38516 activate : function(){
38517 this.tabPanel.activate(this.id);
38521 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
38523 disable : function(){
38524 if(this.tabPanel.active != this){
38525 this.disabled = true;
38526 this.pnode.addClass("disabled");
38531 * Enables this TabPanelItem if it was previously disabled.
38533 enable : function(){
38534 this.disabled = false;
38535 this.pnode.removeClass("disabled");
38539 * Sets the content for this TabPanelItem.
38540 * @param {String} content The content
38541 * @param {Boolean} loadScripts true to look for and load scripts
38543 setContent : function(content, loadScripts){
38544 this.bodyEl.update(content, loadScripts);
38548 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
38549 * @return {Roo.UpdateManager} The UpdateManager
38551 getUpdateManager : function(){
38552 return this.bodyEl.getUpdateManager();
38556 * Set a URL to be used to load the content for this TabPanelItem.
38557 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
38558 * @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)
38559 * @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)
38560 * @return {Roo.UpdateManager} The UpdateManager
38562 setUrl : function(url, params, loadOnce){
38563 if(this.refreshDelegate){
38564 this.un('activate', this.refreshDelegate);
38566 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
38567 this.on("activate", this.refreshDelegate);
38568 return this.bodyEl.getUpdateManager();
38572 _handleRefresh : function(url, params, loadOnce){
38573 if(!loadOnce || !this.loaded){
38574 var updater = this.bodyEl.getUpdateManager();
38575 updater.update(url, params, this._setLoaded.createDelegate(this));
38580 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
38581 * Will fail silently if the setUrl method has not been called.
38582 * This does not activate the panel, just updates its content.
38584 refresh : function(){
38585 if(this.refreshDelegate){
38586 this.loaded = false;
38587 this.refreshDelegate();
38592 _setLoaded : function(){
38593 this.loaded = true;
38597 closeClick : function(e){
38600 this.fireEvent("beforeclose", this, o);
38601 if(o.cancel !== true){
38602 this.tabPanel.removeTab(this.id);
38606 * The text displayed in the tooltip for the close icon.
38609 closeText : "Close this tab"
38612 * This script refer to:
38613 * Title: International Telephone Input
38614 * Author: Jack O'Connor
38615 * Code version: v12.1.12
38616 * Availability: https://github.com/jackocnr/intl-tel-input.git
38619 Roo.bootstrap.PhoneInputData = function() {
38622 "Afghanistan (افغانستان)",
38627 "Albania (Shqipëri)",
38632 "Algeria (الجزائر)",
38657 "Antigua and Barbuda",
38667 "Armenia (Հայաստան)",
38683 "Austria (Österreich)",
38688 "Azerbaijan (Azərbaycan)",
38698 "Bahrain (البحرين)",
38703 "Bangladesh (বাংলাদেশ)",
38713 "Belarus (Беларусь)",
38718 "Belgium (België)",
38748 "Bosnia and Herzegovina (Босна и Херцеговина)",
38763 "British Indian Ocean Territory",
38768 "British Virgin Islands",
38778 "Bulgaria (България)",
38788 "Burundi (Uburundi)",
38793 "Cambodia (កម្ពុជា)",
38798 "Cameroon (Cameroun)",
38807 ["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"]
38810 "Cape Verde (Kabu Verdi)",
38815 "Caribbean Netherlands",
38826 "Central African Republic (République centrafricaine)",
38846 "Christmas Island",
38852 "Cocos (Keeling) Islands",
38863 "Comoros (جزر القمر)",
38868 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
38873 "Congo (Republic) (Congo-Brazzaville)",
38893 "Croatia (Hrvatska)",
38914 "Czech Republic (Česká republika)",
38919 "Denmark (Danmark)",
38934 "Dominican Republic (República Dominicana)",
38938 ["809", "829", "849"]
38956 "Equatorial Guinea (Guinea Ecuatorial)",
38976 "Falkland Islands (Islas Malvinas)",
38981 "Faroe Islands (Føroyar)",
39002 "French Guiana (Guyane française)",
39007 "French Polynesia (Polynésie française)",
39022 "Georgia (საქართველო)",
39027 "Germany (Deutschland)",
39047 "Greenland (Kalaallit Nunaat)",
39084 "Guinea-Bissau (Guiné Bissau)",
39109 "Hungary (Magyarország)",
39114 "Iceland (Ísland)",
39134 "Iraq (العراق)",
39150 "Israel (ישראל)",
39177 "Jordan (الأردن)",
39182 "Kazakhstan (Казахстан)",
39203 "Kuwait (الكويت)",
39208 "Kyrgyzstan (Кыргызстан)",
39218 "Latvia (Latvija)",
39223 "Lebanon (لبنان)",
39238 "Libya (ليبيا)",
39248 "Lithuania (Lietuva)",
39263 "Macedonia (FYROM) (Македонија)",
39268 "Madagascar (Madagasikara)",
39298 "Marshall Islands",
39308 "Mauritania (موريتانيا)",
39313 "Mauritius (Moris)",
39334 "Moldova (Republica Moldova)",
39344 "Mongolia (Монгол)",
39349 "Montenegro (Crna Gora)",
39359 "Morocco (المغرب)",
39365 "Mozambique (Moçambique)",
39370 "Myanmar (Burma) (မြန်မာ)",
39375 "Namibia (Namibië)",
39390 "Netherlands (Nederland)",
39395 "New Caledonia (Nouvelle-Calédonie)",
39430 "North Korea (조선 민주주의 인민 공화국)",
39435 "Northern Mariana Islands",
39451 "Pakistan (پاکستان)",
39461 "Palestine (فلسطين)",
39471 "Papua New Guinea",
39513 "Réunion (La Réunion)",
39519 "Romania (România)",
39535 "Saint Barthélemy",
39546 "Saint Kitts and Nevis",
39556 "Saint Martin (Saint-Martin (partie française))",
39562 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
39567 "Saint Vincent and the Grenadines",
39582 "São Tomé and Príncipe (São Tomé e Príncipe)",
39587 "Saudi Arabia (المملكة العربية السعودية)",
39592 "Senegal (Sénégal)",
39622 "Slovakia (Slovensko)",
39627 "Slovenia (Slovenija)",
39637 "Somalia (Soomaaliya)",
39647 "South Korea (대한민국)",
39652 "South Sudan (جنوب السودان)",
39662 "Sri Lanka (ශ්රී ලංකාව)",
39667 "Sudan (السودان)",
39677 "Svalbard and Jan Mayen",
39688 "Sweden (Sverige)",
39693 "Switzerland (Schweiz)",
39698 "Syria (سوريا)",
39743 "Trinidad and Tobago",
39748 "Tunisia (تونس)",
39753 "Turkey (Türkiye)",
39763 "Turks and Caicos Islands",
39773 "U.S. Virgin Islands",
39783 "Ukraine (Україна)",
39788 "United Arab Emirates (الإمارات العربية المتحدة)",
39810 "Uzbekistan (Oʻzbekiston)",
39820 "Vatican City (Città del Vaticano)",
39831 "Vietnam (Việt Nam)",
39836 "Wallis and Futuna (Wallis-et-Futuna)",
39841 "Western Sahara (الصحراء الغربية)",
39847 "Yemen (اليمن)",
39871 * This script refer to:
39872 * Title: International Telephone Input
39873 * Author: Jack O'Connor
39874 * Code version: v12.1.12
39875 * Availability: https://github.com/jackocnr/intl-tel-input.git
39879 * @class Roo.bootstrap.PhoneInput
39880 * @extends Roo.bootstrap.TriggerField
39881 * An input with International dial-code selection
39883 * @cfg {String} defaultDialCode default '+852'
39884 * @cfg {Array} preferedCountries default []
39887 * Create a new PhoneInput.
39888 * @param {Object} config Configuration options
39891 Roo.bootstrap.PhoneInput = function(config) {
39892 Roo.bootstrap.PhoneInput.superclass.constructor.call(this, config);
39895 Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
39897 listWidth: undefined,
39899 selectedClass: 'active',
39901 invalidClass : "has-warning",
39903 validClass: 'has-success',
39905 allowed: '0123456789',
39910 * @cfg {String} defaultDialCode The default dial code when initializing the input
39912 defaultDialCode: '+852',
39915 * @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
39917 preferedCountries: false,
39919 getAutoCreate : function()
39921 var data = Roo.bootstrap.PhoneInputData();
39922 var align = this.labelAlign || this.parentLabelAlign();
39925 this.allCountries = [];
39926 this.dialCodeMapping = [];
39928 for (var i = 0; i < data.length; i++) {
39930 this.allCountries[i] = {
39934 priority: c[3] || 0,
39935 areaCodes: c[4] || null
39937 this.dialCodeMapping[c[2]] = {
39940 priority: c[3] || 0,
39941 areaCodes: c[4] || null
39953 // type: 'number', -- do not use number - we get the flaky up/down arrows.
39954 maxlength: this.max_length,
39955 cls : 'form-control tel-input',
39956 autocomplete: 'new-password'
39959 var hiddenInput = {
39962 cls: 'hidden-tel-input'
39966 hiddenInput.name = this.name;
39969 if (this.disabled) {
39970 input.disabled = true;
39973 var flag_container = {
39990 cls: this.hasFeedback ? 'has-feedback' : '',
39996 cls: 'dial-code-holder',
40003 cls: 'roo-select2-container input-group',
40010 if (this.fieldLabel.length) {
40013 tooltip: 'This field is required'
40019 cls: 'control-label',
40025 html: this.fieldLabel
40028 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40034 if(this.indicatorpos == 'right') {
40035 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40042 if(align == 'left') {
40050 if(this.labelWidth > 12){
40051 label.style = "width: " + this.labelWidth + 'px';
40053 if(this.labelWidth < 13 && this.labelmd == 0){
40054 this.labelmd = this.labelWidth;
40056 if(this.labellg > 0){
40057 label.cls += ' col-lg-' + this.labellg;
40058 input.cls += ' col-lg-' + (12 - this.labellg);
40060 if(this.labelmd > 0){
40061 label.cls += ' col-md-' + this.labelmd;
40062 container.cls += ' col-md-' + (12 - this.labelmd);
40064 if(this.labelsm > 0){
40065 label.cls += ' col-sm-' + this.labelsm;
40066 container.cls += ' col-sm-' + (12 - this.labelsm);
40068 if(this.labelxs > 0){
40069 label.cls += ' col-xs-' + this.labelxs;
40070 container.cls += ' col-xs-' + (12 - this.labelxs);
40080 var settings = this;
40082 ['xs','sm','md','lg'].map(function(size){
40083 if (settings[size]) {
40084 cfg.cls += ' col-' + size + '-' + settings[size];
40088 this.store = new Roo.data.Store({
40089 proxy : new Roo.data.MemoryProxy({}),
40090 reader : new Roo.data.JsonReader({
40101 'name' : 'dialCode',
40105 'name' : 'priority',
40109 'name' : 'areaCodes',
40116 if(!this.preferedCountries) {
40117 this.preferedCountries = [
40124 var p = this.preferedCountries.reverse();
40127 for (var i = 0; i < p.length; i++) {
40128 for (var j = 0; j < this.allCountries.length; j++) {
40129 if(this.allCountries[j].iso2 == p[i]) {
40130 var t = this.allCountries[j];
40131 this.allCountries.splice(j,1);
40132 this.allCountries.unshift(t);
40138 this.store.proxy.data = {
40140 data: this.allCountries
40146 initEvents : function()
40149 Roo.bootstrap.PhoneInput.superclass.initEvents.call(this);
40151 this.indicator = this.indicatorEl();
40152 this.flag = this.flagEl();
40153 this.dialCodeHolder = this.dialCodeHolderEl();
40155 this.trigger = this.el.select('div.flag-box',true).first();
40156 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
40161 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40162 _this.list.setWidth(lw);
40165 this.list.on('mouseover', this.onViewOver, this);
40166 this.list.on('mousemove', this.onViewMove, this);
40167 this.inputEl().on("keyup", this.onKeyUp, this);
40168 this.inputEl().on("keypress", this.onKeyPress, this);
40170 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
40172 this.view = new Roo.View(this.list, this.tpl, {
40173 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40176 this.view.on('click', this.onViewClick, this);
40177 this.setValue(this.defaultDialCode);
40180 onTriggerClick : function(e)
40182 Roo.log('trigger click');
40187 if(this.isExpanded()){
40189 this.hasFocus = false;
40191 this.store.load({});
40192 this.hasFocus = true;
40197 isExpanded : function()
40199 return this.list.isVisible();
40202 collapse : function()
40204 if(!this.isExpanded()){
40208 Roo.get(document).un('mousedown', this.collapseIf, this);
40209 Roo.get(document).un('mousewheel', this.collapseIf, this);
40210 this.fireEvent('collapse', this);
40214 expand : function()
40218 if(this.isExpanded() || !this.hasFocus){
40222 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
40223 this.list.setWidth(lw);
40226 this.restrictHeight();
40228 Roo.get(document).on('mousedown', this.collapseIf, this);
40229 Roo.get(document).on('mousewheel', this.collapseIf, this);
40231 this.fireEvent('expand', this);
40234 restrictHeight : function()
40236 this.list.alignTo(this.inputEl(), this.listAlign);
40237 this.list.alignTo(this.inputEl(), this.listAlign);
40240 onViewOver : function(e, t)
40242 if(this.inKeyMode){
40245 var item = this.view.findItemFromChild(t);
40248 var index = this.view.indexOf(item);
40249 this.select(index, false);
40254 onViewClick : function(view, doFocus, el, e)
40256 var index = this.view.getSelectedIndexes()[0];
40258 var r = this.store.getAt(index);
40261 this.onSelect(r, index);
40263 if(doFocus !== false && !this.blockFocus){
40264 this.inputEl().focus();
40268 onViewMove : function(e, t)
40270 this.inKeyMode = false;
40273 select : function(index, scrollIntoView)
40275 this.selectedIndex = index;
40276 this.view.select(index);
40277 if(scrollIntoView !== false){
40278 var el = this.view.getNode(index);
40280 this.list.scrollChildIntoView(el, false);
40285 createList : function()
40287 this.list = Roo.get(document.body).createChild({
40289 cls: 'typeahead typeahead-long dropdown-menu tel-list',
40290 style: 'display:none'
40293 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
40296 collapseIf : function(e)
40298 var in_combo = e.within(this.el);
40299 var in_list = e.within(this.list);
40300 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
40302 if (in_combo || in_list || is_list) {
40308 onSelect : function(record, index)
40310 if(this.fireEvent('beforeselect', this, record, index) !== false){
40312 this.setFlagClass(record.data.iso2);
40313 this.setDialCode(record.data.dialCode);
40314 this.hasFocus = false;
40316 this.fireEvent('select', this, record, index);
40320 flagEl : function()
40322 var flag = this.el.select('div.flag',true).first();
40329 dialCodeHolderEl : function()
40331 var d = this.el.select('input.dial-code-holder',true).first();
40338 setDialCode : function(v)
40340 this.dialCodeHolder.dom.value = '+'+v;
40343 setFlagClass : function(n)
40345 this.flag.dom.className = 'flag '+n;
40348 getValue : function()
40350 var v = this.inputEl().getValue();
40351 if(this.dialCodeHolder) {
40352 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
40357 setValue : function(v)
40359 var d = this.getDialCode(v);
40361 //invalid dial code
40362 if(v.length == 0 || !d || d.length == 0) {
40364 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
40365 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40371 this.setFlagClass(this.dialCodeMapping[d].iso2);
40372 this.setDialCode(d);
40373 this.inputEl().dom.value = v.replace('+'+d,'');
40374 this.hiddenEl().dom.value = this.getValue();
40379 getDialCode : function(v)
40383 if (v.length == 0) {
40384 return this.dialCodeHolder.dom.value;
40388 if (v.charAt(0) != "+") {
40391 var numericChars = "";
40392 for (var i = 1; i < v.length; i++) {
40393 var c = v.charAt(i);
40396 if (this.dialCodeMapping[numericChars]) {
40397 dialCode = v.substr(1, i);
40399 if (numericChars.length == 4) {
40409 this.setValue(this.defaultDialCode);
40413 hiddenEl : function()
40415 return this.el.select('input.hidden-tel-input',true).first();
40418 // after setting val
40419 onKeyUp : function(e){
40420 this.setValue(this.getValue());
40423 onKeyPress : function(e){
40424 if(this.allowed.indexOf(String.fromCharCode(e.getCharCode())) === -1){
40431 * @class Roo.bootstrap.MoneyField
40432 * @extends Roo.bootstrap.ComboBox
40433 * Bootstrap MoneyField class
40436 * Create a new MoneyField.
40437 * @param {Object} config Configuration options
40440 Roo.bootstrap.MoneyField = function(config) {
40442 Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
40446 Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
40449 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
40451 allowDecimals : true,
40453 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
40455 decimalSeparator : ".",
40457 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
40459 decimalPrecision : 0,
40461 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
40463 allowNegative : true,
40465 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
40469 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
40471 minValue : Number.NEGATIVE_INFINITY,
40473 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
40475 maxValue : Number.MAX_VALUE,
40477 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
40479 minText : "The minimum value for this field is {0}",
40481 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
40483 maxText : "The maximum value for this field is {0}",
40485 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
40486 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
40488 nanText : "{0} is not a valid number",
40490 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
40494 * @cfg {String} defaults currency of the MoneyField
40495 * value should be in lkey
40497 defaultCurrency : false,
40499 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
40501 thousandsDelimiter : false,
40503 * @cfg {Number} max_length Maximum input field length allowed (defaults to Number.MAX_VALUE)
40514 getAutoCreate : function()
40516 var align = this.labelAlign || this.parentLabelAlign();
40528 cls : 'form-control roo-money-amount-input',
40529 autocomplete: 'new-password'
40532 var hiddenInput = {
40536 cls: 'hidden-number-input'
40539 if(this.max_length) {
40540 input.maxlength = this.max_length;
40544 hiddenInput.name = this.name;
40547 if (this.disabled) {
40548 input.disabled = true;
40551 var clg = 12 - this.inputlg;
40552 var cmd = 12 - this.inputmd;
40553 var csm = 12 - this.inputsm;
40554 var cxs = 12 - this.inputxs;
40558 cls : 'row roo-money-field',
40562 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
40566 cls: 'roo-select2-container input-group',
40570 cls : 'form-control roo-money-currency-input',
40571 autocomplete: 'new-password',
40573 name : this.currencyName
40577 cls : 'input-group-addon',
40591 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
40595 cls: this.hasFeedback ? 'has-feedback' : '',
40606 if (this.fieldLabel.length) {
40609 tooltip: 'This field is required'
40615 cls: 'control-label',
40621 html: this.fieldLabel
40624 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40630 if(this.indicatorpos == 'right') {
40631 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40638 if(align == 'left') {
40646 if(this.labelWidth > 12){
40647 label.style = "width: " + this.labelWidth + 'px';
40649 if(this.labelWidth < 13 && this.labelmd == 0){
40650 this.labelmd = this.labelWidth;
40652 if(this.labellg > 0){
40653 label.cls += ' col-lg-' + this.labellg;
40654 input.cls += ' col-lg-' + (12 - this.labellg);
40656 if(this.labelmd > 0){
40657 label.cls += ' col-md-' + this.labelmd;
40658 container.cls += ' col-md-' + (12 - this.labelmd);
40660 if(this.labelsm > 0){
40661 label.cls += ' col-sm-' + this.labelsm;
40662 container.cls += ' col-sm-' + (12 - this.labelsm);
40664 if(this.labelxs > 0){
40665 label.cls += ' col-xs-' + this.labelxs;
40666 container.cls += ' col-xs-' + (12 - this.labelxs);
40677 var settings = this;
40679 ['xs','sm','md','lg'].map(function(size){
40680 if (settings[size]) {
40681 cfg.cls += ' col-' + size + '-' + settings[size];
40688 initEvents : function()
40690 this.indicator = this.indicatorEl();
40692 this.initCurrencyEvent();
40694 this.initNumberEvent();
40697 initCurrencyEvent : function()
40700 throw "can not find store for combo";
40703 this.store = Roo.factory(this.store, Roo.data);
40704 this.store.parent = this;
40708 this.triggerEl = this.el.select('.input-group-addon', true).first();
40710 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
40715 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40716 _this.list.setWidth(lw);
40719 this.list.on('mouseover', this.onViewOver, this);
40720 this.list.on('mousemove', this.onViewMove, this);
40721 this.list.on('scroll', this.onViewScroll, this);
40724 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
40727 this.view = new Roo.View(this.list, this.tpl, {
40728 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40731 this.view.on('click', this.onViewClick, this);
40733 this.store.on('beforeload', this.onBeforeLoad, this);
40734 this.store.on('load', this.onLoad, this);
40735 this.store.on('loadexception', this.onLoadException, this);
40737 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
40738 "up" : function(e){
40739 this.inKeyMode = true;
40743 "down" : function(e){
40744 if(!this.isExpanded()){
40745 this.onTriggerClick();
40747 this.inKeyMode = true;
40752 "enter" : function(e){
40755 if(this.fireEvent("specialkey", this, e)){
40756 this.onViewClick(false);
40762 "esc" : function(e){
40766 "tab" : function(e){
40769 if(this.fireEvent("specialkey", this, e)){
40770 this.onViewClick(false);
40778 doRelay : function(foo, bar, hname){
40779 if(hname == 'down' || this.scope.isExpanded()){
40780 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
40788 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
40792 initNumberEvent : function(e)
40794 this.inputEl().on("keydown" , this.fireKey, this);
40795 this.inputEl().on("focus", this.onFocus, this);
40796 this.inputEl().on("blur", this.onBlur, this);
40798 this.inputEl().relayEvent('keyup', this);
40800 if(this.indicator){
40801 this.indicator.addClass('invisible');
40804 this.originalValue = this.getValue();
40806 if(this.validationEvent == 'keyup'){
40807 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
40808 this.inputEl().on('keyup', this.filterValidation, this);
40810 else if(this.validationEvent !== false){
40811 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
40814 if(this.selectOnFocus){
40815 this.on("focus", this.preFocus, this);
40818 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
40819 this.inputEl().on("keypress", this.filterKeys, this);
40821 this.inputEl().relayEvent('keypress', this);
40824 var allowed = "0123456789";
40826 if(this.allowDecimals){
40827 allowed += this.decimalSeparator;
40830 if(this.allowNegative){
40834 if(this.thousandsDelimiter) {
40838 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
40840 var keyPress = function(e){
40842 var k = e.getKey();
40844 var c = e.getCharCode();
40847 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40848 allowed.indexOf(String.fromCharCode(c)) === -1
40854 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40858 if(allowed.indexOf(String.fromCharCode(c)) === -1){
40863 this.inputEl().on("keypress", keyPress, this);
40867 onTriggerClick : function(e)
40874 this.loadNext = false;
40876 if(this.isExpanded()){
40881 this.hasFocus = true;
40883 if(this.triggerAction == 'all') {
40884 this.doQuery(this.allQuery, true);
40888 this.doQuery(this.getRawValue());
40891 getCurrency : function()
40893 var v = this.currencyEl().getValue();
40898 restrictHeight : function()
40900 this.list.alignTo(this.currencyEl(), this.listAlign);
40901 this.list.alignTo(this.currencyEl(), this.listAlign);
40904 onViewClick : function(view, doFocus, el, e)
40906 var index = this.view.getSelectedIndexes()[0];
40908 var r = this.store.getAt(index);
40911 this.onSelect(r, index);
40915 onSelect : function(record, index){
40917 if(this.fireEvent('beforeselect', this, record, index) !== false){
40919 this.setFromCurrencyData(index > -1 ? record.data : false);
40923 this.fireEvent('select', this, record, index);
40927 setFromCurrencyData : function(o)
40931 this.lastCurrency = o;
40933 if (this.currencyField) {
40934 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
40936 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
40939 this.lastSelectionText = currency;
40941 //setting default currency
40942 if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
40943 this.setCurrency(this.defaultCurrency);
40947 this.setCurrency(currency);
40950 setFromData : function(o)
40954 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
40956 this.setFromCurrencyData(c);
40961 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
40963 Roo.log('no value set for '+ (this.name ? this.name : this.id));
40966 this.setValue(value);
40970 setCurrency : function(v)
40972 this.currencyValue = v;
40975 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
40980 setValue : function(v)
40982 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
40988 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40990 this.inputEl().dom.value = (v == '') ? '' :
40991 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
40993 if(!this.allowZero && v === '0') {
40994 this.hiddenEl().dom.value = '';
40995 this.inputEl().dom.value = '';
41002 getRawValue : function()
41004 var v = this.inputEl().getValue();
41009 getValue : function()
41011 return this.fixPrecision(this.parseValue(this.getRawValue()));
41014 parseValue : function(value)
41016 if(this.thousandsDelimiter) {
41018 r = new RegExp(",", "g");
41019 value = value.replace(r, "");
41022 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
41023 return isNaN(value) ? '' : value;
41027 fixPrecision : function(value)
41029 if(this.thousandsDelimiter) {
41031 r = new RegExp(",", "g");
41032 value = value.replace(r, "");
41035 var nan = isNaN(value);
41037 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
41038 return nan ? '' : value;
41040 return parseFloat(value).toFixed(this.decimalPrecision);
41043 decimalPrecisionFcn : function(v)
41045 return Math.floor(v);
41048 validateValue : function(value)
41050 if(!Roo.bootstrap.MoneyField.superclass.validateValue.call(this, value)){
41054 var num = this.parseValue(value);
41057 this.markInvalid(String.format(this.nanText, value));
41061 if(num < this.minValue){
41062 this.markInvalid(String.format(this.minText, this.minValue));
41066 if(num > this.maxValue){
41067 this.markInvalid(String.format(this.maxText, this.maxValue));
41074 validate : function()
41076 if(this.disabled || this.allowBlank){
41081 var currency = this.getCurrency();
41083 if(this.validateValue(this.getRawValue()) && currency.length){
41088 this.markInvalid();
41092 getName: function()
41097 beforeBlur : function()
41103 var v = this.parseValue(this.getRawValue());
41110 onBlur : function()
41114 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
41115 //this.el.removeClass(this.focusClass);
41118 this.hasFocus = false;
41120 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
41124 var v = this.getValue();
41126 if(String(v) !== String(this.startValue)){
41127 this.fireEvent('change', this, v, this.startValue);
41130 this.fireEvent("blur", this);
41133 inputEl : function()
41135 return this.el.select('.roo-money-amount-input', true).first();
41138 currencyEl : function()
41140 return this.el.select('.roo-money-currency-input', true).first();
41143 hiddenEl : function()
41145 return this.el.select('input.hidden-number-input',true).first();