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 if (Roo.bootstrap.version == 4) {
24662 this.navgroup = new Roo.bootstrap.ButtonGroup({ cls: 'pagination' });
24665 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
24670 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
24672 * @cfg {Roo.data.Store} dataSource
24673 * The underlying data store providing the paged data
24676 * @cfg {String/HTMLElement/Element} container
24677 * container The id or element that will contain the toolbar
24680 * @cfg {Boolean} displayInfo
24681 * True to display the displayMsg (defaults to false)
24684 * @cfg {Number} pageSize
24685 * The number of records to display per page (defaults to 20)
24689 * @cfg {String} displayMsg
24690 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
24692 displayMsg : 'Displaying {0} - {1} of {2}',
24694 * @cfg {String} emptyMsg
24695 * The message to display when no records are found (defaults to "No data to display")
24697 emptyMsg : 'No data to display',
24699 * Customizable piece of the default paging text (defaults to "Page")
24702 beforePageText : "Page",
24704 * Customizable piece of the default paging text (defaults to "of %0")
24707 afterPageText : "of {0}",
24709 * Customizable piece of the default paging text (defaults to "First Page")
24712 firstText : "First Page",
24714 * Customizable piece of the default paging text (defaults to "Previous Page")
24717 prevText : "Previous Page",
24719 * Customizable piece of the default paging text (defaults to "Next Page")
24722 nextText : "Next Page",
24724 * Customizable piece of the default paging text (defaults to "Last Page")
24727 lastText : "Last Page",
24729 * Customizable piece of the default paging text (defaults to "Refresh")
24732 refreshText : "Refresh",
24736 onRender : function(ct, position)
24738 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
24739 this.navgroup.parentId = this.id;
24740 this.navgroup.onRender(this.el, null);
24741 // add the buttons to the navgroup
24743 if(this.displayInfo){
24744 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
24745 this.displayEl = this.el.select('.x-paging-info', true).first();
24746 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
24747 // this.displayEl = navel.el.select('span',true).first();
24753 Roo.each(_this.buttons, function(e){ // this might need to use render????
24754 Roo.factory(e).render(_this.el);
24758 Roo.each(_this.toolbarItems, function(e) {
24759 _this.navgroup.addItem(e);
24763 this.first = this.navgroup.addItem({
24764 tooltip: this.firstText,
24766 icon : 'fa fa-step-backward',
24768 preventDefault: true,
24769 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
24772 this.prev = this.navgroup.addItem({
24773 tooltip: this.prevText,
24775 icon : 'fa fa-backward',
24777 preventDefault: true,
24778 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
24780 //this.addSeparator();
24783 var field = this.navgroup.addItem( {
24785 cls : 'x-paging-position',
24787 html : this.beforePageText +
24788 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
24789 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
24792 this.field = field.el.select('input', true).first();
24793 this.field.on("keydown", this.onPagingKeydown, this);
24794 this.field.on("focus", function(){this.dom.select();});
24797 this.afterTextEl = field.el.select('.x-paging-after',true).first();
24798 //this.field.setHeight(18);
24799 //this.addSeparator();
24800 this.next = this.navgroup.addItem({
24801 tooltip: this.nextText,
24803 html : ' <i class="fa fa-forward">',
24805 preventDefault: true,
24806 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
24808 this.last = this.navgroup.addItem({
24809 tooltip: this.lastText,
24810 icon : 'fa fa-step-forward',
24813 preventDefault: true,
24814 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
24816 //this.addSeparator();
24817 this.loading = this.navgroup.addItem({
24818 tooltip: this.refreshText,
24819 icon: 'fa fa-refresh',
24820 preventDefault: true,
24821 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
24827 updateInfo : function(){
24828 if(this.displayEl){
24829 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
24830 var msg = count == 0 ?
24834 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
24836 this.displayEl.update(msg);
24841 onLoad : function(ds, r, o)
24843 this.cursor = o.params.start ? o.params.start : 0;
24845 var d = this.getPageData(),
24850 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
24851 this.field.dom.value = ap;
24852 this.first.setDisabled(ap == 1);
24853 this.prev.setDisabled(ap == 1);
24854 this.next.setDisabled(ap == ps);
24855 this.last.setDisabled(ap == ps);
24856 this.loading.enable();
24861 getPageData : function(){
24862 var total = this.ds.getTotalCount();
24865 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
24866 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
24871 onLoadError : function(){
24872 this.loading.enable();
24876 onPagingKeydown : function(e){
24877 var k = e.getKey();
24878 var d = this.getPageData();
24880 var v = this.field.dom.value, pageNum;
24881 if(!v || isNaN(pageNum = parseInt(v, 10))){
24882 this.field.dom.value = d.activePage;
24885 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
24886 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24889 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))
24891 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
24892 this.field.dom.value = pageNum;
24893 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
24896 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
24898 var v = this.field.dom.value, pageNum;
24899 var increment = (e.shiftKey) ? 10 : 1;
24900 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
24903 if(!v || isNaN(pageNum = parseInt(v, 10))) {
24904 this.field.dom.value = d.activePage;
24907 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
24909 this.field.dom.value = parseInt(v, 10) + increment;
24910 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
24911 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24918 beforeLoad : function(){
24920 this.loading.disable();
24925 onClick : function(which){
24934 ds.load({params:{start: 0, limit: this.pageSize}});
24937 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
24940 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
24943 var total = ds.getTotalCount();
24944 var extra = total % this.pageSize;
24945 var lastStart = extra ? (total - extra) : total-this.pageSize;
24946 ds.load({params:{start: lastStart, limit: this.pageSize}});
24949 ds.load({params:{start: this.cursor, limit: this.pageSize}});
24955 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
24956 * @param {Roo.data.Store} store The data store to unbind
24958 unbind : function(ds){
24959 ds.un("beforeload", this.beforeLoad, this);
24960 ds.un("load", this.onLoad, this);
24961 ds.un("loadexception", this.onLoadError, this);
24962 ds.un("remove", this.updateInfo, this);
24963 ds.un("add", this.updateInfo, this);
24964 this.ds = undefined;
24968 * Binds the paging toolbar to the specified {@link Roo.data.Store}
24969 * @param {Roo.data.Store} store The data store to bind
24971 bind : function(ds){
24972 ds.on("beforeload", this.beforeLoad, this);
24973 ds.on("load", this.onLoad, this);
24974 ds.on("loadexception", this.onLoadError, this);
24975 ds.on("remove", this.updateInfo, this);
24976 ds.on("add", this.updateInfo, this);
24987 * @class Roo.bootstrap.MessageBar
24988 * @extends Roo.bootstrap.Component
24989 * Bootstrap MessageBar class
24990 * @cfg {String} html contents of the MessageBar
24991 * @cfg {String} weight (info | success | warning | danger) default info
24992 * @cfg {String} beforeClass insert the bar before the given class
24993 * @cfg {Boolean} closable (true | false) default false
24994 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
24997 * Create a new Element
24998 * @param {Object} config The config object
25001 Roo.bootstrap.MessageBar = function(config){
25002 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
25005 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
25011 beforeClass: 'bootstrap-sticky-wrap',
25013 getAutoCreate : function(){
25017 cls: 'alert alert-dismissable alert-' + this.weight,
25022 html: this.html || ''
25028 cfg.cls += ' alert-messages-fixed';
25042 onRender : function(ct, position)
25044 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
25047 var cfg = Roo.apply({}, this.getAutoCreate());
25051 cfg.cls += ' ' + this.cls;
25054 cfg.style = this.style;
25056 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
25058 this.el.setVisibilityMode(Roo.Element.DISPLAY);
25061 this.el.select('>button.close').on('click', this.hide, this);
25067 if (!this.rendered) {
25073 this.fireEvent('show', this);
25079 if (!this.rendered) {
25085 this.fireEvent('hide', this);
25088 update : function()
25090 // var e = this.el.dom.firstChild;
25092 // if(this.closable){
25093 // e = e.nextSibling;
25096 // e.data = this.html || '';
25098 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
25114 * @class Roo.bootstrap.Graph
25115 * @extends Roo.bootstrap.Component
25116 * Bootstrap Graph class
25120 @cfg {String} graphtype bar | vbar | pie
25121 @cfg {number} g_x coodinator | centre x (pie)
25122 @cfg {number} g_y coodinator | centre y (pie)
25123 @cfg {number} g_r radius (pie)
25124 @cfg {number} g_height height of the chart (respected by all elements in the set)
25125 @cfg {number} g_width width of the chart (respected by all elements in the set)
25126 @cfg {Object} title The title of the chart
25129 -opts (object) options for the chart
25131 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
25132 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
25134 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.
25135 o stacked (boolean) whether or not to tread values as in a stacked bar chart
25137 o stretch (boolean)
25139 -opts (object) options for the pie
25142 o startAngle (number)
25143 o endAngle (number)
25147 * Create a new Input
25148 * @param {Object} config The config object
25151 Roo.bootstrap.Graph = function(config){
25152 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
25158 * The img click event for the img.
25159 * @param {Roo.EventObject} e
25165 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
25176 //g_colors: this.colors,
25183 getAutoCreate : function(){
25194 onRender : function(ct,position){
25197 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
25199 if (typeof(Raphael) == 'undefined') {
25200 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
25204 this.raphael = Raphael(this.el.dom);
25206 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25207 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25208 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25209 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
25211 r.text(160, 10, "Single Series Chart").attr(txtattr);
25212 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
25213 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
25214 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
25216 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
25217 r.barchart(330, 10, 300, 220, data1);
25218 r.barchart(10, 250, 300, 220, data2, {stacked: true});
25219 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
25222 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25223 // r.barchart(30, 30, 560, 250, xdata, {
25224 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
25225 // axis : "0 0 1 1",
25226 // axisxlabels : xdata
25227 // //yvalues : cols,
25230 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25232 // this.load(null,xdata,{
25233 // axis : "0 0 1 1",
25234 // axisxlabels : xdata
25239 load : function(graphtype,xdata,opts)
25241 this.raphael.clear();
25243 graphtype = this.graphtype;
25248 var r = this.raphael,
25249 fin = function () {
25250 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
25252 fout = function () {
25253 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
25255 pfin = function() {
25256 this.sector.stop();
25257 this.sector.scale(1.1, 1.1, this.cx, this.cy);
25260 this.label[0].stop();
25261 this.label[0].attr({ r: 7.5 });
25262 this.label[1].attr({ "font-weight": 800 });
25265 pfout = function() {
25266 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
25269 this.label[0].animate({ r: 5 }, 500, "bounce");
25270 this.label[1].attr({ "font-weight": 400 });
25276 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25279 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25282 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
25283 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
25285 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
25292 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
25297 setTitle: function(o)
25302 initEvents: function() {
25305 this.el.on('click', this.onClick, this);
25309 onClick : function(e)
25311 Roo.log('img onclick');
25312 this.fireEvent('click', this, e);
25324 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25327 * @class Roo.bootstrap.dash.NumberBox
25328 * @extends Roo.bootstrap.Component
25329 * Bootstrap NumberBox class
25330 * @cfg {String} headline Box headline
25331 * @cfg {String} content Box content
25332 * @cfg {String} icon Box icon
25333 * @cfg {String} footer Footer text
25334 * @cfg {String} fhref Footer href
25337 * Create a new NumberBox
25338 * @param {Object} config The config object
25342 Roo.bootstrap.dash.NumberBox = function(config){
25343 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
25347 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
25356 getAutoCreate : function(){
25360 cls : 'small-box ',
25368 cls : 'roo-headline',
25369 html : this.headline
25373 cls : 'roo-content',
25374 html : this.content
25388 cls : 'ion ' + this.icon
25397 cls : 'small-box-footer',
25398 href : this.fhref || '#',
25402 cfg.cn.push(footer);
25409 onRender : function(ct,position){
25410 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
25417 setHeadline: function (value)
25419 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
25422 setFooter: function (value, href)
25424 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
25427 this.el.select('a.small-box-footer',true).first().attr('href', href);
25432 setContent: function (value)
25434 this.el.select('.roo-content',true).first().dom.innerHTML = value;
25437 initEvents: function()
25451 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25454 * @class Roo.bootstrap.dash.TabBox
25455 * @extends Roo.bootstrap.Component
25456 * Bootstrap TabBox class
25457 * @cfg {String} title Title of the TabBox
25458 * @cfg {String} icon Icon of the TabBox
25459 * @cfg {Boolean} showtabs (true|false) show the tabs default true
25460 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
25463 * Create a new TabBox
25464 * @param {Object} config The config object
25468 Roo.bootstrap.dash.TabBox = function(config){
25469 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
25474 * When a pane is added
25475 * @param {Roo.bootstrap.dash.TabPane} pane
25479 * @event activatepane
25480 * When a pane is activated
25481 * @param {Roo.bootstrap.dash.TabPane} pane
25483 "activatepane" : true
25491 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
25496 tabScrollable : false,
25498 getChildContainer : function()
25500 return this.el.select('.tab-content', true).first();
25503 getAutoCreate : function(){
25507 cls: 'pull-left header',
25515 cls: 'fa ' + this.icon
25521 cls: 'nav nav-tabs pull-right',
25527 if(this.tabScrollable){
25534 cls: 'nav nav-tabs pull-right',
25545 cls: 'nav-tabs-custom',
25550 cls: 'tab-content no-padding',
25558 initEvents : function()
25560 //Roo.log('add add pane handler');
25561 this.on('addpane', this.onAddPane, this);
25564 * Updates the box title
25565 * @param {String} html to set the title to.
25567 setTitle : function(value)
25569 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
25571 onAddPane : function(pane)
25573 this.panes.push(pane);
25574 //Roo.log('addpane');
25576 // tabs are rendere left to right..
25577 if(!this.showtabs){
25581 var ctr = this.el.select('.nav-tabs', true).first();
25584 var existing = ctr.select('.nav-tab',true);
25585 var qty = existing.getCount();;
25588 var tab = ctr.createChild({
25590 cls : 'nav-tab' + (qty ? '' : ' active'),
25598 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
25601 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
25603 pane.el.addClass('active');
25608 onTabClick : function(ev,un,ob,pane)
25610 //Roo.log('tab - prev default');
25611 ev.preventDefault();
25614 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
25615 pane.tab.addClass('active');
25616 //Roo.log(pane.title);
25617 this.getChildContainer().select('.tab-pane',true).removeClass('active');
25618 // technically we should have a deactivate event.. but maybe add later.
25619 // and it should not de-activate the selected tab...
25620 this.fireEvent('activatepane', pane);
25621 pane.el.addClass('active');
25622 pane.fireEvent('activate');
25627 getActivePane : function()
25630 Roo.each(this.panes, function(p) {
25631 if(p.el.hasClass('active')){
25652 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25654 * @class Roo.bootstrap.TabPane
25655 * @extends Roo.bootstrap.Component
25656 * Bootstrap TabPane class
25657 * @cfg {Boolean} active (false | true) Default false
25658 * @cfg {String} title title of panel
25662 * Create a new TabPane
25663 * @param {Object} config The config object
25666 Roo.bootstrap.dash.TabPane = function(config){
25667 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
25673 * When a pane is activated
25674 * @param {Roo.bootstrap.dash.TabPane} pane
25681 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
25686 // the tabBox that this is attached to.
25689 getAutoCreate : function()
25697 cfg.cls += ' active';
25702 initEvents : function()
25704 //Roo.log('trigger add pane handler');
25705 this.parent().fireEvent('addpane', this)
25709 * Updates the tab title
25710 * @param {String} html to set the title to.
25712 setTitle: function(str)
25718 this.tab.select('a', true).first().dom.innerHTML = str;
25735 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25738 * @class Roo.bootstrap.menu.Menu
25739 * @extends Roo.bootstrap.Component
25740 * Bootstrap Menu class - container for Menu
25741 * @cfg {String} html Text of the menu
25742 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
25743 * @cfg {String} icon Font awesome icon
25744 * @cfg {String} pos Menu align to (top | bottom) default bottom
25748 * Create a new Menu
25749 * @param {Object} config The config object
25753 Roo.bootstrap.menu.Menu = function(config){
25754 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
25758 * @event beforeshow
25759 * Fires before this menu is displayed
25760 * @param {Roo.bootstrap.menu.Menu} this
25764 * @event beforehide
25765 * Fires before this menu is hidden
25766 * @param {Roo.bootstrap.menu.Menu} this
25771 * Fires after this menu is displayed
25772 * @param {Roo.bootstrap.menu.Menu} this
25777 * Fires after this menu is hidden
25778 * @param {Roo.bootstrap.menu.Menu} this
25783 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
25784 * @param {Roo.bootstrap.menu.Menu} this
25785 * @param {Roo.EventObject} e
25792 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
25796 weight : 'default',
25801 getChildContainer : function() {
25802 if(this.isSubMenu){
25806 return this.el.select('ul.dropdown-menu', true).first();
25809 getAutoCreate : function()
25814 cls : 'roo-menu-text',
25822 cls : 'fa ' + this.icon
25833 cls : 'dropdown-button btn btn-' + this.weight,
25838 cls : 'dropdown-toggle btn btn-' + this.weight,
25848 cls : 'dropdown-menu'
25854 if(this.pos == 'top'){
25855 cfg.cls += ' dropup';
25858 if(this.isSubMenu){
25861 cls : 'dropdown-menu'
25868 onRender : function(ct, position)
25870 this.isSubMenu = ct.hasClass('dropdown-submenu');
25872 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
25875 initEvents : function()
25877 if(this.isSubMenu){
25881 this.hidden = true;
25883 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
25884 this.triggerEl.on('click', this.onTriggerPress, this);
25886 this.buttonEl = this.el.select('button.dropdown-button', true).first();
25887 this.buttonEl.on('click', this.onClick, this);
25893 if(this.isSubMenu){
25897 return this.el.select('ul.dropdown-menu', true).first();
25900 onClick : function(e)
25902 this.fireEvent("click", this, e);
25905 onTriggerPress : function(e)
25907 if (this.isVisible()) {
25914 isVisible : function(){
25915 return !this.hidden;
25920 this.fireEvent("beforeshow", this);
25922 this.hidden = false;
25923 this.el.addClass('open');
25925 Roo.get(document).on("mouseup", this.onMouseUp, this);
25927 this.fireEvent("show", this);
25934 this.fireEvent("beforehide", this);
25936 this.hidden = true;
25937 this.el.removeClass('open');
25939 Roo.get(document).un("mouseup", this.onMouseUp);
25941 this.fireEvent("hide", this);
25944 onMouseUp : function()
25958 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25961 * @class Roo.bootstrap.menu.Item
25962 * @extends Roo.bootstrap.Component
25963 * Bootstrap MenuItem class
25964 * @cfg {Boolean} submenu (true | false) default false
25965 * @cfg {String} html text of the item
25966 * @cfg {String} href the link
25967 * @cfg {Boolean} disable (true | false) default false
25968 * @cfg {Boolean} preventDefault (true | false) default true
25969 * @cfg {String} icon Font awesome icon
25970 * @cfg {String} pos Submenu align to (left | right) default right
25974 * Create a new Item
25975 * @param {Object} config The config object
25979 Roo.bootstrap.menu.Item = function(config){
25980 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
25984 * Fires when the mouse is hovering over this menu
25985 * @param {Roo.bootstrap.menu.Item} this
25986 * @param {Roo.EventObject} e
25991 * Fires when the mouse exits this menu
25992 * @param {Roo.bootstrap.menu.Item} this
25993 * @param {Roo.EventObject} e
25999 * The raw click event for the entire grid.
26000 * @param {Roo.EventObject} e
26006 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
26011 preventDefault: true,
26016 getAutoCreate : function()
26021 cls : 'roo-menu-item-text',
26029 cls : 'fa ' + this.icon
26038 href : this.href || '#',
26045 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
26049 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
26051 if(this.pos == 'left'){
26052 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
26059 initEvents : function()
26061 this.el.on('mouseover', this.onMouseOver, this);
26062 this.el.on('mouseout', this.onMouseOut, this);
26064 this.el.select('a', true).first().on('click', this.onClick, this);
26068 onClick : function(e)
26070 if(this.preventDefault){
26071 e.preventDefault();
26074 this.fireEvent("click", this, e);
26077 onMouseOver : function(e)
26079 if(this.submenu && this.pos == 'left'){
26080 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
26083 this.fireEvent("mouseover", this, e);
26086 onMouseOut : function(e)
26088 this.fireEvent("mouseout", this, e);
26100 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
26103 * @class Roo.bootstrap.menu.Separator
26104 * @extends Roo.bootstrap.Component
26105 * Bootstrap Separator class
26108 * Create a new Separator
26109 * @param {Object} config The config object
26113 Roo.bootstrap.menu.Separator = function(config){
26114 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
26117 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
26119 getAutoCreate : function(){
26140 * @class Roo.bootstrap.Tooltip
26141 * Bootstrap Tooltip class
26142 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
26143 * to determine which dom element triggers the tooltip.
26145 * It needs to add support for additional attributes like tooltip-position
26148 * Create a new Toolti
26149 * @param {Object} config The config object
26152 Roo.bootstrap.Tooltip = function(config){
26153 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
26155 this.alignment = Roo.bootstrap.Tooltip.alignment;
26157 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
26158 this.alignment = config.alignment;
26163 Roo.apply(Roo.bootstrap.Tooltip, {
26165 * @function init initialize tooltip monitoring.
26169 currentTip : false,
26170 currentRegion : false,
26176 Roo.get(document).on('mouseover', this.enter ,this);
26177 Roo.get(document).on('mouseout', this.leave, this);
26180 this.currentTip = new Roo.bootstrap.Tooltip();
26183 enter : function(ev)
26185 var dom = ev.getTarget();
26187 //Roo.log(['enter',dom]);
26188 var el = Roo.fly(dom);
26189 if (this.currentEl) {
26191 //Roo.log(this.currentEl);
26192 //Roo.log(this.currentEl.contains(dom));
26193 if (this.currentEl == el) {
26196 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
26202 if (this.currentTip.el) {
26203 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
26207 if(!el || el.dom == document){
26213 // you can not look for children, as if el is the body.. then everythign is the child..
26214 if (!el.attr('tooltip')) { //
26215 if (!el.select("[tooltip]").elements.length) {
26218 // is the mouse over this child...?
26219 bindEl = el.select("[tooltip]").first();
26220 var xy = ev.getXY();
26221 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
26222 //Roo.log("not in region.");
26225 //Roo.log("child element over..");
26228 this.currentEl = bindEl;
26229 this.currentTip.bind(bindEl);
26230 this.currentRegion = Roo.lib.Region.getRegion(dom);
26231 this.currentTip.enter();
26234 leave : function(ev)
26236 var dom = ev.getTarget();
26237 //Roo.log(['leave',dom]);
26238 if (!this.currentEl) {
26243 if (dom != this.currentEl.dom) {
26246 var xy = ev.getXY();
26247 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
26250 // only activate leave if mouse cursor is outside... bounding box..
26255 if (this.currentTip) {
26256 this.currentTip.leave();
26258 //Roo.log('clear currentEl');
26259 this.currentEl = false;
26264 'left' : ['r-l', [-2,0], 'right'],
26265 'right' : ['l-r', [2,0], 'left'],
26266 'bottom' : ['t-b', [0,2], 'top'],
26267 'top' : [ 'b-t', [0,-2], 'bottom']
26273 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
26278 delay : null, // can be { show : 300 , hide: 500}
26282 hoverState : null, //???
26284 placement : 'bottom',
26288 getAutoCreate : function(){
26295 cls : 'tooltip-arrow'
26298 cls : 'tooltip-inner'
26305 bind : function(el)
26311 enter : function () {
26313 if (this.timeout != null) {
26314 clearTimeout(this.timeout);
26317 this.hoverState = 'in';
26318 //Roo.log("enter - show");
26319 if (!this.delay || !this.delay.show) {
26324 this.timeout = setTimeout(function () {
26325 if (_t.hoverState == 'in') {
26328 }, this.delay.show);
26332 clearTimeout(this.timeout);
26334 this.hoverState = 'out';
26335 if (!this.delay || !this.delay.hide) {
26341 this.timeout = setTimeout(function () {
26342 //Roo.log("leave - timeout");
26344 if (_t.hoverState == 'out') {
26346 Roo.bootstrap.Tooltip.currentEl = false;
26351 show : function (msg)
26354 this.render(document.body);
26357 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
26359 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
26361 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
26363 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
26365 var placement = typeof this.placement == 'function' ?
26366 this.placement.call(this, this.el, on_el) :
26369 var autoToken = /\s?auto?\s?/i;
26370 var autoPlace = autoToken.test(placement);
26372 placement = placement.replace(autoToken, '') || 'top';
26376 //this.el.setXY([0,0]);
26378 //this.el.dom.style.display='block';
26380 //this.el.appendTo(on_el);
26382 var p = this.getPosition();
26383 var box = this.el.getBox();
26389 var align = this.alignment[placement];
26391 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
26393 if(placement == 'top' || placement == 'bottom'){
26395 placement = 'right';
26398 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
26399 placement = 'left';
26402 var scroll = Roo.select('body', true).first().getScroll();
26404 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
26408 align = this.alignment[placement];
26411 this.el.alignTo(this.bindEl, align[0],align[1]);
26412 //var arrow = this.el.select('.arrow',true).first();
26413 //arrow.set(align[2],
26415 this.el.addClass(placement);
26417 this.el.addClass('in fade');
26419 this.hoverState = null;
26421 if (this.el.hasClass('fade')) {
26432 //this.el.setXY([0,0]);
26433 this.el.removeClass('in');
26449 * @class Roo.bootstrap.LocationPicker
26450 * @extends Roo.bootstrap.Component
26451 * Bootstrap LocationPicker class
26452 * @cfg {Number} latitude Position when init default 0
26453 * @cfg {Number} longitude Position when init default 0
26454 * @cfg {Number} zoom default 15
26455 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
26456 * @cfg {Boolean} mapTypeControl default false
26457 * @cfg {Boolean} disableDoubleClickZoom default false
26458 * @cfg {Boolean} scrollwheel default true
26459 * @cfg {Boolean} streetViewControl default false
26460 * @cfg {Number} radius default 0
26461 * @cfg {String} locationName
26462 * @cfg {Boolean} draggable default true
26463 * @cfg {Boolean} enableAutocomplete default false
26464 * @cfg {Boolean} enableReverseGeocode default true
26465 * @cfg {String} markerTitle
26468 * Create a new LocationPicker
26469 * @param {Object} config The config object
26473 Roo.bootstrap.LocationPicker = function(config){
26475 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
26480 * Fires when the picker initialized.
26481 * @param {Roo.bootstrap.LocationPicker} this
26482 * @param {Google Location} location
26486 * @event positionchanged
26487 * Fires when the picker position changed.
26488 * @param {Roo.bootstrap.LocationPicker} this
26489 * @param {Google Location} location
26491 positionchanged : true,
26494 * Fires when the map resize.
26495 * @param {Roo.bootstrap.LocationPicker} this
26500 * Fires when the map show.
26501 * @param {Roo.bootstrap.LocationPicker} this
26506 * Fires when the map hide.
26507 * @param {Roo.bootstrap.LocationPicker} this
26512 * Fires when click the map.
26513 * @param {Roo.bootstrap.LocationPicker} this
26514 * @param {Map event} e
26518 * @event mapRightClick
26519 * Fires when right click the map.
26520 * @param {Roo.bootstrap.LocationPicker} this
26521 * @param {Map event} e
26523 mapRightClick : true,
26525 * @event markerClick
26526 * Fires when click the marker.
26527 * @param {Roo.bootstrap.LocationPicker} this
26528 * @param {Map event} e
26530 markerClick : true,
26532 * @event markerRightClick
26533 * Fires when right click the marker.
26534 * @param {Roo.bootstrap.LocationPicker} this
26535 * @param {Map event} e
26537 markerRightClick : true,
26539 * @event OverlayViewDraw
26540 * Fires when OverlayView Draw
26541 * @param {Roo.bootstrap.LocationPicker} this
26543 OverlayViewDraw : true,
26545 * @event OverlayViewOnAdd
26546 * Fires when OverlayView Draw
26547 * @param {Roo.bootstrap.LocationPicker} this
26549 OverlayViewOnAdd : true,
26551 * @event OverlayViewOnRemove
26552 * Fires when OverlayView Draw
26553 * @param {Roo.bootstrap.LocationPicker} this
26555 OverlayViewOnRemove : true,
26557 * @event OverlayViewShow
26558 * Fires when OverlayView Draw
26559 * @param {Roo.bootstrap.LocationPicker} this
26560 * @param {Pixel} cpx
26562 OverlayViewShow : true,
26564 * @event OverlayViewHide
26565 * Fires when OverlayView Draw
26566 * @param {Roo.bootstrap.LocationPicker} this
26568 OverlayViewHide : true,
26570 * @event loadexception
26571 * Fires when load google lib failed.
26572 * @param {Roo.bootstrap.LocationPicker} this
26574 loadexception : true
26579 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
26581 gMapContext: false,
26587 mapTypeControl: false,
26588 disableDoubleClickZoom: false,
26590 streetViewControl: false,
26594 enableAutocomplete: false,
26595 enableReverseGeocode: true,
26598 getAutoCreate: function()
26603 cls: 'roo-location-picker'
26609 initEvents: function(ct, position)
26611 if(!this.el.getWidth() || this.isApplied()){
26615 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26620 initial: function()
26622 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
26623 this.fireEvent('loadexception', this);
26627 if(!this.mapTypeId){
26628 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
26631 this.gMapContext = this.GMapContext();
26633 this.initOverlayView();
26635 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
26639 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
26640 _this.setPosition(_this.gMapContext.marker.position);
26643 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
26644 _this.fireEvent('mapClick', this, event);
26648 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
26649 _this.fireEvent('mapRightClick', this, event);
26653 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
26654 _this.fireEvent('markerClick', this, event);
26658 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
26659 _this.fireEvent('markerRightClick', this, event);
26663 this.setPosition(this.gMapContext.location);
26665 this.fireEvent('initial', this, this.gMapContext.location);
26668 initOverlayView: function()
26672 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
26676 _this.fireEvent('OverlayViewDraw', _this);
26681 _this.fireEvent('OverlayViewOnAdd', _this);
26684 onRemove: function()
26686 _this.fireEvent('OverlayViewOnRemove', _this);
26689 show: function(cpx)
26691 _this.fireEvent('OverlayViewShow', _this, cpx);
26696 _this.fireEvent('OverlayViewHide', _this);
26702 fromLatLngToContainerPixel: function(event)
26704 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
26707 isApplied: function()
26709 return this.getGmapContext() == false ? false : true;
26712 getGmapContext: function()
26714 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
26717 GMapContext: function()
26719 var position = new google.maps.LatLng(this.latitude, this.longitude);
26721 var _map = new google.maps.Map(this.el.dom, {
26724 mapTypeId: this.mapTypeId,
26725 mapTypeControl: this.mapTypeControl,
26726 disableDoubleClickZoom: this.disableDoubleClickZoom,
26727 scrollwheel: this.scrollwheel,
26728 streetViewControl: this.streetViewControl,
26729 locationName: this.locationName,
26730 draggable: this.draggable,
26731 enableAutocomplete: this.enableAutocomplete,
26732 enableReverseGeocode: this.enableReverseGeocode
26735 var _marker = new google.maps.Marker({
26736 position: position,
26738 title: this.markerTitle,
26739 draggable: this.draggable
26746 location: position,
26747 radius: this.radius,
26748 locationName: this.locationName,
26749 addressComponents: {
26750 formatted_address: null,
26751 addressLine1: null,
26752 addressLine2: null,
26754 streetNumber: null,
26758 stateOrProvince: null
26761 domContainer: this.el.dom,
26762 geodecoder: new google.maps.Geocoder()
26766 drawCircle: function(center, radius, options)
26768 if (this.gMapContext.circle != null) {
26769 this.gMapContext.circle.setMap(null);
26773 options = Roo.apply({}, options, {
26774 strokeColor: "#0000FF",
26775 strokeOpacity: .35,
26777 fillColor: "#0000FF",
26781 options.map = this.gMapContext.map;
26782 options.radius = radius;
26783 options.center = center;
26784 this.gMapContext.circle = new google.maps.Circle(options);
26785 return this.gMapContext.circle;
26791 setPosition: function(location)
26793 this.gMapContext.location = location;
26794 this.gMapContext.marker.setPosition(location);
26795 this.gMapContext.map.panTo(location);
26796 this.drawCircle(location, this.gMapContext.radius, {});
26800 if (this.gMapContext.settings.enableReverseGeocode) {
26801 this.gMapContext.geodecoder.geocode({
26802 latLng: this.gMapContext.location
26803 }, function(results, status) {
26805 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
26806 _this.gMapContext.locationName = results[0].formatted_address;
26807 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
26809 _this.fireEvent('positionchanged', this, location);
26816 this.fireEvent('positionchanged', this, location);
26821 google.maps.event.trigger(this.gMapContext.map, "resize");
26823 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
26825 this.fireEvent('resize', this);
26828 setPositionByLatLng: function(latitude, longitude)
26830 this.setPosition(new google.maps.LatLng(latitude, longitude));
26833 getCurrentPosition: function()
26836 latitude: this.gMapContext.location.lat(),
26837 longitude: this.gMapContext.location.lng()
26841 getAddressName: function()
26843 return this.gMapContext.locationName;
26846 getAddressComponents: function()
26848 return this.gMapContext.addressComponents;
26851 address_component_from_google_geocode: function(address_components)
26855 for (var i = 0; i < address_components.length; i++) {
26856 var component = address_components[i];
26857 if (component.types.indexOf("postal_code") >= 0) {
26858 result.postalCode = component.short_name;
26859 } else if (component.types.indexOf("street_number") >= 0) {
26860 result.streetNumber = component.short_name;
26861 } else if (component.types.indexOf("route") >= 0) {
26862 result.streetName = component.short_name;
26863 } else if (component.types.indexOf("neighborhood") >= 0) {
26864 result.city = component.short_name;
26865 } else if (component.types.indexOf("locality") >= 0) {
26866 result.city = component.short_name;
26867 } else if (component.types.indexOf("sublocality") >= 0) {
26868 result.district = component.short_name;
26869 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
26870 result.stateOrProvince = component.short_name;
26871 } else if (component.types.indexOf("country") >= 0) {
26872 result.country = component.short_name;
26876 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
26877 result.addressLine2 = "";
26881 setZoomLevel: function(zoom)
26883 this.gMapContext.map.setZoom(zoom);
26896 this.fireEvent('show', this);
26907 this.fireEvent('hide', this);
26912 Roo.apply(Roo.bootstrap.LocationPicker, {
26914 OverlayView : function(map, options)
26916 options = options || {};
26930 * @class Roo.bootstrap.Alert
26931 * @extends Roo.bootstrap.Component
26932 * Bootstrap Alert class
26933 * @cfg {String} title The title of alert
26934 * @cfg {String} html The content of alert
26935 * @cfg {String} weight ( success | info | warning | danger )
26936 * @cfg {String} faicon font-awesomeicon
26939 * Create a new alert
26940 * @param {Object} config The config object
26944 Roo.bootstrap.Alert = function(config){
26945 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
26949 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
26956 getAutoCreate : function()
26965 cls : 'roo-alert-icon'
26970 cls : 'roo-alert-title',
26975 cls : 'roo-alert-text',
26982 cfg.cn[0].cls += ' fa ' + this.faicon;
26986 cfg.cls += ' alert-' + this.weight;
26992 initEvents: function()
26994 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26997 setTitle : function(str)
26999 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
27002 setText : function(str)
27004 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
27007 setWeight : function(weight)
27010 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
27013 this.weight = weight;
27015 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
27018 setIcon : function(icon)
27021 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
27024 this.faicon = icon;
27026 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
27047 * @class Roo.bootstrap.UploadCropbox
27048 * @extends Roo.bootstrap.Component
27049 * Bootstrap UploadCropbox class
27050 * @cfg {String} emptyText show when image has been loaded
27051 * @cfg {String} rotateNotify show when image too small to rotate
27052 * @cfg {Number} errorTimeout default 3000
27053 * @cfg {Number} minWidth default 300
27054 * @cfg {Number} minHeight default 300
27055 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
27056 * @cfg {Boolean} isDocument (true|false) default false
27057 * @cfg {String} url action url
27058 * @cfg {String} paramName default 'imageUpload'
27059 * @cfg {String} method default POST
27060 * @cfg {Boolean} loadMask (true|false) default true
27061 * @cfg {Boolean} loadingText default 'Loading...'
27064 * Create a new UploadCropbox
27065 * @param {Object} config The config object
27068 Roo.bootstrap.UploadCropbox = function(config){
27069 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
27073 * @event beforeselectfile
27074 * Fire before select file
27075 * @param {Roo.bootstrap.UploadCropbox} this
27077 "beforeselectfile" : true,
27080 * Fire after initEvent
27081 * @param {Roo.bootstrap.UploadCropbox} this
27086 * Fire after initEvent
27087 * @param {Roo.bootstrap.UploadCropbox} this
27088 * @param {String} data
27093 * Fire when preparing the file data
27094 * @param {Roo.bootstrap.UploadCropbox} this
27095 * @param {Object} file
27100 * Fire when get exception
27101 * @param {Roo.bootstrap.UploadCropbox} this
27102 * @param {XMLHttpRequest} xhr
27104 "exception" : true,
27106 * @event beforeloadcanvas
27107 * Fire before load the canvas
27108 * @param {Roo.bootstrap.UploadCropbox} this
27109 * @param {String} src
27111 "beforeloadcanvas" : true,
27114 * Fire when trash image
27115 * @param {Roo.bootstrap.UploadCropbox} this
27120 * Fire when download the image
27121 * @param {Roo.bootstrap.UploadCropbox} this
27125 * @event footerbuttonclick
27126 * Fire when footerbuttonclick
27127 * @param {Roo.bootstrap.UploadCropbox} this
27128 * @param {String} type
27130 "footerbuttonclick" : true,
27134 * @param {Roo.bootstrap.UploadCropbox} this
27139 * Fire when rotate the image
27140 * @param {Roo.bootstrap.UploadCropbox} this
27141 * @param {String} pos
27146 * Fire when inspect the file
27147 * @param {Roo.bootstrap.UploadCropbox} this
27148 * @param {Object} file
27153 * Fire when xhr upload the file
27154 * @param {Roo.bootstrap.UploadCropbox} this
27155 * @param {Object} data
27160 * Fire when arrange the file data
27161 * @param {Roo.bootstrap.UploadCropbox} this
27162 * @param {Object} formData
27167 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
27170 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
27172 emptyText : 'Click to upload image',
27173 rotateNotify : 'Image is too small to rotate',
27174 errorTimeout : 3000,
27188 cropType : 'image/jpeg',
27190 canvasLoaded : false,
27191 isDocument : false,
27193 paramName : 'imageUpload',
27195 loadingText : 'Loading...',
27198 getAutoCreate : function()
27202 cls : 'roo-upload-cropbox',
27206 cls : 'roo-upload-cropbox-selector',
27211 cls : 'roo-upload-cropbox-body',
27212 style : 'cursor:pointer',
27216 cls : 'roo-upload-cropbox-preview'
27220 cls : 'roo-upload-cropbox-thumb'
27224 cls : 'roo-upload-cropbox-empty-notify',
27225 html : this.emptyText
27229 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
27230 html : this.rotateNotify
27236 cls : 'roo-upload-cropbox-footer',
27239 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
27249 onRender : function(ct, position)
27251 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
27253 if (this.buttons.length) {
27255 Roo.each(this.buttons, function(bb) {
27257 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
27259 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
27265 this.maskEl = this.el;
27269 initEvents : function()
27271 this.urlAPI = (window.createObjectURL && window) ||
27272 (window.URL && URL.revokeObjectURL && URL) ||
27273 (window.webkitURL && webkitURL);
27275 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
27276 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27278 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
27279 this.selectorEl.hide();
27281 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
27282 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27284 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
27285 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27286 this.thumbEl.hide();
27288 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
27289 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27291 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
27292 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27293 this.errorEl.hide();
27295 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
27296 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27297 this.footerEl.hide();
27299 this.setThumbBoxSize();
27305 this.fireEvent('initial', this);
27312 window.addEventListener("resize", function() { _this.resize(); } );
27314 this.bodyEl.on('click', this.beforeSelectFile, this);
27317 this.bodyEl.on('touchstart', this.onTouchStart, this);
27318 this.bodyEl.on('touchmove', this.onTouchMove, this);
27319 this.bodyEl.on('touchend', this.onTouchEnd, this);
27323 this.bodyEl.on('mousedown', this.onMouseDown, this);
27324 this.bodyEl.on('mousemove', this.onMouseMove, this);
27325 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
27326 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
27327 Roo.get(document).on('mouseup', this.onMouseUp, this);
27330 this.selectorEl.on('change', this.onFileSelected, this);
27336 this.baseScale = 1;
27338 this.baseRotate = 1;
27339 this.dragable = false;
27340 this.pinching = false;
27343 this.cropData = false;
27344 this.notifyEl.dom.innerHTML = this.emptyText;
27346 this.selectorEl.dom.value = '';
27350 resize : function()
27352 if(this.fireEvent('resize', this) != false){
27353 this.setThumbBoxPosition();
27354 this.setCanvasPosition();
27358 onFooterButtonClick : function(e, el, o, type)
27361 case 'rotate-left' :
27362 this.onRotateLeft(e);
27364 case 'rotate-right' :
27365 this.onRotateRight(e);
27368 this.beforeSelectFile(e);
27383 this.fireEvent('footerbuttonclick', this, type);
27386 beforeSelectFile : function(e)
27388 e.preventDefault();
27390 if(this.fireEvent('beforeselectfile', this) != false){
27391 this.selectorEl.dom.click();
27395 onFileSelected : function(e)
27397 e.preventDefault();
27399 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
27403 var file = this.selectorEl.dom.files[0];
27405 if(this.fireEvent('inspect', this, file) != false){
27406 this.prepare(file);
27411 trash : function(e)
27413 this.fireEvent('trash', this);
27416 download : function(e)
27418 this.fireEvent('download', this);
27421 loadCanvas : function(src)
27423 if(this.fireEvent('beforeloadcanvas', this, src) != false){
27427 this.imageEl = document.createElement('img');
27431 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
27433 this.imageEl.src = src;
27437 onLoadCanvas : function()
27439 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
27440 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
27442 this.bodyEl.un('click', this.beforeSelectFile, this);
27444 this.notifyEl.hide();
27445 this.thumbEl.show();
27446 this.footerEl.show();
27448 this.baseRotateLevel();
27450 if(this.isDocument){
27451 this.setThumbBoxSize();
27454 this.setThumbBoxPosition();
27456 this.baseScaleLevel();
27462 this.canvasLoaded = true;
27465 this.maskEl.unmask();
27470 setCanvasPosition : function()
27472 if(!this.canvasEl){
27476 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
27477 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
27479 this.previewEl.setLeft(pw);
27480 this.previewEl.setTop(ph);
27484 onMouseDown : function(e)
27488 this.dragable = true;
27489 this.pinching = false;
27491 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
27492 this.dragable = false;
27496 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27497 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27501 onMouseMove : function(e)
27505 if(!this.canvasLoaded){
27509 if (!this.dragable){
27513 var minX = Math.ceil(this.thumbEl.getLeft(true));
27514 var minY = Math.ceil(this.thumbEl.getTop(true));
27516 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
27517 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
27519 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27520 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27522 x = x - this.mouseX;
27523 y = y - this.mouseY;
27525 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
27526 var bgY = Math.ceil(y + this.previewEl.getTop(true));
27528 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
27529 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
27531 this.previewEl.setLeft(bgX);
27532 this.previewEl.setTop(bgY);
27534 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27535 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27538 onMouseUp : function(e)
27542 this.dragable = false;
27545 onMouseWheel : function(e)
27549 this.startScale = this.scale;
27551 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
27553 if(!this.zoomable()){
27554 this.scale = this.startScale;
27563 zoomable : function()
27565 var minScale = this.thumbEl.getWidth() / this.minWidth;
27567 if(this.minWidth < this.minHeight){
27568 minScale = this.thumbEl.getHeight() / this.minHeight;
27571 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
27572 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
27576 (this.rotate == 0 || this.rotate == 180) &&
27578 width > this.imageEl.OriginWidth ||
27579 height > this.imageEl.OriginHeight ||
27580 (width < this.minWidth && height < this.minHeight)
27588 (this.rotate == 90 || this.rotate == 270) &&
27590 width > this.imageEl.OriginWidth ||
27591 height > this.imageEl.OriginHeight ||
27592 (width < this.minHeight && height < this.minWidth)
27599 !this.isDocument &&
27600 (this.rotate == 0 || this.rotate == 180) &&
27602 width < this.minWidth ||
27603 width > this.imageEl.OriginWidth ||
27604 height < this.minHeight ||
27605 height > this.imageEl.OriginHeight
27612 !this.isDocument &&
27613 (this.rotate == 90 || this.rotate == 270) &&
27615 width < this.minHeight ||
27616 width > this.imageEl.OriginWidth ||
27617 height < this.minWidth ||
27618 height > this.imageEl.OriginHeight
27628 onRotateLeft : function(e)
27630 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27632 var minScale = this.thumbEl.getWidth() / this.minWidth;
27634 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27635 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27637 this.startScale = this.scale;
27639 while (this.getScaleLevel() < minScale){
27641 this.scale = this.scale + 1;
27643 if(!this.zoomable()){
27648 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27649 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27654 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27661 this.scale = this.startScale;
27663 this.onRotateFail();
27668 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27670 if(this.isDocument){
27671 this.setThumbBoxSize();
27672 this.setThumbBoxPosition();
27673 this.setCanvasPosition();
27678 this.fireEvent('rotate', this, 'left');
27682 onRotateRight : function(e)
27684 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27686 var minScale = this.thumbEl.getWidth() / this.minWidth;
27688 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27689 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27691 this.startScale = this.scale;
27693 while (this.getScaleLevel() < minScale){
27695 this.scale = this.scale + 1;
27697 if(!this.zoomable()){
27702 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27703 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27708 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27715 this.scale = this.startScale;
27717 this.onRotateFail();
27722 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27724 if(this.isDocument){
27725 this.setThumbBoxSize();
27726 this.setThumbBoxPosition();
27727 this.setCanvasPosition();
27732 this.fireEvent('rotate', this, 'right');
27735 onRotateFail : function()
27737 this.errorEl.show(true);
27741 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
27746 this.previewEl.dom.innerHTML = '';
27748 var canvasEl = document.createElement("canvas");
27750 var contextEl = canvasEl.getContext("2d");
27752 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27753 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27754 var center = this.imageEl.OriginWidth / 2;
27756 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
27757 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27758 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27759 center = this.imageEl.OriginHeight / 2;
27762 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
27764 contextEl.translate(center, center);
27765 contextEl.rotate(this.rotate * Math.PI / 180);
27767 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27769 this.canvasEl = document.createElement("canvas");
27771 this.contextEl = this.canvasEl.getContext("2d");
27773 switch (this.rotate) {
27776 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27777 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27779 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27784 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27785 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27787 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27788 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);
27792 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27797 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27798 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27800 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27801 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);
27805 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);
27810 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27811 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27813 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27814 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27818 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);
27825 this.previewEl.appendChild(this.canvasEl);
27827 this.setCanvasPosition();
27832 if(!this.canvasLoaded){
27836 var imageCanvas = document.createElement("canvas");
27838 var imageContext = imageCanvas.getContext("2d");
27840 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27841 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27843 var center = imageCanvas.width / 2;
27845 imageContext.translate(center, center);
27847 imageContext.rotate(this.rotate * Math.PI / 180);
27849 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27851 var canvas = document.createElement("canvas");
27853 var context = canvas.getContext("2d");
27855 canvas.width = this.minWidth;
27856 canvas.height = this.minHeight;
27858 switch (this.rotate) {
27861 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27862 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27864 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27865 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27867 var targetWidth = this.minWidth - 2 * x;
27868 var targetHeight = this.minHeight - 2 * y;
27872 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27873 scale = targetWidth / width;
27876 if(x > 0 && y == 0){
27877 scale = targetHeight / height;
27880 if(x > 0 && y > 0){
27881 scale = targetWidth / width;
27883 if(width < height){
27884 scale = targetHeight / height;
27888 context.scale(scale, scale);
27890 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27891 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27893 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27894 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27896 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27901 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27902 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27904 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27905 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27907 var targetWidth = this.minWidth - 2 * x;
27908 var targetHeight = this.minHeight - 2 * y;
27912 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27913 scale = targetWidth / width;
27916 if(x > 0 && y == 0){
27917 scale = targetHeight / height;
27920 if(x > 0 && y > 0){
27921 scale = targetWidth / width;
27923 if(width < height){
27924 scale = targetHeight / height;
27928 context.scale(scale, scale);
27930 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27931 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27933 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27934 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27936 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27938 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27943 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27944 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27946 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27947 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27949 var targetWidth = this.minWidth - 2 * x;
27950 var targetHeight = this.minHeight - 2 * y;
27954 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27955 scale = targetWidth / width;
27958 if(x > 0 && y == 0){
27959 scale = targetHeight / height;
27962 if(x > 0 && y > 0){
27963 scale = targetWidth / width;
27965 if(width < height){
27966 scale = targetHeight / height;
27970 context.scale(scale, scale);
27972 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27973 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27975 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27976 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27978 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27979 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27981 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27986 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27987 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27989 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27990 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27992 var targetWidth = this.minWidth - 2 * x;
27993 var targetHeight = this.minHeight - 2 * y;
27997 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27998 scale = targetWidth / width;
28001 if(x > 0 && y == 0){
28002 scale = targetHeight / height;
28005 if(x > 0 && y > 0){
28006 scale = targetWidth / width;
28008 if(width < height){
28009 scale = targetHeight / height;
28013 context.scale(scale, scale);
28015 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
28016 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
28018 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
28019 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
28021 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
28023 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
28030 this.cropData = canvas.toDataURL(this.cropType);
28032 if(this.fireEvent('crop', this, this.cropData) !== false){
28033 this.process(this.file, this.cropData);
28040 setThumbBoxSize : function()
28044 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
28045 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
28046 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
28048 this.minWidth = width;
28049 this.minHeight = height;
28051 if(this.rotate == 90 || this.rotate == 270){
28052 this.minWidth = height;
28053 this.minHeight = width;
28058 width = Math.ceil(this.minWidth * height / this.minHeight);
28060 if(this.minWidth > this.minHeight){
28062 height = Math.ceil(this.minHeight * width / this.minWidth);
28065 this.thumbEl.setStyle({
28066 width : width + 'px',
28067 height : height + 'px'
28074 setThumbBoxPosition : function()
28076 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
28077 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
28079 this.thumbEl.setLeft(x);
28080 this.thumbEl.setTop(y);
28084 baseRotateLevel : function()
28086 this.baseRotate = 1;
28089 typeof(this.exif) != 'undefined' &&
28090 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
28091 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
28093 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
28096 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
28100 baseScaleLevel : function()
28104 if(this.isDocument){
28106 if(this.baseRotate == 6 || this.baseRotate == 8){
28108 height = this.thumbEl.getHeight();
28109 this.baseScale = height / this.imageEl.OriginWidth;
28111 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
28112 width = this.thumbEl.getWidth();
28113 this.baseScale = width / this.imageEl.OriginHeight;
28119 height = this.thumbEl.getHeight();
28120 this.baseScale = height / this.imageEl.OriginHeight;
28122 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
28123 width = this.thumbEl.getWidth();
28124 this.baseScale = width / this.imageEl.OriginWidth;
28130 if(this.baseRotate == 6 || this.baseRotate == 8){
28132 width = this.thumbEl.getHeight();
28133 this.baseScale = width / this.imageEl.OriginHeight;
28135 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
28136 height = this.thumbEl.getWidth();
28137 this.baseScale = height / this.imageEl.OriginHeight;
28140 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28141 height = this.thumbEl.getWidth();
28142 this.baseScale = height / this.imageEl.OriginHeight;
28144 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
28145 width = this.thumbEl.getHeight();
28146 this.baseScale = width / this.imageEl.OriginWidth;
28153 width = this.thumbEl.getWidth();
28154 this.baseScale = width / this.imageEl.OriginWidth;
28156 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
28157 height = this.thumbEl.getHeight();
28158 this.baseScale = height / this.imageEl.OriginHeight;
28161 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28163 height = this.thumbEl.getHeight();
28164 this.baseScale = height / this.imageEl.OriginHeight;
28166 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
28167 width = this.thumbEl.getWidth();
28168 this.baseScale = width / this.imageEl.OriginWidth;
28176 getScaleLevel : function()
28178 return this.baseScale * Math.pow(1.1, this.scale);
28181 onTouchStart : function(e)
28183 if(!this.canvasLoaded){
28184 this.beforeSelectFile(e);
28188 var touches = e.browserEvent.touches;
28194 if(touches.length == 1){
28195 this.onMouseDown(e);
28199 if(touches.length != 2){
28205 for(var i = 0, finger; finger = touches[i]; i++){
28206 coords.push(finger.pageX, finger.pageY);
28209 var x = Math.pow(coords[0] - coords[2], 2);
28210 var y = Math.pow(coords[1] - coords[3], 2);
28212 this.startDistance = Math.sqrt(x + y);
28214 this.startScale = this.scale;
28216 this.pinching = true;
28217 this.dragable = false;
28221 onTouchMove : function(e)
28223 if(!this.pinching && !this.dragable){
28227 var touches = e.browserEvent.touches;
28234 this.onMouseMove(e);
28240 for(var i = 0, finger; finger = touches[i]; i++){
28241 coords.push(finger.pageX, finger.pageY);
28244 var x = Math.pow(coords[0] - coords[2], 2);
28245 var y = Math.pow(coords[1] - coords[3], 2);
28247 this.endDistance = Math.sqrt(x + y);
28249 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
28251 if(!this.zoomable()){
28252 this.scale = this.startScale;
28260 onTouchEnd : function(e)
28262 this.pinching = false;
28263 this.dragable = false;
28267 process : function(file, crop)
28270 this.maskEl.mask(this.loadingText);
28273 this.xhr = new XMLHttpRequest();
28275 file.xhr = this.xhr;
28277 this.xhr.open(this.method, this.url, true);
28280 "Accept": "application/json",
28281 "Cache-Control": "no-cache",
28282 "X-Requested-With": "XMLHttpRequest"
28285 for (var headerName in headers) {
28286 var headerValue = headers[headerName];
28288 this.xhr.setRequestHeader(headerName, headerValue);
28294 this.xhr.onload = function()
28296 _this.xhrOnLoad(_this.xhr);
28299 this.xhr.onerror = function()
28301 _this.xhrOnError(_this.xhr);
28304 var formData = new FormData();
28306 formData.append('returnHTML', 'NO');
28309 formData.append('crop', crop);
28312 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
28313 formData.append(this.paramName, file, file.name);
28316 if(typeof(file.filename) != 'undefined'){
28317 formData.append('filename', file.filename);
28320 if(typeof(file.mimetype) != 'undefined'){
28321 formData.append('mimetype', file.mimetype);
28324 if(this.fireEvent('arrange', this, formData) != false){
28325 this.xhr.send(formData);
28329 xhrOnLoad : function(xhr)
28332 this.maskEl.unmask();
28335 if (xhr.readyState !== 4) {
28336 this.fireEvent('exception', this, xhr);
28340 var response = Roo.decode(xhr.responseText);
28342 if(!response.success){
28343 this.fireEvent('exception', this, xhr);
28347 var response = Roo.decode(xhr.responseText);
28349 this.fireEvent('upload', this, response);
28353 xhrOnError : function()
28356 this.maskEl.unmask();
28359 Roo.log('xhr on error');
28361 var response = Roo.decode(xhr.responseText);
28367 prepare : function(file)
28370 this.maskEl.mask(this.loadingText);
28376 if(typeof(file) === 'string'){
28377 this.loadCanvas(file);
28381 if(!file || !this.urlAPI){
28386 this.cropType = file.type;
28390 if(this.fireEvent('prepare', this, this.file) != false){
28392 var reader = new FileReader();
28394 reader.onload = function (e) {
28395 if (e.target.error) {
28396 Roo.log(e.target.error);
28400 var buffer = e.target.result,
28401 dataView = new DataView(buffer),
28403 maxOffset = dataView.byteLength - 4,
28407 if (dataView.getUint16(0) === 0xffd8) {
28408 while (offset < maxOffset) {
28409 markerBytes = dataView.getUint16(offset);
28411 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
28412 markerLength = dataView.getUint16(offset + 2) + 2;
28413 if (offset + markerLength > dataView.byteLength) {
28414 Roo.log('Invalid meta data: Invalid segment size.');
28418 if(markerBytes == 0xffe1){
28419 _this.parseExifData(
28426 offset += markerLength;
28436 var url = _this.urlAPI.createObjectURL(_this.file);
28438 _this.loadCanvas(url);
28443 reader.readAsArrayBuffer(this.file);
28449 parseExifData : function(dataView, offset, length)
28451 var tiffOffset = offset + 10,
28455 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28456 // No Exif data, might be XMP data instead
28460 // Check for the ASCII code for "Exif" (0x45786966):
28461 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28462 // No Exif data, might be XMP data instead
28465 if (tiffOffset + 8 > dataView.byteLength) {
28466 Roo.log('Invalid Exif data: Invalid segment size.');
28469 // Check for the two null bytes:
28470 if (dataView.getUint16(offset + 8) !== 0x0000) {
28471 Roo.log('Invalid Exif data: Missing byte alignment offset.');
28474 // Check the byte alignment:
28475 switch (dataView.getUint16(tiffOffset)) {
28477 littleEndian = true;
28480 littleEndian = false;
28483 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
28486 // Check for the TIFF tag marker (0x002A):
28487 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
28488 Roo.log('Invalid Exif data: Missing TIFF marker.');
28491 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
28492 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
28494 this.parseExifTags(
28497 tiffOffset + dirOffset,
28502 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
28507 if (dirOffset + 6 > dataView.byteLength) {
28508 Roo.log('Invalid Exif data: Invalid directory offset.');
28511 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
28512 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
28513 if (dirEndOffset + 4 > dataView.byteLength) {
28514 Roo.log('Invalid Exif data: Invalid directory size.');
28517 for (i = 0; i < tagsNumber; i += 1) {
28521 dirOffset + 2 + 12 * i, // tag offset
28525 // Return the offset to the next directory:
28526 return dataView.getUint32(dirEndOffset, littleEndian);
28529 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
28531 var tag = dataView.getUint16(offset, littleEndian);
28533 this.exif[tag] = this.getExifValue(
28537 dataView.getUint16(offset + 2, littleEndian), // tag type
28538 dataView.getUint32(offset + 4, littleEndian), // tag length
28543 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
28545 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
28554 Roo.log('Invalid Exif data: Invalid tag type.');
28558 tagSize = tagType.size * length;
28559 // Determine if the value is contained in the dataOffset bytes,
28560 // or if the value at the dataOffset is a pointer to the actual data:
28561 dataOffset = tagSize > 4 ?
28562 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
28563 if (dataOffset + tagSize > dataView.byteLength) {
28564 Roo.log('Invalid Exif data: Invalid data offset.');
28567 if (length === 1) {
28568 return tagType.getValue(dataView, dataOffset, littleEndian);
28571 for (i = 0; i < length; i += 1) {
28572 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
28575 if (tagType.ascii) {
28577 // Concatenate the chars:
28578 for (i = 0; i < values.length; i += 1) {
28580 // Ignore the terminating NULL byte(s):
28581 if (c === '\u0000') {
28593 Roo.apply(Roo.bootstrap.UploadCropbox, {
28595 'Orientation': 0x0112
28599 1: 0, //'top-left',
28601 3: 180, //'bottom-right',
28602 // 4: 'bottom-left',
28604 6: 90, //'right-top',
28605 // 7: 'right-bottom',
28606 8: 270 //'left-bottom'
28610 // byte, 8-bit unsigned int:
28612 getValue: function (dataView, dataOffset) {
28613 return dataView.getUint8(dataOffset);
28617 // ascii, 8-bit byte:
28619 getValue: function (dataView, dataOffset) {
28620 return String.fromCharCode(dataView.getUint8(dataOffset));
28625 // short, 16 bit int:
28627 getValue: function (dataView, dataOffset, littleEndian) {
28628 return dataView.getUint16(dataOffset, littleEndian);
28632 // long, 32 bit int:
28634 getValue: function (dataView, dataOffset, littleEndian) {
28635 return dataView.getUint32(dataOffset, littleEndian);
28639 // rational = two long values, first is numerator, second is denominator:
28641 getValue: function (dataView, dataOffset, littleEndian) {
28642 return dataView.getUint32(dataOffset, littleEndian) /
28643 dataView.getUint32(dataOffset + 4, littleEndian);
28647 // slong, 32 bit signed int:
28649 getValue: function (dataView, dataOffset, littleEndian) {
28650 return dataView.getInt32(dataOffset, littleEndian);
28654 // srational, two slongs, first is numerator, second is denominator:
28656 getValue: function (dataView, dataOffset, littleEndian) {
28657 return dataView.getInt32(dataOffset, littleEndian) /
28658 dataView.getInt32(dataOffset + 4, littleEndian);
28668 cls : 'btn-group roo-upload-cropbox-rotate-left',
28669 action : 'rotate-left',
28673 cls : 'btn btn-default',
28674 html : '<i class="fa fa-undo"></i>'
28680 cls : 'btn-group roo-upload-cropbox-picture',
28681 action : 'picture',
28685 cls : 'btn btn-default',
28686 html : '<i class="fa fa-picture-o"></i>'
28692 cls : 'btn-group roo-upload-cropbox-rotate-right',
28693 action : 'rotate-right',
28697 cls : 'btn btn-default',
28698 html : '<i class="fa fa-repeat"></i>'
28706 cls : 'btn-group roo-upload-cropbox-rotate-left',
28707 action : 'rotate-left',
28711 cls : 'btn btn-default',
28712 html : '<i class="fa fa-undo"></i>'
28718 cls : 'btn-group roo-upload-cropbox-download',
28719 action : 'download',
28723 cls : 'btn btn-default',
28724 html : '<i class="fa fa-download"></i>'
28730 cls : 'btn-group roo-upload-cropbox-crop',
28735 cls : 'btn btn-default',
28736 html : '<i class="fa fa-crop"></i>'
28742 cls : 'btn-group roo-upload-cropbox-trash',
28747 cls : 'btn btn-default',
28748 html : '<i class="fa fa-trash"></i>'
28754 cls : 'btn-group roo-upload-cropbox-rotate-right',
28755 action : 'rotate-right',
28759 cls : 'btn btn-default',
28760 html : '<i class="fa fa-repeat"></i>'
28768 cls : 'btn-group roo-upload-cropbox-rotate-left',
28769 action : 'rotate-left',
28773 cls : 'btn btn-default',
28774 html : '<i class="fa fa-undo"></i>'
28780 cls : 'btn-group roo-upload-cropbox-rotate-right',
28781 action : 'rotate-right',
28785 cls : 'btn btn-default',
28786 html : '<i class="fa fa-repeat"></i>'
28799 * @class Roo.bootstrap.DocumentManager
28800 * @extends Roo.bootstrap.Component
28801 * Bootstrap DocumentManager class
28802 * @cfg {String} paramName default 'imageUpload'
28803 * @cfg {String} toolTipName default 'filename'
28804 * @cfg {String} method default POST
28805 * @cfg {String} url action url
28806 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
28807 * @cfg {Boolean} multiple multiple upload default true
28808 * @cfg {Number} thumbSize default 300
28809 * @cfg {String} fieldLabel
28810 * @cfg {Number} labelWidth default 4
28811 * @cfg {String} labelAlign (left|top) default left
28812 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
28813 * @cfg {Number} labellg set the width of label (1-12)
28814 * @cfg {Number} labelmd set the width of label (1-12)
28815 * @cfg {Number} labelsm set the width of label (1-12)
28816 * @cfg {Number} labelxs set the width of label (1-12)
28819 * Create a new DocumentManager
28820 * @param {Object} config The config object
28823 Roo.bootstrap.DocumentManager = function(config){
28824 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
28827 this.delegates = [];
28832 * Fire when initial the DocumentManager
28833 * @param {Roo.bootstrap.DocumentManager} this
28838 * inspect selected file
28839 * @param {Roo.bootstrap.DocumentManager} this
28840 * @param {File} file
28845 * Fire when xhr load exception
28846 * @param {Roo.bootstrap.DocumentManager} this
28847 * @param {XMLHttpRequest} xhr
28849 "exception" : true,
28851 * @event afterupload
28852 * Fire when xhr load exception
28853 * @param {Roo.bootstrap.DocumentManager} this
28854 * @param {XMLHttpRequest} xhr
28856 "afterupload" : true,
28859 * prepare the form data
28860 * @param {Roo.bootstrap.DocumentManager} this
28861 * @param {Object} formData
28866 * Fire when remove the file
28867 * @param {Roo.bootstrap.DocumentManager} this
28868 * @param {Object} file
28873 * Fire after refresh the file
28874 * @param {Roo.bootstrap.DocumentManager} this
28879 * Fire after click the image
28880 * @param {Roo.bootstrap.DocumentManager} this
28881 * @param {Object} file
28886 * Fire when upload a image and editable set to true
28887 * @param {Roo.bootstrap.DocumentManager} this
28888 * @param {Object} file
28892 * @event beforeselectfile
28893 * Fire before select file
28894 * @param {Roo.bootstrap.DocumentManager} this
28896 "beforeselectfile" : true,
28899 * Fire before process file
28900 * @param {Roo.bootstrap.DocumentManager} this
28901 * @param {Object} file
28905 * @event previewrendered
28906 * Fire when preview rendered
28907 * @param {Roo.bootstrap.DocumentManager} this
28908 * @param {Object} file
28910 "previewrendered" : true,
28913 "previewResize" : true
28918 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
28927 paramName : 'imageUpload',
28928 toolTipName : 'filename',
28931 labelAlign : 'left',
28941 getAutoCreate : function()
28943 var managerWidget = {
28945 cls : 'roo-document-manager',
28949 cls : 'roo-document-manager-selector',
28954 cls : 'roo-document-manager-uploader',
28958 cls : 'roo-document-manager-upload-btn',
28959 html : '<i class="fa fa-plus"></i>'
28970 cls : 'column col-md-12',
28975 if(this.fieldLabel.length){
28980 cls : 'column col-md-12',
28981 html : this.fieldLabel
28985 cls : 'column col-md-12',
28990 if(this.labelAlign == 'left'){
28995 html : this.fieldLabel
29004 if(this.labelWidth > 12){
29005 content[0].style = "width: " + this.labelWidth + 'px';
29008 if(this.labelWidth < 13 && this.labelmd == 0){
29009 this.labelmd = this.labelWidth;
29012 if(this.labellg > 0){
29013 content[0].cls += ' col-lg-' + this.labellg;
29014 content[1].cls += ' col-lg-' + (12 - this.labellg);
29017 if(this.labelmd > 0){
29018 content[0].cls += ' col-md-' + this.labelmd;
29019 content[1].cls += ' col-md-' + (12 - this.labelmd);
29022 if(this.labelsm > 0){
29023 content[0].cls += ' col-sm-' + this.labelsm;
29024 content[1].cls += ' col-sm-' + (12 - this.labelsm);
29027 if(this.labelxs > 0){
29028 content[0].cls += ' col-xs-' + this.labelxs;
29029 content[1].cls += ' col-xs-' + (12 - this.labelxs);
29037 cls : 'row clearfix',
29045 initEvents : function()
29047 this.managerEl = this.el.select('.roo-document-manager', true).first();
29048 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29050 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
29051 this.selectorEl.hide();
29054 this.selectorEl.attr('multiple', 'multiple');
29057 this.selectorEl.on('change', this.onFileSelected, this);
29059 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
29060 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29062 this.uploader.on('click', this.onUploaderClick, this);
29064 this.renderProgressDialog();
29068 window.addEventListener("resize", function() { _this.refresh(); } );
29070 this.fireEvent('initial', this);
29073 renderProgressDialog : function()
29077 this.progressDialog = new Roo.bootstrap.Modal({
29078 cls : 'roo-document-manager-progress-dialog',
29079 allow_close : false,
29089 btnclick : function() {
29090 _this.uploadCancel();
29096 this.progressDialog.render(Roo.get(document.body));
29098 this.progress = new Roo.bootstrap.Progress({
29099 cls : 'roo-document-manager-progress',
29104 this.progress.render(this.progressDialog.getChildContainer());
29106 this.progressBar = new Roo.bootstrap.ProgressBar({
29107 cls : 'roo-document-manager-progress-bar',
29110 aria_valuemax : 12,
29114 this.progressBar.render(this.progress.getChildContainer());
29117 onUploaderClick : function(e)
29119 e.preventDefault();
29121 if(this.fireEvent('beforeselectfile', this) != false){
29122 this.selectorEl.dom.click();
29127 onFileSelected : function(e)
29129 e.preventDefault();
29131 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
29135 Roo.each(this.selectorEl.dom.files, function(file){
29136 if(this.fireEvent('inspect', this, file) != false){
29137 this.files.push(file);
29147 this.selectorEl.dom.value = '';
29149 if(!this.files || !this.files.length){
29153 if(this.boxes > 0 && this.files.length > this.boxes){
29154 this.files = this.files.slice(0, this.boxes);
29157 this.uploader.show();
29159 if(this.boxes > 0 && this.files.length > this.boxes - 1){
29160 this.uploader.hide();
29169 Roo.each(this.files, function(file){
29171 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29172 var f = this.renderPreview(file);
29177 if(file.type.indexOf('image') != -1){
29178 this.delegates.push(
29180 _this.process(file);
29181 }).createDelegate(this)
29189 _this.process(file);
29190 }).createDelegate(this)
29195 this.files = files;
29197 this.delegates = this.delegates.concat(docs);
29199 if(!this.delegates.length){
29204 this.progressBar.aria_valuemax = this.delegates.length;
29211 arrange : function()
29213 if(!this.delegates.length){
29214 this.progressDialog.hide();
29219 var delegate = this.delegates.shift();
29221 this.progressDialog.show();
29223 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
29225 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
29230 refresh : function()
29232 this.uploader.show();
29234 if(this.boxes > 0 && this.files.length > this.boxes - 1){
29235 this.uploader.hide();
29238 Roo.isTouch ? this.closable(false) : this.closable(true);
29240 this.fireEvent('refresh', this);
29243 onRemove : function(e, el, o)
29245 e.preventDefault();
29247 this.fireEvent('remove', this, o);
29251 remove : function(o)
29255 Roo.each(this.files, function(file){
29256 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
29265 this.files = files;
29272 Roo.each(this.files, function(file){
29277 file.target.remove();
29286 onClick : function(e, el, o)
29288 e.preventDefault();
29290 this.fireEvent('click', this, o);
29294 closable : function(closable)
29296 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
29298 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29310 xhrOnLoad : function(xhr)
29312 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29316 if (xhr.readyState !== 4) {
29318 this.fireEvent('exception', this, xhr);
29322 var response = Roo.decode(xhr.responseText);
29324 if(!response.success){
29326 this.fireEvent('exception', this, xhr);
29330 var file = this.renderPreview(response.data);
29332 this.files.push(file);
29336 this.fireEvent('afterupload', this, xhr);
29340 xhrOnError : function(xhr)
29342 Roo.log('xhr on error');
29344 var response = Roo.decode(xhr.responseText);
29351 process : function(file)
29353 if(this.fireEvent('process', this, file) !== false){
29354 if(this.editable && file.type.indexOf('image') != -1){
29355 this.fireEvent('edit', this, file);
29359 this.uploadStart(file, false);
29366 uploadStart : function(file, crop)
29368 this.xhr = new XMLHttpRequest();
29370 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29375 file.xhr = this.xhr;
29377 this.managerEl.createChild({
29379 cls : 'roo-document-manager-loading',
29383 tooltip : file.name,
29384 cls : 'roo-document-manager-thumb',
29385 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29391 this.xhr.open(this.method, this.url, true);
29394 "Accept": "application/json",
29395 "Cache-Control": "no-cache",
29396 "X-Requested-With": "XMLHttpRequest"
29399 for (var headerName in headers) {
29400 var headerValue = headers[headerName];
29402 this.xhr.setRequestHeader(headerName, headerValue);
29408 this.xhr.onload = function()
29410 _this.xhrOnLoad(_this.xhr);
29413 this.xhr.onerror = function()
29415 _this.xhrOnError(_this.xhr);
29418 var formData = new FormData();
29420 formData.append('returnHTML', 'NO');
29423 formData.append('crop', crop);
29426 formData.append(this.paramName, file, file.name);
29433 if(this.fireEvent('prepare', this, formData, options) != false){
29435 if(options.manually){
29439 this.xhr.send(formData);
29443 this.uploadCancel();
29446 uploadCancel : function()
29452 this.delegates = [];
29454 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29461 renderPreview : function(file)
29463 if(typeof(file.target) != 'undefined' && file.target){
29467 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
29469 var previewEl = this.managerEl.createChild({
29471 cls : 'roo-document-manager-preview',
29475 tooltip : file[this.toolTipName],
29476 cls : 'roo-document-manager-thumb',
29477 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
29482 html : '<i class="fa fa-times-circle"></i>'
29487 var close = previewEl.select('button.close', true).first();
29489 close.on('click', this.onRemove, this, file);
29491 file.target = previewEl;
29493 var image = previewEl.select('img', true).first();
29497 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
29499 image.on('click', this.onClick, this, file);
29501 this.fireEvent('previewrendered', this, file);
29507 onPreviewLoad : function(file, image)
29509 if(typeof(file.target) == 'undefined' || !file.target){
29513 var width = image.dom.naturalWidth || image.dom.width;
29514 var height = image.dom.naturalHeight || image.dom.height;
29516 if(!this.previewResize) {
29520 if(width > height){
29521 file.target.addClass('wide');
29525 file.target.addClass('tall');
29530 uploadFromSource : function(file, crop)
29532 this.xhr = new XMLHttpRequest();
29534 this.managerEl.createChild({
29536 cls : 'roo-document-manager-loading',
29540 tooltip : file.name,
29541 cls : 'roo-document-manager-thumb',
29542 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29548 this.xhr.open(this.method, this.url, true);
29551 "Accept": "application/json",
29552 "Cache-Control": "no-cache",
29553 "X-Requested-With": "XMLHttpRequest"
29556 for (var headerName in headers) {
29557 var headerValue = headers[headerName];
29559 this.xhr.setRequestHeader(headerName, headerValue);
29565 this.xhr.onload = function()
29567 _this.xhrOnLoad(_this.xhr);
29570 this.xhr.onerror = function()
29572 _this.xhrOnError(_this.xhr);
29575 var formData = new FormData();
29577 formData.append('returnHTML', 'NO');
29579 formData.append('crop', crop);
29581 if(typeof(file.filename) != 'undefined'){
29582 formData.append('filename', file.filename);
29585 if(typeof(file.mimetype) != 'undefined'){
29586 formData.append('mimetype', file.mimetype);
29591 if(this.fireEvent('prepare', this, formData) != false){
29592 this.xhr.send(formData);
29602 * @class Roo.bootstrap.DocumentViewer
29603 * @extends Roo.bootstrap.Component
29604 * Bootstrap DocumentViewer class
29605 * @cfg {Boolean} showDownload (true|false) show download button (default true)
29606 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
29609 * Create a new DocumentViewer
29610 * @param {Object} config The config object
29613 Roo.bootstrap.DocumentViewer = function(config){
29614 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
29619 * Fire after initEvent
29620 * @param {Roo.bootstrap.DocumentViewer} this
29626 * @param {Roo.bootstrap.DocumentViewer} this
29631 * Fire after download button
29632 * @param {Roo.bootstrap.DocumentViewer} this
29637 * Fire after trash button
29638 * @param {Roo.bootstrap.DocumentViewer} this
29645 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
29647 showDownload : true,
29651 getAutoCreate : function()
29655 cls : 'roo-document-viewer',
29659 cls : 'roo-document-viewer-body',
29663 cls : 'roo-document-viewer-thumb',
29667 cls : 'roo-document-viewer-image'
29675 cls : 'roo-document-viewer-footer',
29678 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
29682 cls : 'btn-group roo-document-viewer-download',
29686 cls : 'btn btn-default',
29687 html : '<i class="fa fa-download"></i>'
29693 cls : 'btn-group roo-document-viewer-trash',
29697 cls : 'btn btn-default',
29698 html : '<i class="fa fa-trash"></i>'
29711 initEvents : function()
29713 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
29714 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
29716 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
29717 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
29719 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
29720 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
29722 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
29723 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
29725 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
29726 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
29728 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
29729 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
29731 this.bodyEl.on('click', this.onClick, this);
29732 this.downloadBtn.on('click', this.onDownload, this);
29733 this.trashBtn.on('click', this.onTrash, this);
29735 this.downloadBtn.hide();
29736 this.trashBtn.hide();
29738 if(this.showDownload){
29739 this.downloadBtn.show();
29742 if(this.showTrash){
29743 this.trashBtn.show();
29746 if(!this.showDownload && !this.showTrash) {
29747 this.footerEl.hide();
29752 initial : function()
29754 this.fireEvent('initial', this);
29758 onClick : function(e)
29760 e.preventDefault();
29762 this.fireEvent('click', this);
29765 onDownload : function(e)
29767 e.preventDefault();
29769 this.fireEvent('download', this);
29772 onTrash : function(e)
29774 e.preventDefault();
29776 this.fireEvent('trash', this);
29788 * @class Roo.bootstrap.NavProgressBar
29789 * @extends Roo.bootstrap.Component
29790 * Bootstrap NavProgressBar class
29793 * Create a new nav progress bar
29794 * @param {Object} config The config object
29797 Roo.bootstrap.NavProgressBar = function(config){
29798 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
29800 this.bullets = this.bullets || [];
29802 // Roo.bootstrap.NavProgressBar.register(this);
29806 * Fires when the active item changes
29807 * @param {Roo.bootstrap.NavProgressBar} this
29808 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
29809 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
29816 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
29821 getAutoCreate : function()
29823 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
29827 cls : 'roo-navigation-bar-group',
29831 cls : 'roo-navigation-top-bar'
29835 cls : 'roo-navigation-bullets-bar',
29839 cls : 'roo-navigation-bar'
29846 cls : 'roo-navigation-bottom-bar'
29856 initEvents: function()
29861 onRender : function(ct, position)
29863 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
29865 if(this.bullets.length){
29866 Roo.each(this.bullets, function(b){
29875 addItem : function(cfg)
29877 var item = new Roo.bootstrap.NavProgressItem(cfg);
29879 item.parentId = this.id;
29880 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
29883 var top = new Roo.bootstrap.Element({
29885 cls : 'roo-navigation-bar-text'
29888 var bottom = new Roo.bootstrap.Element({
29890 cls : 'roo-navigation-bar-text'
29893 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
29894 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
29896 var topText = new Roo.bootstrap.Element({
29898 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
29901 var bottomText = new Roo.bootstrap.Element({
29903 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
29906 topText.onRender(top.el, null);
29907 bottomText.onRender(bottom.el, null);
29910 item.bottomEl = bottom;
29913 this.barItems.push(item);
29918 getActive : function()
29920 var active = false;
29922 Roo.each(this.barItems, function(v){
29924 if (!v.isActive()) {
29936 setActiveItem : function(item)
29940 Roo.each(this.barItems, function(v){
29941 if (v.rid == item.rid) {
29945 if (v.isActive()) {
29946 v.setActive(false);
29951 item.setActive(true);
29953 this.fireEvent('changed', this, item, prev);
29956 getBarItem: function(rid)
29960 Roo.each(this.barItems, function(e) {
29961 if (e.rid != rid) {
29972 indexOfItem : function(item)
29976 Roo.each(this.barItems, function(v, i){
29978 if (v.rid != item.rid) {
29989 setActiveNext : function()
29991 var i = this.indexOfItem(this.getActive());
29993 if (i > this.barItems.length) {
29997 this.setActiveItem(this.barItems[i+1]);
30000 setActivePrev : function()
30002 var i = this.indexOfItem(this.getActive());
30008 this.setActiveItem(this.barItems[i-1]);
30011 format : function()
30013 if(!this.barItems.length){
30017 var width = 100 / this.barItems.length;
30019 Roo.each(this.barItems, function(i){
30020 i.el.setStyle('width', width + '%');
30021 i.topEl.el.setStyle('width', width + '%');
30022 i.bottomEl.el.setStyle('width', width + '%');
30031 * Nav Progress Item
30036 * @class Roo.bootstrap.NavProgressItem
30037 * @extends Roo.bootstrap.Component
30038 * Bootstrap NavProgressItem class
30039 * @cfg {String} rid the reference id
30040 * @cfg {Boolean} active (true|false) Is item active default false
30041 * @cfg {Boolean} disabled (true|false) Is item active default false
30042 * @cfg {String} html
30043 * @cfg {String} position (top|bottom) text position default bottom
30044 * @cfg {String} icon show icon instead of number
30047 * Create a new NavProgressItem
30048 * @param {Object} config The config object
30050 Roo.bootstrap.NavProgressItem = function(config){
30051 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
30056 * The raw click event for the entire grid.
30057 * @param {Roo.bootstrap.NavProgressItem} this
30058 * @param {Roo.EventObject} e
30065 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
30071 position : 'bottom',
30074 getAutoCreate : function()
30076 var iconCls = 'roo-navigation-bar-item-icon';
30078 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
30082 cls: 'roo-navigation-bar-item',
30092 cfg.cls += ' active';
30095 cfg.cls += ' disabled';
30101 disable : function()
30103 this.setDisabled(true);
30106 enable : function()
30108 this.setDisabled(false);
30111 initEvents: function()
30113 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
30115 this.iconEl.on('click', this.onClick, this);
30118 onClick : function(e)
30120 e.preventDefault();
30126 if(this.fireEvent('click', this, e) === false){
30130 this.parent().setActiveItem(this);
30133 isActive: function ()
30135 return this.active;
30138 setActive : function(state)
30140 if(this.active == state){
30144 this.active = state;
30147 this.el.addClass('active');
30151 this.el.removeClass('active');
30156 setDisabled : function(state)
30158 if(this.disabled == state){
30162 this.disabled = state;
30165 this.el.addClass('disabled');
30169 this.el.removeClass('disabled');
30172 tooltipEl : function()
30174 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
30187 * @class Roo.bootstrap.FieldLabel
30188 * @extends Roo.bootstrap.Component
30189 * Bootstrap FieldLabel class
30190 * @cfg {String} html contents of the element
30191 * @cfg {String} tag tag of the element default label
30192 * @cfg {String} cls class of the element
30193 * @cfg {String} target label target
30194 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
30195 * @cfg {String} invalidClass default "text-warning"
30196 * @cfg {String} validClass default "text-success"
30197 * @cfg {String} iconTooltip default "This field is required"
30198 * @cfg {String} indicatorpos (left|right) default left
30201 * Create a new FieldLabel
30202 * @param {Object} config The config object
30205 Roo.bootstrap.FieldLabel = function(config){
30206 Roo.bootstrap.Element.superclass.constructor.call(this, config);
30211 * Fires after the field has been marked as invalid.
30212 * @param {Roo.form.FieldLabel} this
30213 * @param {String} msg The validation message
30218 * Fires after the field has been validated with no errors.
30219 * @param {Roo.form.FieldLabel} this
30225 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
30232 invalidClass : 'has-warning',
30233 validClass : 'has-success',
30234 iconTooltip : 'This field is required',
30235 indicatorpos : 'left',
30237 getAutoCreate : function(){
30240 if (!this.allowBlank) {
30246 cls : 'roo-bootstrap-field-label ' + this.cls,
30251 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
30252 tooltip : this.iconTooltip
30261 if(this.indicatorpos == 'right'){
30264 cls : 'roo-bootstrap-field-label ' + this.cls,
30273 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
30274 tooltip : this.iconTooltip
30283 initEvents: function()
30285 Roo.bootstrap.Element.superclass.initEvents.call(this);
30287 this.indicator = this.indicatorEl();
30289 if(this.indicator){
30290 this.indicator.removeClass('visible');
30291 this.indicator.addClass('invisible');
30294 Roo.bootstrap.FieldLabel.register(this);
30297 indicatorEl : function()
30299 var indicator = this.el.select('i.roo-required-indicator',true).first();
30310 * Mark this field as valid
30312 markValid : function()
30314 if(this.indicator){
30315 this.indicator.removeClass('visible');
30316 this.indicator.addClass('invisible');
30319 this.el.removeClass(this.invalidClass);
30321 this.el.addClass(this.validClass);
30323 this.fireEvent('valid', this);
30327 * Mark this field as invalid
30328 * @param {String} msg The validation message
30330 markInvalid : function(msg)
30332 if(this.indicator){
30333 this.indicator.removeClass('invisible');
30334 this.indicator.addClass('visible');
30337 this.el.removeClass(this.validClass);
30339 this.el.addClass(this.invalidClass);
30341 this.fireEvent('invalid', this, msg);
30347 Roo.apply(Roo.bootstrap.FieldLabel, {
30352 * register a FieldLabel Group
30353 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
30355 register : function(label)
30357 if(this.groups.hasOwnProperty(label.target)){
30361 this.groups[label.target] = label;
30365 * fetch a FieldLabel Group based on the target
30366 * @param {string} target
30367 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
30369 get: function(target) {
30370 if (typeof(this.groups[target]) == 'undefined') {
30374 return this.groups[target] ;
30383 * page DateSplitField.
30389 * @class Roo.bootstrap.DateSplitField
30390 * @extends Roo.bootstrap.Component
30391 * Bootstrap DateSplitField class
30392 * @cfg {string} fieldLabel - the label associated
30393 * @cfg {Number} labelWidth set the width of label (0-12)
30394 * @cfg {String} labelAlign (top|left)
30395 * @cfg {Boolean} dayAllowBlank (true|false) default false
30396 * @cfg {Boolean} monthAllowBlank (true|false) default false
30397 * @cfg {Boolean} yearAllowBlank (true|false) default false
30398 * @cfg {string} dayPlaceholder
30399 * @cfg {string} monthPlaceholder
30400 * @cfg {string} yearPlaceholder
30401 * @cfg {string} dayFormat default 'd'
30402 * @cfg {string} monthFormat default 'm'
30403 * @cfg {string} yearFormat default 'Y'
30404 * @cfg {Number} labellg set the width of label (1-12)
30405 * @cfg {Number} labelmd set the width of label (1-12)
30406 * @cfg {Number} labelsm set the width of label (1-12)
30407 * @cfg {Number} labelxs set the width of label (1-12)
30411 * Create a new DateSplitField
30412 * @param {Object} config The config object
30415 Roo.bootstrap.DateSplitField = function(config){
30416 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
30422 * getting the data of years
30423 * @param {Roo.bootstrap.DateSplitField} this
30424 * @param {Object} years
30429 * getting the data of days
30430 * @param {Roo.bootstrap.DateSplitField} this
30431 * @param {Object} days
30436 * Fires after the field has been marked as invalid.
30437 * @param {Roo.form.Field} this
30438 * @param {String} msg The validation message
30443 * Fires after the field has been validated with no errors.
30444 * @param {Roo.form.Field} this
30450 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
30453 labelAlign : 'top',
30455 dayAllowBlank : false,
30456 monthAllowBlank : false,
30457 yearAllowBlank : false,
30458 dayPlaceholder : '',
30459 monthPlaceholder : '',
30460 yearPlaceholder : '',
30464 isFormField : true,
30470 getAutoCreate : function()
30474 cls : 'row roo-date-split-field-group',
30479 cls : 'form-hidden-field roo-date-split-field-group-value',
30485 var labelCls = 'col-md-12';
30486 var contentCls = 'col-md-4';
30488 if(this.fieldLabel){
30492 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
30496 html : this.fieldLabel
30501 if(this.labelAlign == 'left'){
30503 if(this.labelWidth > 12){
30504 label.style = "width: " + this.labelWidth + 'px';
30507 if(this.labelWidth < 13 && this.labelmd == 0){
30508 this.labelmd = this.labelWidth;
30511 if(this.labellg > 0){
30512 labelCls = ' col-lg-' + this.labellg;
30513 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
30516 if(this.labelmd > 0){
30517 labelCls = ' col-md-' + this.labelmd;
30518 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
30521 if(this.labelsm > 0){
30522 labelCls = ' col-sm-' + this.labelsm;
30523 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
30526 if(this.labelxs > 0){
30527 labelCls = ' col-xs-' + this.labelxs;
30528 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
30532 label.cls += ' ' + labelCls;
30534 cfg.cn.push(label);
30537 Roo.each(['day', 'month', 'year'], function(t){
30540 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
30547 inputEl: function ()
30549 return this.el.select('.roo-date-split-field-group-value', true).first();
30552 onRender : function(ct, position)
30556 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
30558 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
30560 this.dayField = new Roo.bootstrap.ComboBox({
30561 allowBlank : this.dayAllowBlank,
30562 alwaysQuery : true,
30563 displayField : 'value',
30566 forceSelection : true,
30568 placeholder : this.dayPlaceholder,
30569 selectOnFocus : true,
30570 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30571 triggerAction : 'all',
30573 valueField : 'value',
30574 store : new Roo.data.SimpleStore({
30575 data : (function() {
30577 _this.fireEvent('days', _this, days);
30580 fields : [ 'value' ]
30583 select : function (_self, record, index)
30585 _this.setValue(_this.getValue());
30590 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
30592 this.monthField = new Roo.bootstrap.MonthField({
30593 after : '<i class=\"fa fa-calendar\"></i>',
30594 allowBlank : this.monthAllowBlank,
30595 placeholder : this.monthPlaceholder,
30598 render : function (_self)
30600 this.el.select('span.input-group-addon', true).first().on('click', function(e){
30601 e.preventDefault();
30605 select : function (_self, oldvalue, newvalue)
30607 _this.setValue(_this.getValue());
30612 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
30614 this.yearField = new Roo.bootstrap.ComboBox({
30615 allowBlank : this.yearAllowBlank,
30616 alwaysQuery : true,
30617 displayField : 'value',
30620 forceSelection : true,
30622 placeholder : this.yearPlaceholder,
30623 selectOnFocus : true,
30624 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30625 triggerAction : 'all',
30627 valueField : 'value',
30628 store : new Roo.data.SimpleStore({
30629 data : (function() {
30631 _this.fireEvent('years', _this, years);
30634 fields : [ 'value' ]
30637 select : function (_self, record, index)
30639 _this.setValue(_this.getValue());
30644 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
30647 setValue : function(v, format)
30649 this.inputEl.dom.value = v;
30651 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
30653 var d = Date.parseDate(v, f);
30660 this.setDay(d.format(this.dayFormat));
30661 this.setMonth(d.format(this.monthFormat));
30662 this.setYear(d.format(this.yearFormat));
30669 setDay : function(v)
30671 this.dayField.setValue(v);
30672 this.inputEl.dom.value = this.getValue();
30677 setMonth : function(v)
30679 this.monthField.setValue(v, true);
30680 this.inputEl.dom.value = this.getValue();
30685 setYear : function(v)
30687 this.yearField.setValue(v);
30688 this.inputEl.dom.value = this.getValue();
30693 getDay : function()
30695 return this.dayField.getValue();
30698 getMonth : function()
30700 return this.monthField.getValue();
30703 getYear : function()
30705 return this.yearField.getValue();
30708 getValue : function()
30710 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
30712 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
30722 this.inputEl.dom.value = '';
30727 validate : function()
30729 var d = this.dayField.validate();
30730 var m = this.monthField.validate();
30731 var y = this.yearField.validate();
30736 (!this.dayAllowBlank && !d) ||
30737 (!this.monthAllowBlank && !m) ||
30738 (!this.yearAllowBlank && !y)
30743 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
30752 this.markInvalid();
30757 markValid : function()
30760 var label = this.el.select('label', true).first();
30761 var icon = this.el.select('i.fa-star', true).first();
30767 this.fireEvent('valid', this);
30771 * Mark this field as invalid
30772 * @param {String} msg The validation message
30774 markInvalid : function(msg)
30777 var label = this.el.select('label', true).first();
30778 var icon = this.el.select('i.fa-star', true).first();
30780 if(label && !icon){
30781 this.el.select('.roo-date-split-field-label', true).createChild({
30783 cls : 'text-danger fa fa-lg fa-star',
30784 tooltip : 'This field is required',
30785 style : 'margin-right:5px;'
30789 this.fireEvent('invalid', this, msg);
30792 clearInvalid : function()
30794 var label = this.el.select('label', true).first();
30795 var icon = this.el.select('i.fa-star', true).first();
30801 this.fireEvent('valid', this);
30804 getName: function()
30814 * http://masonry.desandro.com
30816 * The idea is to render all the bricks based on vertical width...
30818 * The original code extends 'outlayer' - we might need to use that....
30824 * @class Roo.bootstrap.LayoutMasonry
30825 * @extends Roo.bootstrap.Component
30826 * Bootstrap Layout Masonry class
30829 * Create a new Element
30830 * @param {Object} config The config object
30833 Roo.bootstrap.LayoutMasonry = function(config){
30835 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
30839 Roo.bootstrap.LayoutMasonry.register(this);
30845 * Fire after layout the items
30846 * @param {Roo.bootstrap.LayoutMasonry} this
30847 * @param {Roo.EventObject} e
30854 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
30857 * @cfg {Boolean} isLayoutInstant = no animation?
30859 isLayoutInstant : false, // needed?
30862 * @cfg {Number} boxWidth width of the columns
30867 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
30872 * @cfg {Number} padWidth padding below box..
30877 * @cfg {Number} gutter gutter width..
30882 * @cfg {Number} maxCols maximum number of columns
30888 * @cfg {Boolean} isAutoInitial defalut true
30890 isAutoInitial : true,
30895 * @cfg {Boolean} isHorizontal defalut false
30897 isHorizontal : false,
30899 currentSize : null,
30905 bricks: null, //CompositeElement
30909 _isLayoutInited : false,
30911 // isAlternative : false, // only use for vertical layout...
30914 * @cfg {Number} alternativePadWidth padding below box..
30916 alternativePadWidth : 50,
30918 selectedBrick : [],
30920 getAutoCreate : function(){
30922 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
30926 cls: 'blog-masonary-wrapper ' + this.cls,
30928 cls : 'mas-boxes masonary'
30935 getChildContainer: function( )
30937 if (this.boxesEl) {
30938 return this.boxesEl;
30941 this.boxesEl = this.el.select('.mas-boxes').first();
30943 return this.boxesEl;
30947 initEvents : function()
30951 if(this.isAutoInitial){
30952 Roo.log('hook children rendered');
30953 this.on('childrenrendered', function() {
30954 Roo.log('children rendered');
30960 initial : function()
30962 this.selectedBrick = [];
30964 this.currentSize = this.el.getBox(true);
30966 Roo.EventManager.onWindowResize(this.resize, this);
30968 if(!this.isAutoInitial){
30976 //this.layout.defer(500,this);
30980 resize : function()
30982 var cs = this.el.getBox(true);
30985 this.currentSize.width == cs.width &&
30986 this.currentSize.x == cs.x &&
30987 this.currentSize.height == cs.height &&
30988 this.currentSize.y == cs.y
30990 Roo.log("no change in with or X or Y");
30994 this.currentSize = cs;
31000 layout : function()
31002 this._resetLayout();
31004 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
31006 this.layoutItems( isInstant );
31008 this._isLayoutInited = true;
31010 this.fireEvent('layout', this);
31014 _resetLayout : function()
31016 if(this.isHorizontal){
31017 this.horizontalMeasureColumns();
31021 this.verticalMeasureColumns();
31025 verticalMeasureColumns : function()
31027 this.getContainerWidth();
31029 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
31030 // this.colWidth = Math.floor(this.containerWidth * 0.8);
31034 var boxWidth = this.boxWidth + this.padWidth;
31036 if(this.containerWidth < this.boxWidth){
31037 boxWidth = this.containerWidth
31040 var containerWidth = this.containerWidth;
31042 var cols = Math.floor(containerWidth / boxWidth);
31044 this.cols = Math.max( cols, 1 );
31046 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
31048 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
31050 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
31052 this.colWidth = boxWidth + avail - this.padWidth;
31054 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
31055 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
31058 horizontalMeasureColumns : function()
31060 this.getContainerWidth();
31062 var boxWidth = this.boxWidth;
31064 if(this.containerWidth < boxWidth){
31065 boxWidth = this.containerWidth;
31068 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
31070 this.el.setHeight(boxWidth);
31074 getContainerWidth : function()
31076 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
31079 layoutItems : function( isInstant )
31081 Roo.log(this.bricks);
31083 var items = Roo.apply([], this.bricks);
31085 if(this.isHorizontal){
31086 this._horizontalLayoutItems( items , isInstant );
31090 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
31091 // this._verticalAlternativeLayoutItems( items , isInstant );
31095 this._verticalLayoutItems( items , isInstant );
31099 _verticalLayoutItems : function ( items , isInstant)
31101 if ( !items || !items.length ) {
31106 ['xs', 'xs', 'xs', 'tall'],
31107 ['xs', 'xs', 'tall'],
31108 ['xs', 'xs', 'sm'],
31109 ['xs', 'xs', 'xs'],
31115 ['sm', 'xs', 'xs'],
31119 ['tall', 'xs', 'xs', 'xs'],
31120 ['tall', 'xs', 'xs'],
31132 Roo.each(items, function(item, k){
31134 switch (item.size) {
31135 // these layouts take up a full box,
31146 boxes.push([item]);
31169 var filterPattern = function(box, length)
31177 var pattern = box.slice(0, length);
31181 Roo.each(pattern, function(i){
31182 format.push(i.size);
31185 Roo.each(standard, function(s){
31187 if(String(s) != String(format)){
31196 if(!match && length == 1){
31201 filterPattern(box, length - 1);
31205 queue.push(pattern);
31207 box = box.slice(length, box.length);
31209 filterPattern(box, 4);
31215 Roo.each(boxes, function(box, k){
31221 if(box.length == 1){
31226 filterPattern(box, 4);
31230 this._processVerticalLayoutQueue( queue, isInstant );
31234 // _verticalAlternativeLayoutItems : function( items , isInstant )
31236 // if ( !items || !items.length ) {
31240 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
31244 _horizontalLayoutItems : function ( items , isInstant)
31246 if ( !items || !items.length || items.length < 3) {
31252 var eItems = items.slice(0, 3);
31254 items = items.slice(3, items.length);
31257 ['xs', 'xs', 'xs', 'wide'],
31258 ['xs', 'xs', 'wide'],
31259 ['xs', 'xs', 'sm'],
31260 ['xs', 'xs', 'xs'],
31266 ['sm', 'xs', 'xs'],
31270 ['wide', 'xs', 'xs', 'xs'],
31271 ['wide', 'xs', 'xs'],
31284 Roo.each(items, function(item, k){
31286 switch (item.size) {
31297 boxes.push([item]);
31321 var filterPattern = function(box, length)
31329 var pattern = box.slice(0, length);
31333 Roo.each(pattern, function(i){
31334 format.push(i.size);
31337 Roo.each(standard, function(s){
31339 if(String(s) != String(format)){
31348 if(!match && length == 1){
31353 filterPattern(box, length - 1);
31357 queue.push(pattern);
31359 box = box.slice(length, box.length);
31361 filterPattern(box, 4);
31367 Roo.each(boxes, function(box, k){
31373 if(box.length == 1){
31378 filterPattern(box, 4);
31385 var pos = this.el.getBox(true);
31389 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31391 var hit_end = false;
31393 Roo.each(queue, function(box){
31397 Roo.each(box, function(b){
31399 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31409 Roo.each(box, function(b){
31411 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31414 mx = Math.max(mx, b.x);
31418 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
31422 Roo.each(box, function(b){
31424 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31438 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
31441 /** Sets position of item in DOM
31442 * @param {Element} item
31443 * @param {Number} x - horizontal position
31444 * @param {Number} y - vertical position
31445 * @param {Boolean} isInstant - disables transitions
31447 _processVerticalLayoutQueue : function( queue, isInstant )
31449 var pos = this.el.getBox(true);
31454 for (var i = 0; i < this.cols; i++){
31458 Roo.each(queue, function(box, k){
31460 var col = k % this.cols;
31462 Roo.each(box, function(b,kk){
31464 b.el.position('absolute');
31466 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31467 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31469 if(b.size == 'md-left' || b.size == 'md-right'){
31470 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31471 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31474 b.el.setWidth(width);
31475 b.el.setHeight(height);
31477 b.el.select('iframe',true).setSize(width,height);
31481 for (var i = 0; i < this.cols; i++){
31483 if(maxY[i] < maxY[col]){
31488 col = Math.min(col, i);
31492 x = pos.x + col * (this.colWidth + this.padWidth);
31496 var positions = [];
31498 switch (box.length){
31500 positions = this.getVerticalOneBoxColPositions(x, y, box);
31503 positions = this.getVerticalTwoBoxColPositions(x, y, box);
31506 positions = this.getVerticalThreeBoxColPositions(x, y, box);
31509 positions = this.getVerticalFourBoxColPositions(x, y, box);
31515 Roo.each(box, function(b,kk){
31517 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31519 var sz = b.el.getSize();
31521 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
31529 for (var i = 0; i < this.cols; i++){
31530 mY = Math.max(mY, maxY[i]);
31533 this.el.setHeight(mY - pos.y);
31537 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
31539 // var pos = this.el.getBox(true);
31542 // var maxX = pos.right;
31544 // var maxHeight = 0;
31546 // Roo.each(items, function(item, k){
31550 // item.el.position('absolute');
31552 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
31554 // item.el.setWidth(width);
31556 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
31558 // item.el.setHeight(height);
31561 // item.el.setXY([x, y], isInstant ? false : true);
31563 // item.el.setXY([maxX - width, y], isInstant ? false : true);
31566 // y = y + height + this.alternativePadWidth;
31568 // maxHeight = maxHeight + height + this.alternativePadWidth;
31572 // this.el.setHeight(maxHeight);
31576 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
31578 var pos = this.el.getBox(true);
31583 var maxX = pos.right;
31585 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
31587 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31589 Roo.each(queue, function(box, k){
31591 Roo.each(box, function(b, kk){
31593 b.el.position('absolute');
31595 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31596 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31598 if(b.size == 'md-left' || b.size == 'md-right'){
31599 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31600 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31603 b.el.setWidth(width);
31604 b.el.setHeight(height);
31612 var positions = [];
31614 switch (box.length){
31616 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
31619 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
31622 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
31625 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
31631 Roo.each(box, function(b,kk){
31633 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31635 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
31643 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
31645 Roo.each(eItems, function(b,k){
31647 b.size = (k == 0) ? 'sm' : 'xs';
31648 b.x = (k == 0) ? 2 : 1;
31649 b.y = (k == 0) ? 2 : 1;
31651 b.el.position('absolute');
31653 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31655 b.el.setWidth(width);
31657 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31659 b.el.setHeight(height);
31663 var positions = [];
31666 x : maxX - this.unitWidth * 2 - this.gutter,
31671 x : maxX - this.unitWidth,
31672 y : minY + (this.unitWidth + this.gutter) * 2
31676 x : maxX - this.unitWidth * 3 - this.gutter * 2,
31680 Roo.each(eItems, function(b,k){
31682 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
31688 getVerticalOneBoxColPositions : function(x, y, box)
31692 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
31694 if(box[0].size == 'md-left'){
31698 if(box[0].size == 'md-right'){
31703 x : x + (this.unitWidth + this.gutter) * rand,
31710 getVerticalTwoBoxColPositions : function(x, y, box)
31714 if(box[0].size == 'xs'){
31718 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
31722 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
31736 x : x + (this.unitWidth + this.gutter) * 2,
31737 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
31744 getVerticalThreeBoxColPositions : function(x, y, box)
31748 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31756 x : x + (this.unitWidth + this.gutter) * 1,
31761 x : x + (this.unitWidth + this.gutter) * 2,
31769 if(box[0].size == 'xs' && box[1].size == 'xs'){
31778 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
31782 x : x + (this.unitWidth + this.gutter) * 1,
31796 x : x + (this.unitWidth + this.gutter) * 2,
31801 x : x + (this.unitWidth + this.gutter) * 2,
31802 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
31809 getVerticalFourBoxColPositions : function(x, y, box)
31813 if(box[0].size == 'xs'){
31822 y : y + (this.unitHeight + this.gutter) * 1
31827 y : y + (this.unitHeight + this.gutter) * 2
31831 x : x + (this.unitWidth + this.gutter) * 1,
31845 x : x + (this.unitWidth + this.gutter) * 2,
31850 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
31851 y : y + (this.unitHeight + this.gutter) * 1
31855 x : x + (this.unitWidth + this.gutter) * 2,
31856 y : y + (this.unitWidth + this.gutter) * 2
31863 getHorizontalOneBoxColPositions : function(maxX, minY, box)
31867 if(box[0].size == 'md-left'){
31869 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31876 if(box[0].size == 'md-right'){
31878 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31879 y : minY + (this.unitWidth + this.gutter) * 1
31885 var rand = Math.floor(Math.random() * (4 - box[0].y));
31888 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31889 y : minY + (this.unitWidth + this.gutter) * rand
31896 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
31900 if(box[0].size == 'xs'){
31903 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31908 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31909 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
31917 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31922 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31923 y : minY + (this.unitWidth + this.gutter) * 2
31930 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
31934 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31937 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31942 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31943 y : minY + (this.unitWidth + this.gutter) * 1
31947 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31948 y : minY + (this.unitWidth + this.gutter) * 2
31955 if(box[0].size == 'xs' && box[1].size == 'xs'){
31958 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31963 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31968 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31969 y : minY + (this.unitWidth + this.gutter) * 1
31977 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31982 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31983 y : minY + (this.unitWidth + this.gutter) * 2
31987 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31988 y : minY + (this.unitWidth + this.gutter) * 2
31995 getHorizontalFourBoxColPositions : function(maxX, minY, box)
31999 if(box[0].size == 'xs'){
32002 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].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),
32012 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),
32017 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
32018 y : minY + (this.unitWidth + this.gutter) * 1
32026 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
32031 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].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),
32037 y : minY + (this.unitWidth + this.gutter) * 2
32041 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),
32042 y : minY + (this.unitWidth + this.gutter) * 2
32050 * remove a Masonry Brick
32051 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
32053 removeBrick : function(brick_id)
32059 for (var i = 0; i<this.bricks.length; i++) {
32060 if (this.bricks[i].id == brick_id) {
32061 this.bricks.splice(i,1);
32062 this.el.dom.removeChild(Roo.get(brick_id).dom);
32069 * adds a Masonry Brick
32070 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32072 addBrick : function(cfg)
32074 var cn = new Roo.bootstrap.MasonryBrick(cfg);
32075 //this.register(cn);
32076 cn.parentId = this.id;
32077 cn.render(this.el);
32082 * register a Masonry Brick
32083 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32086 register : function(brick)
32088 this.bricks.push(brick);
32089 brick.masonryId = this.id;
32093 * clear all the Masonry Brick
32095 clearAll : function()
32098 //this.getChildContainer().dom.innerHTML = "";
32099 this.el.dom.innerHTML = '';
32102 getSelected : function()
32104 if (!this.selectedBrick) {
32108 return this.selectedBrick;
32112 Roo.apply(Roo.bootstrap.LayoutMasonry, {
32116 * register a Masonry Layout
32117 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
32120 register : function(layout)
32122 this.groups[layout.id] = layout;
32125 * fetch a Masonry Layout based on the masonry layout ID
32126 * @param {string} the masonry layout to add
32127 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
32130 get: function(layout_id) {
32131 if (typeof(this.groups[layout_id]) == 'undefined') {
32134 return this.groups[layout_id] ;
32146 * http://masonry.desandro.com
32148 * The idea is to render all the bricks based on vertical width...
32150 * The original code extends 'outlayer' - we might need to use that....
32156 * @class Roo.bootstrap.LayoutMasonryAuto
32157 * @extends Roo.bootstrap.Component
32158 * Bootstrap Layout Masonry class
32161 * Create a new Element
32162 * @param {Object} config The config object
32165 Roo.bootstrap.LayoutMasonryAuto = function(config){
32166 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
32169 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
32172 * @cfg {Boolean} isFitWidth - resize the width..
32174 isFitWidth : false, // options..
32176 * @cfg {Boolean} isOriginLeft = left align?
32178 isOriginLeft : true,
32180 * @cfg {Boolean} isOriginTop = top align?
32182 isOriginTop : false,
32184 * @cfg {Boolean} isLayoutInstant = no animation?
32186 isLayoutInstant : false, // needed?
32188 * @cfg {Boolean} isResizingContainer = not sure if this is used..
32190 isResizingContainer : true,
32192 * @cfg {Number} columnWidth width of the columns
32198 * @cfg {Number} maxCols maximum number of columns
32203 * @cfg {Number} padHeight padding below box..
32209 * @cfg {Boolean} isAutoInitial defalut true
32212 isAutoInitial : true,
32218 initialColumnWidth : 0,
32219 currentSize : null,
32221 colYs : null, // array.
32228 bricks: null, //CompositeElement
32229 cols : 0, // array?
32230 // element : null, // wrapped now this.el
32231 _isLayoutInited : null,
32234 getAutoCreate : function(){
32238 cls: 'blog-masonary-wrapper ' + this.cls,
32240 cls : 'mas-boxes masonary'
32247 getChildContainer: function( )
32249 if (this.boxesEl) {
32250 return this.boxesEl;
32253 this.boxesEl = this.el.select('.mas-boxes').first();
32255 return this.boxesEl;
32259 initEvents : function()
32263 if(this.isAutoInitial){
32264 Roo.log('hook children rendered');
32265 this.on('childrenrendered', function() {
32266 Roo.log('children rendered');
32273 initial : function()
32275 this.reloadItems();
32277 this.currentSize = this.el.getBox(true);
32279 /// was window resize... - let's see if this works..
32280 Roo.EventManager.onWindowResize(this.resize, this);
32282 if(!this.isAutoInitial){
32287 this.layout.defer(500,this);
32290 reloadItems: function()
32292 this.bricks = this.el.select('.masonry-brick', true);
32294 this.bricks.each(function(b) {
32295 //Roo.log(b.getSize());
32296 if (!b.attr('originalwidth')) {
32297 b.attr('originalwidth', b.getSize().width);
32302 Roo.log(this.bricks.elements.length);
32305 resize : function()
32308 var cs = this.el.getBox(true);
32310 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
32311 Roo.log("no change in with or X");
32314 this.currentSize = cs;
32318 layout : function()
32321 this._resetLayout();
32322 //this._manageStamps();
32324 // don't animate first layout
32325 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
32326 this.layoutItems( isInstant );
32328 // flag for initalized
32329 this._isLayoutInited = true;
32332 layoutItems : function( isInstant )
32334 //var items = this._getItemsForLayout( this.items );
32335 // original code supports filtering layout items.. we just ignore it..
32337 this._layoutItems( this.bricks , isInstant );
32339 this._postLayout();
32341 _layoutItems : function ( items , isInstant)
32343 //this.fireEvent( 'layout', this, items );
32346 if ( !items || !items.elements.length ) {
32347 // no items, emit event with empty array
32352 items.each(function(item) {
32353 Roo.log("layout item");
32355 // get x/y object from method
32356 var position = this._getItemLayoutPosition( item );
32358 position.item = item;
32359 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
32360 queue.push( position );
32363 this._processLayoutQueue( queue );
32365 /** Sets position of item in DOM
32366 * @param {Element} item
32367 * @param {Number} x - horizontal position
32368 * @param {Number} y - vertical position
32369 * @param {Boolean} isInstant - disables transitions
32371 _processLayoutQueue : function( queue )
32373 for ( var i=0, len = queue.length; i < len; i++ ) {
32374 var obj = queue[i];
32375 obj.item.position('absolute');
32376 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
32382 * Any logic you want to do after each layout,
32383 * i.e. size the container
32385 _postLayout : function()
32387 this.resizeContainer();
32390 resizeContainer : function()
32392 if ( !this.isResizingContainer ) {
32395 var size = this._getContainerSize();
32397 this.el.setSize(size.width,size.height);
32398 this.boxesEl.setSize(size.width,size.height);
32404 _resetLayout : function()
32406 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
32407 this.colWidth = this.el.getWidth();
32408 //this.gutter = this.el.getWidth();
32410 this.measureColumns();
32416 this.colYs.push( 0 );
32422 measureColumns : function()
32424 this.getContainerWidth();
32425 // if columnWidth is 0, default to outerWidth of first item
32426 if ( !this.columnWidth ) {
32427 var firstItem = this.bricks.first();
32428 Roo.log(firstItem);
32429 this.columnWidth = this.containerWidth;
32430 if (firstItem && firstItem.attr('originalwidth') ) {
32431 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
32433 // columnWidth fall back to item of first element
32434 Roo.log("set column width?");
32435 this.initialColumnWidth = this.columnWidth ;
32437 // if first elem has no width, default to size of container
32442 if (this.initialColumnWidth) {
32443 this.columnWidth = this.initialColumnWidth;
32448 // column width is fixed at the top - however if container width get's smaller we should
32451 // this bit calcs how man columns..
32453 var columnWidth = this.columnWidth += this.gutter;
32455 // calculate columns
32456 var containerWidth = this.containerWidth + this.gutter;
32458 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
32459 // fix rounding errors, typically with gutters
32460 var excess = columnWidth - containerWidth % columnWidth;
32463 // if overshoot is less than a pixel, round up, otherwise floor it
32464 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
32465 cols = Math[ mathMethod ]( cols );
32466 this.cols = Math.max( cols, 1 );
32467 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
32469 // padding positioning..
32470 var totalColWidth = this.cols * this.columnWidth;
32471 var padavail = this.containerWidth - totalColWidth;
32472 // so for 2 columns - we need 3 'pads'
32474 var padNeeded = (1+this.cols) * this.padWidth;
32476 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
32478 this.columnWidth += padExtra
32479 //this.padWidth = Math.floor(padavail / ( this.cols));
32481 // adjust colum width so that padding is fixed??
32483 // we have 3 columns ... total = width * 3
32484 // we have X left over... that should be used by
32486 //if (this.expandC) {
32494 getContainerWidth : function()
32496 /* // container is parent if fit width
32497 var container = this.isFitWidth ? this.element.parentNode : this.element;
32498 // check that this.size and size are there
32499 // IE8 triggers resize on body size change, so they might not be
32501 var size = getSize( container ); //FIXME
32502 this.containerWidth = size && size.innerWidth; //FIXME
32505 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
32509 _getItemLayoutPosition : function( item ) // what is item?
32511 // we resize the item to our columnWidth..
32513 item.setWidth(this.columnWidth);
32514 item.autoBoxAdjust = false;
32516 var sz = item.getSize();
32518 // how many columns does this brick span
32519 var remainder = this.containerWidth % this.columnWidth;
32521 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
32522 // round if off by 1 pixel, otherwise use ceil
32523 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
32524 colSpan = Math.min( colSpan, this.cols );
32526 // normally this should be '1' as we dont' currently allow multi width columns..
32528 var colGroup = this._getColGroup( colSpan );
32529 // get the minimum Y value from the columns
32530 var minimumY = Math.min.apply( Math, colGroup );
32531 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32533 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
32535 // position the brick
32537 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
32538 y: this.currentSize.y + minimumY + this.padHeight
32542 // apply setHeight to necessary columns
32543 var setHeight = minimumY + sz.height + this.padHeight;
32544 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32546 var setSpan = this.cols + 1 - colGroup.length;
32547 for ( var i = 0; i < setSpan; i++ ) {
32548 this.colYs[ shortColIndex + i ] = setHeight ;
32555 * @param {Number} colSpan - number of columns the element spans
32556 * @returns {Array} colGroup
32558 _getColGroup : function( colSpan )
32560 if ( colSpan < 2 ) {
32561 // if brick spans only one column, use all the column Ys
32566 // how many different places could this brick fit horizontally
32567 var groupCount = this.cols + 1 - colSpan;
32568 // for each group potential horizontal position
32569 for ( var i = 0; i < groupCount; i++ ) {
32570 // make an array of colY values for that one group
32571 var groupColYs = this.colYs.slice( i, i + colSpan );
32572 // and get the max value of the array
32573 colGroup[i] = Math.max.apply( Math, groupColYs );
32578 _manageStamp : function( stamp )
32580 var stampSize = stamp.getSize();
32581 var offset = stamp.getBox();
32582 // get the columns that this stamp affects
32583 var firstX = this.isOriginLeft ? offset.x : offset.right;
32584 var lastX = firstX + stampSize.width;
32585 var firstCol = Math.floor( firstX / this.columnWidth );
32586 firstCol = Math.max( 0, firstCol );
32588 var lastCol = Math.floor( lastX / this.columnWidth );
32589 // lastCol should not go over if multiple of columnWidth #425
32590 lastCol -= lastX % this.columnWidth ? 0 : 1;
32591 lastCol = Math.min( this.cols - 1, lastCol );
32593 // set colYs to bottom of the stamp
32594 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
32597 for ( var i = firstCol; i <= lastCol; i++ ) {
32598 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
32603 _getContainerSize : function()
32605 this.maxY = Math.max.apply( Math, this.colYs );
32610 if ( this.isFitWidth ) {
32611 size.width = this._getContainerFitWidth();
32617 _getContainerFitWidth : function()
32619 var unusedCols = 0;
32620 // count unused columns
32623 if ( this.colYs[i] !== 0 ) {
32628 // fit container to columns that have been used
32629 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
32632 needsResizeLayout : function()
32634 var previousWidth = this.containerWidth;
32635 this.getContainerWidth();
32636 return previousWidth !== this.containerWidth;
32651 * @class Roo.bootstrap.MasonryBrick
32652 * @extends Roo.bootstrap.Component
32653 * Bootstrap MasonryBrick class
32656 * Create a new MasonryBrick
32657 * @param {Object} config The config object
32660 Roo.bootstrap.MasonryBrick = function(config){
32662 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
32664 Roo.bootstrap.MasonryBrick.register(this);
32670 * When a MasonryBrick is clcik
32671 * @param {Roo.bootstrap.MasonryBrick} this
32672 * @param {Roo.EventObject} e
32678 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
32681 * @cfg {String} title
32685 * @cfg {String} html
32689 * @cfg {String} bgimage
32693 * @cfg {String} videourl
32697 * @cfg {String} cls
32701 * @cfg {String} href
32705 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
32710 * @cfg {String} placetitle (center|bottom)
32715 * @cfg {Boolean} isFitContainer defalut true
32717 isFitContainer : true,
32720 * @cfg {Boolean} preventDefault defalut false
32722 preventDefault : false,
32725 * @cfg {Boolean} inverse defalut false
32727 maskInverse : false,
32729 getAutoCreate : function()
32731 if(!this.isFitContainer){
32732 return this.getSplitAutoCreate();
32735 var cls = 'masonry-brick masonry-brick-full';
32737 if(this.href.length){
32738 cls += ' masonry-brick-link';
32741 if(this.bgimage.length){
32742 cls += ' masonry-brick-image';
32745 if(this.maskInverse){
32746 cls += ' mask-inverse';
32749 if(!this.html.length && !this.maskInverse && !this.videourl.length){
32750 cls += ' enable-mask';
32754 cls += ' masonry-' + this.size + '-brick';
32757 if(this.placetitle.length){
32759 switch (this.placetitle) {
32761 cls += ' masonry-center-title';
32764 cls += ' masonry-bottom-title';
32771 if(!this.html.length && !this.bgimage.length){
32772 cls += ' masonry-center-title';
32775 if(!this.html.length && this.bgimage.length){
32776 cls += ' masonry-bottom-title';
32781 cls += ' ' + this.cls;
32785 tag: (this.href.length) ? 'a' : 'div',
32790 cls: 'masonry-brick-mask'
32794 cls: 'masonry-brick-paragraph',
32800 if(this.href.length){
32801 cfg.href = this.href;
32804 var cn = cfg.cn[1].cn;
32806 if(this.title.length){
32809 cls: 'masonry-brick-title',
32814 if(this.html.length){
32817 cls: 'masonry-brick-text',
32822 if (!this.title.length && !this.html.length) {
32823 cfg.cn[1].cls += ' hide';
32826 if(this.bgimage.length){
32829 cls: 'masonry-brick-image-view',
32834 if(this.videourl.length){
32835 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32836 // youtube support only?
32839 cls: 'masonry-brick-image-view',
32842 allowfullscreen : true
32850 getSplitAutoCreate : function()
32852 var cls = 'masonry-brick masonry-brick-split';
32854 if(this.href.length){
32855 cls += ' masonry-brick-link';
32858 if(this.bgimage.length){
32859 cls += ' masonry-brick-image';
32863 cls += ' masonry-' + this.size + '-brick';
32866 switch (this.placetitle) {
32868 cls += ' masonry-center-title';
32871 cls += ' masonry-bottom-title';
32874 if(!this.bgimage.length){
32875 cls += ' masonry-center-title';
32878 if(this.bgimage.length){
32879 cls += ' masonry-bottom-title';
32885 cls += ' ' + this.cls;
32889 tag: (this.href.length) ? 'a' : 'div',
32894 cls: 'masonry-brick-split-head',
32898 cls: 'masonry-brick-paragraph',
32905 cls: 'masonry-brick-split-body',
32911 if(this.href.length){
32912 cfg.href = this.href;
32915 if(this.title.length){
32916 cfg.cn[0].cn[0].cn.push({
32918 cls: 'masonry-brick-title',
32923 if(this.html.length){
32924 cfg.cn[1].cn.push({
32926 cls: 'masonry-brick-text',
32931 if(this.bgimage.length){
32932 cfg.cn[0].cn.push({
32934 cls: 'masonry-brick-image-view',
32939 if(this.videourl.length){
32940 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32941 // youtube support only?
32942 cfg.cn[0].cn.cn.push({
32944 cls: 'masonry-brick-image-view',
32947 allowfullscreen : true
32954 initEvents: function()
32956 switch (this.size) {
32989 this.el.on('touchstart', this.onTouchStart, this);
32990 this.el.on('touchmove', this.onTouchMove, this);
32991 this.el.on('touchend', this.onTouchEnd, this);
32992 this.el.on('contextmenu', this.onContextMenu, this);
32994 this.el.on('mouseenter' ,this.enter, this);
32995 this.el.on('mouseleave', this.leave, this);
32996 this.el.on('click', this.onClick, this);
32999 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
33000 this.parent().bricks.push(this);
33005 onClick: function(e, el)
33007 var time = this.endTimer - this.startTimer;
33008 // Roo.log(e.preventDefault());
33011 e.preventDefault();
33016 if(!this.preventDefault){
33020 e.preventDefault();
33022 if (this.activeClass != '') {
33023 this.selectBrick();
33026 this.fireEvent('click', this, e);
33029 enter: function(e, el)
33031 e.preventDefault();
33033 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
33037 if(this.bgimage.length && this.html.length){
33038 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
33042 leave: function(e, el)
33044 e.preventDefault();
33046 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
33050 if(this.bgimage.length && this.html.length){
33051 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
33055 onTouchStart: function(e, el)
33057 // e.preventDefault();
33059 this.touchmoved = false;
33061 if(!this.isFitContainer){
33065 if(!this.bgimage.length || !this.html.length){
33069 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
33071 this.timer = new Date().getTime();
33075 onTouchMove: function(e, el)
33077 this.touchmoved = true;
33080 onContextMenu : function(e,el)
33082 e.preventDefault();
33083 e.stopPropagation();
33087 onTouchEnd: function(e, el)
33089 // e.preventDefault();
33091 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
33098 if(!this.bgimage.length || !this.html.length){
33100 if(this.href.length){
33101 window.location.href = this.href;
33107 if(!this.isFitContainer){
33111 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
33113 window.location.href = this.href;
33116 //selection on single brick only
33117 selectBrick : function() {
33119 if (!this.parentId) {
33123 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
33124 var index = m.selectedBrick.indexOf(this.id);
33127 m.selectedBrick.splice(index,1);
33128 this.el.removeClass(this.activeClass);
33132 for(var i = 0; i < m.selectedBrick.length; i++) {
33133 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
33134 b.el.removeClass(b.activeClass);
33137 m.selectedBrick = [];
33139 m.selectedBrick.push(this.id);
33140 this.el.addClass(this.activeClass);
33144 isSelected : function(){
33145 return this.el.hasClass(this.activeClass);
33150 Roo.apply(Roo.bootstrap.MasonryBrick, {
33153 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
33155 * register a Masonry Brick
33156 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
33159 register : function(brick)
33161 //this.groups[brick.id] = brick;
33162 this.groups.add(brick.id, brick);
33165 * fetch a masonry brick based on the masonry brick ID
33166 * @param {string} the masonry brick to add
33167 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
33170 get: function(brick_id)
33172 // if (typeof(this.groups[brick_id]) == 'undefined') {
33175 // return this.groups[brick_id] ;
33177 if(this.groups.key(brick_id)) {
33178 return this.groups.key(brick_id);
33196 * @class Roo.bootstrap.Brick
33197 * @extends Roo.bootstrap.Component
33198 * Bootstrap Brick class
33201 * Create a new Brick
33202 * @param {Object} config The config object
33205 Roo.bootstrap.Brick = function(config){
33206 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
33212 * When a Brick is click
33213 * @param {Roo.bootstrap.Brick} this
33214 * @param {Roo.EventObject} e
33220 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
33223 * @cfg {String} title
33227 * @cfg {String} html
33231 * @cfg {String} bgimage
33235 * @cfg {String} cls
33239 * @cfg {String} href
33243 * @cfg {String} video
33247 * @cfg {Boolean} square
33251 getAutoCreate : function()
33253 var cls = 'roo-brick';
33255 if(this.href.length){
33256 cls += ' roo-brick-link';
33259 if(this.bgimage.length){
33260 cls += ' roo-brick-image';
33263 if(!this.html.length && !this.bgimage.length){
33264 cls += ' roo-brick-center-title';
33267 if(!this.html.length && this.bgimage.length){
33268 cls += ' roo-brick-bottom-title';
33272 cls += ' ' + this.cls;
33276 tag: (this.href.length) ? 'a' : 'div',
33281 cls: 'roo-brick-paragraph',
33287 if(this.href.length){
33288 cfg.href = this.href;
33291 var cn = cfg.cn[0].cn;
33293 if(this.title.length){
33296 cls: 'roo-brick-title',
33301 if(this.html.length){
33304 cls: 'roo-brick-text',
33311 if(this.bgimage.length){
33314 cls: 'roo-brick-image-view',
33322 initEvents: function()
33324 if(this.title.length || this.html.length){
33325 this.el.on('mouseenter' ,this.enter, this);
33326 this.el.on('mouseleave', this.leave, this);
33329 Roo.EventManager.onWindowResize(this.resize, this);
33331 if(this.bgimage.length){
33332 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
33333 this.imageEl.on('load', this.onImageLoad, this);
33340 onImageLoad : function()
33345 resize : function()
33347 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
33349 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
33351 if(this.bgimage.length){
33352 var image = this.el.select('.roo-brick-image-view', true).first();
33354 image.setWidth(paragraph.getWidth());
33357 image.setHeight(paragraph.getWidth());
33360 this.el.setHeight(image.getHeight());
33361 paragraph.setHeight(image.getHeight());
33367 enter: function(e, el)
33369 e.preventDefault();
33371 if(this.bgimage.length){
33372 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
33373 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
33377 leave: function(e, el)
33379 e.preventDefault();
33381 if(this.bgimage.length){
33382 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
33383 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
33398 * @class Roo.bootstrap.NumberField
33399 * @extends Roo.bootstrap.Input
33400 * Bootstrap NumberField class
33406 * Create a new NumberField
33407 * @param {Object} config The config object
33410 Roo.bootstrap.NumberField = function(config){
33411 Roo.bootstrap.NumberField.superclass.constructor.call(this, config);
33414 Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
33417 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
33419 allowDecimals : true,
33421 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
33423 decimalSeparator : ".",
33425 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
33427 decimalPrecision : 2,
33429 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
33431 allowNegative : true,
33434 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
33438 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
33440 minValue : Number.NEGATIVE_INFINITY,
33442 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
33444 maxValue : Number.MAX_VALUE,
33446 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
33448 minText : "The minimum value for this field is {0}",
33450 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
33452 maxText : "The maximum value for this field is {0}",
33454 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
33455 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
33457 nanText : "{0} is not a valid number",
33459 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
33461 thousandsDelimiter : false,
33463 * @cfg {String} valueAlign alignment of value
33465 valueAlign : "left",
33467 getAutoCreate : function()
33469 var hiddenInput = {
33473 cls: 'hidden-number-input'
33477 hiddenInput.name = this.name;
33482 var cfg = Roo.bootstrap.NumberField.superclass.getAutoCreate.call(this);
33484 this.name = hiddenInput.name;
33486 if(cfg.cn.length > 0) {
33487 cfg.cn.push(hiddenInput);
33494 initEvents : function()
33496 Roo.bootstrap.NumberField.superclass.initEvents.call(this);
33498 var allowed = "0123456789";
33500 if(this.allowDecimals){
33501 allowed += this.decimalSeparator;
33504 if(this.allowNegative){
33508 if(this.thousandsDelimiter) {
33512 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
33514 var keyPress = function(e){
33516 var k = e.getKey();
33518 var c = e.getCharCode();
33521 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
33522 allowed.indexOf(String.fromCharCode(c)) === -1
33528 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
33532 if(allowed.indexOf(String.fromCharCode(c)) === -1){
33537 this.el.on("keypress", keyPress, this);
33540 validateValue : function(value)
33543 if(!Roo.bootstrap.NumberField.superclass.validateValue.call(this, value)){
33547 var num = this.parseValue(value);
33550 this.markInvalid(String.format(this.nanText, value));
33554 if(num < this.minValue){
33555 this.markInvalid(String.format(this.minText, this.minValue));
33559 if(num > this.maxValue){
33560 this.markInvalid(String.format(this.maxText, this.maxValue));
33567 getValue : function()
33569 var v = this.hiddenEl().getValue();
33571 return this.fixPrecision(this.parseValue(v));
33574 parseValue : function(value)
33576 if(this.thousandsDelimiter) {
33578 r = new RegExp(",", "g");
33579 value = value.replace(r, "");
33582 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
33583 return isNaN(value) ? '' : value;
33586 fixPrecision : function(value)
33588 if(this.thousandsDelimiter) {
33590 r = new RegExp(",", "g");
33591 value = value.replace(r, "");
33594 var nan = isNaN(value);
33596 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
33597 return nan ? '' : value;
33599 return parseFloat(value).toFixed(this.decimalPrecision);
33602 setValue : function(v)
33604 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
33610 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
33612 this.inputEl().dom.value = (v == '') ? '' :
33613 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
33615 if(!this.allowZero && v === '0') {
33616 this.hiddenEl().dom.value = '';
33617 this.inputEl().dom.value = '';
33624 decimalPrecisionFcn : function(v)
33626 return Math.floor(v);
33629 beforeBlur : function()
33631 var v = this.parseValue(this.getRawValue());
33633 if(v || v === 0 || v === ''){
33638 hiddenEl : function()
33640 return this.el.select('input.hidden-number-input',true).first();
33652 * @class Roo.bootstrap.DocumentSlider
33653 * @extends Roo.bootstrap.Component
33654 * Bootstrap DocumentSlider class
33657 * Create a new DocumentViewer
33658 * @param {Object} config The config object
33661 Roo.bootstrap.DocumentSlider = function(config){
33662 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
33669 * Fire after initEvent
33670 * @param {Roo.bootstrap.DocumentSlider} this
33675 * Fire after update
33676 * @param {Roo.bootstrap.DocumentSlider} this
33682 * @param {Roo.bootstrap.DocumentSlider} this
33688 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
33694 getAutoCreate : function()
33698 cls : 'roo-document-slider',
33702 cls : 'roo-document-slider-header',
33706 cls : 'roo-document-slider-header-title'
33712 cls : 'roo-document-slider-body',
33716 cls : 'roo-document-slider-prev',
33720 cls : 'fa fa-chevron-left'
33726 cls : 'roo-document-slider-thumb',
33730 cls : 'roo-document-slider-image'
33736 cls : 'roo-document-slider-next',
33740 cls : 'fa fa-chevron-right'
33752 initEvents : function()
33754 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
33755 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
33757 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
33758 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
33760 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
33761 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
33763 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
33764 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
33766 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
33767 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
33769 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
33770 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33772 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
33773 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33775 this.thumbEl.on('click', this.onClick, this);
33777 this.prevIndicator.on('click', this.prev, this);
33779 this.nextIndicator.on('click', this.next, this);
33783 initial : function()
33785 if(this.files.length){
33786 this.indicator = 1;
33790 this.fireEvent('initial', this);
33793 update : function()
33795 this.imageEl.attr('src', this.files[this.indicator - 1]);
33797 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
33799 this.prevIndicator.show();
33801 if(this.indicator == 1){
33802 this.prevIndicator.hide();
33805 this.nextIndicator.show();
33807 if(this.indicator == this.files.length){
33808 this.nextIndicator.hide();
33811 this.thumbEl.scrollTo('top');
33813 this.fireEvent('update', this);
33816 onClick : function(e)
33818 e.preventDefault();
33820 this.fireEvent('click', this);
33825 e.preventDefault();
33827 this.indicator = Math.max(1, this.indicator - 1);
33834 e.preventDefault();
33836 this.indicator = Math.min(this.files.length, this.indicator + 1);
33850 * @class Roo.bootstrap.RadioSet
33851 * @extends Roo.bootstrap.Input
33852 * Bootstrap RadioSet class
33853 * @cfg {String} indicatorpos (left|right) default left
33854 * @cfg {Boolean} inline (true|false) inline the element (default true)
33855 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
33857 * Create a new RadioSet
33858 * @param {Object} config The config object
33861 Roo.bootstrap.RadioSet = function(config){
33863 Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
33867 Roo.bootstrap.RadioSet.register(this);
33872 * Fires when the element is checked or unchecked.
33873 * @param {Roo.bootstrap.RadioSet} this This radio
33874 * @param {Roo.bootstrap.Radio} item The checked item
33879 * Fires when the element is click.
33880 * @param {Roo.bootstrap.RadioSet} this This radio set
33881 * @param {Roo.bootstrap.Radio} item The checked item
33882 * @param {Roo.EventObject} e The event object
33889 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
33897 indicatorpos : 'left',
33899 getAutoCreate : function()
33903 cls : 'roo-radio-set-label',
33907 html : this.fieldLabel
33912 if(this.indicatorpos == 'left'){
33915 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
33916 tooltip : 'This field is required'
33921 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
33922 tooltip : 'This field is required'
33928 cls : 'roo-radio-set-items'
33931 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
33933 if (align === 'left' && this.fieldLabel.length) {
33936 cls : "roo-radio-set-right",
33942 if(this.labelWidth > 12){
33943 label.style = "width: " + this.labelWidth + 'px';
33946 if(this.labelWidth < 13 && this.labelmd == 0){
33947 this.labelmd = this.labelWidth;
33950 if(this.labellg > 0){
33951 label.cls += ' col-lg-' + this.labellg;
33952 items.cls += ' col-lg-' + (12 - this.labellg);
33955 if(this.labelmd > 0){
33956 label.cls += ' col-md-' + this.labelmd;
33957 items.cls += ' col-md-' + (12 - this.labelmd);
33960 if(this.labelsm > 0){
33961 label.cls += ' col-sm-' + this.labelsm;
33962 items.cls += ' col-sm-' + (12 - this.labelsm);
33965 if(this.labelxs > 0){
33966 label.cls += ' col-xs-' + this.labelxs;
33967 items.cls += ' col-xs-' + (12 - this.labelxs);
33973 cls : 'roo-radio-set',
33977 cls : 'roo-radio-set-input',
33980 value : this.value ? this.value : ''
33987 if(this.weight.length){
33988 cfg.cls += ' roo-radio-' + this.weight;
33992 cfg.cls += ' roo-radio-set-inline';
33996 ['xs','sm','md','lg'].map(function(size){
33997 if (settings[size]) {
33998 cfg.cls += ' col-' + size + '-' + settings[size];
34006 initEvents : function()
34008 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
34009 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
34011 if(!this.fieldLabel.length){
34012 this.labelEl.hide();
34015 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
34016 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
34018 this.indicator = this.indicatorEl();
34020 if(this.indicator){
34021 this.indicator.addClass('invisible');
34024 this.originalValue = this.getValue();
34028 inputEl: function ()
34030 return this.el.select('.roo-radio-set-input', true).first();
34033 getChildContainer : function()
34035 return this.itemsEl;
34038 register : function(item)
34040 this.radioes.push(item);
34044 validate : function()
34046 if(this.getVisibilityEl().hasClass('hidden')){
34052 Roo.each(this.radioes, function(i){
34061 if(this.allowBlank) {
34065 if(this.disabled || valid){
34070 this.markInvalid();
34075 markValid : function()
34077 if(this.labelEl.isVisible(true)){
34078 this.indicatorEl().removeClass('visible');
34079 this.indicatorEl().addClass('invisible');
34082 this.el.removeClass([this.invalidClass, this.validClass]);
34083 this.el.addClass(this.validClass);
34085 this.fireEvent('valid', this);
34088 markInvalid : function(msg)
34090 if(this.allowBlank || this.disabled){
34094 if(this.labelEl.isVisible(true)){
34095 this.indicatorEl().removeClass('invisible');
34096 this.indicatorEl().addClass('visible');
34099 this.el.removeClass([this.invalidClass, this.validClass]);
34100 this.el.addClass(this.invalidClass);
34102 this.fireEvent('invalid', this, msg);
34106 setValue : function(v, suppressEvent)
34108 if(this.value === v){
34115 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
34118 Roo.each(this.radioes, function(i){
34120 i.el.removeClass('checked');
34123 Roo.each(this.radioes, function(i){
34125 if(i.value === v || i.value.toString() === v.toString()){
34127 i.el.addClass('checked');
34129 if(suppressEvent !== true){
34130 this.fireEvent('check', this, i);
34141 clearInvalid : function(){
34143 if(!this.el || this.preventMark){
34147 this.el.removeClass([this.invalidClass]);
34149 this.fireEvent('valid', this);
34154 Roo.apply(Roo.bootstrap.RadioSet, {
34158 register : function(set)
34160 this.groups[set.name] = set;
34163 get: function(name)
34165 if (typeof(this.groups[name]) == 'undefined') {
34169 return this.groups[name] ;
34175 * Ext JS Library 1.1.1
34176 * Copyright(c) 2006-2007, Ext JS, LLC.
34178 * Originally Released Under LGPL - original licence link has changed is not relivant.
34181 * <script type="text/javascript">
34186 * @class Roo.bootstrap.SplitBar
34187 * @extends Roo.util.Observable
34188 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
34192 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
34193 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
34194 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
34195 split.minSize = 100;
34196 split.maxSize = 600;
34197 split.animate = true;
34198 split.on('moved', splitterMoved);
34201 * Create a new SplitBar
34202 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
34203 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
34204 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34205 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
34206 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
34207 position of the SplitBar).
34209 Roo.bootstrap.SplitBar = function(cfg){
34214 // dragElement : elm
34215 // resizingElement: el,
34217 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
34218 // placement : Roo.bootstrap.SplitBar.LEFT ,
34219 // existingProxy ???
34222 this.el = Roo.get(cfg.dragElement, true);
34223 this.el.dom.unselectable = "on";
34225 this.resizingEl = Roo.get(cfg.resizingElement, true);
34229 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34230 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
34233 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
34236 * The minimum size of the resizing element. (Defaults to 0)
34242 * The maximum size of the resizing element. (Defaults to 2000)
34245 this.maxSize = 2000;
34248 * Whether to animate the transition to the new size
34251 this.animate = false;
34254 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
34257 this.useShim = false;
34262 if(!cfg.existingProxy){
34264 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
34266 this.proxy = Roo.get(cfg.existingProxy).dom;
34269 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
34272 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
34275 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
34278 this.dragSpecs = {};
34281 * @private The adapter to use to positon and resize elements
34283 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34284 this.adapter.init(this);
34286 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34288 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
34289 this.el.addClass("roo-splitbar-h");
34292 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
34293 this.el.addClass("roo-splitbar-v");
34299 * Fires when the splitter is moved (alias for {@link #event-moved})
34300 * @param {Roo.bootstrap.SplitBar} this
34301 * @param {Number} newSize the new width or height
34306 * Fires when the splitter is moved
34307 * @param {Roo.bootstrap.SplitBar} this
34308 * @param {Number} newSize the new width or height
34312 * @event beforeresize
34313 * Fires before the splitter is dragged
34314 * @param {Roo.bootstrap.SplitBar} this
34316 "beforeresize" : true,
34318 "beforeapply" : true
34321 Roo.util.Observable.call(this);
34324 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
34325 onStartProxyDrag : function(x, y){
34326 this.fireEvent("beforeresize", this);
34328 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
34330 o.enableDisplayMode("block");
34331 // all splitbars share the same overlay
34332 Roo.bootstrap.SplitBar.prototype.overlay = o;
34334 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
34335 this.overlay.show();
34336 Roo.get(this.proxy).setDisplayed("block");
34337 var size = this.adapter.getElementSize(this);
34338 this.activeMinSize = this.getMinimumSize();;
34339 this.activeMaxSize = this.getMaximumSize();;
34340 var c1 = size - this.activeMinSize;
34341 var c2 = Math.max(this.activeMaxSize - size, 0);
34342 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34343 this.dd.resetConstraints();
34344 this.dd.setXConstraint(
34345 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
34346 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
34348 this.dd.setYConstraint(0, 0);
34350 this.dd.resetConstraints();
34351 this.dd.setXConstraint(0, 0);
34352 this.dd.setYConstraint(
34353 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
34354 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
34357 this.dragSpecs.startSize = size;
34358 this.dragSpecs.startPoint = [x, y];
34359 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
34363 * @private Called after the drag operation by the DDProxy
34365 onEndProxyDrag : function(e){
34366 Roo.get(this.proxy).setDisplayed(false);
34367 var endPoint = Roo.lib.Event.getXY(e);
34369 this.overlay.hide();
34372 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34373 newSize = this.dragSpecs.startSize +
34374 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
34375 endPoint[0] - this.dragSpecs.startPoint[0] :
34376 this.dragSpecs.startPoint[0] - endPoint[0]
34379 newSize = this.dragSpecs.startSize +
34380 (this.placement == Roo.bootstrap.SplitBar.TOP ?
34381 endPoint[1] - this.dragSpecs.startPoint[1] :
34382 this.dragSpecs.startPoint[1] - endPoint[1]
34385 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
34386 if(newSize != this.dragSpecs.startSize){
34387 if(this.fireEvent('beforeapply', this, newSize) !== false){
34388 this.adapter.setElementSize(this, newSize);
34389 this.fireEvent("moved", this, newSize);
34390 this.fireEvent("resize", this, newSize);
34396 * Get the adapter this SplitBar uses
34397 * @return The adapter object
34399 getAdapter : function(){
34400 return this.adapter;
34404 * Set the adapter this SplitBar uses
34405 * @param {Object} adapter A SplitBar adapter object
34407 setAdapter : function(adapter){
34408 this.adapter = adapter;
34409 this.adapter.init(this);
34413 * Gets the minimum size for the resizing element
34414 * @return {Number} The minimum size
34416 getMinimumSize : function(){
34417 return this.minSize;
34421 * Sets the minimum size for the resizing element
34422 * @param {Number} minSize The minimum size
34424 setMinimumSize : function(minSize){
34425 this.minSize = minSize;
34429 * Gets the maximum size for the resizing element
34430 * @return {Number} The maximum size
34432 getMaximumSize : function(){
34433 return this.maxSize;
34437 * Sets the maximum size for the resizing element
34438 * @param {Number} maxSize The maximum size
34440 setMaximumSize : function(maxSize){
34441 this.maxSize = maxSize;
34445 * Sets the initialize size for the resizing element
34446 * @param {Number} size The initial size
34448 setCurrentSize : function(size){
34449 var oldAnimate = this.animate;
34450 this.animate = false;
34451 this.adapter.setElementSize(this, size);
34452 this.animate = oldAnimate;
34456 * Destroy this splitbar.
34457 * @param {Boolean} removeEl True to remove the element
34459 destroy : function(removeEl){
34461 this.shim.remove();
34464 this.proxy.parentNode.removeChild(this.proxy);
34472 * @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.
34474 Roo.bootstrap.SplitBar.createProxy = function(dir){
34475 var proxy = new Roo.Element(document.createElement("div"));
34476 proxy.unselectable();
34477 var cls = 'roo-splitbar-proxy';
34478 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
34479 document.body.appendChild(proxy.dom);
34484 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
34485 * Default Adapter. It assumes the splitter and resizing element are not positioned
34486 * elements and only gets/sets the width of the element. Generally used for table based layouts.
34488 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
34491 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
34492 // do nothing for now
34493 init : function(s){
34497 * Called before drag operations to get the current size of the resizing element.
34498 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34500 getElementSize : function(s){
34501 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34502 return s.resizingEl.getWidth();
34504 return s.resizingEl.getHeight();
34509 * Called after drag operations to set the size of the resizing element.
34510 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34511 * @param {Number} newSize The new size to set
34512 * @param {Function} onComplete A function to be invoked when resizing is complete
34514 setElementSize : function(s, newSize, onComplete){
34515 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34517 s.resizingEl.setWidth(newSize);
34519 onComplete(s, newSize);
34522 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
34527 s.resizingEl.setHeight(newSize);
34529 onComplete(s, newSize);
34532 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
34539 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
34540 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
34541 * Adapter that moves the splitter element to align with the resized sizing element.
34542 * Used with an absolute positioned SplitBar.
34543 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
34544 * document.body, make sure you assign an id to the body element.
34546 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
34547 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34548 this.container = Roo.get(container);
34551 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
34552 init : function(s){
34553 this.basic.init(s);
34556 getElementSize : function(s){
34557 return this.basic.getElementSize(s);
34560 setElementSize : function(s, newSize, onComplete){
34561 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
34564 moveSplitter : function(s){
34565 var yes = Roo.bootstrap.SplitBar;
34566 switch(s.placement){
34568 s.el.setX(s.resizingEl.getRight());
34571 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
34574 s.el.setY(s.resizingEl.getBottom());
34577 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
34584 * Orientation constant - Create a vertical SplitBar
34588 Roo.bootstrap.SplitBar.VERTICAL = 1;
34591 * Orientation constant - Create a horizontal SplitBar
34595 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
34598 * Placement constant - The resizing element is to the left of the splitter element
34602 Roo.bootstrap.SplitBar.LEFT = 1;
34605 * Placement constant - The resizing element is to the right of the splitter element
34609 Roo.bootstrap.SplitBar.RIGHT = 2;
34612 * Placement constant - The resizing element is positioned above the splitter element
34616 Roo.bootstrap.SplitBar.TOP = 3;
34619 * Placement constant - The resizing element is positioned under splitter element
34623 Roo.bootstrap.SplitBar.BOTTOM = 4;
34624 Roo.namespace("Roo.bootstrap.layout");/*
34626 * Ext JS Library 1.1.1
34627 * Copyright(c) 2006-2007, Ext JS, LLC.
34629 * Originally Released Under LGPL - original licence link has changed is not relivant.
34632 * <script type="text/javascript">
34636 * @class Roo.bootstrap.layout.Manager
34637 * @extends Roo.bootstrap.Component
34638 * Base class for layout managers.
34640 Roo.bootstrap.layout.Manager = function(config)
34642 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
34648 /** false to disable window resize monitoring @type Boolean */
34649 this.monitorWindowResize = true;
34654 * Fires when a layout is performed.
34655 * @param {Roo.LayoutManager} this
34659 * @event regionresized
34660 * Fires when the user resizes a region.
34661 * @param {Roo.LayoutRegion} region The resized region
34662 * @param {Number} newSize The new size (width for east/west, height for north/south)
34664 "regionresized" : true,
34666 * @event regioncollapsed
34667 * Fires when a region is collapsed.
34668 * @param {Roo.LayoutRegion} region The collapsed region
34670 "regioncollapsed" : true,
34672 * @event regionexpanded
34673 * Fires when a region is expanded.
34674 * @param {Roo.LayoutRegion} region The expanded region
34676 "regionexpanded" : true
34678 this.updating = false;
34681 this.el = Roo.get(config.el);
34687 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
34692 monitorWindowResize : true,
34698 onRender : function(ct, position)
34701 this.el = Roo.get(ct);
34704 //this.fireEvent('render',this);
34708 initEvents: function()
34712 // ie scrollbar fix
34713 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
34714 document.body.scroll = "no";
34715 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
34716 this.el.position('relative');
34718 this.id = this.el.id;
34719 this.el.addClass("roo-layout-container");
34720 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34721 if(this.el.dom != document.body ) {
34722 this.el.on('resize', this.layout,this);
34723 this.el.on('show', this.layout,this);
34729 * Returns true if this layout is currently being updated
34730 * @return {Boolean}
34732 isUpdating : function(){
34733 return this.updating;
34737 * Suspend the LayoutManager from doing auto-layouts while
34738 * making multiple add or remove calls
34740 beginUpdate : function(){
34741 this.updating = true;
34745 * Restore auto-layouts and optionally disable the manager from performing a layout
34746 * @param {Boolean} noLayout true to disable a layout update
34748 endUpdate : function(noLayout){
34749 this.updating = false;
34755 layout: function(){
34759 onRegionResized : function(region, newSize){
34760 this.fireEvent("regionresized", region, newSize);
34764 onRegionCollapsed : function(region){
34765 this.fireEvent("regioncollapsed", region);
34768 onRegionExpanded : function(region){
34769 this.fireEvent("regionexpanded", region);
34773 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
34774 * performs box-model adjustments.
34775 * @return {Object} The size as an object {width: (the width), height: (the height)}
34777 getViewSize : function()
34780 if(this.el.dom != document.body){
34781 size = this.el.getSize();
34783 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
34785 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
34786 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34791 * Returns the Element this layout is bound to.
34792 * @return {Roo.Element}
34794 getEl : function(){
34799 * Returns the specified region.
34800 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
34801 * @return {Roo.LayoutRegion}
34803 getRegion : function(target){
34804 return this.regions[target.toLowerCase()];
34807 onWindowResize : function(){
34808 if(this.monitorWindowResize){
34815 * Ext JS Library 1.1.1
34816 * Copyright(c) 2006-2007, Ext JS, LLC.
34818 * Originally Released Under LGPL - original licence link has changed is not relivant.
34821 * <script type="text/javascript">
34824 * @class Roo.bootstrap.layout.Border
34825 * @extends Roo.bootstrap.layout.Manager
34826 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
34827 * please see: examples/bootstrap/nested.html<br><br>
34829 <b>The container the layout is rendered into can be either the body element or any other element.
34830 If it is not the body element, the container needs to either be an absolute positioned element,
34831 or you will need to add "position:relative" to the css of the container. You will also need to specify
34832 the container size if it is not the body element.</b>
34835 * Create a new Border
34836 * @param {Object} config Configuration options
34838 Roo.bootstrap.layout.Border = function(config){
34839 config = config || {};
34840 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
34844 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34845 if(config[region]){
34846 config[region].region = region;
34847 this.addRegion(config[region]);
34853 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
34855 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
34857 * Creates and adds a new region if it doesn't already exist.
34858 * @param {String} target The target region key (north, south, east, west or center).
34859 * @param {Object} config The regions config object
34860 * @return {BorderLayoutRegion} The new region
34862 addRegion : function(config)
34864 if(!this.regions[config.region]){
34865 var r = this.factory(config);
34866 this.bindRegion(r);
34868 return this.regions[config.region];
34872 bindRegion : function(r){
34873 this.regions[r.config.region] = r;
34875 r.on("visibilitychange", this.layout, this);
34876 r.on("paneladded", this.layout, this);
34877 r.on("panelremoved", this.layout, this);
34878 r.on("invalidated", this.layout, this);
34879 r.on("resized", this.onRegionResized, this);
34880 r.on("collapsed", this.onRegionCollapsed, this);
34881 r.on("expanded", this.onRegionExpanded, this);
34885 * Performs a layout update.
34887 layout : function()
34889 if(this.updating) {
34893 // render all the rebions if they have not been done alreayd?
34894 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34895 if(this.regions[region] && !this.regions[region].bodyEl){
34896 this.regions[region].onRender(this.el)
34900 var size = this.getViewSize();
34901 var w = size.width;
34902 var h = size.height;
34907 //var x = 0, y = 0;
34909 var rs = this.regions;
34910 var north = rs["north"];
34911 var south = rs["south"];
34912 var west = rs["west"];
34913 var east = rs["east"];
34914 var center = rs["center"];
34915 //if(this.hideOnLayout){ // not supported anymore
34916 //c.el.setStyle("display", "none");
34918 if(north && north.isVisible()){
34919 var b = north.getBox();
34920 var m = north.getMargins();
34921 b.width = w - (m.left+m.right);
34924 centerY = b.height + b.y + m.bottom;
34925 centerH -= centerY;
34926 north.updateBox(this.safeBox(b));
34928 if(south && south.isVisible()){
34929 var b = south.getBox();
34930 var m = south.getMargins();
34931 b.width = w - (m.left+m.right);
34933 var totalHeight = (b.height + m.top + m.bottom);
34934 b.y = h - totalHeight + m.top;
34935 centerH -= totalHeight;
34936 south.updateBox(this.safeBox(b));
34938 if(west && west.isVisible()){
34939 var b = west.getBox();
34940 var m = west.getMargins();
34941 b.height = centerH - (m.top+m.bottom);
34943 b.y = centerY + m.top;
34944 var totalWidth = (b.width + m.left + m.right);
34945 centerX += totalWidth;
34946 centerW -= totalWidth;
34947 west.updateBox(this.safeBox(b));
34949 if(east && east.isVisible()){
34950 var b = east.getBox();
34951 var m = east.getMargins();
34952 b.height = centerH - (m.top+m.bottom);
34953 var totalWidth = (b.width + m.left + m.right);
34954 b.x = w - totalWidth + m.left;
34955 b.y = centerY + m.top;
34956 centerW -= totalWidth;
34957 east.updateBox(this.safeBox(b));
34960 var m = center.getMargins();
34962 x: centerX + m.left,
34963 y: centerY + m.top,
34964 width: centerW - (m.left+m.right),
34965 height: centerH - (m.top+m.bottom)
34967 //if(this.hideOnLayout){
34968 //center.el.setStyle("display", "block");
34970 center.updateBox(this.safeBox(centerBox));
34973 this.fireEvent("layout", this);
34977 safeBox : function(box){
34978 box.width = Math.max(0, box.width);
34979 box.height = Math.max(0, box.height);
34984 * Adds a ContentPanel (or subclass) to this layout.
34985 * @param {String} target The target region key (north, south, east, west or center).
34986 * @param {Roo.ContentPanel} panel The panel to add
34987 * @return {Roo.ContentPanel} The added panel
34989 add : function(target, panel){
34991 target = target.toLowerCase();
34992 return this.regions[target].add(panel);
34996 * Remove a ContentPanel (or subclass) to this layout.
34997 * @param {String} target The target region key (north, south, east, west or center).
34998 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
34999 * @return {Roo.ContentPanel} The removed panel
35001 remove : function(target, panel){
35002 target = target.toLowerCase();
35003 return this.regions[target].remove(panel);
35007 * Searches all regions for a panel with the specified id
35008 * @param {String} panelId
35009 * @return {Roo.ContentPanel} The panel or null if it wasn't found
35011 findPanel : function(panelId){
35012 var rs = this.regions;
35013 for(var target in rs){
35014 if(typeof rs[target] != "function"){
35015 var p = rs[target].getPanel(panelId);
35025 * Searches all regions for a panel with the specified id and activates (shows) it.
35026 * @param {String/ContentPanel} panelId The panels id or the panel itself
35027 * @return {Roo.ContentPanel} The shown panel or null
35029 showPanel : function(panelId) {
35030 var rs = this.regions;
35031 for(var target in rs){
35032 var r = rs[target];
35033 if(typeof r != "function"){
35034 if(r.hasPanel(panelId)){
35035 return r.showPanel(panelId);
35043 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
35044 * @param {Roo.state.Provider} provider (optional) An alternate state provider
35047 restoreState : function(provider){
35049 provider = Roo.state.Manager;
35051 var sm = new Roo.LayoutStateManager();
35052 sm.init(this, provider);
35058 * Adds a xtype elements to the layout.
35062 xtype : 'ContentPanel',
35069 xtype : 'NestedLayoutPanel',
35075 items : [ ... list of content panels or nested layout panels.. ]
35079 * @param {Object} cfg Xtype definition of item to add.
35081 addxtype : function(cfg)
35083 // basically accepts a pannel...
35084 // can accept a layout region..!?!?
35085 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
35088 // theory? children can only be panels??
35090 //if (!cfg.xtype.match(/Panel$/)) {
35095 if (typeof(cfg.region) == 'undefined') {
35096 Roo.log("Failed to add Panel, region was not set");
35100 var region = cfg.region;
35106 xitems = cfg.items;
35113 case 'Content': // ContentPanel (el, cfg)
35114 case 'Scroll': // ContentPanel (el, cfg)
35116 cfg.autoCreate = true;
35117 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35119 // var el = this.el.createChild();
35120 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
35123 this.add(region, ret);
35127 case 'TreePanel': // our new panel!
35128 cfg.el = this.el.createChild();
35129 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35130 this.add(region, ret);
35135 // create a new Layout (which is a Border Layout...
35137 var clayout = cfg.layout;
35138 clayout.el = this.el.createChild();
35139 clayout.items = clayout.items || [];
35143 // replace this exitems with the clayout ones..
35144 xitems = clayout.items;
35146 // force background off if it's in center...
35147 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
35148 cfg.background = false;
35150 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
35153 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35154 //console.log('adding nested layout panel ' + cfg.toSource());
35155 this.add(region, ret);
35156 nb = {}; /// find first...
35161 // needs grid and region
35163 //var el = this.getRegion(region).el.createChild();
35165 *var el = this.el.createChild();
35166 // create the grid first...
35167 cfg.grid.container = el;
35168 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
35171 if (region == 'center' && this.active ) {
35172 cfg.background = false;
35175 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35177 this.add(region, ret);
35179 if (cfg.background) {
35180 // render grid on panel activation (if panel background)
35181 ret.on('activate', function(gp) {
35182 if (!gp.grid.rendered) {
35183 // gp.grid.render(el);
35187 // cfg.grid.render(el);
35193 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
35194 // it was the old xcomponent building that caused this before.
35195 // espeically if border is the top element in the tree.
35205 if (typeof(Roo[cfg.xtype]) != 'undefined') {
35207 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35208 this.add(region, ret);
35212 throw "Can not add '" + cfg.xtype + "' to Border";
35218 this.beginUpdate();
35222 Roo.each(xitems, function(i) {
35223 region = nb && i.region ? i.region : false;
35225 var add = ret.addxtype(i);
35228 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
35229 if (!i.background) {
35230 abn[region] = nb[region] ;
35237 // make the last non-background panel active..
35238 //if (nb) { Roo.log(abn); }
35241 for(var r in abn) {
35242 region = this.getRegion(r);
35244 // tried using nb[r], but it does not work..
35246 region.showPanel(abn[r]);
35257 factory : function(cfg)
35260 var validRegions = Roo.bootstrap.layout.Border.regions;
35262 var target = cfg.region;
35265 var r = Roo.bootstrap.layout;
35269 return new r.North(cfg);
35271 return new r.South(cfg);
35273 return new r.East(cfg);
35275 return new r.West(cfg);
35277 return new r.Center(cfg);
35279 throw 'Layout region "'+target+'" not supported.';
35286 * Ext JS Library 1.1.1
35287 * Copyright(c) 2006-2007, Ext JS, LLC.
35289 * Originally Released Under LGPL - original licence link has changed is not relivant.
35292 * <script type="text/javascript">
35296 * @class Roo.bootstrap.layout.Basic
35297 * @extends Roo.util.Observable
35298 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
35299 * and does not have a titlebar, tabs or any other features. All it does is size and position
35300 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
35301 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35302 * @cfg {string} region the region that it inhabits..
35303 * @cfg {bool} skipConfig skip config?
35307 Roo.bootstrap.layout.Basic = function(config){
35309 this.mgr = config.mgr;
35311 this.position = config.region;
35313 var skipConfig = config.skipConfig;
35317 * @scope Roo.BasicLayoutRegion
35321 * @event beforeremove
35322 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
35323 * @param {Roo.LayoutRegion} this
35324 * @param {Roo.ContentPanel} panel The panel
35325 * @param {Object} e The cancel event object
35327 "beforeremove" : true,
35329 * @event invalidated
35330 * Fires when the layout for this region is changed.
35331 * @param {Roo.LayoutRegion} this
35333 "invalidated" : true,
35335 * @event visibilitychange
35336 * Fires when this region is shown or hidden
35337 * @param {Roo.LayoutRegion} this
35338 * @param {Boolean} visibility true or false
35340 "visibilitychange" : true,
35342 * @event paneladded
35343 * Fires when a panel is added.
35344 * @param {Roo.LayoutRegion} this
35345 * @param {Roo.ContentPanel} panel The panel
35347 "paneladded" : true,
35349 * @event panelremoved
35350 * Fires when a panel is removed.
35351 * @param {Roo.LayoutRegion} this
35352 * @param {Roo.ContentPanel} panel The panel
35354 "panelremoved" : true,
35356 * @event beforecollapse
35357 * Fires when this region before collapse.
35358 * @param {Roo.LayoutRegion} this
35360 "beforecollapse" : true,
35363 * Fires when this region is collapsed.
35364 * @param {Roo.LayoutRegion} this
35366 "collapsed" : true,
35369 * Fires when this region is expanded.
35370 * @param {Roo.LayoutRegion} this
35375 * Fires when this region is slid into view.
35376 * @param {Roo.LayoutRegion} this
35378 "slideshow" : true,
35381 * Fires when this region slides out of view.
35382 * @param {Roo.LayoutRegion} this
35384 "slidehide" : true,
35386 * @event panelactivated
35387 * Fires when a panel is activated.
35388 * @param {Roo.LayoutRegion} this
35389 * @param {Roo.ContentPanel} panel The activated panel
35391 "panelactivated" : true,
35394 * Fires when the user resizes this region.
35395 * @param {Roo.LayoutRegion} this
35396 * @param {Number} newSize The new size (width for east/west, height for north/south)
35400 /** A collection of panels in this region. @type Roo.util.MixedCollection */
35401 this.panels = new Roo.util.MixedCollection();
35402 this.panels.getKey = this.getPanelId.createDelegate(this);
35404 this.activePanel = null;
35405 // ensure listeners are added...
35407 if (config.listeners || config.events) {
35408 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
35409 listeners : config.listeners || {},
35410 events : config.events || {}
35414 if(skipConfig !== true){
35415 this.applyConfig(config);
35419 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
35421 getPanelId : function(p){
35425 applyConfig : function(config){
35426 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35427 this.config = config;
35432 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
35433 * the width, for horizontal (north, south) the height.
35434 * @param {Number} newSize The new width or height
35436 resizeTo : function(newSize){
35437 var el = this.el ? this.el :
35438 (this.activePanel ? this.activePanel.getEl() : null);
35440 switch(this.position){
35443 el.setWidth(newSize);
35444 this.fireEvent("resized", this, newSize);
35448 el.setHeight(newSize);
35449 this.fireEvent("resized", this, newSize);
35455 getBox : function(){
35456 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
35459 getMargins : function(){
35460 return this.margins;
35463 updateBox : function(box){
35465 var el = this.activePanel.getEl();
35466 el.dom.style.left = box.x + "px";
35467 el.dom.style.top = box.y + "px";
35468 this.activePanel.setSize(box.width, box.height);
35472 * Returns the container element for this region.
35473 * @return {Roo.Element}
35475 getEl : function(){
35476 return this.activePanel;
35480 * Returns true if this region is currently visible.
35481 * @return {Boolean}
35483 isVisible : function(){
35484 return this.activePanel ? true : false;
35487 setActivePanel : function(panel){
35488 panel = this.getPanel(panel);
35489 if(this.activePanel && this.activePanel != panel){
35490 this.activePanel.setActiveState(false);
35491 this.activePanel.getEl().setLeftTop(-10000,-10000);
35493 this.activePanel = panel;
35494 panel.setActiveState(true);
35496 panel.setSize(this.box.width, this.box.height);
35498 this.fireEvent("panelactivated", this, panel);
35499 this.fireEvent("invalidated");
35503 * Show the specified panel.
35504 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
35505 * @return {Roo.ContentPanel} The shown panel or null
35507 showPanel : function(panel){
35508 panel = this.getPanel(panel);
35510 this.setActivePanel(panel);
35516 * Get the active panel for this region.
35517 * @return {Roo.ContentPanel} The active panel or null
35519 getActivePanel : function(){
35520 return this.activePanel;
35524 * Add the passed ContentPanel(s)
35525 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35526 * @return {Roo.ContentPanel} The panel added (if only one was added)
35528 add : function(panel){
35529 if(arguments.length > 1){
35530 for(var i = 0, len = arguments.length; i < len; i++) {
35531 this.add(arguments[i]);
35535 if(this.hasPanel(panel)){
35536 this.showPanel(panel);
35539 var el = panel.getEl();
35540 if(el.dom.parentNode != this.mgr.el.dom){
35541 this.mgr.el.dom.appendChild(el.dom);
35543 if(panel.setRegion){
35544 panel.setRegion(this);
35546 this.panels.add(panel);
35547 el.setStyle("position", "absolute");
35548 if(!panel.background){
35549 this.setActivePanel(panel);
35550 if(this.config.initialSize && this.panels.getCount()==1){
35551 this.resizeTo(this.config.initialSize);
35554 this.fireEvent("paneladded", this, panel);
35559 * Returns true if the panel is in this region.
35560 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35561 * @return {Boolean}
35563 hasPanel : function(panel){
35564 if(typeof panel == "object"){ // must be panel obj
35565 panel = panel.getId();
35567 return this.getPanel(panel) ? true : false;
35571 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35572 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35573 * @param {Boolean} preservePanel Overrides the config preservePanel option
35574 * @return {Roo.ContentPanel} The panel that was removed
35576 remove : function(panel, preservePanel){
35577 panel = this.getPanel(panel);
35582 this.fireEvent("beforeremove", this, panel, e);
35583 if(e.cancel === true){
35586 var panelId = panel.getId();
35587 this.panels.removeKey(panelId);
35592 * Returns the panel specified or null if it's not in this region.
35593 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35594 * @return {Roo.ContentPanel}
35596 getPanel : function(id){
35597 if(typeof id == "object"){ // must be panel obj
35600 return this.panels.get(id);
35604 * Returns this regions position (north/south/east/west/center).
35607 getPosition: function(){
35608 return this.position;
35612 * Ext JS Library 1.1.1
35613 * Copyright(c) 2006-2007, Ext JS, LLC.
35615 * Originally Released Under LGPL - original licence link has changed is not relivant.
35618 * <script type="text/javascript">
35622 * @class Roo.bootstrap.layout.Region
35623 * @extends Roo.bootstrap.layout.Basic
35624 * This class represents a region in a layout manager.
35626 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
35627 * @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})
35628 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
35629 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
35630 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
35631 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
35632 * @cfg {String} title The title for the region (overrides panel titles)
35633 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
35634 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
35635 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
35636 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
35637 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
35638 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
35639 * the space available, similar to FireFox 1.5 tabs (defaults to false)
35640 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
35641 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
35642 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
35644 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
35645 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
35646 * @cfg {Boolean} disableTabTips True to disable tab tooltips
35647 * @cfg {Number} width For East/West panels
35648 * @cfg {Number} height For North/South panels
35649 * @cfg {Boolean} split To show the splitter
35650 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
35652 * @cfg {string} cls Extra CSS classes to add to region
35654 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35655 * @cfg {string} region the region that it inhabits..
35658 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
35659 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
35661 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
35662 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
35663 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
35665 Roo.bootstrap.layout.Region = function(config)
35667 this.applyConfig(config);
35669 var mgr = config.mgr;
35670 var pos = config.region;
35671 config.skipConfig = true;
35672 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
35675 this.onRender(mgr.el);
35678 this.visible = true;
35679 this.collapsed = false;
35680 this.unrendered_panels = [];
35683 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
35685 position: '', // set by wrapper (eg. north/south etc..)
35686 unrendered_panels : null, // unrendered panels.
35687 createBody : function(){
35688 /** This region's body element
35689 * @type Roo.Element */
35690 this.bodyEl = this.el.createChild({
35692 cls: "roo-layout-panel-body tab-content" // bootstrap added...
35696 onRender: function(ctr, pos)
35698 var dh = Roo.DomHelper;
35699 /** This region's container element
35700 * @type Roo.Element */
35701 this.el = dh.append(ctr.dom, {
35703 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
35705 /** This region's title element
35706 * @type Roo.Element */
35708 this.titleEl = dh.append(this.el.dom,
35711 unselectable: "on",
35712 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
35714 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
35715 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
35718 this.titleEl.enableDisplayMode();
35719 /** This region's title text element
35720 * @type HTMLElement */
35721 this.titleTextEl = this.titleEl.dom.firstChild;
35722 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
35724 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
35725 this.closeBtn.enableDisplayMode();
35726 this.closeBtn.on("click", this.closeClicked, this);
35727 this.closeBtn.hide();
35729 this.createBody(this.config);
35730 if(this.config.hideWhenEmpty){
35732 this.on("paneladded", this.validateVisibility, this);
35733 this.on("panelremoved", this.validateVisibility, this);
35735 if(this.autoScroll){
35736 this.bodyEl.setStyle("overflow", "auto");
35738 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
35740 //if(c.titlebar !== false){
35741 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
35742 this.titleEl.hide();
35744 this.titleEl.show();
35745 if(this.config.title){
35746 this.titleTextEl.innerHTML = this.config.title;
35750 if(this.config.collapsed){
35751 this.collapse(true);
35753 if(this.config.hidden){
35757 if (this.unrendered_panels && this.unrendered_panels.length) {
35758 for (var i =0;i< this.unrendered_panels.length; i++) {
35759 this.add(this.unrendered_panels[i]);
35761 this.unrendered_panels = null;
35767 applyConfig : function(c)
35770 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
35771 var dh = Roo.DomHelper;
35772 if(c.titlebar !== false){
35773 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
35774 this.collapseBtn.on("click", this.collapse, this);
35775 this.collapseBtn.enableDisplayMode();
35777 if(c.showPin === true || this.showPin){
35778 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
35779 this.stickBtn.enableDisplayMode();
35780 this.stickBtn.on("click", this.expand, this);
35781 this.stickBtn.hide();
35786 /** This region's collapsed element
35787 * @type Roo.Element */
35790 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
35791 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
35794 if(c.floatable !== false){
35795 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
35796 this.collapsedEl.on("click", this.collapseClick, this);
35799 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
35800 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
35801 id: "message", unselectable: "on", style:{"float":"left"}});
35802 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
35804 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
35805 this.expandBtn.on("click", this.expand, this);
35809 if(this.collapseBtn){
35810 this.collapseBtn.setVisible(c.collapsible == true);
35813 this.cmargins = c.cmargins || this.cmargins ||
35814 (this.position == "west" || this.position == "east" ?
35815 {top: 0, left: 2, right:2, bottom: 0} :
35816 {top: 2, left: 0, right:0, bottom: 2});
35818 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35821 this.bottomTabs = c.tabPosition != "top";
35823 this.autoScroll = c.autoScroll || false;
35828 this.duration = c.duration || .30;
35829 this.slideDuration = c.slideDuration || .45;
35834 * Returns true if this region is currently visible.
35835 * @return {Boolean}
35837 isVisible : function(){
35838 return this.visible;
35842 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
35843 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
35845 //setCollapsedTitle : function(title){
35846 // title = title || " ";
35847 // if(this.collapsedTitleTextEl){
35848 // this.collapsedTitleTextEl.innerHTML = title;
35852 getBox : function(){
35854 // if(!this.collapsed){
35855 b = this.el.getBox(false, true);
35857 // b = this.collapsedEl.getBox(false, true);
35862 getMargins : function(){
35863 return this.margins;
35864 //return this.collapsed ? this.cmargins : this.margins;
35867 highlight : function(){
35868 this.el.addClass("x-layout-panel-dragover");
35871 unhighlight : function(){
35872 this.el.removeClass("x-layout-panel-dragover");
35875 updateBox : function(box)
35877 if (!this.bodyEl) {
35878 return; // not rendered yet..
35882 if(!this.collapsed){
35883 this.el.dom.style.left = box.x + "px";
35884 this.el.dom.style.top = box.y + "px";
35885 this.updateBody(box.width, box.height);
35887 this.collapsedEl.dom.style.left = box.x + "px";
35888 this.collapsedEl.dom.style.top = box.y + "px";
35889 this.collapsedEl.setSize(box.width, box.height);
35892 this.tabs.autoSizeTabs();
35896 updateBody : function(w, h)
35899 this.el.setWidth(w);
35900 w -= this.el.getBorderWidth("rl");
35901 if(this.config.adjustments){
35902 w += this.config.adjustments[0];
35905 if(h !== null && h > 0){
35906 this.el.setHeight(h);
35907 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
35908 h -= this.el.getBorderWidth("tb");
35909 if(this.config.adjustments){
35910 h += this.config.adjustments[1];
35912 this.bodyEl.setHeight(h);
35914 h = this.tabs.syncHeight(h);
35917 if(this.panelSize){
35918 w = w !== null ? w : this.panelSize.width;
35919 h = h !== null ? h : this.panelSize.height;
35921 if(this.activePanel){
35922 var el = this.activePanel.getEl();
35923 w = w !== null ? w : el.getWidth();
35924 h = h !== null ? h : el.getHeight();
35925 this.panelSize = {width: w, height: h};
35926 this.activePanel.setSize(w, h);
35928 if(Roo.isIE && this.tabs){
35929 this.tabs.el.repaint();
35934 * Returns the container element for this region.
35935 * @return {Roo.Element}
35937 getEl : function(){
35942 * Hides this region.
35945 //if(!this.collapsed){
35946 this.el.dom.style.left = "-2000px";
35949 // this.collapsedEl.dom.style.left = "-2000px";
35950 // this.collapsedEl.hide();
35952 this.visible = false;
35953 this.fireEvent("visibilitychange", this, false);
35957 * Shows this region if it was previously hidden.
35960 //if(!this.collapsed){
35963 // this.collapsedEl.show();
35965 this.visible = true;
35966 this.fireEvent("visibilitychange", this, true);
35969 closeClicked : function(){
35970 if(this.activePanel){
35971 this.remove(this.activePanel);
35975 collapseClick : function(e){
35977 e.stopPropagation();
35980 e.stopPropagation();
35986 * Collapses this region.
35987 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
35990 collapse : function(skipAnim, skipCheck = false){
35991 if(this.collapsed) {
35995 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
35997 this.collapsed = true;
35999 this.split.el.hide();
36001 if(this.config.animate && skipAnim !== true){
36002 this.fireEvent("invalidated", this);
36003 this.animateCollapse();
36005 this.el.setLocation(-20000,-20000);
36007 this.collapsedEl.show();
36008 this.fireEvent("collapsed", this);
36009 this.fireEvent("invalidated", this);
36015 animateCollapse : function(){
36020 * Expands this region if it was previously collapsed.
36021 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
36022 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
36025 expand : function(e, skipAnim){
36027 e.stopPropagation();
36029 if(!this.collapsed || this.el.hasActiveFx()) {
36033 this.afterSlideIn();
36036 this.collapsed = false;
36037 if(this.config.animate && skipAnim !== true){
36038 this.animateExpand();
36042 this.split.el.show();
36044 this.collapsedEl.setLocation(-2000,-2000);
36045 this.collapsedEl.hide();
36046 this.fireEvent("invalidated", this);
36047 this.fireEvent("expanded", this);
36051 animateExpand : function(){
36055 initTabs : function()
36057 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
36059 var ts = new Roo.bootstrap.panel.Tabs({
36060 el: this.bodyEl.dom,
36061 tabPosition: this.bottomTabs ? 'bottom' : 'top',
36062 disableTooltips: this.config.disableTabTips,
36063 toolbar : this.config.toolbar
36066 if(this.config.hideTabs){
36067 ts.stripWrap.setDisplayed(false);
36070 ts.resizeTabs = this.config.resizeTabs === true;
36071 ts.minTabWidth = this.config.minTabWidth || 40;
36072 ts.maxTabWidth = this.config.maxTabWidth || 250;
36073 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
36074 ts.monitorResize = false;
36075 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
36076 ts.bodyEl.addClass('roo-layout-tabs-body');
36077 this.panels.each(this.initPanelAsTab, this);
36080 initPanelAsTab : function(panel){
36081 var ti = this.tabs.addTab(
36085 this.config.closeOnTab && panel.isClosable(),
36088 if(panel.tabTip !== undefined){
36089 ti.setTooltip(panel.tabTip);
36091 ti.on("activate", function(){
36092 this.setActivePanel(panel);
36095 if(this.config.closeOnTab){
36096 ti.on("beforeclose", function(t, e){
36098 this.remove(panel);
36102 panel.tabItem = ti;
36107 updatePanelTitle : function(panel, title)
36109 if(this.activePanel == panel){
36110 this.updateTitle(title);
36113 var ti = this.tabs.getTab(panel.getEl().id);
36115 if(panel.tabTip !== undefined){
36116 ti.setTooltip(panel.tabTip);
36121 updateTitle : function(title){
36122 if(this.titleTextEl && !this.config.title){
36123 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
36127 setActivePanel : function(panel)
36129 panel = this.getPanel(panel);
36130 if(this.activePanel && this.activePanel != panel){
36131 if(this.activePanel.setActiveState(false) === false){
36135 this.activePanel = panel;
36136 panel.setActiveState(true);
36137 if(this.panelSize){
36138 panel.setSize(this.panelSize.width, this.panelSize.height);
36141 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
36143 this.updateTitle(panel.getTitle());
36145 this.fireEvent("invalidated", this);
36147 this.fireEvent("panelactivated", this, panel);
36151 * Shows the specified panel.
36152 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
36153 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
36155 showPanel : function(panel)
36157 panel = this.getPanel(panel);
36160 var tab = this.tabs.getTab(panel.getEl().id);
36161 if(tab.isHidden()){
36162 this.tabs.unhideTab(tab.id);
36166 this.setActivePanel(panel);
36173 * Get the active panel for this region.
36174 * @return {Roo.ContentPanel} The active panel or null
36176 getActivePanel : function(){
36177 return this.activePanel;
36180 validateVisibility : function(){
36181 if(this.panels.getCount() < 1){
36182 this.updateTitle(" ");
36183 this.closeBtn.hide();
36186 if(!this.isVisible()){
36193 * Adds the passed ContentPanel(s) to this region.
36194 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
36195 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
36197 add : function(panel)
36199 if(arguments.length > 1){
36200 for(var i = 0, len = arguments.length; i < len; i++) {
36201 this.add(arguments[i]);
36206 // if we have not been rendered yet, then we can not really do much of this..
36207 if (!this.bodyEl) {
36208 this.unrendered_panels.push(panel);
36215 if(this.hasPanel(panel)){
36216 this.showPanel(panel);
36219 panel.setRegion(this);
36220 this.panels.add(panel);
36221 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
36222 // sinle panel - no tab...?? would it not be better to render it with the tabs,
36223 // and hide them... ???
36224 this.bodyEl.dom.appendChild(panel.getEl().dom);
36225 if(panel.background !== true){
36226 this.setActivePanel(panel);
36228 this.fireEvent("paneladded", this, panel);
36235 this.initPanelAsTab(panel);
36239 if(panel.background !== true){
36240 this.tabs.activate(panel.getEl().id);
36242 this.fireEvent("paneladded", this, panel);
36247 * Hides the tab for the specified panel.
36248 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36250 hidePanel : function(panel){
36251 if(this.tabs && (panel = this.getPanel(panel))){
36252 this.tabs.hideTab(panel.getEl().id);
36257 * Unhides the tab for a previously hidden panel.
36258 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36260 unhidePanel : function(panel){
36261 if(this.tabs && (panel = this.getPanel(panel))){
36262 this.tabs.unhideTab(panel.getEl().id);
36266 clearPanels : function(){
36267 while(this.panels.getCount() > 0){
36268 this.remove(this.panels.first());
36273 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
36274 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36275 * @param {Boolean} preservePanel Overrides the config preservePanel option
36276 * @return {Roo.ContentPanel} The panel that was removed
36278 remove : function(panel, preservePanel)
36280 panel = this.getPanel(panel);
36285 this.fireEvent("beforeremove", this, panel, e);
36286 if(e.cancel === true){
36289 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
36290 var panelId = panel.getId();
36291 this.panels.removeKey(panelId);
36293 document.body.appendChild(panel.getEl().dom);
36296 this.tabs.removeTab(panel.getEl().id);
36297 }else if (!preservePanel){
36298 this.bodyEl.dom.removeChild(panel.getEl().dom);
36300 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
36301 var p = this.panels.first();
36302 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
36303 tempEl.appendChild(p.getEl().dom);
36304 this.bodyEl.update("");
36305 this.bodyEl.dom.appendChild(p.getEl().dom);
36307 this.updateTitle(p.getTitle());
36309 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
36310 this.setActivePanel(p);
36312 panel.setRegion(null);
36313 if(this.activePanel == panel){
36314 this.activePanel = null;
36316 if(this.config.autoDestroy !== false && preservePanel !== true){
36317 try{panel.destroy();}catch(e){}
36319 this.fireEvent("panelremoved", this, panel);
36324 * Returns the TabPanel component used by this region
36325 * @return {Roo.TabPanel}
36327 getTabs : function(){
36331 createTool : function(parentEl, className){
36332 var btn = Roo.DomHelper.append(parentEl, {
36334 cls: "x-layout-tools-button",
36337 cls: "roo-layout-tools-button-inner " + className,
36341 btn.addClassOnOver("roo-layout-tools-button-over");
36346 * Ext JS Library 1.1.1
36347 * Copyright(c) 2006-2007, Ext JS, LLC.
36349 * Originally Released Under LGPL - original licence link has changed is not relivant.
36352 * <script type="text/javascript">
36358 * @class Roo.SplitLayoutRegion
36359 * @extends Roo.LayoutRegion
36360 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
36362 Roo.bootstrap.layout.Split = function(config){
36363 this.cursor = config.cursor;
36364 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
36367 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
36369 splitTip : "Drag to resize.",
36370 collapsibleSplitTip : "Drag to resize. Double click to hide.",
36371 useSplitTips : false,
36373 applyConfig : function(config){
36374 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
36377 onRender : function(ctr,pos) {
36379 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
36380 if(!this.config.split){
36385 var splitEl = Roo.DomHelper.append(ctr.dom, {
36387 id: this.el.id + "-split",
36388 cls: "roo-layout-split roo-layout-split-"+this.position,
36391 /** The SplitBar for this region
36392 * @type Roo.SplitBar */
36393 // does not exist yet...
36394 Roo.log([this.position, this.orientation]);
36396 this.split = new Roo.bootstrap.SplitBar({
36397 dragElement : splitEl,
36398 resizingElement: this.el,
36399 orientation : this.orientation
36402 this.split.on("moved", this.onSplitMove, this);
36403 this.split.useShim = this.config.useShim === true;
36404 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
36405 if(this.useSplitTips){
36406 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
36408 //if(config.collapsible){
36409 // this.split.el.on("dblclick", this.collapse, this);
36412 if(typeof this.config.minSize != "undefined"){
36413 this.split.minSize = this.config.minSize;
36415 if(typeof this.config.maxSize != "undefined"){
36416 this.split.maxSize = this.config.maxSize;
36418 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
36419 this.hideSplitter();
36424 getHMaxSize : function(){
36425 var cmax = this.config.maxSize || 10000;
36426 var center = this.mgr.getRegion("center");
36427 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
36430 getVMaxSize : function(){
36431 var cmax = this.config.maxSize || 10000;
36432 var center = this.mgr.getRegion("center");
36433 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
36436 onSplitMove : function(split, newSize){
36437 this.fireEvent("resized", this, newSize);
36441 * Returns the {@link Roo.SplitBar} for this region.
36442 * @return {Roo.SplitBar}
36444 getSplitBar : function(){
36449 this.hideSplitter();
36450 Roo.bootstrap.layout.Split.superclass.hide.call(this);
36453 hideSplitter : function(){
36455 this.split.el.setLocation(-2000,-2000);
36456 this.split.el.hide();
36462 this.split.el.show();
36464 Roo.bootstrap.layout.Split.superclass.show.call(this);
36467 beforeSlide: function(){
36468 if(Roo.isGecko){// firefox overflow auto bug workaround
36469 this.bodyEl.clip();
36471 this.tabs.bodyEl.clip();
36473 if(this.activePanel){
36474 this.activePanel.getEl().clip();
36476 if(this.activePanel.beforeSlide){
36477 this.activePanel.beforeSlide();
36483 afterSlide : function(){
36484 if(Roo.isGecko){// firefox overflow auto bug workaround
36485 this.bodyEl.unclip();
36487 this.tabs.bodyEl.unclip();
36489 if(this.activePanel){
36490 this.activePanel.getEl().unclip();
36491 if(this.activePanel.afterSlide){
36492 this.activePanel.afterSlide();
36498 initAutoHide : function(){
36499 if(this.autoHide !== false){
36500 if(!this.autoHideHd){
36501 var st = new Roo.util.DelayedTask(this.slideIn, this);
36502 this.autoHideHd = {
36503 "mouseout": function(e){
36504 if(!e.within(this.el, true)){
36508 "mouseover" : function(e){
36514 this.el.on(this.autoHideHd);
36518 clearAutoHide : function(){
36519 if(this.autoHide !== false){
36520 this.el.un("mouseout", this.autoHideHd.mouseout);
36521 this.el.un("mouseover", this.autoHideHd.mouseover);
36525 clearMonitor : function(){
36526 Roo.get(document).un("click", this.slideInIf, this);
36529 // these names are backwards but not changed for compat
36530 slideOut : function(){
36531 if(this.isSlid || this.el.hasActiveFx()){
36534 this.isSlid = true;
36535 if(this.collapseBtn){
36536 this.collapseBtn.hide();
36538 this.closeBtnState = this.closeBtn.getStyle('display');
36539 this.closeBtn.hide();
36541 this.stickBtn.show();
36544 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
36545 this.beforeSlide();
36546 this.el.setStyle("z-index", 10001);
36547 this.el.slideIn(this.getSlideAnchor(), {
36548 callback: function(){
36550 this.initAutoHide();
36551 Roo.get(document).on("click", this.slideInIf, this);
36552 this.fireEvent("slideshow", this);
36559 afterSlideIn : function(){
36560 this.clearAutoHide();
36561 this.isSlid = false;
36562 this.clearMonitor();
36563 this.el.setStyle("z-index", "");
36564 if(this.collapseBtn){
36565 this.collapseBtn.show();
36567 this.closeBtn.setStyle('display', this.closeBtnState);
36569 this.stickBtn.hide();
36571 this.fireEvent("slidehide", this);
36574 slideIn : function(cb){
36575 if(!this.isSlid || this.el.hasActiveFx()){
36579 this.isSlid = false;
36580 this.beforeSlide();
36581 this.el.slideOut(this.getSlideAnchor(), {
36582 callback: function(){
36583 this.el.setLeftTop(-10000, -10000);
36585 this.afterSlideIn();
36593 slideInIf : function(e){
36594 if(!e.within(this.el)){
36599 animateCollapse : function(){
36600 this.beforeSlide();
36601 this.el.setStyle("z-index", 20000);
36602 var anchor = this.getSlideAnchor();
36603 this.el.slideOut(anchor, {
36604 callback : function(){
36605 this.el.setStyle("z-index", "");
36606 this.collapsedEl.slideIn(anchor, {duration:.3});
36608 this.el.setLocation(-10000,-10000);
36610 this.fireEvent("collapsed", this);
36617 animateExpand : function(){
36618 this.beforeSlide();
36619 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
36620 this.el.setStyle("z-index", 20000);
36621 this.collapsedEl.hide({
36624 this.el.slideIn(this.getSlideAnchor(), {
36625 callback : function(){
36626 this.el.setStyle("z-index", "");
36629 this.split.el.show();
36631 this.fireEvent("invalidated", this);
36632 this.fireEvent("expanded", this);
36660 getAnchor : function(){
36661 return this.anchors[this.position];
36664 getCollapseAnchor : function(){
36665 return this.canchors[this.position];
36668 getSlideAnchor : function(){
36669 return this.sanchors[this.position];
36672 getAlignAdj : function(){
36673 var cm = this.cmargins;
36674 switch(this.position){
36690 getExpandAdj : function(){
36691 var c = this.collapsedEl, cm = this.cmargins;
36692 switch(this.position){
36694 return [-(cm.right+c.getWidth()+cm.left), 0];
36697 return [cm.right+c.getWidth()+cm.left, 0];
36700 return [0, -(cm.top+cm.bottom+c.getHeight())];
36703 return [0, cm.top+cm.bottom+c.getHeight()];
36709 * Ext JS Library 1.1.1
36710 * Copyright(c) 2006-2007, Ext JS, LLC.
36712 * Originally Released Under LGPL - original licence link has changed is not relivant.
36715 * <script type="text/javascript">
36718 * These classes are private internal classes
36720 Roo.bootstrap.layout.Center = function(config){
36721 config.region = "center";
36722 Roo.bootstrap.layout.Region.call(this, config);
36723 this.visible = true;
36724 this.minWidth = config.minWidth || 20;
36725 this.minHeight = config.minHeight || 20;
36728 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
36730 // center panel can't be hidden
36734 // center panel can't be hidden
36737 getMinWidth: function(){
36738 return this.minWidth;
36741 getMinHeight: function(){
36742 return this.minHeight;
36755 Roo.bootstrap.layout.North = function(config)
36757 config.region = 'north';
36758 config.cursor = 'n-resize';
36760 Roo.bootstrap.layout.Split.call(this, config);
36764 this.split.placement = Roo.bootstrap.SplitBar.TOP;
36765 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36766 this.split.el.addClass("roo-layout-split-v");
36768 var size = config.initialSize || config.height;
36769 if(typeof size != "undefined"){
36770 this.el.setHeight(size);
36773 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
36775 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36779 getBox : function(){
36780 if(this.collapsed){
36781 return this.collapsedEl.getBox();
36783 var box = this.el.getBox();
36785 box.height += this.split.el.getHeight();
36790 updateBox : function(box){
36791 if(this.split && !this.collapsed){
36792 box.height -= this.split.el.getHeight();
36793 this.split.el.setLeft(box.x);
36794 this.split.el.setTop(box.y+box.height);
36795 this.split.el.setWidth(box.width);
36797 if(this.collapsed){
36798 this.updateBody(box.width, null);
36800 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36808 Roo.bootstrap.layout.South = function(config){
36809 config.region = 'south';
36810 config.cursor = 's-resize';
36811 Roo.bootstrap.layout.Split.call(this, config);
36813 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
36814 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36815 this.split.el.addClass("roo-layout-split-v");
36817 var size = config.initialSize || config.height;
36818 if(typeof size != "undefined"){
36819 this.el.setHeight(size);
36823 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
36824 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36825 getBox : function(){
36826 if(this.collapsed){
36827 return this.collapsedEl.getBox();
36829 var box = this.el.getBox();
36831 var sh = this.split.el.getHeight();
36838 updateBox : function(box){
36839 if(this.split && !this.collapsed){
36840 var sh = this.split.el.getHeight();
36843 this.split.el.setLeft(box.x);
36844 this.split.el.setTop(box.y-sh);
36845 this.split.el.setWidth(box.width);
36847 if(this.collapsed){
36848 this.updateBody(box.width, null);
36850 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36854 Roo.bootstrap.layout.East = function(config){
36855 config.region = "east";
36856 config.cursor = "e-resize";
36857 Roo.bootstrap.layout.Split.call(this, config);
36859 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
36860 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36861 this.split.el.addClass("roo-layout-split-h");
36863 var size = config.initialSize || config.width;
36864 if(typeof size != "undefined"){
36865 this.el.setWidth(size);
36868 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
36869 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36870 getBox : function(){
36871 if(this.collapsed){
36872 return this.collapsedEl.getBox();
36874 var box = this.el.getBox();
36876 var sw = this.split.el.getWidth();
36883 updateBox : function(box){
36884 if(this.split && !this.collapsed){
36885 var sw = this.split.el.getWidth();
36887 this.split.el.setLeft(box.x);
36888 this.split.el.setTop(box.y);
36889 this.split.el.setHeight(box.height);
36892 if(this.collapsed){
36893 this.updateBody(null, box.height);
36895 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36899 Roo.bootstrap.layout.West = function(config){
36900 config.region = "west";
36901 config.cursor = "w-resize";
36903 Roo.bootstrap.layout.Split.call(this, config);
36905 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
36906 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36907 this.split.el.addClass("roo-layout-split-h");
36911 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
36912 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36914 onRender: function(ctr, pos)
36916 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
36917 var size = this.config.initialSize || this.config.width;
36918 if(typeof size != "undefined"){
36919 this.el.setWidth(size);
36923 getBox : function(){
36924 if(this.collapsed){
36925 return this.collapsedEl.getBox();
36927 var box = this.el.getBox();
36929 box.width += this.split.el.getWidth();
36934 updateBox : function(box){
36935 if(this.split && !this.collapsed){
36936 var sw = this.split.el.getWidth();
36938 this.split.el.setLeft(box.x+box.width);
36939 this.split.el.setTop(box.y);
36940 this.split.el.setHeight(box.height);
36942 if(this.collapsed){
36943 this.updateBody(null, box.height);
36945 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36948 Roo.namespace("Roo.bootstrap.panel");/*
36950 * Ext JS Library 1.1.1
36951 * Copyright(c) 2006-2007, Ext JS, LLC.
36953 * Originally Released Under LGPL - original licence link has changed is not relivant.
36956 * <script type="text/javascript">
36959 * @class Roo.ContentPanel
36960 * @extends Roo.util.Observable
36961 * A basic ContentPanel element.
36962 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
36963 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
36964 * @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
36965 * @cfg {Boolean} closable True if the panel can be closed/removed
36966 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
36967 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
36968 * @cfg {Toolbar} toolbar A toolbar for this panel
36969 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
36970 * @cfg {String} title The title for this panel
36971 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
36972 * @cfg {String} url Calls {@link #setUrl} with this value
36973 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
36974 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
36975 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
36976 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
36977 * @cfg {Boolean} badges render the badges
36980 * Create a new ContentPanel.
36981 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
36982 * @param {String/Object} config A string to set only the title or a config object
36983 * @param {String} content (optional) Set the HTML content for this panel
36984 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
36986 Roo.bootstrap.panel.Content = function( config){
36988 this.tpl = config.tpl || false;
36990 var el = config.el;
36991 var content = config.content;
36993 if(config.autoCreate){ // xtype is available if this is called from factory
36996 this.el = Roo.get(el);
36997 if(!this.el && config && config.autoCreate){
36998 if(typeof config.autoCreate == "object"){
36999 if(!config.autoCreate.id){
37000 config.autoCreate.id = config.id||el;
37002 this.el = Roo.DomHelper.append(document.body,
37003 config.autoCreate, true);
37005 var elcfg = { tag: "div",
37006 cls: "roo-layout-inactive-content",
37010 elcfg.html = config.html;
37014 this.el = Roo.DomHelper.append(document.body, elcfg , true);
37017 this.closable = false;
37018 this.loaded = false;
37019 this.active = false;
37022 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
37024 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
37026 this.wrapEl = this.el; //this.el.wrap();
37028 if (config.toolbar.items) {
37029 ti = config.toolbar.items ;
37030 delete config.toolbar.items ;
37034 this.toolbar.render(this.wrapEl, 'before');
37035 for(var i =0;i < ti.length;i++) {
37036 // Roo.log(['add child', items[i]]);
37037 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37039 this.toolbar.items = nitems;
37040 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
37041 delete config.toolbar;
37045 // xtype created footer. - not sure if will work as we normally have to render first..
37046 if (this.footer && !this.footer.el && this.footer.xtype) {
37047 if (!this.wrapEl) {
37048 this.wrapEl = this.el.wrap();
37051 this.footer.container = this.wrapEl.createChild();
37053 this.footer = Roo.factory(this.footer, Roo);
37058 if(typeof config == "string"){
37059 this.title = config;
37061 Roo.apply(this, config);
37065 this.resizeEl = Roo.get(this.resizeEl, true);
37067 this.resizeEl = this.el;
37069 // handle view.xtype
37077 * Fires when this panel is activated.
37078 * @param {Roo.ContentPanel} this
37082 * @event deactivate
37083 * Fires when this panel is activated.
37084 * @param {Roo.ContentPanel} this
37086 "deactivate" : true,
37090 * Fires when this panel is resized if fitToFrame is true.
37091 * @param {Roo.ContentPanel} this
37092 * @param {Number} width The width after any component adjustments
37093 * @param {Number} height The height after any component adjustments
37099 * Fires when this tab is created
37100 * @param {Roo.ContentPanel} this
37111 if(this.autoScroll){
37112 this.resizeEl.setStyle("overflow", "auto");
37114 // fix randome scrolling
37115 //this.el.on('scroll', function() {
37116 // Roo.log('fix random scolling');
37117 // this.scrollTo('top',0);
37120 content = content || this.content;
37122 this.setContent(content);
37124 if(config && config.url){
37125 this.setUrl(this.url, this.params, this.loadOnce);
37130 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
37132 if (this.view && typeof(this.view.xtype) != 'undefined') {
37133 this.view.el = this.el.appendChild(document.createElement("div"));
37134 this.view = Roo.factory(this.view);
37135 this.view.render && this.view.render(false, '');
37139 this.fireEvent('render', this);
37142 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
37146 setRegion : function(region){
37147 this.region = region;
37148 this.setActiveClass(region && !this.background);
37152 setActiveClass: function(state)
37155 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
37156 this.el.setStyle('position','relative');
37158 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
37159 this.el.setStyle('position', 'absolute');
37164 * Returns the toolbar for this Panel if one was configured.
37165 * @return {Roo.Toolbar}
37167 getToolbar : function(){
37168 return this.toolbar;
37171 setActiveState : function(active)
37173 this.active = active;
37174 this.setActiveClass(active);
37176 if(this.fireEvent("deactivate", this) === false){
37181 this.fireEvent("activate", this);
37185 * Updates this panel's element
37186 * @param {String} content The new content
37187 * @param {Boolean} loadScripts (optional) true to look for and process scripts
37189 setContent : function(content, loadScripts){
37190 this.el.update(content, loadScripts);
37193 ignoreResize : function(w, h){
37194 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
37197 this.lastSize = {width: w, height: h};
37202 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
37203 * @return {Roo.UpdateManager} The UpdateManager
37205 getUpdateManager : function(){
37206 return this.el.getUpdateManager();
37209 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
37210 * @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:
37213 url: "your-url.php",
37214 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
37215 callback: yourFunction,
37216 scope: yourObject, //(optional scope)
37219 text: "Loading...",
37224 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
37225 * 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.
37226 * @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}
37227 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
37228 * @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.
37229 * @return {Roo.ContentPanel} this
37232 var um = this.el.getUpdateManager();
37233 um.update.apply(um, arguments);
37239 * 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.
37240 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
37241 * @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)
37242 * @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)
37243 * @return {Roo.UpdateManager} The UpdateManager
37245 setUrl : function(url, params, loadOnce){
37246 if(this.refreshDelegate){
37247 this.removeListener("activate", this.refreshDelegate);
37249 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
37250 this.on("activate", this.refreshDelegate);
37251 return this.el.getUpdateManager();
37254 _handleRefresh : function(url, params, loadOnce){
37255 if(!loadOnce || !this.loaded){
37256 var updater = this.el.getUpdateManager();
37257 updater.update(url, params, this._setLoaded.createDelegate(this));
37261 _setLoaded : function(){
37262 this.loaded = true;
37266 * Returns this panel's id
37269 getId : function(){
37274 * Returns this panel's element - used by regiosn to add.
37275 * @return {Roo.Element}
37277 getEl : function(){
37278 return this.wrapEl || this.el;
37283 adjustForComponents : function(width, height)
37285 //Roo.log('adjustForComponents ');
37286 if(this.resizeEl != this.el){
37287 width -= this.el.getFrameWidth('lr');
37288 height -= this.el.getFrameWidth('tb');
37291 var te = this.toolbar.getEl();
37292 te.setWidth(width);
37293 height -= te.getHeight();
37296 var te = this.footer.getEl();
37297 te.setWidth(width);
37298 height -= te.getHeight();
37302 if(this.adjustments){
37303 width += this.adjustments[0];
37304 height += this.adjustments[1];
37306 return {"width": width, "height": height};
37309 setSize : function(width, height){
37310 if(this.fitToFrame && !this.ignoreResize(width, height)){
37311 if(this.fitContainer && this.resizeEl != this.el){
37312 this.el.setSize(width, height);
37314 var size = this.adjustForComponents(width, height);
37315 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
37316 this.fireEvent('resize', this, size.width, size.height);
37321 * Returns this panel's title
37324 getTitle : function(){
37326 if (typeof(this.title) != 'object') {
37331 for (var k in this.title) {
37332 if (!this.title.hasOwnProperty(k)) {
37336 if (k.indexOf('-') >= 0) {
37337 var s = k.split('-');
37338 for (var i = 0; i<s.length; i++) {
37339 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
37342 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
37349 * Set this panel's title
37350 * @param {String} title
37352 setTitle : function(title){
37353 this.title = title;
37355 this.region.updatePanelTitle(this, title);
37360 * Returns true is this panel was configured to be closable
37361 * @return {Boolean}
37363 isClosable : function(){
37364 return this.closable;
37367 beforeSlide : function(){
37369 this.resizeEl.clip();
37372 afterSlide : function(){
37374 this.resizeEl.unclip();
37378 * Force a content refresh from the URL specified in the {@link #setUrl} method.
37379 * Will fail silently if the {@link #setUrl} method has not been called.
37380 * This does not activate the panel, just updates its content.
37382 refresh : function(){
37383 if(this.refreshDelegate){
37384 this.loaded = false;
37385 this.refreshDelegate();
37390 * Destroys this panel
37392 destroy : function(){
37393 this.el.removeAllListeners();
37394 var tempEl = document.createElement("span");
37395 tempEl.appendChild(this.el.dom);
37396 tempEl.innerHTML = "";
37402 * form - if the content panel contains a form - this is a reference to it.
37403 * @type {Roo.form.Form}
37407 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
37408 * This contains a reference to it.
37414 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
37424 * @param {Object} cfg Xtype definition of item to add.
37428 getChildContainer: function () {
37429 return this.getEl();
37434 var ret = new Roo.factory(cfg);
37439 if (cfg.xtype.match(/^Form$/)) {
37442 //if (this.footer) {
37443 // el = this.footer.container.insertSibling(false, 'before');
37445 el = this.el.createChild();
37448 this.form = new Roo.form.Form(cfg);
37451 if ( this.form.allItems.length) {
37452 this.form.render(el.dom);
37456 // should only have one of theses..
37457 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
37458 // views.. should not be just added - used named prop 'view''
37460 cfg.el = this.el.appendChild(document.createElement("div"));
37463 var ret = new Roo.factory(cfg);
37465 ret.render && ret.render(false, ''); // render blank..
37475 * @class Roo.bootstrap.panel.Grid
37476 * @extends Roo.bootstrap.panel.Content
37478 * Create a new GridPanel.
37479 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
37480 * @param {Object} config A the config object
37486 Roo.bootstrap.panel.Grid = function(config)
37490 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
37491 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
37493 config.el = this.wrapper;
37494 //this.el = this.wrapper;
37496 if (config.container) {
37497 // ctor'ed from a Border/panel.grid
37500 this.wrapper.setStyle("overflow", "hidden");
37501 this.wrapper.addClass('roo-grid-container');
37506 if(config.toolbar){
37507 var tool_el = this.wrapper.createChild();
37508 this.toolbar = Roo.factory(config.toolbar);
37510 if (config.toolbar.items) {
37511 ti = config.toolbar.items ;
37512 delete config.toolbar.items ;
37516 this.toolbar.render(tool_el);
37517 for(var i =0;i < ti.length;i++) {
37518 // Roo.log(['add child', items[i]]);
37519 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37521 this.toolbar.items = nitems;
37523 delete config.toolbar;
37526 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
37527 config.grid.scrollBody = true;;
37528 config.grid.monitorWindowResize = false; // turn off autosizing
37529 config.grid.autoHeight = false;
37530 config.grid.autoWidth = false;
37532 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
37534 if (config.background) {
37535 // render grid on panel activation (if panel background)
37536 this.on('activate', function(gp) {
37537 if (!gp.grid.rendered) {
37538 gp.grid.render(this.wrapper);
37539 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37544 this.grid.render(this.wrapper);
37545 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37548 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
37549 // ??? needed ??? config.el = this.wrapper;
37554 // xtype created footer. - not sure if will work as we normally have to render first..
37555 if (this.footer && !this.footer.el && this.footer.xtype) {
37557 var ctr = this.grid.getView().getFooterPanel(true);
37558 this.footer.dataSource = this.grid.dataSource;
37559 this.footer = Roo.factory(this.footer, Roo);
37560 this.footer.render(ctr);
37570 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
37571 getId : function(){
37572 return this.grid.id;
37576 * Returns the grid for this panel
37577 * @return {Roo.bootstrap.Table}
37579 getGrid : function(){
37583 setSize : function(width, height){
37584 if(!this.ignoreResize(width, height)){
37585 var grid = this.grid;
37586 var size = this.adjustForComponents(width, height);
37587 var gridel = grid.getGridEl();
37588 gridel.setSize(size.width, size.height);
37590 var thd = grid.getGridEl().select('thead',true).first();
37591 var tbd = grid.getGridEl().select('tbody', true).first();
37593 tbd.setSize(width, height - thd.getHeight());
37602 beforeSlide : function(){
37603 this.grid.getView().scroller.clip();
37606 afterSlide : function(){
37607 this.grid.getView().scroller.unclip();
37610 destroy : function(){
37611 this.grid.destroy();
37613 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
37618 * @class Roo.bootstrap.panel.Nest
37619 * @extends Roo.bootstrap.panel.Content
37621 * Create a new Panel, that can contain a layout.Border.
37624 * @param {Roo.BorderLayout} layout The layout for this panel
37625 * @param {String/Object} config A string to set only the title or a config object
37627 Roo.bootstrap.panel.Nest = function(config)
37629 // construct with only one argument..
37630 /* FIXME - implement nicer consturctors
37631 if (layout.layout) {
37633 layout = config.layout;
37634 delete config.layout;
37636 if (layout.xtype && !layout.getEl) {
37637 // then layout needs constructing..
37638 layout = Roo.factory(layout, Roo);
37642 config.el = config.layout.getEl();
37644 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
37646 config.layout.monitorWindowResize = false; // turn off autosizing
37647 this.layout = config.layout;
37648 this.layout.getEl().addClass("roo-layout-nested-layout");
37655 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
37657 setSize : function(width, height){
37658 if(!this.ignoreResize(width, height)){
37659 var size = this.adjustForComponents(width, height);
37660 var el = this.layout.getEl();
37661 if (size.height < 1) {
37662 el.setWidth(size.width);
37664 el.setSize(size.width, size.height);
37666 var touch = el.dom.offsetWidth;
37667 this.layout.layout();
37668 // ie requires a double layout on the first pass
37669 if(Roo.isIE && !this.initialized){
37670 this.initialized = true;
37671 this.layout.layout();
37676 // activate all subpanels if not currently active..
37678 setActiveState : function(active){
37679 this.active = active;
37680 this.setActiveClass(active);
37683 this.fireEvent("deactivate", this);
37687 this.fireEvent("activate", this);
37688 // not sure if this should happen before or after..
37689 if (!this.layout) {
37690 return; // should not happen..
37693 for (var r in this.layout.regions) {
37694 reg = this.layout.getRegion(r);
37695 if (reg.getActivePanel()) {
37696 //reg.showPanel(reg.getActivePanel()); // force it to activate..
37697 reg.setActivePanel(reg.getActivePanel());
37700 if (!reg.panels.length) {
37703 reg.showPanel(reg.getPanel(0));
37712 * Returns the nested BorderLayout for this panel
37713 * @return {Roo.BorderLayout}
37715 getLayout : function(){
37716 return this.layout;
37720 * Adds a xtype elements to the layout of the nested panel
37724 xtype : 'ContentPanel',
37731 xtype : 'NestedLayoutPanel',
37737 items : [ ... list of content panels or nested layout panels.. ]
37741 * @param {Object} cfg Xtype definition of item to add.
37743 addxtype : function(cfg) {
37744 return this.layout.addxtype(cfg);
37749 * Ext JS Library 1.1.1
37750 * Copyright(c) 2006-2007, Ext JS, LLC.
37752 * Originally Released Under LGPL - original licence link has changed is not relivant.
37755 * <script type="text/javascript">
37758 * @class Roo.TabPanel
37759 * @extends Roo.util.Observable
37760 * A lightweight tab container.
37764 // basic tabs 1, built from existing content
37765 var tabs = new Roo.TabPanel("tabs1");
37766 tabs.addTab("script", "View Script");
37767 tabs.addTab("markup", "View Markup");
37768 tabs.activate("script");
37770 // more advanced tabs, built from javascript
37771 var jtabs = new Roo.TabPanel("jtabs");
37772 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
37774 // set up the UpdateManager
37775 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
37776 var updater = tab2.getUpdateManager();
37777 updater.setDefaultUrl("ajax1.htm");
37778 tab2.on('activate', updater.refresh, updater, true);
37780 // Use setUrl for Ajax loading
37781 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
37782 tab3.setUrl("ajax2.htm", null, true);
37785 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
37788 jtabs.activate("jtabs-1");
37791 * Create a new TabPanel.
37792 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
37793 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
37795 Roo.bootstrap.panel.Tabs = function(config){
37797 * The container element for this TabPanel.
37798 * @type Roo.Element
37800 this.el = Roo.get(config.el);
37803 if(typeof config == "boolean"){
37804 this.tabPosition = config ? "bottom" : "top";
37806 Roo.apply(this, config);
37810 if(this.tabPosition == "bottom"){
37811 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37812 this.el.addClass("roo-tabs-bottom");
37814 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
37815 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
37816 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
37818 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
37820 if(this.tabPosition != "bottom"){
37821 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
37822 * @type Roo.Element
37824 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37825 this.el.addClass("roo-tabs-top");
37829 this.bodyEl.setStyle("position", "relative");
37831 this.active = null;
37832 this.activateDelegate = this.activate.createDelegate(this);
37837 * Fires when the active tab changes
37838 * @param {Roo.TabPanel} this
37839 * @param {Roo.TabPanelItem} activePanel The new active tab
37843 * @event beforetabchange
37844 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
37845 * @param {Roo.TabPanel} this
37846 * @param {Object} e Set cancel to true on this object to cancel the tab change
37847 * @param {Roo.TabPanelItem} tab The tab being changed to
37849 "beforetabchange" : true
37852 Roo.EventManager.onWindowResize(this.onResize, this);
37853 this.cpad = this.el.getPadding("lr");
37854 this.hiddenCount = 0;
37857 // toolbar on the tabbar support...
37858 if (this.toolbar) {
37859 alert("no toolbar support yet");
37860 this.toolbar = false;
37862 var tcfg = this.toolbar;
37863 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
37864 this.toolbar = new Roo.Toolbar(tcfg);
37865 if (Roo.isSafari) {
37866 var tbl = tcfg.container.child('table', true);
37867 tbl.setAttribute('width', '100%');
37875 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
37878 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
37880 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
37882 tabPosition : "top",
37884 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
37886 currentTabWidth : 0,
37888 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
37892 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
37896 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
37898 preferredTabWidth : 175,
37900 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
37902 resizeTabs : false,
37904 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
37906 monitorResize : true,
37908 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
37913 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
37914 * @param {String} id The id of the div to use <b>or create</b>
37915 * @param {String} text The text for the tab
37916 * @param {String} content (optional) Content to put in the TabPanelItem body
37917 * @param {Boolean} closable (optional) True to create a close icon on the tab
37918 * @return {Roo.TabPanelItem} The created TabPanelItem
37920 addTab : function(id, text, content, closable, tpl)
37922 var item = new Roo.bootstrap.panel.TabItem({
37926 closable : closable,
37929 this.addTabItem(item);
37931 item.setContent(content);
37937 * Returns the {@link Roo.TabPanelItem} with the specified id/index
37938 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
37939 * @return {Roo.TabPanelItem}
37941 getTab : function(id){
37942 return this.items[id];
37946 * Hides the {@link Roo.TabPanelItem} with the specified id/index
37947 * @param {String/Number} id The id or index of the TabPanelItem to hide.
37949 hideTab : function(id){
37950 var t = this.items[id];
37953 this.hiddenCount++;
37954 this.autoSizeTabs();
37959 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
37960 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
37962 unhideTab : function(id){
37963 var t = this.items[id];
37965 t.setHidden(false);
37966 this.hiddenCount--;
37967 this.autoSizeTabs();
37972 * Adds an existing {@link Roo.TabPanelItem}.
37973 * @param {Roo.TabPanelItem} item The TabPanelItem to add
37975 addTabItem : function(item){
37976 this.items[item.id] = item;
37977 this.items.push(item);
37978 // if(this.resizeTabs){
37979 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
37980 // this.autoSizeTabs();
37982 // item.autoSize();
37987 * Removes a {@link Roo.TabPanelItem}.
37988 * @param {String/Number} id The id or index of the TabPanelItem to remove.
37990 removeTab : function(id){
37991 var items = this.items;
37992 var tab = items[id];
37993 if(!tab) { return; }
37994 var index = items.indexOf(tab);
37995 if(this.active == tab && items.length > 1){
37996 var newTab = this.getNextAvailable(index);
38001 this.stripEl.dom.removeChild(tab.pnode.dom);
38002 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
38003 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
38005 items.splice(index, 1);
38006 delete this.items[tab.id];
38007 tab.fireEvent("close", tab);
38008 tab.purgeListeners();
38009 this.autoSizeTabs();
38012 getNextAvailable : function(start){
38013 var items = this.items;
38015 // look for a next tab that will slide over to
38016 // replace the one being removed
38017 while(index < items.length){
38018 var item = items[++index];
38019 if(item && !item.isHidden()){
38023 // if one isn't found select the previous tab (on the left)
38026 var item = items[--index];
38027 if(item && !item.isHidden()){
38035 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
38036 * @param {String/Number} id The id or index of the TabPanelItem to disable.
38038 disableTab : function(id){
38039 var tab = this.items[id];
38040 if(tab && this.active != tab){
38046 * Enables a {@link Roo.TabPanelItem} that is disabled.
38047 * @param {String/Number} id The id or index of the TabPanelItem to enable.
38049 enableTab : function(id){
38050 var tab = this.items[id];
38055 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
38056 * @param {String/Number} id The id or index of the TabPanelItem to activate.
38057 * @return {Roo.TabPanelItem} The TabPanelItem.
38059 activate : function(id){
38060 var tab = this.items[id];
38064 if(tab == this.active || tab.disabled){
38068 this.fireEvent("beforetabchange", this, e, tab);
38069 if(e.cancel !== true && !tab.disabled){
38071 this.active.hide();
38073 this.active = this.items[id];
38074 this.active.show();
38075 this.fireEvent("tabchange", this, this.active);
38081 * Gets the active {@link Roo.TabPanelItem}.
38082 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
38084 getActiveTab : function(){
38085 return this.active;
38089 * Updates the tab body element to fit the height of the container element
38090 * for overflow scrolling
38091 * @param {Number} targetHeight (optional) Override the starting height from the elements height
38093 syncHeight : function(targetHeight){
38094 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
38095 var bm = this.bodyEl.getMargins();
38096 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
38097 this.bodyEl.setHeight(newHeight);
38101 onResize : function(){
38102 if(this.monitorResize){
38103 this.autoSizeTabs();
38108 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
38110 beginUpdate : function(){
38111 this.updating = true;
38115 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
38117 endUpdate : function(){
38118 this.updating = false;
38119 this.autoSizeTabs();
38123 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
38125 autoSizeTabs : function(){
38126 var count = this.items.length;
38127 var vcount = count - this.hiddenCount;
38128 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
38131 var w = Math.max(this.el.getWidth() - this.cpad, 10);
38132 var availWidth = Math.floor(w / vcount);
38133 var b = this.stripBody;
38134 if(b.getWidth() > w){
38135 var tabs = this.items;
38136 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
38137 if(availWidth < this.minTabWidth){
38138 /*if(!this.sleft){ // incomplete scrolling code
38139 this.createScrollButtons();
38142 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
38145 if(this.currentTabWidth < this.preferredTabWidth){
38146 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
38152 * Returns the number of tabs in this TabPanel.
38155 getCount : function(){
38156 return this.items.length;
38160 * Resizes all the tabs to the passed width
38161 * @param {Number} The new width
38163 setTabWidth : function(width){
38164 this.currentTabWidth = width;
38165 for(var i = 0, len = this.items.length; i < len; i++) {
38166 if(!this.items[i].isHidden()) {
38167 this.items[i].setWidth(width);
38173 * Destroys this TabPanel
38174 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
38176 destroy : function(removeEl){
38177 Roo.EventManager.removeResizeListener(this.onResize, this);
38178 for(var i = 0, len = this.items.length; i < len; i++){
38179 this.items[i].purgeListeners();
38181 if(removeEl === true){
38182 this.el.update("");
38187 createStrip : function(container)
38189 var strip = document.createElement("nav");
38190 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
38191 container.appendChild(strip);
38195 createStripList : function(strip)
38197 // div wrapper for retard IE
38198 // returns the "tr" element.
38199 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
38200 //'<div class="x-tabs-strip-wrap">'+
38201 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
38202 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
38203 return strip.firstChild; //.firstChild.firstChild.firstChild;
38205 createBody : function(container)
38207 var body = document.createElement("div");
38208 Roo.id(body, "tab-body");
38209 //Roo.fly(body).addClass("x-tabs-body");
38210 Roo.fly(body).addClass("tab-content");
38211 container.appendChild(body);
38214 createItemBody :function(bodyEl, id){
38215 var body = Roo.getDom(id);
38217 body = document.createElement("div");
38220 //Roo.fly(body).addClass("x-tabs-item-body");
38221 Roo.fly(body).addClass("tab-pane");
38222 bodyEl.insertBefore(body, bodyEl.firstChild);
38226 createStripElements : function(stripEl, text, closable, tpl)
38228 var td = document.createElement("li"); // was td..
38231 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
38234 stripEl.appendChild(td);
38236 td.className = "x-tabs-closable";
38237 if(!this.closeTpl){
38238 this.closeTpl = new Roo.Template(
38239 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38240 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
38241 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
38244 var el = this.closeTpl.overwrite(td, {"text": text});
38245 var close = el.getElementsByTagName("div")[0];
38246 var inner = el.getElementsByTagName("em")[0];
38247 return {"el": el, "close": close, "inner": inner};
38250 // not sure what this is..
38251 // if(!this.tabTpl){
38252 //this.tabTpl = new Roo.Template(
38253 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38254 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
38256 // this.tabTpl = new Roo.Template(
38257 // '<a href="#">' +
38258 // '<span unselectable="on"' +
38259 // (this.disableTooltips ? '' : ' title="{text}"') +
38260 // ' >{text}</span></a>'
38266 var template = tpl || this.tabTpl || false;
38270 template = new Roo.Template(
38272 '<span unselectable="on"' +
38273 (this.disableTooltips ? '' : ' title="{text}"') +
38274 ' >{text}</span></a>'
38278 switch (typeof(template)) {
38282 template = new Roo.Template(template);
38288 var el = template.overwrite(td, {"text": text});
38290 var inner = el.getElementsByTagName("span")[0];
38292 return {"el": el, "inner": inner};
38300 * @class Roo.TabPanelItem
38301 * @extends Roo.util.Observable
38302 * Represents an individual item (tab plus body) in a TabPanel.
38303 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
38304 * @param {String} id The id of this TabPanelItem
38305 * @param {String} text The text for the tab of this TabPanelItem
38306 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
38308 Roo.bootstrap.panel.TabItem = function(config){
38310 * The {@link Roo.TabPanel} this TabPanelItem belongs to
38311 * @type Roo.TabPanel
38313 this.tabPanel = config.panel;
38315 * The id for this TabPanelItem
38318 this.id = config.id;
38320 this.disabled = false;
38322 this.text = config.text;
38324 this.loaded = false;
38325 this.closable = config.closable;
38328 * The body element for this TabPanelItem.
38329 * @type Roo.Element
38331 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
38332 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
38333 this.bodyEl.setStyle("display", "block");
38334 this.bodyEl.setStyle("zoom", "1");
38335 //this.hideAction();
38337 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
38339 this.el = Roo.get(els.el);
38340 this.inner = Roo.get(els.inner, true);
38341 this.textEl = Roo.get(this.el.dom.firstChild, true);
38342 this.pnode = Roo.get(els.el.parentNode, true);
38343 // this.el.on("mousedown", this.onTabMouseDown, this);
38344 this.el.on("click", this.onTabClick, this);
38346 if(config.closable){
38347 var c = Roo.get(els.close, true);
38348 c.dom.title = this.closeText;
38349 c.addClassOnOver("close-over");
38350 c.on("click", this.closeClick, this);
38356 * Fires when this tab becomes the active tab.
38357 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38358 * @param {Roo.TabPanelItem} this
38362 * @event beforeclose
38363 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
38364 * @param {Roo.TabPanelItem} this
38365 * @param {Object} e Set cancel to true on this object to cancel the close.
38367 "beforeclose": true,
38370 * Fires when this tab is closed.
38371 * @param {Roo.TabPanelItem} this
38375 * @event deactivate
38376 * Fires when this tab is no longer the active tab.
38377 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38378 * @param {Roo.TabPanelItem} this
38380 "deactivate" : true
38382 this.hidden = false;
38384 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
38387 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
38389 purgeListeners : function(){
38390 Roo.util.Observable.prototype.purgeListeners.call(this);
38391 this.el.removeAllListeners();
38394 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
38397 this.pnode.addClass("active");
38400 this.tabPanel.stripWrap.repaint();
38402 this.fireEvent("activate", this.tabPanel, this);
38406 * Returns true if this tab is the active tab.
38407 * @return {Boolean}
38409 isActive : function(){
38410 return this.tabPanel.getActiveTab() == this;
38414 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
38417 this.pnode.removeClass("active");
38419 this.fireEvent("deactivate", this.tabPanel, this);
38422 hideAction : function(){
38423 this.bodyEl.hide();
38424 this.bodyEl.setStyle("position", "absolute");
38425 this.bodyEl.setLeft("-20000px");
38426 this.bodyEl.setTop("-20000px");
38429 showAction : function(){
38430 this.bodyEl.setStyle("position", "relative");
38431 this.bodyEl.setTop("");
38432 this.bodyEl.setLeft("");
38433 this.bodyEl.show();
38437 * Set the tooltip for the tab.
38438 * @param {String} tooltip The tab's tooltip
38440 setTooltip : function(text){
38441 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
38442 this.textEl.dom.qtip = text;
38443 this.textEl.dom.removeAttribute('title');
38445 this.textEl.dom.title = text;
38449 onTabClick : function(e){
38450 e.preventDefault();
38451 this.tabPanel.activate(this.id);
38454 onTabMouseDown : function(e){
38455 e.preventDefault();
38456 this.tabPanel.activate(this.id);
38459 getWidth : function(){
38460 return this.inner.getWidth();
38463 setWidth : function(width){
38464 var iwidth = width - this.pnode.getPadding("lr");
38465 this.inner.setWidth(iwidth);
38466 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
38467 this.pnode.setWidth(width);
38471 * Show or hide the tab
38472 * @param {Boolean} hidden True to hide or false to show.
38474 setHidden : function(hidden){
38475 this.hidden = hidden;
38476 this.pnode.setStyle("display", hidden ? "none" : "");
38480 * Returns true if this tab is "hidden"
38481 * @return {Boolean}
38483 isHidden : function(){
38484 return this.hidden;
38488 * Returns the text for this tab
38491 getText : function(){
38495 autoSize : function(){
38496 //this.el.beginMeasure();
38497 this.textEl.setWidth(1);
38499 * #2804 [new] Tabs in Roojs
38500 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
38502 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
38503 //this.el.endMeasure();
38507 * Sets the text for the tab (Note: this also sets the tooltip text)
38508 * @param {String} text The tab's text and tooltip
38510 setText : function(text){
38512 this.textEl.update(text);
38513 this.setTooltip(text);
38514 //if(!this.tabPanel.resizeTabs){
38515 // this.autoSize();
38519 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
38521 activate : function(){
38522 this.tabPanel.activate(this.id);
38526 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
38528 disable : function(){
38529 if(this.tabPanel.active != this){
38530 this.disabled = true;
38531 this.pnode.addClass("disabled");
38536 * Enables this TabPanelItem if it was previously disabled.
38538 enable : function(){
38539 this.disabled = false;
38540 this.pnode.removeClass("disabled");
38544 * Sets the content for this TabPanelItem.
38545 * @param {String} content The content
38546 * @param {Boolean} loadScripts true to look for and load scripts
38548 setContent : function(content, loadScripts){
38549 this.bodyEl.update(content, loadScripts);
38553 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
38554 * @return {Roo.UpdateManager} The UpdateManager
38556 getUpdateManager : function(){
38557 return this.bodyEl.getUpdateManager();
38561 * Set a URL to be used to load the content for this TabPanelItem.
38562 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
38563 * @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)
38564 * @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)
38565 * @return {Roo.UpdateManager} The UpdateManager
38567 setUrl : function(url, params, loadOnce){
38568 if(this.refreshDelegate){
38569 this.un('activate', this.refreshDelegate);
38571 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
38572 this.on("activate", this.refreshDelegate);
38573 return this.bodyEl.getUpdateManager();
38577 _handleRefresh : function(url, params, loadOnce){
38578 if(!loadOnce || !this.loaded){
38579 var updater = this.bodyEl.getUpdateManager();
38580 updater.update(url, params, this._setLoaded.createDelegate(this));
38585 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
38586 * Will fail silently if the setUrl method has not been called.
38587 * This does not activate the panel, just updates its content.
38589 refresh : function(){
38590 if(this.refreshDelegate){
38591 this.loaded = false;
38592 this.refreshDelegate();
38597 _setLoaded : function(){
38598 this.loaded = true;
38602 closeClick : function(e){
38605 this.fireEvent("beforeclose", this, o);
38606 if(o.cancel !== true){
38607 this.tabPanel.removeTab(this.id);
38611 * The text displayed in the tooltip for the close icon.
38614 closeText : "Close this tab"
38617 * This script refer to:
38618 * Title: International Telephone Input
38619 * Author: Jack O'Connor
38620 * Code version: v12.1.12
38621 * Availability: https://github.com/jackocnr/intl-tel-input.git
38624 Roo.bootstrap.PhoneInputData = function() {
38627 "Afghanistan (افغانستان)",
38632 "Albania (Shqipëri)",
38637 "Algeria (الجزائر)",
38662 "Antigua and Barbuda",
38672 "Armenia (Հայաստան)",
38688 "Austria (Österreich)",
38693 "Azerbaijan (Azərbaycan)",
38703 "Bahrain (البحرين)",
38708 "Bangladesh (বাংলাদেশ)",
38718 "Belarus (Беларусь)",
38723 "Belgium (België)",
38753 "Bosnia and Herzegovina (Босна и Херцеговина)",
38768 "British Indian Ocean Territory",
38773 "British Virgin Islands",
38783 "Bulgaria (България)",
38793 "Burundi (Uburundi)",
38798 "Cambodia (កម្ពុជា)",
38803 "Cameroon (Cameroun)",
38812 ["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"]
38815 "Cape Verde (Kabu Verdi)",
38820 "Caribbean Netherlands",
38831 "Central African Republic (République centrafricaine)",
38851 "Christmas Island",
38857 "Cocos (Keeling) Islands",
38868 "Comoros (جزر القمر)",
38873 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
38878 "Congo (Republic) (Congo-Brazzaville)",
38898 "Croatia (Hrvatska)",
38919 "Czech Republic (Česká republika)",
38924 "Denmark (Danmark)",
38939 "Dominican Republic (República Dominicana)",
38943 ["809", "829", "849"]
38961 "Equatorial Guinea (Guinea Ecuatorial)",
38981 "Falkland Islands (Islas Malvinas)",
38986 "Faroe Islands (Føroyar)",
39007 "French Guiana (Guyane française)",
39012 "French Polynesia (Polynésie française)",
39027 "Georgia (საქართველო)",
39032 "Germany (Deutschland)",
39052 "Greenland (Kalaallit Nunaat)",
39089 "Guinea-Bissau (Guiné Bissau)",
39114 "Hungary (Magyarország)",
39119 "Iceland (Ísland)",
39139 "Iraq (العراق)",
39155 "Israel (ישראל)",
39182 "Jordan (الأردن)",
39187 "Kazakhstan (Казахстан)",
39208 "Kuwait (الكويت)",
39213 "Kyrgyzstan (Кыргызстан)",
39223 "Latvia (Latvija)",
39228 "Lebanon (لبنان)",
39243 "Libya (ليبيا)",
39253 "Lithuania (Lietuva)",
39268 "Macedonia (FYROM) (Македонија)",
39273 "Madagascar (Madagasikara)",
39303 "Marshall Islands",
39313 "Mauritania (موريتانيا)",
39318 "Mauritius (Moris)",
39339 "Moldova (Republica Moldova)",
39349 "Mongolia (Монгол)",
39354 "Montenegro (Crna Gora)",
39364 "Morocco (المغرب)",
39370 "Mozambique (Moçambique)",
39375 "Myanmar (Burma) (မြန်မာ)",
39380 "Namibia (Namibië)",
39395 "Netherlands (Nederland)",
39400 "New Caledonia (Nouvelle-Calédonie)",
39435 "North Korea (조선 민주주의 인민 공화국)",
39440 "Northern Mariana Islands",
39456 "Pakistan (پاکستان)",
39466 "Palestine (فلسطين)",
39476 "Papua New Guinea",
39518 "Réunion (La Réunion)",
39524 "Romania (România)",
39540 "Saint Barthélemy",
39551 "Saint Kitts and Nevis",
39561 "Saint Martin (Saint-Martin (partie française))",
39567 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
39572 "Saint Vincent and the Grenadines",
39587 "São Tomé and Príncipe (São Tomé e Príncipe)",
39592 "Saudi Arabia (المملكة العربية السعودية)",
39597 "Senegal (Sénégal)",
39627 "Slovakia (Slovensko)",
39632 "Slovenia (Slovenija)",
39642 "Somalia (Soomaaliya)",
39652 "South Korea (대한민국)",
39657 "South Sudan (جنوب السودان)",
39667 "Sri Lanka (ශ්රී ලංකාව)",
39672 "Sudan (السودان)",
39682 "Svalbard and Jan Mayen",
39693 "Sweden (Sverige)",
39698 "Switzerland (Schweiz)",
39703 "Syria (سوريا)",
39748 "Trinidad and Tobago",
39753 "Tunisia (تونس)",
39758 "Turkey (Türkiye)",
39768 "Turks and Caicos Islands",
39778 "U.S. Virgin Islands",
39788 "Ukraine (Україна)",
39793 "United Arab Emirates (الإمارات العربية المتحدة)",
39815 "Uzbekistan (Oʻzbekiston)",
39825 "Vatican City (Città del Vaticano)",
39836 "Vietnam (Việt Nam)",
39841 "Wallis and Futuna (Wallis-et-Futuna)",
39846 "Western Sahara (الصحراء الغربية)",
39852 "Yemen (اليمن)",
39876 * This script refer to:
39877 * Title: International Telephone Input
39878 * Author: Jack O'Connor
39879 * Code version: v12.1.12
39880 * Availability: https://github.com/jackocnr/intl-tel-input.git
39884 * @class Roo.bootstrap.PhoneInput
39885 * @extends Roo.bootstrap.TriggerField
39886 * An input with International dial-code selection
39888 * @cfg {String} defaultDialCode default '+852'
39889 * @cfg {Array} preferedCountries default []
39892 * Create a new PhoneInput.
39893 * @param {Object} config Configuration options
39896 Roo.bootstrap.PhoneInput = function(config) {
39897 Roo.bootstrap.PhoneInput.superclass.constructor.call(this, config);
39900 Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
39902 listWidth: undefined,
39904 selectedClass: 'active',
39906 invalidClass : "has-warning",
39908 validClass: 'has-success',
39910 allowed: '0123456789',
39915 * @cfg {String} defaultDialCode The default dial code when initializing the input
39917 defaultDialCode: '+852',
39920 * @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
39922 preferedCountries: false,
39924 getAutoCreate : function()
39926 var data = Roo.bootstrap.PhoneInputData();
39927 var align = this.labelAlign || this.parentLabelAlign();
39930 this.allCountries = [];
39931 this.dialCodeMapping = [];
39933 for (var i = 0; i < data.length; i++) {
39935 this.allCountries[i] = {
39939 priority: c[3] || 0,
39940 areaCodes: c[4] || null
39942 this.dialCodeMapping[c[2]] = {
39945 priority: c[3] || 0,
39946 areaCodes: c[4] || null
39958 // type: 'number', -- do not use number - we get the flaky up/down arrows.
39959 maxlength: this.max_length,
39960 cls : 'form-control tel-input',
39961 autocomplete: 'new-password'
39964 var hiddenInput = {
39967 cls: 'hidden-tel-input'
39971 hiddenInput.name = this.name;
39974 if (this.disabled) {
39975 input.disabled = true;
39978 var flag_container = {
39995 cls: this.hasFeedback ? 'has-feedback' : '',
40001 cls: 'dial-code-holder',
40008 cls: 'roo-select2-container input-group',
40015 if (this.fieldLabel.length) {
40018 tooltip: 'This field is required'
40024 cls: 'control-label',
40030 html: this.fieldLabel
40033 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40039 if(this.indicatorpos == 'right') {
40040 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40047 if(align == 'left') {
40055 if(this.labelWidth > 12){
40056 label.style = "width: " + this.labelWidth + 'px';
40058 if(this.labelWidth < 13 && this.labelmd == 0){
40059 this.labelmd = this.labelWidth;
40061 if(this.labellg > 0){
40062 label.cls += ' col-lg-' + this.labellg;
40063 input.cls += ' col-lg-' + (12 - this.labellg);
40065 if(this.labelmd > 0){
40066 label.cls += ' col-md-' + this.labelmd;
40067 container.cls += ' col-md-' + (12 - this.labelmd);
40069 if(this.labelsm > 0){
40070 label.cls += ' col-sm-' + this.labelsm;
40071 container.cls += ' col-sm-' + (12 - this.labelsm);
40073 if(this.labelxs > 0){
40074 label.cls += ' col-xs-' + this.labelxs;
40075 container.cls += ' col-xs-' + (12 - this.labelxs);
40085 var settings = this;
40087 ['xs','sm','md','lg'].map(function(size){
40088 if (settings[size]) {
40089 cfg.cls += ' col-' + size + '-' + settings[size];
40093 this.store = new Roo.data.Store({
40094 proxy : new Roo.data.MemoryProxy({}),
40095 reader : new Roo.data.JsonReader({
40106 'name' : 'dialCode',
40110 'name' : 'priority',
40114 'name' : 'areaCodes',
40121 if(!this.preferedCountries) {
40122 this.preferedCountries = [
40129 var p = this.preferedCountries.reverse();
40132 for (var i = 0; i < p.length; i++) {
40133 for (var j = 0; j < this.allCountries.length; j++) {
40134 if(this.allCountries[j].iso2 == p[i]) {
40135 var t = this.allCountries[j];
40136 this.allCountries.splice(j,1);
40137 this.allCountries.unshift(t);
40143 this.store.proxy.data = {
40145 data: this.allCountries
40151 initEvents : function()
40154 Roo.bootstrap.PhoneInput.superclass.initEvents.call(this);
40156 this.indicator = this.indicatorEl();
40157 this.flag = this.flagEl();
40158 this.dialCodeHolder = this.dialCodeHolderEl();
40160 this.trigger = this.el.select('div.flag-box',true).first();
40161 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
40166 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40167 _this.list.setWidth(lw);
40170 this.list.on('mouseover', this.onViewOver, this);
40171 this.list.on('mousemove', this.onViewMove, this);
40172 this.inputEl().on("keyup", this.onKeyUp, this);
40173 this.inputEl().on("keypress", this.onKeyPress, this);
40175 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
40177 this.view = new Roo.View(this.list, this.tpl, {
40178 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40181 this.view.on('click', this.onViewClick, this);
40182 this.setValue(this.defaultDialCode);
40185 onTriggerClick : function(e)
40187 Roo.log('trigger click');
40192 if(this.isExpanded()){
40194 this.hasFocus = false;
40196 this.store.load({});
40197 this.hasFocus = true;
40202 isExpanded : function()
40204 return this.list.isVisible();
40207 collapse : function()
40209 if(!this.isExpanded()){
40213 Roo.get(document).un('mousedown', this.collapseIf, this);
40214 Roo.get(document).un('mousewheel', this.collapseIf, this);
40215 this.fireEvent('collapse', this);
40219 expand : function()
40223 if(this.isExpanded() || !this.hasFocus){
40227 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
40228 this.list.setWidth(lw);
40231 this.restrictHeight();
40233 Roo.get(document).on('mousedown', this.collapseIf, this);
40234 Roo.get(document).on('mousewheel', this.collapseIf, this);
40236 this.fireEvent('expand', this);
40239 restrictHeight : function()
40241 this.list.alignTo(this.inputEl(), this.listAlign);
40242 this.list.alignTo(this.inputEl(), this.listAlign);
40245 onViewOver : function(e, t)
40247 if(this.inKeyMode){
40250 var item = this.view.findItemFromChild(t);
40253 var index = this.view.indexOf(item);
40254 this.select(index, false);
40259 onViewClick : function(view, doFocus, el, e)
40261 var index = this.view.getSelectedIndexes()[0];
40263 var r = this.store.getAt(index);
40266 this.onSelect(r, index);
40268 if(doFocus !== false && !this.blockFocus){
40269 this.inputEl().focus();
40273 onViewMove : function(e, t)
40275 this.inKeyMode = false;
40278 select : function(index, scrollIntoView)
40280 this.selectedIndex = index;
40281 this.view.select(index);
40282 if(scrollIntoView !== false){
40283 var el = this.view.getNode(index);
40285 this.list.scrollChildIntoView(el, false);
40290 createList : function()
40292 this.list = Roo.get(document.body).createChild({
40294 cls: 'typeahead typeahead-long dropdown-menu tel-list',
40295 style: 'display:none'
40298 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
40301 collapseIf : function(e)
40303 var in_combo = e.within(this.el);
40304 var in_list = e.within(this.list);
40305 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
40307 if (in_combo || in_list || is_list) {
40313 onSelect : function(record, index)
40315 if(this.fireEvent('beforeselect', this, record, index) !== false){
40317 this.setFlagClass(record.data.iso2);
40318 this.setDialCode(record.data.dialCode);
40319 this.hasFocus = false;
40321 this.fireEvent('select', this, record, index);
40325 flagEl : function()
40327 var flag = this.el.select('div.flag',true).first();
40334 dialCodeHolderEl : function()
40336 var d = this.el.select('input.dial-code-holder',true).first();
40343 setDialCode : function(v)
40345 this.dialCodeHolder.dom.value = '+'+v;
40348 setFlagClass : function(n)
40350 this.flag.dom.className = 'flag '+n;
40353 getValue : function()
40355 var v = this.inputEl().getValue();
40356 if(this.dialCodeHolder) {
40357 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
40362 setValue : function(v)
40364 var d = this.getDialCode(v);
40366 //invalid dial code
40367 if(v.length == 0 || !d || d.length == 0) {
40369 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
40370 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40376 this.setFlagClass(this.dialCodeMapping[d].iso2);
40377 this.setDialCode(d);
40378 this.inputEl().dom.value = v.replace('+'+d,'');
40379 this.hiddenEl().dom.value = this.getValue();
40384 getDialCode : function(v)
40388 if (v.length == 0) {
40389 return this.dialCodeHolder.dom.value;
40393 if (v.charAt(0) != "+") {
40396 var numericChars = "";
40397 for (var i = 1; i < v.length; i++) {
40398 var c = v.charAt(i);
40401 if (this.dialCodeMapping[numericChars]) {
40402 dialCode = v.substr(1, i);
40404 if (numericChars.length == 4) {
40414 this.setValue(this.defaultDialCode);
40418 hiddenEl : function()
40420 return this.el.select('input.hidden-tel-input',true).first();
40423 // after setting val
40424 onKeyUp : function(e){
40425 this.setValue(this.getValue());
40428 onKeyPress : function(e){
40429 if(this.allowed.indexOf(String.fromCharCode(e.getCharCode())) === -1){
40436 * @class Roo.bootstrap.MoneyField
40437 * @extends Roo.bootstrap.ComboBox
40438 * Bootstrap MoneyField class
40441 * Create a new MoneyField.
40442 * @param {Object} config Configuration options
40445 Roo.bootstrap.MoneyField = function(config) {
40447 Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
40451 Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
40454 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
40456 allowDecimals : true,
40458 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
40460 decimalSeparator : ".",
40462 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
40464 decimalPrecision : 0,
40466 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
40468 allowNegative : true,
40470 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
40474 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
40476 minValue : Number.NEGATIVE_INFINITY,
40478 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
40480 maxValue : Number.MAX_VALUE,
40482 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
40484 minText : "The minimum value for this field is {0}",
40486 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
40488 maxText : "The maximum value for this field is {0}",
40490 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
40491 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
40493 nanText : "{0} is not a valid number",
40495 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
40499 * @cfg {String} defaults currency of the MoneyField
40500 * value should be in lkey
40502 defaultCurrency : false,
40504 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
40506 thousandsDelimiter : false,
40508 * @cfg {Number} max_length Maximum input field length allowed (defaults to Number.MAX_VALUE)
40519 getAutoCreate : function()
40521 var align = this.labelAlign || this.parentLabelAlign();
40533 cls : 'form-control roo-money-amount-input',
40534 autocomplete: 'new-password'
40537 var hiddenInput = {
40541 cls: 'hidden-number-input'
40544 if(this.max_length) {
40545 input.maxlength = this.max_length;
40549 hiddenInput.name = this.name;
40552 if (this.disabled) {
40553 input.disabled = true;
40556 var clg = 12 - this.inputlg;
40557 var cmd = 12 - this.inputmd;
40558 var csm = 12 - this.inputsm;
40559 var cxs = 12 - this.inputxs;
40563 cls : 'row roo-money-field',
40567 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
40571 cls: 'roo-select2-container input-group',
40575 cls : 'form-control roo-money-currency-input',
40576 autocomplete: 'new-password',
40578 name : this.currencyName
40582 cls : 'input-group-addon',
40596 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
40600 cls: this.hasFeedback ? 'has-feedback' : '',
40611 if (this.fieldLabel.length) {
40614 tooltip: 'This field is required'
40620 cls: 'control-label',
40626 html: this.fieldLabel
40629 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40635 if(this.indicatorpos == 'right') {
40636 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40643 if(align == 'left') {
40651 if(this.labelWidth > 12){
40652 label.style = "width: " + this.labelWidth + 'px';
40654 if(this.labelWidth < 13 && this.labelmd == 0){
40655 this.labelmd = this.labelWidth;
40657 if(this.labellg > 0){
40658 label.cls += ' col-lg-' + this.labellg;
40659 input.cls += ' col-lg-' + (12 - this.labellg);
40661 if(this.labelmd > 0){
40662 label.cls += ' col-md-' + this.labelmd;
40663 container.cls += ' col-md-' + (12 - this.labelmd);
40665 if(this.labelsm > 0){
40666 label.cls += ' col-sm-' + this.labelsm;
40667 container.cls += ' col-sm-' + (12 - this.labelsm);
40669 if(this.labelxs > 0){
40670 label.cls += ' col-xs-' + this.labelxs;
40671 container.cls += ' col-xs-' + (12 - this.labelxs);
40682 var settings = this;
40684 ['xs','sm','md','lg'].map(function(size){
40685 if (settings[size]) {
40686 cfg.cls += ' col-' + size + '-' + settings[size];
40693 initEvents : function()
40695 this.indicator = this.indicatorEl();
40697 this.initCurrencyEvent();
40699 this.initNumberEvent();
40702 initCurrencyEvent : function()
40705 throw "can not find store for combo";
40708 this.store = Roo.factory(this.store, Roo.data);
40709 this.store.parent = this;
40713 this.triggerEl = this.el.select('.input-group-addon', true).first();
40715 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
40720 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40721 _this.list.setWidth(lw);
40724 this.list.on('mouseover', this.onViewOver, this);
40725 this.list.on('mousemove', this.onViewMove, this);
40726 this.list.on('scroll', this.onViewScroll, this);
40729 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
40732 this.view = new Roo.View(this.list, this.tpl, {
40733 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40736 this.view.on('click', this.onViewClick, this);
40738 this.store.on('beforeload', this.onBeforeLoad, this);
40739 this.store.on('load', this.onLoad, this);
40740 this.store.on('loadexception', this.onLoadException, this);
40742 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
40743 "up" : function(e){
40744 this.inKeyMode = true;
40748 "down" : function(e){
40749 if(!this.isExpanded()){
40750 this.onTriggerClick();
40752 this.inKeyMode = true;
40757 "enter" : function(e){
40760 if(this.fireEvent("specialkey", this, e)){
40761 this.onViewClick(false);
40767 "esc" : function(e){
40771 "tab" : function(e){
40774 if(this.fireEvent("specialkey", this, e)){
40775 this.onViewClick(false);
40783 doRelay : function(foo, bar, hname){
40784 if(hname == 'down' || this.scope.isExpanded()){
40785 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
40793 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
40797 initNumberEvent : function(e)
40799 this.inputEl().on("keydown" , this.fireKey, this);
40800 this.inputEl().on("focus", this.onFocus, this);
40801 this.inputEl().on("blur", this.onBlur, this);
40803 this.inputEl().relayEvent('keyup', this);
40805 if(this.indicator){
40806 this.indicator.addClass('invisible');
40809 this.originalValue = this.getValue();
40811 if(this.validationEvent == 'keyup'){
40812 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
40813 this.inputEl().on('keyup', this.filterValidation, this);
40815 else if(this.validationEvent !== false){
40816 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
40819 if(this.selectOnFocus){
40820 this.on("focus", this.preFocus, this);
40823 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
40824 this.inputEl().on("keypress", this.filterKeys, this);
40826 this.inputEl().relayEvent('keypress', this);
40829 var allowed = "0123456789";
40831 if(this.allowDecimals){
40832 allowed += this.decimalSeparator;
40835 if(this.allowNegative){
40839 if(this.thousandsDelimiter) {
40843 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
40845 var keyPress = function(e){
40847 var k = e.getKey();
40849 var c = e.getCharCode();
40852 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40853 allowed.indexOf(String.fromCharCode(c)) === -1
40859 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40863 if(allowed.indexOf(String.fromCharCode(c)) === -1){
40868 this.inputEl().on("keypress", keyPress, this);
40872 onTriggerClick : function(e)
40879 this.loadNext = false;
40881 if(this.isExpanded()){
40886 this.hasFocus = true;
40888 if(this.triggerAction == 'all') {
40889 this.doQuery(this.allQuery, true);
40893 this.doQuery(this.getRawValue());
40896 getCurrency : function()
40898 var v = this.currencyEl().getValue();
40903 restrictHeight : function()
40905 this.list.alignTo(this.currencyEl(), this.listAlign);
40906 this.list.alignTo(this.currencyEl(), this.listAlign);
40909 onViewClick : function(view, doFocus, el, e)
40911 var index = this.view.getSelectedIndexes()[0];
40913 var r = this.store.getAt(index);
40916 this.onSelect(r, index);
40920 onSelect : function(record, index){
40922 if(this.fireEvent('beforeselect', this, record, index) !== false){
40924 this.setFromCurrencyData(index > -1 ? record.data : false);
40928 this.fireEvent('select', this, record, index);
40932 setFromCurrencyData : function(o)
40936 this.lastCurrency = o;
40938 if (this.currencyField) {
40939 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
40941 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
40944 this.lastSelectionText = currency;
40946 //setting default currency
40947 if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
40948 this.setCurrency(this.defaultCurrency);
40952 this.setCurrency(currency);
40955 setFromData : function(o)
40959 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
40961 this.setFromCurrencyData(c);
40966 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
40968 Roo.log('no value set for '+ (this.name ? this.name : this.id));
40971 this.setValue(value);
40975 setCurrency : function(v)
40977 this.currencyValue = v;
40980 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
40985 setValue : function(v)
40987 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
40993 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40995 this.inputEl().dom.value = (v == '') ? '' :
40996 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
40998 if(!this.allowZero && v === '0') {
40999 this.hiddenEl().dom.value = '';
41000 this.inputEl().dom.value = '';
41007 getRawValue : function()
41009 var v = this.inputEl().getValue();
41014 getValue : function()
41016 return this.fixPrecision(this.parseValue(this.getRawValue()));
41019 parseValue : function(value)
41021 if(this.thousandsDelimiter) {
41023 r = new RegExp(",", "g");
41024 value = value.replace(r, "");
41027 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
41028 return isNaN(value) ? '' : value;
41032 fixPrecision : function(value)
41034 if(this.thousandsDelimiter) {
41036 r = new RegExp(",", "g");
41037 value = value.replace(r, "");
41040 var nan = isNaN(value);
41042 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
41043 return nan ? '' : value;
41045 return parseFloat(value).toFixed(this.decimalPrecision);
41048 decimalPrecisionFcn : function(v)
41050 return Math.floor(v);
41053 validateValue : function(value)
41055 if(!Roo.bootstrap.MoneyField.superclass.validateValue.call(this, value)){
41059 var num = this.parseValue(value);
41062 this.markInvalid(String.format(this.nanText, value));
41066 if(num < this.minValue){
41067 this.markInvalid(String.format(this.minText, this.minValue));
41071 if(num > this.maxValue){
41072 this.markInvalid(String.format(this.maxText, this.maxValue));
41079 validate : function()
41081 if(this.disabled || this.allowBlank){
41086 var currency = this.getCurrency();
41088 if(this.validateValue(this.getRawValue()) && currency.length){
41093 this.markInvalid();
41097 getName: function()
41102 beforeBlur : function()
41108 var v = this.parseValue(this.getRawValue());
41115 onBlur : function()
41119 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
41120 //this.el.removeClass(this.focusClass);
41123 this.hasFocus = false;
41125 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
41129 var v = this.getValue();
41131 if(String(v) !== String(this.startValue)){
41132 this.fireEvent('change', this, v, this.startValue);
41135 this.fireEvent("blur", this);
41138 inputEl : function()
41140 return this.el.select('.roo-money-amount-input', true).first();
41143 currencyEl : function()
41145 return this.el.select('.roo-money-currency-input', true).first();
41148 hiddenEl : function()
41150 return this.el.select('input.hidden-number-input',true).first();