4 * base class for bootstrap elements.
8 Roo.bootstrap = Roo.bootstrap || {};
10 * @class Roo.bootstrap.Component
11 * @extends Roo.Component
12 * Bootstrap Component base class
13 * @cfg {String} cls css class
14 * @cfg {String} style any extra css
15 * @cfg {Object} xattr extra attributes to add to 'element' (used by builder to store stuff.)
16 * @cfg {Boolean} can_build_overlaid True if element can be rebuild from a HTML page
17 * @cfg {string} dataId cutomer id
18 * @cfg {string} name Specifies name attribute
19 * @cfg {string} tooltip Text for the tooltip
20 * @cfg {string} container_method method to fetch parents container element (used by NavHeaderbar - getHeaderChildContainer)
21 * @cfg {string|object} visibilityEl (el|parent) What element to use for visibility (@see getVisibilityEl())
24 * Do not use directly - it does not do anything..
25 * @param {Object} config The config object
30 Roo.bootstrap.Component = function(config){
31 Roo.bootstrap.Component.superclass.constructor.call(this, config);
35 * @event childrenrendered
36 * Fires when the children have been rendered..
37 * @param {Roo.bootstrap.Component} this
39 "childrenrendered" : true
48 Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent, {
51 allowDomMove : false, // to stop relocations in parent onRender...
61 * Initialize Events for the element
63 initEvents : function() { },
69 can_build_overlaid : true,
71 container_method : false,
78 // returns the parent component..
79 return Roo.ComponentMgr.get(this.parentId)
85 onRender : function(ct, position)
87 // Roo.log("Call onRender: " + this.xtype);
89 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
92 if (this.el.attr('xtype')) {
93 this.el.attr('xtypex', this.el.attr('xtype'));
94 this.el.dom.removeAttribute('xtype');
104 var cfg = Roo.apply({}, this.getAutoCreate());
106 cfg.id = this.id || Roo.id();
108 // fill in the extra attributes
109 if (this.xattr && typeof(this.xattr) =='object') {
110 for (var i in this.xattr) {
111 cfg[i] = this.xattr[i];
116 cfg.dataId = this.dataId;
120 cfg.cls = (typeof(cfg.cls) == 'undefined') ? this.cls : cfg.cls + ' ' + this.cls;
123 if (this.style) { // fixme needs to support more complex style data.
124 cfg.style = this.style;
128 cfg.name = this.name;
131 this.el = ct.createChild(cfg, position);
134 this.tooltipEl().attr('tooltip', this.tooltip);
137 if(this.tabIndex !== undefined){
138 this.el.dom.setAttribute('tabIndex', this.tabIndex);
145 * Fetch the element to add children to
146 * @return {Roo.Element} defaults to this.el
148 getChildContainer : function()
153 * Fetch the element to display the tooltip on.
154 * @return {Roo.Element} defaults to this.el
156 tooltipEl : function()
161 addxtype : function(tree,cntr)
165 cn = Roo.factory(tree);
166 //Roo.log(['addxtype', cn]);
168 cn.parentType = this.xtype; //??
169 cn.parentId = this.id;
171 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
172 if (typeof(cn.container_method) == 'string') {
173 cntr = cn.container_method;
177 var has_flexy_each = (typeof(tree['flexy:foreach']) != 'undefined');
179 var has_flexy_if = (typeof(tree['flexy:if']) != 'undefined');
181 var build_from_html = Roo.XComponent.build_from_html;
183 var is_body = (tree.xtype == 'Body') ;
185 var page_has_body = (Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body');
187 var self_cntr_el = Roo.get(this[cntr](false));
189 // do not try and build conditional elements
190 if ((has_flexy_each || has_flexy_if || this.can_build_overlaid == false ) && build_from_html) {
194 if (!has_flexy_each || !build_from_html || is_body || !page_has_body) {
195 if(!has_flexy_if || typeof(tree.name) == 'undefined' || !build_from_html || is_body || !page_has_body){
196 return this.addxtypeChild(tree,cntr, is_body);
199 var echild =self_cntr_el ? self_cntr_el.child('>*[name=' + tree.name + ']') : false;
202 return this.addxtypeChild(Roo.apply({}, tree),cntr);
205 Roo.log('skipping render');
211 if (!build_from_html) {
215 // this i think handles overlaying multiple children of the same type
216 // with the sam eelement.. - which might be buggy..
218 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
224 if (echild && echild.attr('xtype').split('.').pop() != cn.xtype) {
228 ret = this.addxtypeChild(Roo.apply({}, tree),cntr);
235 addxtypeChild : function (tree, cntr, is_body)
237 Roo.debug && Roo.log('addxtypeChild:' + cntr);
239 cntr = (typeof(cntr) == 'undefined' ) ? 'getChildContainer' : cntr;
242 var has_flexy = (typeof(tree['flexy:if']) != 'undefined') ||
243 (typeof(tree['flexy:foreach']) != 'undefined');
247 skip_children = false;
248 // render the element if it's not BODY.
251 // if parent was disabled, then do not try and create the children..
252 if(!this[cntr](true)){
257 cn = Roo.factory(tree);
259 cn.parentType = this.xtype; //??
260 cn.parentId = this.id;
262 var build_from_html = Roo.XComponent.build_from_html;
265 // does the container contain child eleemnts with 'xtype' attributes.
266 // that match this xtype..
267 // note - when we render we create these as well..
268 // so we should check to see if body has xtype set.
269 if (build_from_html && Roo.get(document.body).attr('xtype') == 'Roo.bootstrap.Body') {
271 var self_cntr_el = Roo.get(this[cntr](false));
272 var echild =self_cntr_el ? self_cntr_el.child('>*[xtype]') : false;
274 //Roo.log(Roo.XComponent.build_from_html);
275 //Roo.log("got echild:");
278 // there is a scenario where some of the child elements are flexy:if (and all of the same type)
279 // and are not displayed -this causes this to use up the wrong element when matching.
280 // at present the only work around for this is to nest flexy:if elements in another element that is always rendered.
283 if (echild && echild.attr('xtype').split('.').pop() == cn.xtype) {
284 // Roo.log("found child for " + this.xtype +": " + echild.attr('xtype') );
290 //echild.dom.removeAttribute('xtype');
292 Roo.debug && Roo.log("MISSING " + cn.xtype + " on child of " + (this.el ? this.el.attr('xbuilderid') : 'no parent'));
293 Roo.debug && Roo.log(self_cntr_el);
294 Roo.debug && Roo.log(echild);
295 Roo.debug && Roo.log(cn);
301 // if object has flexy:if - then it may or may not be rendered.
302 if (build_from_html && has_flexy && !cn.el && cn.can_build_overlaid) {
303 // skip a flexy if element.
304 Roo.debug && Roo.log('skipping render');
305 Roo.debug && Roo.log(tree);
307 Roo.debug && Roo.log('skipping all children');
308 skip_children = true;
313 // actually if flexy:foreach is found, we really want to create
314 // multiple copies here...
316 //Roo.log(this[cntr]());
317 // some elements do not have render methods.. like the layouts...
319 if(this[cntr](true) === false){
324 cn.render && cn.render(this[cntr](true));
327 // then add the element..
334 if (typeof (tree.menu) != 'undefined') {
335 tree.menu.parentType = cn.xtype;
336 tree.menu.triggerEl = cn.el;
337 nitems.push(cn.addxtype(Roo.apply({}, tree.menu)));
341 if (!tree.items || !tree.items.length) {
343 //Roo.log(["no children", this]);
348 var items = tree.items;
351 //Roo.log(items.length);
353 if (!skip_children) {
354 for(var i =0;i < items.length;i++) {
355 // Roo.log(['add child', items[i]]);
356 nitems.push(cn.addxtype(Roo.apply({}, items[i])));
362 //Roo.log("fire childrenrendered");
364 cn.fireEvent('childrenrendered', this);
370 * Set the element that will be used to show or hide
372 setVisibilityEl : function(el)
374 this.visibilityEl = el;
378 * Get the element that will be used to show or hide
380 getVisibilityEl : function()
382 if (typeof(this.visibilityEl) == 'object') {
383 return this.visibilityEl;
386 if (typeof(this.visibilityEl) == 'string') {
387 return this.visibilityEl == 'parent' ? this.parent().getEl() : this.getEl();
394 * Show a component - removes 'hidden' class
398 if(!this.getVisibilityEl()){
402 this.getVisibilityEl().removeClass('hidden');
407 * Hide a component - adds 'hidden' class
411 if(!this.getVisibilityEl()){
415 this.getVisibilityEl().addClass('hidden');
428 * @class Roo.bootstrap.Body
429 * @extends Roo.bootstrap.Component
430 * Bootstrap Body class
434 * @param {Object} config The config object
437 Roo.bootstrap.Body = function(config){
439 config = config || {};
441 Roo.bootstrap.Body.superclass.constructor.call(this, config);
442 this.el = Roo.get(config.el ? config.el : document.body );
443 if (this.cls && this.cls.length) {
444 Roo.get(document.body).addClass(this.cls);
448 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, {
450 is_body : true,// just to make sure it's constructed?
455 onRender : function(ct, position)
457 /* Roo.log("Roo.bootstrap.Body - onRender");
458 if (this.cls && this.cls.length) {
459 Roo.get(document.body).addClass(this.cls);
478 * @class Roo.bootstrap.ButtonGroup
479 * @extends Roo.bootstrap.Component
480 * Bootstrap ButtonGroup class
481 * @cfg {String} size lg | sm | xs (default empty normal)
482 * @cfg {String} align vertical | justified (default none)
483 * @cfg {String} direction up | down (default down)
484 * @cfg {Boolean} toolbar false | true
485 * @cfg {Boolean} btn true | false
490 * @param {Object} config The config object
493 Roo.bootstrap.ButtonGroup = function(config){
494 Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
497 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, {
505 getAutoCreate : function(){
511 cfg.html = this.html || cfg.html;
522 if (['vertical','justified'].indexOf(this.align)!==-1) {
523 cfg.cls = 'btn-group-' + this.align;
525 if (this.align == 'justified') {
526 console.log(this.items);
530 if (['lg','sm','xs'].indexOf(this.size)!==-1) {
531 cfg.cls += ' btn-group-' + this.size;
534 if (this.direction == 'up') {
535 cfg.cls += ' dropup' ;
551 * @class Roo.bootstrap.Button
552 * @extends Roo.bootstrap.Component
553 * Bootstrap Button class
554 * @cfg {String} html The button content
555 * @cfg {String} weight (default | primary | success | info | warning | danger | link ) default
556 * @cfg {String} size ( lg | sm | xs)
557 * @cfg {String} tag ( a | input | submit)
558 * @cfg {String} href empty or href
559 * @cfg {Boolean} disabled default false;
560 * @cfg {Boolean} isClose default false;
561 * @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)
562 * @cfg {String} badge text for badge
563 * @cfg {String} theme default
564 * @cfg {Boolean} inverse
565 * @cfg {Boolean} toggle is it a slidy toggle button
566 * @cfg {Boolean} pressed (true|false) default null - if the button ahs active state
567 * @cfg {String} ontext text for on toggle state
568 * @cfg {String} offtext text for off toggle state
569 * @cfg {Boolean} defaulton
570 * @cfg {Boolean} preventDefault default true
571 * @cfg {Boolean} removeClass remove the standard class..
572 * @cfg {String} target target for a href. (_self|_blank|_parent|_top| other)
575 * Create a new button
576 * @param {Object} config The config object
580 Roo.bootstrap.Button = function(config){
581 Roo.bootstrap.Button.superclass.constructor.call(this, config);
582 this.weightClass = ["btn-default",
594 * When a butotn is pressed
595 * @param {Roo.bootstrap.Button} btn
596 * @param {Roo.EventObject} e
601 * After the button has been toggles
602 * @param {Roo.bootstrap.Button} btn
603 * @param {Roo.EventObject} e
604 * @param {boolean} pressed (also available as button.pressed)
610 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
628 preventDefault: true,
637 getAutoCreate : function(){
645 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
646 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
651 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
653 if (this.toggle == true) {
656 cls: 'slider-frame roo-button',
661 'data-off-text':'OFF',
662 cls: 'slider-button',
668 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
669 cfg.cls += ' '+this.weight;
678 cfg["aria-hidden"] = true;
680 cfg.html = "×";
686 if (this.theme==='default') {
687 cfg.cls = 'btn roo-button';
689 //if (this.parentType != 'Navbar') {
690 this.weight = this.weight.length ? this.weight : 'default';
692 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
694 cfg.cls += ' btn-' + this.weight;
696 } else if (this.theme==='glow') {
699 cfg.cls = 'btn-glow roo-button';
701 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
703 cfg.cls += ' ' + this.weight;
709 this.cls += ' inverse';
713 if (this.active || this.pressed === true) {
714 cfg.cls += ' active';
718 cfg.disabled = 'disabled';
722 Roo.log('changing to ul' );
724 this.glyphicon = 'caret';
727 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
729 //gsRoo.log(this.parentType);
730 if (this.parentType === 'Navbar' && !this.parent().bar) {
731 Roo.log('changing to li?');
740 href : this.href || '#'
743 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
744 cfg.cls += ' dropdown';
751 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
753 if (this.glyphicon) {
754 cfg.html = ' ' + cfg.html;
759 cls: 'glyphicon glyphicon-' + this.glyphicon
769 // cfg.cls='btn roo-button';
773 var value = cfg.html;
778 cls: 'glyphicon glyphicon-' + this.glyphicon,
797 cfg.cls += ' dropdown';
798 cfg.html = typeof(cfg.html) != 'undefined' ? cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
801 if (cfg.tag !== 'a' && this.href !== '') {
802 throw "Tag must be a to set href.";
803 } else if (this.href.length > 0) {
804 cfg.href = this.href;
807 if(this.removeClass){
812 cfg.target = this.target;
817 initEvents: function() {
818 // Roo.log('init events?');
819 // Roo.log(this.el.dom);
822 if (typeof (this.menu) != 'undefined') {
823 this.menu.parentType = this.xtype;
824 this.menu.triggerEl = this.el;
825 this.addxtype(Roo.apply({}, this.menu));
829 if (this.el.hasClass('roo-button')) {
830 this.el.on('click', this.onClick, this);
832 this.el.select('.roo-button').on('click', this.onClick, this);
835 if(this.removeClass){
836 this.el.on('click', this.onClick, this);
839 this.el.enableDisplayMode();
842 onClick : function(e)
849 Roo.log('button on click ');
850 if(this.preventDefault){
854 if (this.pressed === true || this.pressed === false) {
855 this.pressed = !this.pressed;
856 this.el[this.pressed ? 'addClass' : 'removeClass']('active');
857 this.fireEvent('toggle', this, e, this.pressed);
861 this.fireEvent('click', this, e);
865 * Enables this button
869 this.disabled = false;
870 this.el.removeClass('disabled');
874 * Disable this button
878 this.disabled = true;
879 this.el.addClass('disabled');
882 * sets the active state on/off,
883 * @param {Boolean} state (optional) Force a particular state
885 setActive : function(v) {
887 this.el[v ? 'addClass' : 'removeClass']('active');
891 * toggles the current active state
893 toggleActive : function()
895 var active = this.el.hasClass('active');
896 this.setActive(!active);
901 * get the current active state
902 * @return {boolean} true if it's active
904 isActive : function()
906 return this.el.hasClass('active');
909 * set the text of the first selected button
911 setText : function(str)
913 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
916 * get the text of the first selected button
920 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
931 setWeight : function(str)
933 this.el.removeClass(this.weightClass);
934 this.el.addClass('btn-' + str);
948 * @class Roo.bootstrap.Column
949 * @extends Roo.bootstrap.Component
950 * Bootstrap Column class
951 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
952 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
953 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
954 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
955 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
956 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
957 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
958 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
961 * @cfg {Boolean} hidden (true|false) hide the element
962 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
963 * @cfg {String} fa (ban|check|...) font awesome icon
964 * @cfg {Number} fasize (1|2|....) font awsome size
966 * @cfg {String} icon (info-sign|check|...) glyphicon name
968 * @cfg {String} html content of column.
971 * Create a new Column
972 * @param {Object} config The config object
975 Roo.bootstrap.Column = function(config){
976 Roo.bootstrap.Column.superclass.constructor.call(this, config);
979 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
997 getAutoCreate : function(){
998 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
1006 ['xs','sm','md','lg'].map(function(size){
1007 //Roo.log( size + ':' + settings[size]);
1009 if (settings[size+'off'] !== false) {
1010 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
1013 if (settings[size] === false) {
1017 if (!settings[size]) { // 0 = hidden
1018 cfg.cls += ' hidden-' + size;
1021 cfg.cls += ' col-' + size + '-' + settings[size];
1026 cfg.cls += ' hidden';
1029 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1030 cfg.cls +=' alert alert-' + this.alert;
1034 if (this.html.length) {
1035 cfg.html = this.html;
1039 if (this.fasize > 1) {
1040 fasize = ' fa-' + this.fasize + 'x';
1042 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
1047 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
1066 * @class Roo.bootstrap.Container
1067 * @extends Roo.bootstrap.Component
1068 * Bootstrap Container class
1069 * @cfg {Boolean} jumbotron is it a jumbotron element
1070 * @cfg {String} html content of element
1071 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1072 * @cfg {String} panel (default|primary|success|info|warning|danger) render as panel - type - primary/success.....
1073 * @cfg {String} header content of header (for panel)
1074 * @cfg {String} footer content of footer (for panel)
1075 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1076 * @cfg {String} tag (header|aside|section) type of HTML tag.
1077 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1078 * @cfg {String} fa font awesome icon
1079 * @cfg {String} icon (info-sign|check|...) glyphicon name
1080 * @cfg {Boolean} hidden (true|false) hide the element
1081 * @cfg {Boolean} expandable (true|false) default false
1082 * @cfg {Boolean} expanded (true|false) default true
1083 * @cfg {String} rheader contet on the right of header
1084 * @cfg {Boolean} clickable (true|false) default false
1088 * Create a new Container
1089 * @param {Object} config The config object
1092 Roo.bootstrap.Container = function(config){
1093 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1099 * After the panel has been expand
1101 * @param {Roo.bootstrap.Container} this
1106 * After the panel has been collapsed
1108 * @param {Roo.bootstrap.Container} this
1113 * When a element is chick
1114 * @param {Roo.bootstrap.Container} this
1115 * @param {Roo.EventObject} e
1121 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1139 getChildContainer : function() {
1145 if (this.panel.length) {
1146 return this.el.select('.panel-body',true).first();
1153 getAutoCreate : function(){
1156 tag : this.tag || 'div',
1160 if (this.jumbotron) {
1161 cfg.cls = 'jumbotron';
1166 // - this is applied by the parent..
1168 // cfg.cls = this.cls + '';
1171 if (this.sticky.length) {
1173 var bd = Roo.get(document.body);
1174 if (!bd.hasClass('bootstrap-sticky')) {
1175 bd.addClass('bootstrap-sticky');
1176 Roo.select('html',true).setStyle('height', '100%');
1179 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1183 if (this.well.length) {
1184 switch (this.well) {
1187 cfg.cls +=' well well-' +this.well;
1196 cfg.cls += ' hidden';
1200 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1201 cfg.cls +=' alert alert-' + this.alert;
1206 if (this.panel.length) {
1207 cfg.cls += ' panel panel-' + this.panel;
1209 if (this.header.length) {
1213 if(this.expandable){
1215 cfg.cls = cfg.cls + ' expandable';
1219 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1227 cls : 'panel-title',
1228 html : (this.expandable ? ' ' : '') + this.header
1232 cls: 'panel-header-right',
1238 cls : 'panel-heading',
1239 style : this.expandable ? 'cursor: pointer' : '',
1247 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1252 if (this.footer.length) {
1254 cls : 'panel-footer',
1263 body.html = this.html || cfg.html;
1264 // prefix with the icons..
1266 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1269 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1274 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1275 cfg.cls = 'container';
1281 initEvents: function()
1283 if(this.expandable){
1284 var headerEl = this.headerEl();
1287 headerEl.on('click', this.onToggleClick, this);
1292 this.el.on('click', this.onClick, this);
1297 onToggleClick : function()
1299 var headerEl = this.headerEl();
1315 if(this.fireEvent('expand', this)) {
1317 this.expanded = true;
1319 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1321 this.el.select('.panel-body',true).first().removeClass('hide');
1323 var toggleEl = this.toggleEl();
1329 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1334 collapse : function()
1336 if(this.fireEvent('collapse', this)) {
1338 this.expanded = false;
1340 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1341 this.el.select('.panel-body',true).first().addClass('hide');
1343 var toggleEl = this.toggleEl();
1349 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1353 toggleEl : function()
1355 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1359 return this.el.select('.panel-heading .fa',true).first();
1362 headerEl : function()
1364 if(!this.el || !this.panel.length || !this.header.length){
1368 return this.el.select('.panel-heading',true).first()
1373 if(!this.el || !this.panel.length){
1377 return this.el.select('.panel-body',true).first()
1380 titleEl : function()
1382 if(!this.el || !this.panel.length || !this.header.length){
1386 return this.el.select('.panel-title',true).first();
1389 setTitle : function(v)
1391 var titleEl = this.titleEl();
1397 titleEl.dom.innerHTML = v;
1400 getTitle : function()
1403 var titleEl = this.titleEl();
1409 return titleEl.dom.innerHTML;
1412 setRightTitle : function(v)
1414 var t = this.el.select('.panel-header-right',true).first();
1420 t.dom.innerHTML = v;
1423 onClick : function(e)
1427 this.fireEvent('click', this, e);
1440 * @class Roo.bootstrap.Img
1441 * @extends Roo.bootstrap.Component
1442 * Bootstrap Img class
1443 * @cfg {Boolean} imgResponsive false | true
1444 * @cfg {String} border rounded | circle | thumbnail
1445 * @cfg {String} src image source
1446 * @cfg {String} alt image alternative text
1447 * @cfg {String} href a tag href
1448 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
1449 * @cfg {String} xsUrl xs image source
1450 * @cfg {String} smUrl sm image source
1451 * @cfg {String} mdUrl md image source
1452 * @cfg {String} lgUrl lg image source
1455 * Create a new Input
1456 * @param {Object} config The config object
1459 Roo.bootstrap.Img = function(config){
1460 Roo.bootstrap.Img.superclass.constructor.call(this, config);
1466 * The img click event for the img.
1467 * @param {Roo.EventObject} e
1473 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
1475 imgResponsive: true,
1485 getAutoCreate : function()
1487 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1488 return this.createSingleImg();
1493 cls: 'roo-image-responsive-group',
1498 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
1500 if(!_this[size + 'Url']){
1506 cls: (_this.imgResponsive) ? 'img-responsive' : '',
1507 html: _this.html || cfg.html,
1508 src: _this[size + 'Url']
1511 img.cls += ' roo-image-responsive-' + size;
1513 var s = ['xs', 'sm', 'md', 'lg'];
1515 s.splice(s.indexOf(size), 1);
1517 Roo.each(s, function(ss){
1518 img.cls += ' hidden-' + ss;
1521 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
1522 cfg.cls += ' img-' + _this.border;
1526 cfg.alt = _this.alt;
1539 a.target = _this.target;
1543 cfg.cn.push((_this.href) ? a : img);
1550 createSingleImg : function()
1554 cls: (this.imgResponsive) ? 'img-responsive' : '',
1556 src : 'about:blank' // just incase src get's set to undefined?!?
1559 cfg.html = this.html || cfg.html;
1561 cfg.src = this.src || cfg.src;
1563 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
1564 cfg.cls += ' img-' + this.border;
1581 a.target = this.target;
1586 return (this.href) ? a : cfg;
1589 initEvents: function()
1592 this.el.on('click', this.onClick, this);
1597 onClick : function(e)
1599 Roo.log('img onclick');
1600 this.fireEvent('click', this, e);
1603 * Sets the url of the image - used to update it
1604 * @param {String} url the url of the image
1607 setSrc : function(url)
1611 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1612 this.el.dom.src = url;
1616 this.el.select('img', true).first().dom.src = url;
1632 * @class Roo.bootstrap.Link
1633 * @extends Roo.bootstrap.Component
1634 * Bootstrap Link Class
1635 * @cfg {String} alt image alternative text
1636 * @cfg {String} href a tag href
1637 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
1638 * @cfg {String} html the content of the link.
1639 * @cfg {String} anchor name for the anchor link
1640 * @cfg {String} fa - favicon
1642 * @cfg {Boolean} preventDefault (true | false) default false
1646 * Create a new Input
1647 * @param {Object} config The config object
1650 Roo.bootstrap.Link = function(config){
1651 Roo.bootstrap.Link.superclass.constructor.call(this, config);
1657 * The img click event for the img.
1658 * @param {Roo.EventObject} e
1664 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
1668 preventDefault: false,
1674 getAutoCreate : function()
1676 var html = this.html || '';
1678 if (this.fa !== false) {
1679 html = '<i class="fa fa-' + this.fa + '"></i>';
1684 // anchor's do not require html/href...
1685 if (this.anchor === false) {
1687 cfg.href = this.href || '#';
1689 cfg.name = this.anchor;
1690 if (this.html !== false || this.fa !== false) {
1693 if (this.href !== false) {
1694 cfg.href = this.href;
1698 if(this.alt !== false){
1703 if(this.target !== false) {
1704 cfg.target = this.target;
1710 initEvents: function() {
1712 if(!this.href || this.preventDefault){
1713 this.el.on('click', this.onClick, this);
1717 onClick : function(e)
1719 if(this.preventDefault){
1722 //Roo.log('img onclick');
1723 this.fireEvent('click', this, e);
1736 * @class Roo.bootstrap.Header
1737 * @extends Roo.bootstrap.Component
1738 * Bootstrap Header class
1739 * @cfg {String} html content of header
1740 * @cfg {Number} level (1|2|3|4|5|6) default 1
1743 * Create a new Header
1744 * @param {Object} config The config object
1748 Roo.bootstrap.Header = function(config){
1749 Roo.bootstrap.Header.superclass.constructor.call(this, config);
1752 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
1760 getAutoCreate : function(){
1765 tag: 'h' + (1 *this.level),
1766 html: this.html || ''
1778 * Ext JS Library 1.1.1
1779 * Copyright(c) 2006-2007, Ext JS, LLC.
1781 * Originally Released Under LGPL - original licence link has changed is not relivant.
1784 * <script type="text/javascript">
1788 * @class Roo.bootstrap.MenuMgr
1789 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
1792 Roo.bootstrap.MenuMgr = function(){
1793 var menus, active, groups = {}, attached = false, lastShow = new Date();
1795 // private - called when first menu is created
1798 active = new Roo.util.MixedCollection();
1799 Roo.get(document).addKeyListener(27, function(){
1800 if(active.length > 0){
1808 if(active && active.length > 0){
1809 var c = active.clone();
1819 if(active.length < 1){
1820 Roo.get(document).un("mouseup", onMouseDown);
1828 var last = active.last();
1829 lastShow = new Date();
1832 Roo.get(document).on("mouseup", onMouseDown);
1837 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
1838 m.parentMenu.activeChild = m;
1839 }else if(last && last.isVisible()){
1840 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
1845 function onBeforeHide(m){
1847 m.activeChild.hide();
1849 if(m.autoHideTimer){
1850 clearTimeout(m.autoHideTimer);
1851 delete m.autoHideTimer;
1856 function onBeforeShow(m){
1857 var pm = m.parentMenu;
1858 if(!pm && !m.allowOtherMenus){
1860 }else if(pm && pm.activeChild && active != m){
1861 pm.activeChild.hide();
1865 // private this should really trigger on mouseup..
1866 function onMouseDown(e){
1867 Roo.log("on Mouse Up");
1869 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
1870 Roo.log("MenuManager hideAll");
1879 function onBeforeCheck(mi, state){
1881 var g = groups[mi.group];
1882 for(var i = 0, l = g.length; i < l; i++){
1884 g[i].setChecked(false);
1893 * Hides all menus that are currently visible
1895 hideAll : function(){
1900 register : function(menu){
1904 menus[menu.id] = menu;
1905 menu.on("beforehide", onBeforeHide);
1906 menu.on("hide", onHide);
1907 menu.on("beforeshow", onBeforeShow);
1908 menu.on("show", onShow);
1910 if(g && menu.events["checkchange"]){
1914 groups[g].push(menu);
1915 menu.on("checkchange", onCheck);
1920 * Returns a {@link Roo.menu.Menu} object
1921 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
1922 * be used to generate and return a new Menu instance.
1924 get : function(menu){
1925 if(typeof menu == "string"){ // menu id
1927 }else if(menu.events){ // menu instance
1930 /*else if(typeof menu.length == 'number'){ // array of menu items?
1931 return new Roo.bootstrap.Menu({items:menu});
1932 }else{ // otherwise, must be a config
1933 return new Roo.bootstrap.Menu(menu);
1940 unregister : function(menu){
1941 delete menus[menu.id];
1942 menu.un("beforehide", onBeforeHide);
1943 menu.un("hide", onHide);
1944 menu.un("beforeshow", onBeforeShow);
1945 menu.un("show", onShow);
1947 if(g && menu.events["checkchange"]){
1948 groups[g].remove(menu);
1949 menu.un("checkchange", onCheck);
1954 registerCheckable : function(menuItem){
1955 var g = menuItem.group;
1960 groups[g].push(menuItem);
1961 menuItem.on("beforecheckchange", onBeforeCheck);
1966 unregisterCheckable : function(menuItem){
1967 var g = menuItem.group;
1969 groups[g].remove(menuItem);
1970 menuItem.un("beforecheckchange", onBeforeCheck);
1982 * @class Roo.bootstrap.Menu
1983 * @extends Roo.bootstrap.Component
1984 * Bootstrap Menu class - container for MenuItems
1985 * @cfg {String} type (dropdown|treeview|submenu) type of menu
1986 * @cfg {bool} hidden if the menu should be hidden when rendered.
1987 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
1988 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
1992 * @param {Object} config The config object
1996 Roo.bootstrap.Menu = function(config){
1997 Roo.bootstrap.Menu.superclass.constructor.call(this, config);
1998 if (this.registerMenu && this.type != 'treeview') {
1999 Roo.bootstrap.MenuMgr.register(this);
2004 * Fires before this menu is displayed
2005 * @param {Roo.menu.Menu} this
2010 * Fires before this menu is hidden
2011 * @param {Roo.menu.Menu} this
2016 * Fires after this menu is displayed
2017 * @param {Roo.menu.Menu} this
2022 * Fires after this menu is hidden
2023 * @param {Roo.menu.Menu} this
2028 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
2029 * @param {Roo.menu.Menu} this
2030 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2031 * @param {Roo.EventObject} e
2036 * Fires when the mouse is hovering over this menu
2037 * @param {Roo.menu.Menu} this
2038 * @param {Roo.EventObject} e
2039 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2044 * Fires when the mouse exits this menu
2045 * @param {Roo.menu.Menu} this
2046 * @param {Roo.EventObject} e
2047 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2052 * Fires when a menu item contained in this menu is clicked
2053 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
2054 * @param {Roo.EventObject} e
2058 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
2061 Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component, {
2065 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
2068 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
2070 registerMenu : true,
2072 menuItems :false, // stores the menu items..
2082 getChildContainer : function() {
2086 getAutoCreate : function(){
2088 //if (['right'].indexOf(this.align)!==-1) {
2089 // cfg.cn[1].cls += ' pull-right'
2095 cls : 'dropdown-menu' ,
2096 style : 'z-index:1000'
2100 if (this.type === 'submenu') {
2101 cfg.cls = 'submenu active';
2103 if (this.type === 'treeview') {
2104 cfg.cls = 'treeview-menu';
2109 initEvents : function() {
2111 // Roo.log("ADD event");
2112 // Roo.log(this.triggerEl.dom);
2114 this.triggerEl.on('click', this.onTriggerClick, this);
2116 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
2118 this.triggerEl.addClass('dropdown-toggle');
2121 this.el.on('touchstart' , this.onTouch, this);
2123 this.el.on('click' , this.onClick, this);
2125 this.el.on("mouseover", this.onMouseOver, this);
2126 this.el.on("mouseout", this.onMouseOut, this);
2130 findTargetItem : function(e)
2132 var t = e.getTarget(".dropdown-menu-item", this.el, true);
2136 //Roo.log(t); Roo.log(t.id);
2138 //Roo.log(this.menuitems);
2139 return this.menuitems.get(t.id);
2141 //return this.items.get(t.menuItemId);
2147 onTouch : function(e)
2149 Roo.log("menu.onTouch");
2150 //e.stopEvent(); this make the user popdown broken
2154 onClick : function(e)
2156 Roo.log("menu.onClick");
2158 var t = this.findTargetItem(e);
2159 if(!t || t.isContainer){
2164 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
2165 if(t == this.activeItem && t.shouldDeactivate(e)){
2166 this.activeItem.deactivate();
2167 delete this.activeItem;
2171 this.setActiveItem(t, true);
2179 Roo.log('pass click event');
2183 this.fireEvent("click", this, t, e);
2187 if(!t.href.length || t.href == '#'){
2188 (function() { _this.hide(); }).defer(100);
2193 onMouseOver : function(e){
2194 var t = this.findTargetItem(e);
2197 // if(t.canActivate && !t.disabled){
2198 // this.setActiveItem(t, true);
2202 this.fireEvent("mouseover", this, e, t);
2204 isVisible : function(){
2205 return !this.hidden;
2207 onMouseOut : function(e){
2208 var t = this.findTargetItem(e);
2211 // if(t == this.activeItem && t.shouldDeactivate(e)){
2212 // this.activeItem.deactivate();
2213 // delete this.activeItem;
2216 this.fireEvent("mouseout", this, e, t);
2221 * Displays this menu relative to another element
2222 * @param {String/HTMLElement/Roo.Element} element The element to align to
2223 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
2224 * the element (defaults to this.defaultAlign)
2225 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2227 show : function(el, pos, parentMenu){
2228 this.parentMenu = parentMenu;
2232 this.fireEvent("beforeshow", this);
2233 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
2236 * Displays this menu at a specific xy position
2237 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
2238 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2240 showAt : function(xy, parentMenu, /* private: */_e){
2241 this.parentMenu = parentMenu;
2246 this.fireEvent("beforeshow", this);
2247 //xy = this.el.adjustForConstraints(xy);
2251 this.hideMenuItems();
2252 this.hidden = false;
2253 this.triggerEl.addClass('open');
2255 if(this.el.getWidth() + xy[0] > Roo.lib.Dom.getViewWidth()){
2256 xy[0] = xy[0] - this.el.getWidth() + this.triggerEl.getWidth();
2259 if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
2264 this.fireEvent("show", this);
2270 this.doFocus.defer(50, this);
2274 doFocus : function(){
2276 this.focusEl.focus();
2281 * Hides this menu and optionally all parent menus
2282 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
2284 hide : function(deep)
2287 this.hideMenuItems();
2288 if(this.el && this.isVisible()){
2289 this.fireEvent("beforehide", this);
2290 if(this.activeItem){
2291 this.activeItem.deactivate();
2292 this.activeItem = null;
2294 this.triggerEl.removeClass('open');;
2296 this.fireEvent("hide", this);
2298 if(deep === true && this.parentMenu){
2299 this.parentMenu.hide(true);
2303 onTriggerClick : function(e)
2305 Roo.log('trigger click');
2307 var target = e.getTarget();
2309 Roo.log(target.nodeName.toLowerCase());
2311 if(target.nodeName.toLowerCase() === 'i'){
2317 onTriggerPress : function(e)
2319 Roo.log('trigger press');
2320 //Roo.log(e.getTarget());
2321 // Roo.log(this.triggerEl.dom);
2323 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
2324 var pel = Roo.get(e.getTarget());
2325 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
2326 Roo.log('is treeview or dropdown?');
2330 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
2334 if (this.isVisible()) {
2339 this.show(this.triggerEl, false, false);
2342 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
2349 hideMenuItems : function()
2351 Roo.log("hide Menu Items");
2355 //$(backdrop).remove()
2356 this.el.select('.open',true).each(function(aa) {
2358 aa.removeClass('open');
2359 //var parent = getParent($(this))
2360 //var relatedTarget = { relatedTarget: this }
2362 //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
2363 //if (e.isDefaultPrevented()) return
2364 //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
2367 addxtypeChild : function (tree, cntr) {
2368 var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
2370 this.menuitems.add(comp);
2382 this.getEl().dom.innerHTML = '';
2383 this.menuitems.clear();
2397 * @class Roo.bootstrap.MenuItem
2398 * @extends Roo.bootstrap.Component
2399 * Bootstrap MenuItem class
2400 * @cfg {String} html the menu label
2401 * @cfg {String} href the link
2402 * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
2403 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
2404 * @cfg {Boolean} active used on sidebars to highlight active itesm
2405 * @cfg {String} fa favicon to show on left of menu item.
2406 * @cfg {Roo.bootsrap.Menu} menu the child menu.
2410 * Create a new MenuItem
2411 * @param {Object} config The config object
2415 Roo.bootstrap.MenuItem = function(config){
2416 Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
2421 * The raw click event for the entire grid.
2422 * @param {Roo.bootstrap.MenuItem} this
2423 * @param {Roo.EventObject} e
2429 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component, {
2433 preventDefault: false,
2434 isContainer : false,
2438 getAutoCreate : function(){
2440 if(this.isContainer){
2443 cls: 'dropdown-menu-item'
2457 if (this.fa !== false) {
2460 cls : 'fa fa-' + this.fa
2469 cls: 'dropdown-menu-item',
2472 if (this.parent().type == 'treeview') {
2473 cfg.cls = 'treeview-menu';
2476 cfg.cls += ' active';
2481 anc.href = this.href || cfg.cn[0].href ;
2482 ctag.html = this.html || cfg.cn[0].html ;
2486 initEvents: function()
2488 if (this.parent().type == 'treeview') {
2489 this.el.select('a').on('click', this.onClick, this);
2493 this.menu.parentType = this.xtype;
2494 this.menu.triggerEl = this.el;
2495 this.menu = this.addxtype(Roo.apply({}, this.menu));
2499 onClick : function(e)
2501 Roo.log('item on click ');
2503 if(this.preventDefault){
2506 //this.parent().hideMenuItems();
2508 this.fireEvent('click', this, e);
2527 * @class Roo.bootstrap.MenuSeparator
2528 * @extends Roo.bootstrap.Component
2529 * Bootstrap MenuSeparator class
2532 * Create a new MenuItem
2533 * @param {Object} config The config object
2537 Roo.bootstrap.MenuSeparator = function(config){
2538 Roo.bootstrap.MenuSeparator.superclass.constructor.call(this, config);
2541 Roo.extend(Roo.bootstrap.MenuSeparator, Roo.bootstrap.Component, {
2543 getAutoCreate : function(){
2562 * @class Roo.bootstrap.Modal
2563 * @extends Roo.bootstrap.Component
2564 * Bootstrap Modal class
2565 * @cfg {String} title Title of dialog
2566 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
2567 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
2568 * @cfg {Boolean} specificTitle default false
2569 * @cfg {Array} buttons Array of buttons or standard button set..
2570 * @cfg {String} buttonPosition (left|right|center) default right
2571 * @cfg {Boolean} animate default true
2572 * @cfg {Boolean} allow_close default true
2573 * @cfg {Boolean} fitwindow default false
2574 * @cfg {String} size (sm|lg) default empty
2578 * Create a new Modal Dialog
2579 * @param {Object} config The config object
2582 Roo.bootstrap.Modal = function(config){
2583 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2588 * The raw btnclick event for the button
2589 * @param {Roo.EventObject} e
2594 * Fire when dialog resize
2595 * @param {Roo.bootstrap.Modal} this
2596 * @param {Roo.EventObject} e
2600 this.buttons = this.buttons || [];
2603 this.tmpl = Roo.factory(this.tmpl);
2608 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
2610 title : 'test dialog',
2620 specificTitle: false,
2622 buttonPosition: 'right',
2641 onRender : function(ct, position)
2643 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2646 var cfg = Roo.apply({}, this.getAutoCreate());
2649 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2651 //if (!cfg.name.length) {
2655 cfg.cls += ' ' + this.cls;
2658 cfg.style = this.style;
2660 this.el = Roo.get(document.body).createChild(cfg, position);
2662 //var type = this.el.dom.type;
2665 if(this.tabIndex !== undefined){
2666 this.el.dom.setAttribute('tabIndex', this.tabIndex);
2669 this.dialogEl = this.el.select('.modal-dialog',true).first();
2670 this.bodyEl = this.el.select('.modal-body',true).first();
2671 this.closeEl = this.el.select('.modal-header .close', true).first();
2672 this.headerEl = this.el.select('.modal-header',true).first();
2673 this.titleEl = this.el.select('.modal-title',true).first();
2674 this.footerEl = this.el.select('.modal-footer',true).first();
2676 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2677 this.maskEl.enableDisplayMode("block");
2679 //this.el.addClass("x-dlg-modal");
2681 if (this.buttons.length) {
2682 Roo.each(this.buttons, function(bb) {
2683 var b = Roo.apply({}, bb);
2684 b.xns = b.xns || Roo.bootstrap;
2685 b.xtype = b.xtype || 'Button';
2686 if (typeof(b.listeners) == 'undefined') {
2687 b.listeners = { click : this.onButtonClick.createDelegate(this) };
2690 var btn = Roo.factory(b);
2692 btn.render(this.el.select('.modal-footer div').first());
2696 // render the children.
2699 if(typeof(this.items) != 'undefined'){
2700 var items = this.items;
2703 for(var i =0;i < items.length;i++) {
2704 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2708 this.items = nitems;
2710 // where are these used - they used to be body/close/footer
2714 //this.el.addClass([this.fieldClass, this.cls]);
2718 getAutoCreate : function(){
2723 html : this.html || ''
2728 cls : 'modal-title',
2732 if(this.specificTitle){
2738 if (this.allow_close) {
2750 if(this.size.length){
2751 size = 'modal-' + this.size;
2758 cls: "modal-dialog " + size,
2761 cls : "modal-content",
2764 cls : 'modal-header',
2769 cls : 'modal-footer',
2773 cls: 'btn-' + this.buttonPosition
2790 modal.cls += ' fade';
2796 getChildContainer : function() {
2801 getButtonContainer : function() {
2802 return this.el.select('.modal-footer div',true).first();
2805 initEvents : function()
2807 if (this.allow_close) {
2808 this.closeEl.on('click', this.hide, this);
2810 Roo.EventManager.onWindowResize(this.resize, this, true);
2817 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2818 if (this.fitwindow) {
2819 var w = this.width || Roo.lib.Dom.getViewportWidth(true) - 30;
2820 var h = this.height || Roo.lib.Dom.getViewportHeight(true) - 60;
2825 setSize : function(w,h)
2835 if (!this.rendered) {
2839 //this.el.setStyle('display', 'block');
2840 this.el.addClass('show');
2842 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
2845 this.el.addClass('in');
2848 this.el.addClass('in');
2852 // not sure how we can show data in here..
2854 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2857 Roo.get(document.body).addClass("x-body-masked");
2859 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2860 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2865 this.fireEvent('show', this);
2867 // set zindex here - otherwise it appears to be ignored...
2868 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2871 this.items.forEach( function(e) {
2872 e.layout ? e.layout() : false;
2880 if(this.fireEvent("beforehide", this) !== false){
2882 Roo.get(document.body).removeClass("x-body-masked");
2883 this.el.removeClass('in');
2884 this.el.select('.modal-dialog', true).first().setStyle('transform','');
2886 if(this.animate){ // why
2887 this.el.addClass('hideing');
2889 if (!this.el.hasClass('hideing')) {
2890 return; // it's been shown again...
2892 this.el.removeClass('show');
2893 this.el.removeClass('hideing');
2897 this.el.removeClass('show');
2899 this.fireEvent('hide', this);
2902 isVisible : function()
2905 return this.el.hasClass('show') && !this.el.hasClass('hideing');
2909 addButton : function(str, cb)
2913 var b = Roo.apply({}, { html : str } );
2914 b.xns = b.xns || Roo.bootstrap;
2915 b.xtype = b.xtype || 'Button';
2916 if (typeof(b.listeners) == 'undefined') {
2917 b.listeners = { click : cb.createDelegate(this) };
2920 var btn = Roo.factory(b);
2922 btn.render(this.el.select('.modal-footer div').first());
2928 setDefaultButton : function(btn)
2930 //this.el.select('.modal-footer').()
2934 resizeTo: function(w,h)
2938 this.dialogEl.setWidth(w);
2939 if (this.diff === false) {
2940 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
2943 this.bodyEl.setHeight(h-this.diff);
2945 this.fireEvent('resize', this);
2948 setContentSize : function(w, h)
2952 onButtonClick: function(btn,e)
2955 this.fireEvent('btnclick', btn.name, e);
2958 * Set the title of the Dialog
2959 * @param {String} str new Title
2961 setTitle: function(str) {
2962 this.titleEl.dom.innerHTML = str;
2965 * Set the body of the Dialog
2966 * @param {String} str new Title
2968 setBody: function(str) {
2969 this.bodyEl.dom.innerHTML = str;
2972 * Set the body of the Dialog using the template
2973 * @param {Obj} data - apply this data to the template and replace the body contents.
2975 applyBody: function(obj)
2978 Roo.log("Error - using apply Body without a template");
2981 this.tmpl.overwrite(this.bodyEl, obj);
2987 Roo.apply(Roo.bootstrap.Modal, {
2989 * Button config that displays a single OK button
2998 * Button config that displays Yes and No buttons
3014 * Button config that displays OK and Cancel buttons
3029 * Button config that displays Yes, No and Cancel buttons
3053 * messagebox - can be used as a replace
3057 * @class Roo.MessageBox
3058 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
3062 Roo.Msg.alert('Status', 'Changes saved successfully.');
3064 // Prompt for user data:
3065 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
3067 // process text value...
3071 // Show a dialog using config options:
3073 title:'Save Changes?',
3074 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
3075 buttons: Roo.Msg.YESNOCANCEL,
3082 Roo.bootstrap.MessageBox = function(){
3083 var dlg, opt, mask, waitTimer;
3084 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
3085 var buttons, activeTextEl, bwidth;
3089 var handleButton = function(button){
3091 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
3095 var handleHide = function(){
3097 dlg.el.removeClass(opt.cls);
3100 // Roo.TaskMgr.stop(waitTimer);
3101 // waitTimer = null;
3106 var updateButtons = function(b){
3109 buttons["ok"].hide();
3110 buttons["cancel"].hide();
3111 buttons["yes"].hide();
3112 buttons["no"].hide();
3113 //dlg.footer.dom.style.display = 'none';
3116 dlg.footerEl.dom.style.display = '';
3117 for(var k in buttons){
3118 if(typeof buttons[k] != "function"){
3121 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
3122 width += buttons[k].el.getWidth()+15;
3132 var handleEsc = function(d, k, e){
3133 if(opt && opt.closable !== false){
3143 * Returns a reference to the underlying {@link Roo.BasicDialog} element
3144 * @return {Roo.BasicDialog} The BasicDialog element
3146 getDialog : function(){
3148 dlg = new Roo.bootstrap.Modal( {
3151 //constraintoviewport:false,
3153 //collapsible : false,
3158 //buttonAlign:"center",
3159 closeClick : function(){
3160 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3163 handleButton("cancel");
3168 dlg.on("hide", handleHide);
3170 //dlg.addKeyListener(27, handleEsc);
3172 this.buttons = buttons;
3173 var bt = this.buttonText;
3174 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3175 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3176 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3177 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3179 bodyEl = dlg.bodyEl.createChild({
3181 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3182 '<textarea class="roo-mb-textarea"></textarea>' +
3183 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
3185 msgEl = bodyEl.dom.firstChild;
3186 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3187 textboxEl.enableDisplayMode();
3188 textboxEl.addKeyListener([10,13], function(){
3189 if(dlg.isVisible() && opt && opt.buttons){
3192 }else if(opt.buttons.yes){
3193 handleButton("yes");
3197 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3198 textareaEl.enableDisplayMode();
3199 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3200 progressEl.enableDisplayMode();
3202 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
3203 var pf = progressEl.dom.firstChild;
3205 pp = Roo.get(pf.firstChild);
3206 pp.setHeight(pf.offsetHeight);
3214 * Updates the message box body text
3215 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3216 * the XHTML-compliant non-breaking space character '&#160;')
3217 * @return {Roo.MessageBox} This message box
3219 updateText : function(text)
3221 if(!dlg.isVisible() && !opt.width){
3222 dlg.dialogEl.setStyle({ 'max-width' : this.maxWidth});
3223 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
3225 msgEl.innerHTML = text || ' ';
3227 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3228 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3230 Math.min(opt.width || cw , this.maxWidth),
3231 Math.max(opt.minWidth || this.minWidth, bwidth)
3234 activeTextEl.setWidth(w);
3236 if(dlg.isVisible()){
3237 dlg.fixedcenter = false;
3239 // to big, make it scroll. = But as usual stupid IE does not support
3242 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3243 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3244 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3246 bodyEl.dom.style.height = '';
3247 bodyEl.dom.style.overflowY = '';
3250 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3252 bodyEl.dom.style.overflowX = '';
3255 dlg.setContentSize(w, bodyEl.getHeight());
3256 if(dlg.isVisible()){
3257 dlg.fixedcenter = true;
3263 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
3264 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3265 * @param {Number} value Any number between 0 and 1 (e.g., .5)
3266 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3267 * @return {Roo.MessageBox} This message box
3269 updateProgress : function(value, text){
3271 this.updateText(text);
3274 if (pp) { // weird bug on my firefox - for some reason this is not defined
3275 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3276 pp.setHeight(Math.floor(progressEl.dom.firstChild.offsetHeight));
3282 * Returns true if the message box is currently displayed
3283 * @return {Boolean} True if the message box is visible, else false
3285 isVisible : function(){
3286 return dlg && dlg.isVisible();
3290 * Hides the message box if it is displayed
3293 if(this.isVisible()){
3299 * Displays a new message box, or reinitializes an existing message box, based on the config options
3300 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3301 * The following config object properties are supported:
3303 Property Type Description
3304 ---------- --------------- ------------------------------------------------------------------------------------
3305 animEl String/Element An id or Element from which the message box should animate as it opens and
3306 closes (defaults to undefined)
3307 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3308 cancel:'Bar'}), or false to not show any buttons (defaults to false)
3309 closable Boolean False to hide the top-right close button (defaults to true). Note that
3310 progress and wait dialogs will ignore this property and always hide the
3311 close button as they can only be closed programmatically.
3312 cls String A custom CSS class to apply to the message box element
3313 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
3314 displayed (defaults to 75)
3315 fn Function A callback function to execute after closing the dialog. The arguments to the
3316 function will be btn (the name of the button that was clicked, if applicable,
3317 e.g. "ok"), and text (the value of the active text field, if applicable).
3318 Progress and wait dialogs will ignore this option since they do not respond to
3319 user actions and can only be closed programmatically, so any required function
3320 should be called by the same code after it closes the dialog.
3321 icon String A CSS class that provides a background image to be used as an icon for
3322 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3323 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
3324 minWidth Number The minimum width in pixels of the message box (defaults to 100)
3325 modal Boolean False to allow user interaction with the page while the message box is
3326 displayed (defaults to true)
3327 msg String A string that will replace the existing message box body text (defaults
3328 to the XHTML-compliant non-breaking space character ' ')
3329 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
3330 progress Boolean True to display a progress bar (defaults to false)
3331 progressText String The text to display inside the progress bar if progress = true (defaults to '')
3332 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
3333 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
3334 title String The title text
3335 value String The string value to set into the active textbox element if displayed
3336 wait Boolean True to display a progress bar (defaults to false)
3337 width Number The width of the dialog in pixels
3344 msg: 'Please enter your address:',
3346 buttons: Roo.MessageBox.OKCANCEL,
3349 animEl: 'addAddressBtn'
3352 * @param {Object} config Configuration options
3353 * @return {Roo.MessageBox} This message box
3355 show : function(options)
3358 // this causes nightmares if you show one dialog after another
3359 // especially on callbacks..
3361 if(this.isVisible()){
3364 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3365 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
3366 Roo.log("New Dialog Message:" + options.msg )
3367 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3368 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3371 var d = this.getDialog();
3373 d.setTitle(opt.title || " ");
3374 d.closeEl.setDisplayed(opt.closable !== false);
3375 activeTextEl = textboxEl;
3376 opt.prompt = opt.prompt || (opt.multiline ? true : false);
3381 textareaEl.setHeight(typeof opt.multiline == "number" ?
3382 opt.multiline : this.defaultTextHeight);
3383 activeTextEl = textareaEl;
3392 progressEl.setDisplayed(opt.progress === true);
3393 this.updateProgress(0);
3394 activeTextEl.dom.value = opt.value || "";
3396 dlg.setDefaultButton(activeTextEl);
3398 var bs = opt.buttons;
3402 }else if(bs && bs.yes){
3403 db = buttons["yes"];
3405 dlg.setDefaultButton(db);
3407 bwidth = updateButtons(opt.buttons);
3408 this.updateText(opt.msg);
3410 d.el.addClass(opt.cls);
3412 d.proxyDrag = opt.proxyDrag === true;
3413 d.modal = opt.modal !== false;
3414 d.mask = opt.modal !== false ? mask : false;
3416 // force it to the end of the z-index stack so it gets a cursor in FF
3417 document.body.appendChild(dlg.el.dom);
3418 d.animateTarget = null;
3419 d.show(options.animEl);
3425 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
3426 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3427 * and closing the message box when the process is complete.
3428 * @param {String} title The title bar text
3429 * @param {String} msg The message box body text
3430 * @return {Roo.MessageBox} This message box
3432 progress : function(title, msg){
3439 minWidth: this.minProgressWidth,
3446 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3447 * If a callback function is passed it will be called after the user clicks the button, and the
3448 * id of the button that was clicked will be passed as the only parameter to the callback
3449 * (could also be the top-right close button).
3450 * @param {String} title The title bar text
3451 * @param {String} msg The message box body text
3452 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3453 * @param {Object} scope (optional) The scope of the callback function
3454 * @return {Roo.MessageBox} This message box
3456 alert : function(title, msg, fn, scope)
3471 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
3472 * interaction while waiting for a long-running process to complete that does not have defined intervals.
3473 * You are responsible for closing the message box when the process is complete.
3474 * @param {String} msg The message box body text
3475 * @param {String} title (optional) The title bar text
3476 * @return {Roo.MessageBox} This message box
3478 wait : function(msg, title){
3489 waitTimer = Roo.TaskMgr.start({
3491 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3499 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3500 * If a callback function is passed it will be called after the user clicks either button, and the id of the
3501 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3502 * @param {String} title The title bar text
3503 * @param {String} msg The message box body text
3504 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3505 * @param {Object} scope (optional) The scope of the callback function
3506 * @return {Roo.MessageBox} This message box
3508 confirm : function(title, msg, fn, scope){
3512 buttons: this.YESNO,
3521 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3522 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
3523 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3524 * (could also be the top-right close button) and the text that was entered will be passed as the two
3525 * parameters to the callback.
3526 * @param {String} title The title bar text
3527 * @param {String} msg The message box body text
3528 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3529 * @param {Object} scope (optional) The scope of the callback function
3530 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3531 * property, or the height in pixels to create the textbox (defaults to false / single-line)
3532 * @return {Roo.MessageBox} This message box
3534 prompt : function(title, msg, fn, scope, multiline){
3538 buttons: this.OKCANCEL,
3543 multiline: multiline,
3550 * Button config that displays a single OK button
3555 * Button config that displays Yes and No buttons
3558 YESNO : {yes:true, no:true},
3560 * Button config that displays OK and Cancel buttons
3563 OKCANCEL : {ok:true, cancel:true},
3565 * Button config that displays Yes, No and Cancel buttons
3568 YESNOCANCEL : {yes:true, no:true, cancel:true},
3571 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3574 defaultTextHeight : 75,
3576 * The maximum width in pixels of the message box (defaults to 600)
3581 * The minimum width in pixels of the message box (defaults to 100)
3586 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
3587 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3590 minProgressWidth : 250,
3592 * An object containing the default button text strings that can be overriden for localized language support.
3593 * Supported properties are: ok, cancel, yes and no.
3594 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3607 * Shorthand for {@link Roo.MessageBox}
3609 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3610 Roo.Msg = Roo.Msg || Roo.MessageBox;
3619 * @class Roo.bootstrap.Navbar
3620 * @extends Roo.bootstrap.Component
3621 * Bootstrap Navbar class
3624 * Create a new Navbar
3625 * @param {Object} config The config object
3629 Roo.bootstrap.Navbar = function(config){
3630 Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3634 * @event beforetoggle
3635 * Fire before toggle the menu
3636 * @param {Roo.EventObject} e
3638 "beforetoggle" : true
3642 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component, {
3651 getAutoCreate : function(){
3654 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3658 initEvents :function ()
3660 //Roo.log(this.el.select('.navbar-toggle',true));
3661 this.el.select('.navbar-toggle',true).on('click', function() {
3662 if(this.fireEvent('beforetoggle', this) !== false){
3663 this.el.select('.navbar-collapse',true).toggleClass('in');
3673 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3675 var size = this.el.getSize();
3676 this.maskEl.setSize(size.width, size.height);
3677 this.maskEl.enableDisplayMode("block");
3686 getChildContainer : function()
3688 if (this.el.select('.collapse').getCount()) {
3689 return this.el.select('.collapse',true).first();
3722 * @class Roo.bootstrap.NavSimplebar
3723 * @extends Roo.bootstrap.Navbar
3724 * Bootstrap Sidebar class
3726 * @cfg {Boolean} inverse is inverted color
3728 * @cfg {String} type (nav | pills | tabs)
3729 * @cfg {Boolean} arrangement stacked | justified
3730 * @cfg {String} align (left | right) alignment
3732 * @cfg {Boolean} main (true|false) main nav bar? default false
3733 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3735 * @cfg {String} tag (header|footer|nav|div) default is nav
3741 * Create a new Sidebar
3742 * @param {Object} config The config object
3746 Roo.bootstrap.NavSimplebar = function(config){
3747 Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
3750 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar, {
3766 getAutoCreate : function(){
3770 tag : this.tag || 'div',
3783 this.type = this.type || 'nav';
3784 if (['tabs','pills'].indexOf(this.type)!==-1) {
3785 cfg.cn[0].cls += ' nav-' + this.type
3789 if (this.type!=='nav') {
3790 Roo.log('nav type must be nav/tabs/pills')
3792 cfg.cn[0].cls += ' navbar-nav'
3798 if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
3799 cfg.cn[0].cls += ' nav-' + this.arrangement;
3803 if (this.align === 'right') {
3804 cfg.cn[0].cls += ' navbar-right';
3808 cfg.cls += ' navbar-inverse';
3835 * @class Roo.bootstrap.NavHeaderbar
3836 * @extends Roo.bootstrap.NavSimplebar
3837 * Bootstrap Sidebar class
3839 * @cfg {String} brand what is brand
3840 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
3841 * @cfg {String} brand_href href of the brand
3842 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
3843 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
3844 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
3845 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
3848 * Create a new Sidebar
3849 * @param {Object} config The config object
3853 Roo.bootstrap.NavHeaderbar = function(config){
3854 Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
3858 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar, {
3865 desktopCenter : false,
3868 getAutoCreate : function(){
3871 tag: this.nav || 'nav',
3878 if (this.desktopCenter) {
3879 cn.push({cls : 'container', cn : []});
3886 cls: 'navbar-header',
3891 cls: 'navbar-toggle',
3892 'data-toggle': 'collapse',
3897 html: 'Toggle navigation'
3919 cls: 'collapse navbar-collapse',
3923 cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
3925 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
3926 cfg.cls += ' navbar-' + this.position;
3928 // tag can override this..
3930 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
3933 if (this.brand !== '') {
3936 href: this.brand_href ? this.brand_href : '#',
3937 cls: 'navbar-brand',
3945 cfg.cls += ' main-nav';
3953 getHeaderChildContainer : function()
3955 if (this.srButton && this.el.select('.navbar-header').getCount()) {
3956 return this.el.select('.navbar-header',true).first();
3959 return this.getChildContainer();
3963 initEvents : function()
3965 Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
3967 if (this.autohide) {
3972 Roo.get(document).on('scroll',function(e) {
3973 var ns = Roo.get(document).getScroll().top;
3974 var os = prevScroll;
3978 ft.removeClass('slideDown');
3979 ft.addClass('slideUp');
3982 ft.removeClass('slideUp');
3983 ft.addClass('slideDown');
4004 * @class Roo.bootstrap.NavSidebar
4005 * @extends Roo.bootstrap.Navbar
4006 * Bootstrap Sidebar class
4009 * Create a new Sidebar
4010 * @param {Object} config The config object
4014 Roo.bootstrap.NavSidebar = function(config){
4015 Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
4018 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar, {
4020 sidebar : true, // used by Navbar Item and NavbarGroup at present...
4022 getAutoCreate : function(){
4027 cls: 'sidebar sidebar-nav'
4049 * @class Roo.bootstrap.NavGroup
4050 * @extends Roo.bootstrap.Component
4051 * Bootstrap NavGroup class
4052 * @cfg {String} align (left|right)
4053 * @cfg {Boolean} inverse
4054 * @cfg {String} type (nav|pills|tab) default nav
4055 * @cfg {String} navId - reference Id for navbar.
4059 * Create a new nav group
4060 * @param {Object} config The config object
4063 Roo.bootstrap.NavGroup = function(config){
4064 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
4067 Roo.bootstrap.NavGroup.register(this);
4071 * Fires when the active item changes
4072 * @param {Roo.bootstrap.NavGroup} this
4073 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
4074 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
4081 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
4092 getAutoCreate : function()
4094 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
4101 if (['tabs','pills'].indexOf(this.type)!==-1) {
4102 cfg.cls += ' nav-' + this.type
4104 if (this.type!=='nav') {
4105 Roo.log('nav type must be nav/tabs/pills')
4107 cfg.cls += ' navbar-nav'
4110 if (this.parent() && this.parent().sidebar) {
4113 cls: 'dashboard-menu sidebar-menu'
4119 if (this.form === true) {
4125 if (this.align === 'right') {
4126 cfg.cls += ' navbar-right';
4128 cfg.cls += ' navbar-left';
4132 if (this.align === 'right') {
4133 cfg.cls += ' navbar-right';
4137 cfg.cls += ' navbar-inverse';
4145 * sets the active Navigation item
4146 * @param {Roo.bootstrap.NavItem} the new current navitem
4148 setActiveItem : function(item)
4151 Roo.each(this.navItems, function(v){
4156 v.setActive(false, true);
4163 item.setActive(true, true);
4164 this.fireEvent('changed', this, item, prev);
4169 * gets the active Navigation item
4170 * @return {Roo.bootstrap.NavItem} the current navitem
4172 getActive : function()
4176 Roo.each(this.navItems, function(v){
4187 indexOfNav : function()
4191 Roo.each(this.navItems, function(v,i){
4202 * adds a Navigation item
4203 * @param {Roo.bootstrap.NavItem} the navitem to add
4205 addItem : function(cfg)
4207 var cn = new Roo.bootstrap.NavItem(cfg);
4209 cn.parentId = this.id;
4210 cn.onRender(this.el, null);
4214 * register a Navigation item
4215 * @param {Roo.bootstrap.NavItem} the navitem to add
4217 register : function(item)
4219 this.navItems.push( item);
4220 item.navId = this.navId;
4225 * clear all the Navigation item
4228 clearAll : function()
4231 this.el.dom.innerHTML = '';
4234 getNavItem: function(tabId)
4237 Roo.each(this.navItems, function(e) {
4238 if (e.tabId == tabId) {
4248 setActiveNext : function()
4250 var i = this.indexOfNav(this.getActive());
4251 if (i > this.navItems.length) {
4254 this.setActiveItem(this.navItems[i+1]);
4256 setActivePrev : function()
4258 var i = this.indexOfNav(this.getActive());
4262 this.setActiveItem(this.navItems[i-1]);
4264 clearWasActive : function(except) {
4265 Roo.each(this.navItems, function(e) {
4266 if (e.tabId != except.tabId && e.was_active) {
4267 e.was_active = false;
4274 getWasActive : function ()
4277 Roo.each(this.navItems, function(e) {
4292 Roo.apply(Roo.bootstrap.NavGroup, {
4296 * register a Navigation Group
4297 * @param {Roo.bootstrap.NavGroup} the navgroup to add
4299 register : function(navgrp)
4301 this.groups[navgrp.navId] = navgrp;
4305 * fetch a Navigation Group based on the navigation ID
4306 * @param {string} the navgroup to add
4307 * @returns {Roo.bootstrap.NavGroup} the navgroup
4309 get: function(navId) {
4310 if (typeof(this.groups[navId]) == 'undefined') {
4312 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4314 return this.groups[navId] ;
4329 * @class Roo.bootstrap.NavItem
4330 * @extends Roo.bootstrap.Component
4331 * Bootstrap Navbar.NavItem class
4332 * @cfg {String} href link to
4333 * @cfg {String} html content of button
4334 * @cfg {String} badge text inside badge
4335 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4336 * @cfg {String} glyphicon name of glyphicon
4337 * @cfg {String} icon name of font awesome icon
4338 * @cfg {Boolean} active Is item active
4339 * @cfg {Boolean} disabled Is item disabled
4341 * @cfg {Boolean} preventDefault (true | false) default false
4342 * @cfg {String} tabId the tab that this item activates.
4343 * @cfg {String} tagtype (a|span) render as a href or span?
4344 * @cfg {Boolean} animateRef (true|false) link to element default false
4347 * Create a new Navbar Item
4348 * @param {Object} config The config object
4350 Roo.bootstrap.NavItem = function(config){
4351 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4356 * The raw click event for the entire grid.
4357 * @param {Roo.EventObject} e
4362 * Fires when the active item active state changes
4363 * @param {Roo.bootstrap.NavItem} this
4364 * @param {boolean} state the new state
4370 * Fires when scroll to element
4371 * @param {Roo.bootstrap.NavItem} this
4372 * @param {Object} options
4373 * @param {Roo.EventObject} e
4381 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
4389 preventDefault : false,
4396 getAutoCreate : function(){
4405 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4407 if (this.disabled) {
4408 cfg.cls += ' disabled';
4411 if (this.href || this.html || this.glyphicon || this.icon) {
4415 href : this.href || "#",
4416 html: this.html || ''
4421 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4424 if(this.glyphicon) {
4425 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
4430 cfg.cn[0].html += " <span class='caret'></span>";
4434 if (this.badge !== '') {
4436 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
4444 initEvents: function()
4446 if (typeof (this.menu) != 'undefined') {
4447 this.menu.parentType = this.xtype;
4448 this.menu.triggerEl = this.el;
4449 this.menu = this.addxtype(Roo.apply({}, this.menu));
4452 this.el.select('a',true).on('click', this.onClick, this);
4454 if(this.tagtype == 'span'){
4455 this.el.select('span',true).on('click', this.onClick, this);
4458 // at this point parent should be available..
4459 this.parent().register(this);
4462 onClick : function(e)
4464 if (e.getTarget('.dropdown-menu-item')) {
4465 // did you click on a menu itemm.... - then don't trigger onclick..
4470 this.preventDefault ||
4473 Roo.log("NavItem - prevent Default?");
4477 if (this.disabled) {
4481 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4482 if (tg && tg.transition) {
4483 Roo.log("waiting for the transitionend");
4489 //Roo.log("fire event clicked");
4490 if(this.fireEvent('click', this, e) === false){
4494 if(this.tagtype == 'span'){
4498 //Roo.log(this.href);
4499 var ael = this.el.select('a',true).first();
4502 if(ael && this.animateRef && this.href.indexOf('#') > -1){
4503 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4504 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4505 return; // ignore... - it's a 'hash' to another page.
4507 Roo.log("NavItem - prevent Default?");
4509 this.scrollToElement(e);
4513 var p = this.parent();
4515 if (['tabs','pills'].indexOf(p.type)!==-1) {
4516 if (typeof(p.setActiveItem) !== 'undefined') {
4517 p.setActiveItem(this);
4521 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4522 if (p.parentType == 'NavHeaderbar' && !this.menu) {
4523 // remove the collapsed menu expand...
4524 p.parent().el.select('.navbar-collapse',true).removeClass('in');
4528 isActive: function () {
4531 setActive : function(state, fire, is_was_active)
4533 if (this.active && !state && this.navId) {
4534 this.was_active = true;
4535 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4537 nv.clearWasActive(this);
4541 this.active = state;
4544 this.el.removeClass('active');
4545 } else if (!this.el.hasClass('active')) {
4546 this.el.addClass('active');
4549 this.fireEvent('changed', this, state);
4552 // show a panel if it's registered and related..
4554 if (!this.navId || !this.tabId || !state || is_was_active) {
4558 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4562 var pan = tg.getPanelByName(this.tabId);
4566 // if we can not flip to new panel - go back to old nav highlight..
4567 if (false == tg.showPanel(pan)) {
4568 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4570 var onav = nv.getWasActive();
4572 onav.setActive(true, false, true);
4581 // this should not be here...
4582 setDisabled : function(state)
4584 this.disabled = state;
4586 this.el.removeClass('disabled');
4587 } else if (!this.el.hasClass('disabled')) {
4588 this.el.addClass('disabled');
4594 * Fetch the element to display the tooltip on.
4595 * @return {Roo.Element} defaults to this.el
4597 tooltipEl : function()
4599 return this.el.select('' + this.tagtype + '', true).first();
4602 scrollToElement : function(e)
4604 var c = document.body;
4607 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4609 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4610 c = document.documentElement;
4613 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4619 var o = target.calcOffsetsTo(c);
4626 this.fireEvent('scrollto', this, options, e);
4628 Roo.get(c).scrollTo('top', options.value, true);
4641 * <span> icon </span>
4642 * <span> text </span>
4643 * <span>badge </span>
4647 * @class Roo.bootstrap.NavSidebarItem
4648 * @extends Roo.bootstrap.NavItem
4649 * Bootstrap Navbar.NavSidebarItem class
4650 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4651 * {Boolean} open is the menu open
4652 * {Boolean} buttonView use button as the tigger el rather that a (default false)
4653 * {String} buttonWeight (default|primary|success|info|warning|danger)the extra classes for the button
4654 * {String} buttonSize (sm|md|lg)the extra classes for the button
4655 * {Boolean} showArrow show arrow next to the text (default true)
4657 * Create a new Navbar Button
4658 * @param {Object} config The config object
4660 Roo.bootstrap.NavSidebarItem = function(config){
4661 Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4666 * The raw click event for the entire grid.
4667 * @param {Roo.EventObject} e
4672 * Fires when the active item active state changes
4673 * @param {Roo.bootstrap.NavSidebarItem} this
4674 * @param {boolean} state the new state
4682 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem, {
4684 badgeWeight : 'default',
4690 buttonWeight : 'default',
4696 getAutoCreate : function(){
4701 href : this.href || '#',
4707 if(this.buttonView){
4710 href : this.href || '#',
4711 cls: 'btn btn-' + this.buttonWeight + ' btn-' + this.buttonSize + 'roo-button-dropdown-toggle',
4724 cfg.cls += ' active';
4727 if (this.disabled) {
4728 cfg.cls += ' disabled';
4731 cfg.cls += ' open x-open';
4734 if (this.glyphicon || this.icon) {
4735 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
4736 a.cn.push({ tag : 'i', cls : c }) ;
4739 if(!this.buttonView){
4742 html : this.html || ''
4749 if (this.badge !== '') {
4750 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
4756 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
4759 a.cls += ' dropdown-toggle treeview' ;
4765 initEvents : function()
4767 if (typeof (this.menu) != 'undefined') {
4768 this.menu.parentType = this.xtype;
4769 this.menu.triggerEl = this.el;
4770 this.menu = this.addxtype(Roo.apply({}, this.menu));
4773 this.el.on('click', this.onClick, this);
4775 if(this.badge !== ''){
4776 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
4781 onClick : function(e)
4788 if(this.preventDefault){
4792 this.fireEvent('click', this);
4795 disable : function()
4797 this.setDisabled(true);
4802 this.setDisabled(false);
4805 setDisabled : function(state)
4807 if(this.disabled == state){
4811 this.disabled = state;
4814 this.el.addClass('disabled');
4818 this.el.removeClass('disabled');
4823 setActive : function(state)
4825 if(this.active == state){
4829 this.active = state;
4832 this.el.addClass('active');
4836 this.el.removeClass('active');
4841 isActive: function ()
4846 setBadge : function(str)
4852 this.badgeEl.dom.innerHTML = str;
4869 * @class Roo.bootstrap.Row
4870 * @extends Roo.bootstrap.Component
4871 * Bootstrap Row class (contains columns...)
4875 * @param {Object} config The config object
4878 Roo.bootstrap.Row = function(config){
4879 Roo.bootstrap.Row.superclass.constructor.call(this, config);
4882 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
4884 getAutoCreate : function(){
4903 * @class Roo.bootstrap.Element
4904 * @extends Roo.bootstrap.Component
4905 * Bootstrap Element class
4906 * @cfg {String} html contents of the element
4907 * @cfg {String} tag tag of the element
4908 * @cfg {String} cls class of the element
4909 * @cfg {Boolean} preventDefault (true|false) default false
4910 * @cfg {Boolean} clickable (true|false) default false
4913 * Create a new Element
4914 * @param {Object} config The config object
4917 Roo.bootstrap.Element = function(config){
4918 Roo.bootstrap.Element.superclass.constructor.call(this, config);
4924 * When a element is chick
4925 * @param {Roo.bootstrap.Element} this
4926 * @param {Roo.EventObject} e
4932 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
4937 preventDefault: false,
4940 getAutoCreate : function(){
4944 // cls: this.cls, double assign in parent class Component.js :: onRender
4951 initEvents: function()
4953 Roo.bootstrap.Element.superclass.initEvents.call(this);
4956 this.el.on('click', this.onClick, this);
4961 onClick : function(e)
4963 if(this.preventDefault){
4967 this.fireEvent('click', this, e);
4970 getValue : function()
4972 return this.el.dom.innerHTML;
4975 setValue : function(value)
4977 this.el.dom.innerHTML = value;
4992 * @class Roo.bootstrap.Pagination
4993 * @extends Roo.bootstrap.Component
4994 * Bootstrap Pagination class
4995 * @cfg {String} size xs | sm | md | lg
4996 * @cfg {Boolean} inverse false | true
4999 * Create a new Pagination
5000 * @param {Object} config The config object
5003 Roo.bootstrap.Pagination = function(config){
5004 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
5007 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
5013 getAutoCreate : function(){
5019 cfg.cls += ' inverse';
5025 cfg.cls += " " + this.cls;
5043 * @class Roo.bootstrap.PaginationItem
5044 * @extends Roo.bootstrap.Component
5045 * Bootstrap PaginationItem class
5046 * @cfg {String} html text
5047 * @cfg {String} href the link
5048 * @cfg {Boolean} preventDefault (true | false) default true
5049 * @cfg {Boolean} active (true | false) default false
5050 * @cfg {Boolean} disabled default false
5054 * Create a new PaginationItem
5055 * @param {Object} config The config object
5059 Roo.bootstrap.PaginationItem = function(config){
5060 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
5065 * The raw click event for the entire grid.
5066 * @param {Roo.EventObject} e
5072 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
5076 preventDefault: true,
5081 getAutoCreate : function(){
5087 href : this.href ? this.href : '#',
5088 html : this.html ? this.html : ''
5098 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
5102 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
5108 initEvents: function() {
5110 this.el.on('click', this.onClick, this);
5113 onClick : function(e)
5115 Roo.log('PaginationItem on click ');
5116 if(this.preventDefault){
5124 this.fireEvent('click', this, e);
5140 * @class Roo.bootstrap.Slider
5141 * @extends Roo.bootstrap.Component
5142 * Bootstrap Slider class
5145 * Create a new Slider
5146 * @param {Object} config The config object
5149 Roo.bootstrap.Slider = function(config){
5150 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
5153 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
5155 getAutoCreate : function(){
5159 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
5163 cls: 'ui-slider-handle ui-state-default ui-corner-all'
5175 * Ext JS Library 1.1.1
5176 * Copyright(c) 2006-2007, Ext JS, LLC.
5178 * Originally Released Under LGPL - original licence link has changed is not relivant.
5181 * <script type="text/javascript">
5186 * @class Roo.grid.ColumnModel
5187 * @extends Roo.util.Observable
5188 * This is the default implementation of a ColumnModel used by the Grid. It defines
5189 * the columns in the grid.
5192 var colModel = new Roo.grid.ColumnModel([
5193 {header: "Ticker", width: 60, sortable: true, locked: true},
5194 {header: "Company Name", width: 150, sortable: true},
5195 {header: "Market Cap.", width: 100, sortable: true},
5196 {header: "$ Sales", width: 100, sortable: true, renderer: money},
5197 {header: "Employees", width: 100, sortable: true, resizable: false}
5202 * The config options listed for this class are options which may appear in each
5203 * individual column definition.
5204 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5206 * @param {Object} config An Array of column config objects. See this class's
5207 * config objects for details.
5209 Roo.grid.ColumnModel = function(config){
5211 * The config passed into the constructor
5213 this.config = config;
5216 // if no id, create one
5217 // if the column does not have a dataIndex mapping,
5218 // map it to the order it is in the config
5219 for(var i = 0, len = config.length; i < len; i++){
5221 if(typeof c.dataIndex == "undefined"){
5224 if(typeof c.renderer == "string"){
5225 c.renderer = Roo.util.Format[c.renderer];
5227 if(typeof c.id == "undefined"){
5230 if(c.editor && c.editor.xtype){
5231 c.editor = Roo.factory(c.editor, Roo.grid);
5233 if(c.editor && c.editor.isFormField){
5234 c.editor = new Roo.grid.GridEditor(c.editor);
5236 this.lookup[c.id] = c;
5240 * The width of columns which have no width specified (defaults to 100)
5243 this.defaultWidth = 100;
5246 * Default sortable of columns which have no sortable specified (defaults to false)
5249 this.defaultSortable = false;
5253 * @event widthchange
5254 * Fires when the width of a column changes.
5255 * @param {ColumnModel} this
5256 * @param {Number} columnIndex The column index
5257 * @param {Number} newWidth The new width
5259 "widthchange": true,
5261 * @event headerchange
5262 * Fires when the text of a header changes.
5263 * @param {ColumnModel} this
5264 * @param {Number} columnIndex The column index
5265 * @param {Number} newText The new header text
5267 "headerchange": true,
5269 * @event hiddenchange
5270 * Fires when a column is hidden or "unhidden".
5271 * @param {ColumnModel} this
5272 * @param {Number} columnIndex The column index
5273 * @param {Boolean} hidden true if hidden, false otherwise
5275 "hiddenchange": true,
5277 * @event columnmoved
5278 * Fires when a column is moved.
5279 * @param {ColumnModel} this
5280 * @param {Number} oldIndex
5281 * @param {Number} newIndex
5283 "columnmoved" : true,
5285 * @event columlockchange
5286 * Fires when a column's locked state is changed
5287 * @param {ColumnModel} this
5288 * @param {Number} colIndex
5289 * @param {Boolean} locked true if locked
5291 "columnlockchange" : true
5293 Roo.grid.ColumnModel.superclass.constructor.call(this);
5295 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5297 * @cfg {String} header The header text to display in the Grid view.
5300 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5301 * {@link Roo.data.Record} definition from which to draw the column's value. If not
5302 * specified, the column's index is used as an index into the Record's data Array.
5305 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5306 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5309 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5310 * Defaults to the value of the {@link #defaultSortable} property.
5311 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5314 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
5317 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
5320 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5323 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5326 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5327 * given the cell's data value. See {@link #setRenderer}. If not specified, the
5328 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
5329 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5332 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
5335 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
5338 * @cfg {String} cursor (Optional)
5341 * @cfg {String} tooltip (Optional)
5344 * @cfg {Number} xs (Optional)
5347 * @cfg {Number} sm (Optional)
5350 * @cfg {Number} md (Optional)
5353 * @cfg {Number} lg (Optional)
5356 * Returns the id of the column at the specified index.
5357 * @param {Number} index The column index
5358 * @return {String} the id
5360 getColumnId : function(index){
5361 return this.config[index].id;
5365 * Returns the column for a specified id.
5366 * @param {String} id The column id
5367 * @return {Object} the column
5369 getColumnById : function(id){
5370 return this.lookup[id];
5375 * Returns the column for a specified dataIndex.
5376 * @param {String} dataIndex The column dataIndex
5377 * @return {Object|Boolean} the column or false if not found
5379 getColumnByDataIndex: function(dataIndex){
5380 var index = this.findColumnIndex(dataIndex);
5381 return index > -1 ? this.config[index] : false;
5385 * Returns the index for a specified column id.
5386 * @param {String} id The column id
5387 * @return {Number} the index, or -1 if not found
5389 getIndexById : function(id){
5390 for(var i = 0, len = this.config.length; i < len; i++){
5391 if(this.config[i].id == id){
5399 * Returns the index for a specified column dataIndex.
5400 * @param {String} dataIndex The column dataIndex
5401 * @return {Number} the index, or -1 if not found
5404 findColumnIndex : function(dataIndex){
5405 for(var i = 0, len = this.config.length; i < len; i++){
5406 if(this.config[i].dataIndex == dataIndex){
5414 moveColumn : function(oldIndex, newIndex){
5415 var c = this.config[oldIndex];
5416 this.config.splice(oldIndex, 1);
5417 this.config.splice(newIndex, 0, c);
5418 this.dataMap = null;
5419 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5422 isLocked : function(colIndex){
5423 return this.config[colIndex].locked === true;
5426 setLocked : function(colIndex, value, suppressEvent){
5427 if(this.isLocked(colIndex) == value){
5430 this.config[colIndex].locked = value;
5432 this.fireEvent("columnlockchange", this, colIndex, value);
5436 getTotalLockedWidth : function(){
5438 for(var i = 0; i < this.config.length; i++){
5439 if(this.isLocked(i) && !this.isHidden(i)){
5440 this.totalWidth += this.getColumnWidth(i);
5446 getLockedCount : function(){
5447 for(var i = 0, len = this.config.length; i < len; i++){
5448 if(!this.isLocked(i)){
5453 return this.config.length;
5457 * Returns the number of columns.
5460 getColumnCount : function(visibleOnly){
5461 if(visibleOnly === true){
5463 for(var i = 0, len = this.config.length; i < len; i++){
5464 if(!this.isHidden(i)){
5470 return this.config.length;
5474 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5475 * @param {Function} fn
5476 * @param {Object} scope (optional)
5477 * @return {Array} result
5479 getColumnsBy : function(fn, scope){
5481 for(var i = 0, len = this.config.length; i < len; i++){
5482 var c = this.config[i];
5483 if(fn.call(scope||this, c, i) === true){
5491 * Returns true if the specified column is sortable.
5492 * @param {Number} col The column index
5495 isSortable : function(col){
5496 if(typeof this.config[col].sortable == "undefined"){
5497 return this.defaultSortable;
5499 return this.config[col].sortable;
5503 * Returns the rendering (formatting) function defined for the column.
5504 * @param {Number} col The column index.
5505 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5507 getRenderer : function(col){
5508 if(!this.config[col].renderer){
5509 return Roo.grid.ColumnModel.defaultRenderer;
5511 return this.config[col].renderer;
5515 * Sets the rendering (formatting) function for a column.
5516 * @param {Number} col The column index
5517 * @param {Function} fn The function to use to process the cell's raw data
5518 * to return HTML markup for the grid view. The render function is called with
5519 * the following parameters:<ul>
5520 * <li>Data value.</li>
5521 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5522 * <li>css A CSS style string to apply to the table cell.</li>
5523 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5524 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5525 * <li>Row index</li>
5526 * <li>Column index</li>
5527 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5529 setRenderer : function(col, fn){
5530 this.config[col].renderer = fn;
5534 * Returns the width for the specified column.
5535 * @param {Number} col The column index
5538 getColumnWidth : function(col){
5539 return this.config[col].width * 1 || this.defaultWidth;
5543 * Sets the width for a column.
5544 * @param {Number} col The column index
5545 * @param {Number} width The new width
5547 setColumnWidth : function(col, width, suppressEvent){
5548 this.config[col].width = width;
5549 this.totalWidth = null;
5551 this.fireEvent("widthchange", this, col, width);
5556 * Returns the total width of all columns.
5557 * @param {Boolean} includeHidden True to include hidden column widths
5560 getTotalWidth : function(includeHidden){
5561 if(!this.totalWidth){
5562 this.totalWidth = 0;
5563 for(var i = 0, len = this.config.length; i < len; i++){
5564 if(includeHidden || !this.isHidden(i)){
5565 this.totalWidth += this.getColumnWidth(i);
5569 return this.totalWidth;
5573 * Returns the header for the specified column.
5574 * @param {Number} col The column index
5577 getColumnHeader : function(col){
5578 return this.config[col].header;
5582 * Sets the header for a column.
5583 * @param {Number} col The column index
5584 * @param {String} header The new header
5586 setColumnHeader : function(col, header){
5587 this.config[col].header = header;
5588 this.fireEvent("headerchange", this, col, header);
5592 * Returns the tooltip for the specified column.
5593 * @param {Number} col The column index
5596 getColumnTooltip : function(col){
5597 return this.config[col].tooltip;
5600 * Sets the tooltip for a column.
5601 * @param {Number} col The column index
5602 * @param {String} tooltip The new tooltip
5604 setColumnTooltip : function(col, tooltip){
5605 this.config[col].tooltip = tooltip;
5609 * Returns the dataIndex for the specified column.
5610 * @param {Number} col The column index
5613 getDataIndex : function(col){
5614 return this.config[col].dataIndex;
5618 * Sets the dataIndex for a column.
5619 * @param {Number} col The column index
5620 * @param {Number} dataIndex The new dataIndex
5622 setDataIndex : function(col, dataIndex){
5623 this.config[col].dataIndex = dataIndex;
5629 * Returns true if the cell is editable.
5630 * @param {Number} colIndex The column index
5631 * @param {Number} rowIndex The row index - this is nto actually used..?
5634 isCellEditable : function(colIndex, rowIndex){
5635 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5639 * Returns the editor defined for the cell/column.
5640 * return false or null to disable editing.
5641 * @param {Number} colIndex The column index
5642 * @param {Number} rowIndex The row index
5645 getCellEditor : function(colIndex, rowIndex){
5646 return this.config[colIndex].editor;
5650 * Sets if a column is editable.
5651 * @param {Number} col The column index
5652 * @param {Boolean} editable True if the column is editable
5654 setEditable : function(col, editable){
5655 this.config[col].editable = editable;
5660 * Returns true if the column is hidden.
5661 * @param {Number} colIndex The column index
5664 isHidden : function(colIndex){
5665 return this.config[colIndex].hidden;
5670 * Returns true if the column width cannot be changed
5672 isFixed : function(colIndex){
5673 return this.config[colIndex].fixed;
5677 * Returns true if the column can be resized
5680 isResizable : function(colIndex){
5681 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5684 * Sets if a column is hidden.
5685 * @param {Number} colIndex The column index
5686 * @param {Boolean} hidden True if the column is hidden
5688 setHidden : function(colIndex, hidden){
5689 this.config[colIndex].hidden = hidden;
5690 this.totalWidth = null;
5691 this.fireEvent("hiddenchange", this, colIndex, hidden);
5695 * Sets the editor for a column.
5696 * @param {Number} col The column index
5697 * @param {Object} editor The editor object
5699 setEditor : function(col, editor){
5700 this.config[col].editor = editor;
5704 Roo.grid.ColumnModel.defaultRenderer = function(value)
5706 if(typeof value == "object") {
5709 if(typeof value == "string" && value.length < 1){
5713 return String.format("{0}", value);
5716 // Alias for backwards compatibility
5717 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
5720 * Ext JS Library 1.1.1
5721 * Copyright(c) 2006-2007, Ext JS, LLC.
5723 * Originally Released Under LGPL - original licence link has changed is not relivant.
5726 * <script type="text/javascript">
5730 * @class Roo.LoadMask
5731 * A simple utility class for generically masking elements while loading data. If the element being masked has
5732 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
5733 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
5734 * element's UpdateManager load indicator and will be destroyed after the initial load.
5736 * Create a new LoadMask
5737 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
5738 * @param {Object} config The config object
5740 Roo.LoadMask = function(el, config){
5741 this.el = Roo.get(el);
5742 Roo.apply(this, config);
5744 this.store.on('beforeload', this.onBeforeLoad, this);
5745 this.store.on('load', this.onLoad, this);
5746 this.store.on('loadexception', this.onLoadException, this);
5747 this.removeMask = false;
5749 var um = this.el.getUpdateManager();
5750 um.showLoadIndicator = false; // disable the default indicator
5751 um.on('beforeupdate', this.onBeforeLoad, this);
5752 um.on('update', this.onLoad, this);
5753 um.on('failure', this.onLoad, this);
5754 this.removeMask = true;
5758 Roo.LoadMask.prototype = {
5760 * @cfg {Boolean} removeMask
5761 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
5762 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
5766 * The text to display in a centered loading message box (defaults to 'Loading...')
5770 * @cfg {String} msgCls
5771 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
5773 msgCls : 'x-mask-loading',
5776 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
5782 * Disables the mask to prevent it from being displayed
5784 disable : function(){
5785 this.disabled = true;
5789 * Enables the mask so that it can be displayed
5791 enable : function(){
5792 this.disabled = false;
5795 onLoadException : function()
5799 if (typeof(arguments[3]) != 'undefined') {
5800 Roo.MessageBox.alert("Error loading",arguments[3]);
5804 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
5805 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
5812 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5817 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5821 onBeforeLoad : function(){
5823 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
5828 destroy : function(){
5830 this.store.un('beforeload', this.onBeforeLoad, this);
5831 this.store.un('load', this.onLoad, this);
5832 this.store.un('loadexception', this.onLoadException, this);
5834 var um = this.el.getUpdateManager();
5835 um.un('beforeupdate', this.onBeforeLoad, this);
5836 um.un('update', this.onLoad, this);
5837 um.un('failure', this.onLoad, this);
5848 * @class Roo.bootstrap.Table
5849 * @extends Roo.bootstrap.Component
5850 * Bootstrap Table class
5851 * @cfg {String} cls table class
5852 * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
5853 * @cfg {String} bgcolor Specifies the background color for a table
5854 * @cfg {Number} border Specifies whether the table cells should have borders or not
5855 * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
5856 * @cfg {Number} cellspacing Specifies the space between cells
5857 * @cfg {String} frame Specifies which parts of the outside borders that should be visible
5858 * @cfg {String} rules Specifies which parts of the inside borders that should be visible
5859 * @cfg {String} sortable Specifies that the table should be sortable
5860 * @cfg {String} summary Specifies a summary of the content of a table
5861 * @cfg {Number} width Specifies the width of a table
5862 * @cfg {String} layout table layout (auto | fixed | initial | inherit)
5864 * @cfg {boolean} striped Should the rows be alternative striped
5865 * @cfg {boolean} bordered Add borders to the table
5866 * @cfg {boolean} hover Add hover highlighting
5867 * @cfg {boolean} condensed Format condensed
5868 * @cfg {boolean} responsive Format condensed
5869 * @cfg {Boolean} loadMask (true|false) default false
5870 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
5871 * @cfg {Boolean} headerShow (true|false) generate thead, default true
5872 * @cfg {Boolean} rowSelection (true|false) default false
5873 * @cfg {Boolean} cellSelection (true|false) default false
5874 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
5875 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
5876 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
5880 * Create a new Table
5881 * @param {Object} config The config object
5884 Roo.bootstrap.Table = function(config){
5885 Roo.bootstrap.Table.superclass.constructor.call(this, config);
5890 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
5891 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
5892 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
5893 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
5895 this.sm = this.sm || {xtype: 'RowSelectionModel'};
5897 this.sm.grid = this;
5898 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
5899 this.sm = this.selModel;
5900 this.sm.xmodule = this.xmodule || false;
5903 if (this.cm && typeof(this.cm.config) == 'undefined') {
5904 this.colModel = new Roo.grid.ColumnModel(this.cm);
5905 this.cm = this.colModel;
5906 this.cm.xmodule = this.xmodule || false;
5909 this.store= Roo.factory(this.store, Roo.data);
5910 this.ds = this.store;
5911 this.ds.xmodule = this.xmodule || false;
5914 if (this.footer && this.store) {
5915 this.footer.dataSource = this.ds;
5916 this.footer = Roo.factory(this.footer);
5923 * Fires when a cell is clicked
5924 * @param {Roo.bootstrap.Table} this
5925 * @param {Roo.Element} el
5926 * @param {Number} rowIndex
5927 * @param {Number} columnIndex
5928 * @param {Roo.EventObject} e
5932 * @event celldblclick
5933 * Fires when a cell is double clicked
5934 * @param {Roo.bootstrap.Table} this
5935 * @param {Roo.Element} el
5936 * @param {Number} rowIndex
5937 * @param {Number} columnIndex
5938 * @param {Roo.EventObject} e
5940 "celldblclick" : true,
5943 * Fires when a row is clicked
5944 * @param {Roo.bootstrap.Table} this
5945 * @param {Roo.Element} el
5946 * @param {Number} rowIndex
5947 * @param {Roo.EventObject} e
5951 * @event rowdblclick
5952 * Fires when a row is double clicked
5953 * @param {Roo.bootstrap.Table} this
5954 * @param {Roo.Element} el
5955 * @param {Number} rowIndex
5956 * @param {Roo.EventObject} e
5958 "rowdblclick" : true,
5961 * Fires when a mouseover occur
5962 * @param {Roo.bootstrap.Table} this
5963 * @param {Roo.Element} el
5964 * @param {Number} rowIndex
5965 * @param {Number} columnIndex
5966 * @param {Roo.EventObject} e
5971 * Fires when a mouseout occur
5972 * @param {Roo.bootstrap.Table} this
5973 * @param {Roo.Element} el
5974 * @param {Number} rowIndex
5975 * @param {Number} columnIndex
5976 * @param {Roo.EventObject} e
5981 * Fires when a row is rendered, so you can change add a style to it.
5982 * @param {Roo.bootstrap.Table} this
5983 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
5987 * @event rowsrendered
5988 * Fires when all the rows have been rendered
5989 * @param {Roo.bootstrap.Table} this
5991 'rowsrendered' : true,
5993 * @event contextmenu
5994 * The raw contextmenu event for the entire grid.
5995 * @param {Roo.EventObject} e
5997 "contextmenu" : true,
5999 * @event rowcontextmenu
6000 * Fires when a row is right clicked
6001 * @param {Roo.bootstrap.Table} this
6002 * @param {Number} rowIndex
6003 * @param {Roo.EventObject} e
6005 "rowcontextmenu" : true,
6007 * @event cellcontextmenu
6008 * Fires when a cell is right clicked
6009 * @param {Roo.bootstrap.Table} this
6010 * @param {Number} rowIndex
6011 * @param {Number} cellIndex
6012 * @param {Roo.EventObject} e
6014 "cellcontextmenu" : true,
6016 * @event headercontextmenu
6017 * Fires when a header is right clicked
6018 * @param {Roo.bootstrap.Table} this
6019 * @param {Number} columnIndex
6020 * @param {Roo.EventObject} e
6022 "headercontextmenu" : true
6026 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
6052 rowSelection : false,
6053 cellSelection : false,
6056 // Roo.Element - the tbody
6058 // Roo.Element - thead element
6061 container: false, // used by gridpanel...
6067 getAutoCreate : function()
6069 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
6076 if (this.scrollBody) {
6077 cfg.cls += ' table-body-fixed';
6080 cfg.cls += ' table-striped';
6084 cfg.cls += ' table-hover';
6086 if (this.bordered) {
6087 cfg.cls += ' table-bordered';
6089 if (this.condensed) {
6090 cfg.cls += ' table-condensed';
6092 if (this.responsive) {
6093 cfg.cls += ' table-responsive';
6097 cfg.cls+= ' ' +this.cls;
6100 // this lot should be simplifed...
6103 cfg.align=this.align;
6106 cfg.bgcolor=this.bgcolor;
6109 cfg.border=this.border;
6111 if (this.cellpadding) {
6112 cfg.cellpadding=this.cellpadding;
6114 if (this.cellspacing) {
6115 cfg.cellspacing=this.cellspacing;
6118 cfg.frame=this.frame;
6121 cfg.rules=this.rules;
6123 if (this.sortable) {
6124 cfg.sortable=this.sortable;
6127 cfg.summary=this.summary;
6130 cfg.width=this.width;
6133 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
6136 if(this.store || this.cm){
6137 if(this.headerShow){
6138 cfg.cn.push(this.renderHeader());
6141 cfg.cn.push(this.renderBody());
6143 if(this.footerShow){
6144 cfg.cn.push(this.renderFooter());
6146 // where does this come from?
6147 //cfg.cls+= ' TableGrid';
6150 return { cn : [ cfg ] };
6153 initEvents : function()
6155 if(!this.store || !this.cm){
6158 if (this.selModel) {
6159 this.selModel.initEvents();
6163 //Roo.log('initEvents with ds!!!!');
6165 this.mainBody = this.el.select('tbody', true).first();
6166 this.mainHead = this.el.select('thead', true).first();
6173 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6174 e.on('click', _this.sort, _this);
6177 this.mainBody.on("click", this.onClick, this);
6178 this.mainBody.on("dblclick", this.onDblClick, this);
6180 // why is this done????? = it breaks dialogs??
6181 //this.parent().el.setStyle('position', 'relative');
6185 this.footer.parentId = this.id;
6186 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
6189 this.el.select('tfoot tr td').first().addClass('hide');
6193 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
6195 this.store.on('load', this.onLoad, this);
6196 this.store.on('beforeload', this.onBeforeLoad, this);
6197 this.store.on('update', this.onUpdate, this);
6198 this.store.on('add', this.onAdd, this);
6199 this.store.on("clear", this.clear, this);
6201 this.el.on("contextmenu", this.onContextMenu, this);
6203 this.mainBody.on('scroll', this.onBodyScroll, this);
6205 this.cm.on("headerchange", this.onHeaderChange, this);
6207 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
6211 onContextMenu : function(e, t)
6213 this.processEvent("contextmenu", e);
6216 processEvent : function(name, e)
6218 if (name != 'touchstart' ) {
6219 this.fireEvent(name, e);
6222 var t = e.getTarget();
6224 var cell = Roo.get(t);
6230 if(cell.findParent('tfoot', false, true)){
6234 if(cell.findParent('thead', false, true)){
6236 if(e.getTarget().nodeName.toLowerCase() != 'th'){
6237 cell = Roo.get(t).findParent('th', false, true);
6239 Roo.log("failed to find th in thead?");
6240 Roo.log(e.getTarget());
6245 var cellIndex = cell.dom.cellIndex;
6247 var ename = name == 'touchstart' ? 'click' : name;
6248 this.fireEvent("header" + ename, this, cellIndex, e);
6253 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6254 cell = Roo.get(t).findParent('td', false, true);
6256 Roo.log("failed to find th in tbody?");
6257 Roo.log(e.getTarget());
6262 var row = cell.findParent('tr', false, true);
6263 var cellIndex = cell.dom.cellIndex;
6264 var rowIndex = row.dom.rowIndex - 1;
6268 this.fireEvent("row" + name, this, rowIndex, e);
6272 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6278 onMouseover : function(e, el)
6280 var cell = Roo.get(el);
6286 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6287 cell = cell.findParent('td', false, true);
6290 var row = cell.findParent('tr', false, true);
6291 var cellIndex = cell.dom.cellIndex;
6292 var rowIndex = row.dom.rowIndex - 1; // start from 0
6294 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
6298 onMouseout : function(e, el)
6300 var cell = Roo.get(el);
6306 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6307 cell = cell.findParent('td', false, true);
6310 var row = cell.findParent('tr', false, true);
6311 var cellIndex = cell.dom.cellIndex;
6312 var rowIndex = row.dom.rowIndex - 1; // start from 0
6314 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6318 onClick : function(e, el)
6320 var cell = Roo.get(el);
6322 if(!cell || (!this.cellSelection && !this.rowSelection)){
6326 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6327 cell = cell.findParent('td', false, true);
6330 if(!cell || typeof(cell) == 'undefined'){
6334 var row = cell.findParent('tr', false, true);
6336 if(!row || typeof(row) == 'undefined'){
6340 var cellIndex = cell.dom.cellIndex;
6341 var rowIndex = this.getRowIndex(row);
6343 // why??? - should these not be based on SelectionModel?
6344 if(this.cellSelection){
6345 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6348 if(this.rowSelection){
6349 this.fireEvent('rowclick', this, row, rowIndex, e);
6355 onDblClick : function(e,el)
6357 var cell = Roo.get(el);
6359 if(!cell || (!this.cellSelection && !this.rowSelection)){
6363 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6364 cell = cell.findParent('td', false, true);
6367 if(!cell || typeof(cell) == 'undefined'){
6371 var row = cell.findParent('tr', false, true);
6373 if(!row || typeof(row) == 'undefined'){
6377 var cellIndex = cell.dom.cellIndex;
6378 var rowIndex = this.getRowIndex(row);
6380 if(this.cellSelection){
6381 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6384 if(this.rowSelection){
6385 this.fireEvent('rowdblclick', this, row, rowIndex, e);
6389 sort : function(e,el)
6391 var col = Roo.get(el);
6393 if(!col.hasClass('sortable')){
6397 var sort = col.attr('sort');
6400 if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6404 this.store.sortInfo = {field : sort, direction : dir};
6407 Roo.log("calling footer first");
6408 this.footer.onClick('first');
6411 this.store.load({ params : { start : 0 } });
6415 renderHeader : function()
6423 this.totalWidth = 0;
6425 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6427 var config = cm.config[i];
6431 cls : 'x-hcol-' + i,
6433 html: cm.getColumnHeader(i)
6438 if(typeof(config.sortable) != 'undefined' && config.sortable){
6440 c.html = '<i class="glyphicon"></i>' + c.html;
6443 if(typeof(config.lgHeader) != 'undefined'){
6444 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6447 if(typeof(config.mdHeader) != 'undefined'){
6448 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6451 if(typeof(config.smHeader) != 'undefined'){
6452 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6455 if(typeof(config.xsHeader) != 'undefined'){
6456 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6463 if(typeof(config.tooltip) != 'undefined'){
6464 c.tooltip = config.tooltip;
6467 if(typeof(config.colspan) != 'undefined'){
6468 c.colspan = config.colspan;
6471 if(typeof(config.hidden) != 'undefined' && config.hidden){
6472 c.style += ' display:none;';
6475 if(typeof(config.dataIndex) != 'undefined'){
6476 c.sort = config.dataIndex;
6481 if(typeof(config.align) != 'undefined' && config.align.length){
6482 c.style += ' text-align:' + config.align + ';';
6485 if(typeof(config.width) != 'undefined'){
6486 c.style += ' width:' + config.width + 'px;';
6487 this.totalWidth += config.width;
6489 this.totalWidth += 100; // assume minimum of 100 per column?
6492 if(typeof(config.cls) != 'undefined'){
6493 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6496 ['xs','sm','md','lg'].map(function(size){
6498 if(typeof(config[size]) == 'undefined'){
6502 if (!config[size]) { // 0 = hidden
6503 c.cls += ' hidden-' + size;
6507 c.cls += ' col-' + size + '-' + config[size];
6517 renderBody : function()
6527 colspan : this.cm.getColumnCount()
6537 renderFooter : function()
6547 colspan : this.cm.getColumnCount()
6561 // Roo.log('ds onload');
6566 var ds = this.store;
6568 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6569 e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6570 if (_this.store.sortInfo) {
6572 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6573 e.select('i', true).addClass(['glyphicon-arrow-up']);
6576 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6577 e.select('i', true).addClass(['glyphicon-arrow-down']);
6582 var tbody = this.mainBody;
6584 if(ds.getCount() > 0){
6585 ds.data.each(function(d,rowIndex){
6586 var row = this.renderRow(cm, ds, rowIndex);
6588 tbody.createChild(row);
6592 if(row.cellObjects.length){
6593 Roo.each(row.cellObjects, function(r){
6594 _this.renderCellObject(r);
6601 Roo.each(this.el.select('tbody td', true).elements, function(e){
6602 e.on('mouseover', _this.onMouseover, _this);
6605 Roo.each(this.el.select('tbody td', true).elements, function(e){
6606 e.on('mouseout', _this.onMouseout, _this);
6608 this.fireEvent('rowsrendered', this);
6609 //if(this.loadMask){
6610 // this.maskEl.hide();
6617 onUpdate : function(ds,record)
6619 this.refreshRow(record);
6623 onRemove : function(ds, record, index, isUpdate){
6624 if(isUpdate !== true){
6625 this.fireEvent("beforerowremoved", this, index, record);
6627 var bt = this.mainBody.dom;
6629 var rows = this.el.select('tbody > tr', true).elements;
6631 if(typeof(rows[index]) != 'undefined'){
6632 bt.removeChild(rows[index].dom);
6635 // if(bt.rows[index]){
6636 // bt.removeChild(bt.rows[index]);
6639 if(isUpdate !== true){
6640 //this.stripeRows(index);
6641 //this.syncRowHeights(index, index);
6643 this.fireEvent("rowremoved", this, index, record);
6647 onAdd : function(ds, records, rowIndex)
6649 //Roo.log('on Add called');
6650 // - note this does not handle multiple adding very well..
6651 var bt = this.mainBody.dom;
6652 for (var i =0 ; i < records.length;i++) {
6653 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6654 //Roo.log(records[i]);
6655 //Roo.log(this.store.getAt(rowIndex+i));
6656 this.insertRow(this.store, rowIndex + i, false);
6663 refreshRow : function(record){
6664 var ds = this.store, index;
6665 if(typeof record == 'number'){
6667 record = ds.getAt(index);
6669 index = ds.indexOf(record);
6671 this.insertRow(ds, index, true);
6673 this.onRemove(ds, record, index+1, true);
6675 //this.syncRowHeights(index, index);
6677 this.fireEvent("rowupdated", this, index, record);
6680 insertRow : function(dm, rowIndex, isUpdate){
6683 this.fireEvent("beforerowsinserted", this, rowIndex);
6685 //var s = this.getScrollState();
6686 var row = this.renderRow(this.cm, this.store, rowIndex);
6687 // insert before rowIndex..
6688 var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
6692 if(row.cellObjects.length){
6693 Roo.each(row.cellObjects, function(r){
6694 _this.renderCellObject(r);
6699 this.fireEvent("rowsinserted", this, rowIndex);
6700 //this.syncRowHeights(firstRow, lastRow);
6701 //this.stripeRows(firstRow);
6708 getRowDom : function(rowIndex)
6710 var rows = this.el.select('tbody > tr', true).elements;
6712 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
6715 // returns the object tree for a tr..
6718 renderRow : function(cm, ds, rowIndex)
6720 var d = ds.getAt(rowIndex);
6724 cls : 'x-row-' + rowIndex,
6728 var cellObjects = [];
6730 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6731 var config = cm.config[i];
6733 var renderer = cm.getRenderer(i);
6737 if(typeof(renderer) !== 'undefined'){
6738 value = renderer(d.data[cm.getDataIndex(i)], false, d);
6740 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
6741 // and are rendered into the cells after the row is rendered - using the id for the element.
6743 if(typeof(value) === 'object'){
6753 rowIndex : rowIndex,
6758 this.fireEvent('rowclass', this, rowcfg);
6762 cls : rowcfg.rowClass + ' x-col-' + i,
6764 html: (typeof(value) === 'object') ? '' : value
6771 if(typeof(config.colspan) != 'undefined'){
6772 td.colspan = config.colspan;
6775 if(typeof(config.hidden) != 'undefined' && config.hidden){
6776 td.style += ' display:none;';
6779 if(typeof(config.align) != 'undefined' && config.align.length){
6780 td.style += ' text-align:' + config.align + ';';
6783 if(typeof(config.width) != 'undefined'){
6784 td.style += ' width:' + config.width + 'px;';
6787 if(typeof(config.cursor) != 'undefined'){
6788 td.style += ' cursor:' + config.cursor + ';';
6791 if(typeof(config.cls) != 'undefined'){
6792 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
6795 ['xs','sm','md','lg'].map(function(size){
6797 if(typeof(config[size]) == 'undefined'){
6801 if (!config[size]) { // 0 = hidden
6802 td.cls += ' hidden-' + size;
6806 td.cls += ' col-' + size + '-' + config[size];
6814 row.cellObjects = cellObjects;
6822 onBeforeLoad : function()
6824 //Roo.log('ds onBeforeLoad');
6828 //if(this.loadMask){
6829 // this.maskEl.show();
6837 this.el.select('tbody', true).first().dom.innerHTML = '';
6840 * Show or hide a row.
6841 * @param {Number} rowIndex to show or hide
6842 * @param {Boolean} state hide
6844 setRowVisibility : function(rowIndex, state)
6846 var bt = this.mainBody.dom;
6848 var rows = this.el.select('tbody > tr', true).elements;
6850 if(typeof(rows[rowIndex]) == 'undefined'){
6853 rows[rowIndex].dom.style.display = state ? '' : 'none';
6857 getSelectionModel : function(){
6859 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
6861 return this.selModel;
6864 * Render the Roo.bootstrap object from renderder
6866 renderCellObject : function(r)
6870 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
6872 var t = r.cfg.render(r.container);
6875 Roo.each(r.cfg.cn, function(c){
6877 container: t.getChildContainer(),
6880 _this.renderCellObject(child);
6885 getRowIndex : function(row)
6889 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
6900 * Returns the grid's underlying element = used by panel.Grid
6901 * @return {Element} The element
6903 getGridEl : function(){
6907 * Forces a resize - used by panel.Grid
6908 * @return {Element} The element
6910 autoSize : function()
6912 //var ctr = Roo.get(this.container.dom.parentElement);
6913 var ctr = Roo.get(this.el.dom);
6915 var thd = this.getGridEl().select('thead',true).first();
6916 var tbd = this.getGridEl().select('tbody', true).first();
6917 var tfd = this.getGridEl().select('tfoot', true).first();
6919 var cw = ctr.getWidth();
6923 tbd.setSize(ctr.getWidth(),
6924 ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
6926 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
6929 cw = Math.max(cw, this.totalWidth);
6930 this.getGridEl().select('tr',true).setWidth(cw);
6931 // resize 'expandable coloumn?
6933 return; // we doe not have a view in this design..
6936 onBodyScroll: function()
6938 //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
6940 this.mainHead.setStyle({
6941 'position' : 'relative',
6942 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
6948 var scrollHeight = this.mainBody.dom.scrollHeight;
6950 var scrollTop = Math.ceil(this.mainBody.getScroll().top);
6952 var height = this.mainBody.getHeight();
6954 if(scrollHeight - height == scrollTop) {
6956 var total = this.ds.getTotalCount();
6958 if(this.footer.cursor + this.footer.pageSize < total){
6960 this.footer.ds.load({
6962 start : this.footer.cursor + this.footer.pageSize,
6963 limit : this.footer.pageSize
6973 onHeaderChange : function()
6975 var header = this.renderHeader();
6976 var table = this.el.select('table', true).first();
6978 this.mainHead.remove();
6979 this.mainHead = table.createChild(header, this.mainBody, false);
6982 onHiddenChange : function(colModel, colIndex, hidden)
6984 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
6985 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
6987 this.CSS.updateRule(thSelector, "display", "");
6988 this.CSS.updateRule(tdSelector, "display", "");
6991 this.CSS.updateRule(thSelector, "display", "none");
6992 this.CSS.updateRule(tdSelector, "display", "none");
6995 this.onHeaderChange();
7012 * @class Roo.bootstrap.TableCell
7013 * @extends Roo.bootstrap.Component
7014 * Bootstrap TableCell class
7015 * @cfg {String} html cell contain text
7016 * @cfg {String} cls cell class
7017 * @cfg {String} tag cell tag (td|th) default td
7018 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
7019 * @cfg {String} align Aligns the content in a cell
7020 * @cfg {String} axis Categorizes cells
7021 * @cfg {String} bgcolor Specifies the background color of a cell
7022 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7023 * @cfg {Number} colspan Specifies the number of columns a cell should span
7024 * @cfg {String} headers Specifies one or more header cells a cell is related to
7025 * @cfg {Number} height Sets the height of a cell
7026 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
7027 * @cfg {Number} rowspan Sets the number of rows a cell should span
7028 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
7029 * @cfg {String} valign Vertical aligns the content in a cell
7030 * @cfg {Number} width Specifies the width of a cell
7033 * Create a new TableCell
7034 * @param {Object} config The config object
7037 Roo.bootstrap.TableCell = function(config){
7038 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
7041 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
7061 getAutoCreate : function(){
7062 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
7082 cfg.align=this.align
7088 cfg.bgcolor=this.bgcolor
7091 cfg.charoff=this.charoff
7094 cfg.colspan=this.colspan
7097 cfg.headers=this.headers
7100 cfg.height=this.height
7103 cfg.nowrap=this.nowrap
7106 cfg.rowspan=this.rowspan
7109 cfg.scope=this.scope
7112 cfg.valign=this.valign
7115 cfg.width=this.width
7134 * @class Roo.bootstrap.TableRow
7135 * @extends Roo.bootstrap.Component
7136 * Bootstrap TableRow class
7137 * @cfg {String} cls row class
7138 * @cfg {String} align Aligns the content in a table row
7139 * @cfg {String} bgcolor Specifies a background color for a table row
7140 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7141 * @cfg {String} valign Vertical aligns the content in a table row
7144 * Create a new TableRow
7145 * @param {Object} config The config object
7148 Roo.bootstrap.TableRow = function(config){
7149 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
7152 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
7160 getAutoCreate : function(){
7161 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
7171 cfg.align = this.align;
7174 cfg.bgcolor = this.bgcolor;
7177 cfg.charoff = this.charoff;
7180 cfg.valign = this.valign;
7198 * @class Roo.bootstrap.TableBody
7199 * @extends Roo.bootstrap.Component
7200 * Bootstrap TableBody class
7201 * @cfg {String} cls element class
7202 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
7203 * @cfg {String} align Aligns the content inside the element
7204 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
7205 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
7208 * Create a new TableBody
7209 * @param {Object} config The config object
7212 Roo.bootstrap.TableBody = function(config){
7213 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
7216 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
7224 getAutoCreate : function(){
7225 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
7239 cfg.align = this.align;
7242 cfg.charoff = this.charoff;
7245 cfg.valign = this.valign;
7252 // initEvents : function()
7259 // this.store = Roo.factory(this.store, Roo.data);
7260 // this.store.on('load', this.onLoad, this);
7262 // this.store.load();
7266 // onLoad: function ()
7268 // this.fireEvent('load', this);
7278 * Ext JS Library 1.1.1
7279 * Copyright(c) 2006-2007, Ext JS, LLC.
7281 * Originally Released Under LGPL - original licence link has changed is not relivant.
7284 * <script type="text/javascript">
7287 // as we use this in bootstrap.
7288 Roo.namespace('Roo.form');
7290 * @class Roo.form.Action
7291 * Internal Class used to handle form actions
7293 * @param {Roo.form.BasicForm} el The form element or its id
7294 * @param {Object} config Configuration options
7299 // define the action interface
7300 Roo.form.Action = function(form, options){
7302 this.options = options || {};
7305 * Client Validation Failed
7308 Roo.form.Action.CLIENT_INVALID = 'client';
7310 * Server Validation Failed
7313 Roo.form.Action.SERVER_INVALID = 'server';
7315 * Connect to Server Failed
7318 Roo.form.Action.CONNECT_FAILURE = 'connect';
7320 * Reading Data from Server Failed
7323 Roo.form.Action.LOAD_FAILURE = 'load';
7325 Roo.form.Action.prototype = {
7327 failureType : undefined,
7328 response : undefined,
7332 run : function(options){
7337 success : function(response){
7342 handleResponse : function(response){
7346 // default connection failure
7347 failure : function(response){
7349 this.response = response;
7350 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7351 this.form.afterAction(this, false);
7354 processResponse : function(response){
7355 this.response = response;
7356 if(!response.responseText){
7359 this.result = this.handleResponse(response);
7363 // utility functions used internally
7364 getUrl : function(appendParams){
7365 var url = this.options.url || this.form.url || this.form.el.dom.action;
7367 var p = this.getParams();
7369 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7375 getMethod : function(){
7376 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7379 getParams : function(){
7380 var bp = this.form.baseParams;
7381 var p = this.options.params;
7383 if(typeof p == "object"){
7384 p = Roo.urlEncode(Roo.applyIf(p, bp));
7385 }else if(typeof p == 'string' && bp){
7386 p += '&' + Roo.urlEncode(bp);
7389 p = Roo.urlEncode(bp);
7394 createCallback : function(){
7396 success: this.success,
7397 failure: this.failure,
7399 timeout: (this.form.timeout*1000),
7400 upload: this.form.fileUpload ? this.success : undefined
7405 Roo.form.Action.Submit = function(form, options){
7406 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7409 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7412 haveProgress : false,
7413 uploadComplete : false,
7415 // uploadProgress indicator.
7416 uploadProgress : function()
7418 if (!this.form.progressUrl) {
7422 if (!this.haveProgress) {
7423 Roo.MessageBox.progress("Uploading", "Uploading");
7425 if (this.uploadComplete) {
7426 Roo.MessageBox.hide();
7430 this.haveProgress = true;
7432 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7434 var c = new Roo.data.Connection();
7436 url : this.form.progressUrl,
7441 success : function(req){
7442 //console.log(data);
7446 rdata = Roo.decode(req.responseText)
7448 Roo.log("Invalid data from server..");
7452 if (!rdata || !rdata.success) {
7454 Roo.MessageBox.alert(Roo.encode(rdata));
7457 var data = rdata.data;
7459 if (this.uploadComplete) {
7460 Roo.MessageBox.hide();
7465 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7466 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7469 this.uploadProgress.defer(2000,this);
7472 failure: function(data) {
7473 Roo.log('progress url failed ');
7484 // run get Values on the form, so it syncs any secondary forms.
7485 this.form.getValues();
7487 var o = this.options;
7488 var method = this.getMethod();
7489 var isPost = method == 'POST';
7490 if(o.clientValidation === false || this.form.isValid()){
7492 if (this.form.progressUrl) {
7493 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7494 (new Date() * 1) + '' + Math.random());
7499 Roo.Ajax.request(Roo.apply(this.createCallback(), {
7500 form:this.form.el.dom,
7501 url:this.getUrl(!isPost),
7503 params:isPost ? this.getParams() : null,
7504 isUpload: this.form.fileUpload
7507 this.uploadProgress();
7509 }else if (o.clientValidation !== false){ // client validation failed
7510 this.failureType = Roo.form.Action.CLIENT_INVALID;
7511 this.form.afterAction(this, false);
7515 success : function(response)
7517 this.uploadComplete= true;
7518 if (this.haveProgress) {
7519 Roo.MessageBox.hide();
7523 var result = this.processResponse(response);
7524 if(result === true || result.success){
7525 this.form.afterAction(this, true);
7529 this.form.markInvalid(result.errors);
7530 this.failureType = Roo.form.Action.SERVER_INVALID;
7532 this.form.afterAction(this, false);
7534 failure : function(response)
7536 this.uploadComplete= true;
7537 if (this.haveProgress) {
7538 Roo.MessageBox.hide();
7541 this.response = response;
7542 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7543 this.form.afterAction(this, false);
7546 handleResponse : function(response){
7547 if(this.form.errorReader){
7548 var rs = this.form.errorReader.read(response);
7551 for(var i = 0, len = rs.records.length; i < len; i++) {
7552 var r = rs.records[i];
7556 if(errors.length < 1){
7560 success : rs.success,
7566 ret = Roo.decode(response.responseText);
7570 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7580 Roo.form.Action.Load = function(form, options){
7581 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7582 this.reader = this.form.reader;
7585 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7590 Roo.Ajax.request(Roo.apply(
7591 this.createCallback(), {
7592 method:this.getMethod(),
7593 url:this.getUrl(false),
7594 params:this.getParams()
7598 success : function(response){
7600 var result = this.processResponse(response);
7601 if(result === true || !result.success || !result.data){
7602 this.failureType = Roo.form.Action.LOAD_FAILURE;
7603 this.form.afterAction(this, false);
7606 this.form.clearInvalid();
7607 this.form.setValues(result.data);
7608 this.form.afterAction(this, true);
7611 handleResponse : function(response){
7612 if(this.form.reader){
7613 var rs = this.form.reader.read(response);
7614 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7616 success : rs.success,
7620 return Roo.decode(response.responseText);
7624 Roo.form.Action.ACTION_TYPES = {
7625 'load' : Roo.form.Action.Load,
7626 'submit' : Roo.form.Action.Submit
7635 * @class Roo.bootstrap.Form
7636 * @extends Roo.bootstrap.Component
7637 * Bootstrap Form class
7638 * @cfg {String} method GET | POST (default POST)
7639 * @cfg {String} labelAlign top | left (default top)
7640 * @cfg {String} align left | right - for navbars
7641 * @cfg {Boolean} loadMask load mask when submit (default true)
7646 * @param {Object} config The config object
7650 Roo.bootstrap.Form = function(config){
7652 Roo.bootstrap.Form.superclass.constructor.call(this, config);
7654 Roo.bootstrap.Form.popover.apply();
7658 * @event clientvalidation
7659 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
7660 * @param {Form} this
7661 * @param {Boolean} valid true if the form has passed client-side validation
7663 clientvalidation: true,
7665 * @event beforeaction
7666 * Fires before any action is performed. Return false to cancel the action.
7667 * @param {Form} this
7668 * @param {Action} action The action to be performed
7672 * @event actionfailed
7673 * Fires when an action fails.
7674 * @param {Form} this
7675 * @param {Action} action The action that failed
7677 actionfailed : true,
7679 * @event actioncomplete
7680 * Fires when an action is completed.
7681 * @param {Form} this
7682 * @param {Action} action The action that completed
7684 actioncomplete : true
7688 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component, {
7691 * @cfg {String} method
7692 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
7697 * The URL to use for form actions if one isn't supplied in the action options.
7700 * @cfg {Boolean} fileUpload
7701 * Set to true if this form is a file upload.
7705 * @cfg {Object} baseParams
7706 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
7710 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
7714 * @cfg {Sting} align (left|right) for navbar forms
7719 activeAction : null,
7722 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
7723 * element by passing it or its id or mask the form itself by passing in true.
7726 waitMsgTarget : false,
7731 * @cfg {Boolean} errorMask (true|false) default false
7736 * @cfg {Number} maskOffset Default 100
7741 * @cfg {Boolean} maskBody
7745 getAutoCreate : function(){
7749 method : this.method || 'POST',
7750 id : this.id || Roo.id(),
7753 if (this.parent().xtype.match(/^Nav/)) {
7754 cfg.cls = 'navbar-form navbar-' + this.align;
7758 if (this.labelAlign == 'left' ) {
7759 cfg.cls += ' form-horizontal';
7765 initEvents : function()
7767 this.el.on('submit', this.onSubmit, this);
7768 // this was added as random key presses on the form where triggering form submit.
7769 this.el.on('keypress', function(e) {
7770 if (e.getCharCode() != 13) {
7773 // we might need to allow it for textareas.. and some other items.
7774 // check e.getTarget().
7776 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
7780 Roo.log("keypress blocked");
7788 onSubmit : function(e){
7793 * Returns true if client-side validation on the form is successful.
7796 isValid : function(){
7797 var items = this.getItems();
7801 items.each(function(f){
7808 if(!target && f.el.isVisible(true)){
7814 if(this.errorMask && !valid){
7815 Roo.bootstrap.Form.popover.mask(this, target);
7822 * Returns true if any fields in this form have changed since their original load.
7825 isDirty : function(){
7827 var items = this.getItems();
7828 items.each(function(f){
7838 * Performs a predefined action (submit or load) or custom actions you define on this form.
7839 * @param {String} actionName The name of the action type
7840 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
7841 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
7842 * accept other config options):
7844 Property Type Description
7845 ---------------- --------------- ----------------------------------------------------------------------------------
7846 url String The url for the action (defaults to the form's url)
7847 method String The form method to use (defaults to the form's method, or POST if not defined)
7848 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
7849 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
7850 validate the form on the client (defaults to false)
7852 * @return {BasicForm} this
7854 doAction : function(action, options){
7855 if(typeof action == 'string'){
7856 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
7858 if(this.fireEvent('beforeaction', this, action) !== false){
7859 this.beforeAction(action);
7860 action.run.defer(100, action);
7866 beforeAction : function(action){
7867 var o = action.options;
7872 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
7874 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7877 // not really supported yet.. ??
7879 //if(this.waitMsgTarget === true){
7880 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7881 //}else if(this.waitMsgTarget){
7882 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
7883 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
7885 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
7891 afterAction : function(action, success){
7892 this.activeAction = null;
7893 var o = action.options;
7898 Roo.get(document.body).unmask();
7904 //if(this.waitMsgTarget === true){
7905 // this.el.unmask();
7906 //}else if(this.waitMsgTarget){
7907 // this.waitMsgTarget.unmask();
7909 // Roo.MessageBox.updateProgress(1);
7910 // Roo.MessageBox.hide();
7917 Roo.callback(o.success, o.scope, [this, action]);
7918 this.fireEvent('actioncomplete', this, action);
7922 // failure condition..
7923 // we have a scenario where updates need confirming.
7924 // eg. if a locking scenario exists..
7925 // we look for { errors : { needs_confirm : true }} in the response.
7927 (typeof(action.result) != 'undefined') &&
7928 (typeof(action.result.errors) != 'undefined') &&
7929 (typeof(action.result.errors.needs_confirm) != 'undefined')
7932 Roo.log("not supported yet");
7935 Roo.MessageBox.confirm(
7936 "Change requires confirmation",
7937 action.result.errorMsg,
7942 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
7952 Roo.callback(o.failure, o.scope, [this, action]);
7953 // show an error message if no failed handler is set..
7954 if (!this.hasListener('actionfailed')) {
7955 Roo.log("need to add dialog support");
7957 Roo.MessageBox.alert("Error",
7958 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
7959 action.result.errorMsg :
7960 "Saving Failed, please check your entries or try again"
7965 this.fireEvent('actionfailed', this, action);
7970 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
7971 * @param {String} id The value to search for
7974 findField : function(id){
7975 var items = this.getItems();
7976 var field = items.get(id);
7978 items.each(function(f){
7979 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
7986 return field || null;
7989 * Mark fields in this form invalid in bulk.
7990 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
7991 * @return {BasicForm} this
7993 markInvalid : function(errors){
7994 if(errors instanceof Array){
7995 for(var i = 0, len = errors.length; i < len; i++){
7996 var fieldError = errors[i];
7997 var f = this.findField(fieldError.id);
7999 f.markInvalid(fieldError.msg);
8005 if(typeof errors[id] != 'function' && (field = this.findField(id))){
8006 field.markInvalid(errors[id]);
8010 //Roo.each(this.childForms || [], function (f) {
8011 // f.markInvalid(errors);
8018 * Set values for fields in this form in bulk.
8019 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
8020 * @return {BasicForm} this
8022 setValues : function(values){
8023 if(values instanceof Array){ // array of objects
8024 for(var i = 0, len = values.length; i < len; i++){
8026 var f = this.findField(v.id);
8028 f.setValue(v.value);
8029 if(this.trackResetOnLoad){
8030 f.originalValue = f.getValue();
8034 }else{ // object hash
8037 if(typeof values[id] != 'function' && (field = this.findField(id))){
8039 if (field.setFromData &&
8041 field.displayField &&
8042 // combos' with local stores can
8043 // be queried via setValue()
8044 // to set their value..
8045 (field.store && !field.store.isLocal)
8049 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
8050 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
8051 field.setFromData(sd);
8053 } else if(field.setFromData && (field.store && !field.store.isLocal)) {
8055 field.setFromData(values);
8058 field.setValue(values[id]);
8062 if(this.trackResetOnLoad){
8063 field.originalValue = field.getValue();
8069 //Roo.each(this.childForms || [], function (f) {
8070 // f.setValues(values);
8077 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
8078 * they are returned as an array.
8079 * @param {Boolean} asString
8082 getValues : function(asString){
8083 //if (this.childForms) {
8084 // copy values from the child forms
8085 // Roo.each(this.childForms, function (f) {
8086 // this.setValues(f.getValues());
8092 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
8093 if(asString === true){
8096 return Roo.urlDecode(fs);
8100 * Returns the fields in this form as an object with key/value pairs.
8101 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
8104 getFieldValues : function(with_hidden)
8106 var items = this.getItems();
8108 items.each(function(f){
8114 var v = f.getValue();
8116 if (f.inputType =='radio') {
8117 if (typeof(ret[f.getName()]) == 'undefined') {
8118 ret[f.getName()] = ''; // empty..
8121 if (!f.el.dom.checked) {
8129 if(f.xtype == 'MoneyField'){
8130 ret[f.currencyName] = f.getCurrency();
8133 // not sure if this supported any more..
8134 if ((typeof(v) == 'object') && f.getRawValue) {
8135 v = f.getRawValue() ; // dates..
8137 // combo boxes where name != hiddenName...
8138 if (f.name !== false && f.name != '' && f.name != f.getName()) {
8139 ret[f.name] = f.getRawValue();
8141 ret[f.getName()] = v;
8148 * Clears all invalid messages in this form.
8149 * @return {BasicForm} this
8151 clearInvalid : function(){
8152 var items = this.getItems();
8154 items.each(function(f){
8163 * @return {BasicForm} this
8166 var items = this.getItems();
8167 items.each(function(f){
8171 Roo.each(this.childForms || [], function (f) {
8179 getItems : function()
8181 var r=new Roo.util.MixedCollection(false, function(o){
8182 return o.id || (o.id = Roo.id());
8184 var iter = function(el) {
8191 Roo.each(el.items,function(e) {
8200 hideFields : function(items)
8202 Roo.each(items, function(i){
8204 var f = this.findField(i);
8210 if(f.xtype == 'DateField'){
8211 f.setVisible(false);
8220 showFields : function(items)
8222 Roo.each(items, function(i){
8224 var f = this.findField(i);
8230 if(f.xtype == 'DateField'){
8242 Roo.apply(Roo.bootstrap.Form, {
8269 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
8270 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
8271 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
8272 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
8275 this.maskEl.top.enableDisplayMode("block");
8276 this.maskEl.left.enableDisplayMode("block");
8277 this.maskEl.bottom.enableDisplayMode("block");
8278 this.maskEl.right.enableDisplayMode("block");
8280 this.toolTip = new Roo.bootstrap.Tooltip({
8281 cls : 'roo-form-error-popover',
8283 'left' : ['r-l', [-2,0], 'right'],
8284 'right' : ['l-r', [2,0], 'left'],
8285 'bottom' : ['tl-bl', [0,2], 'top'],
8286 'top' : [ 'bl-tl', [0,-2], 'bottom']
8290 this.toolTip.render(Roo.get(document.body));
8292 this.toolTip.el.enableDisplayMode("block");
8294 Roo.get(document.body).on('click', function(){
8298 Roo.get(document.body).on('touchstart', function(){
8302 this.isApplied = true
8305 mask : function(form, target)
8309 this.target = target;
8311 if(!this.form.errorMask || !target.el){
8315 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
8317 Roo.log(scrollable);
8319 var ot = this.target.el.calcOffsetsTo(scrollable);
8321 var scrollTo = ot[1] - this.form.maskOffset;
8323 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
8325 scrollable.scrollTo('top', scrollTo);
8327 var box = this.target.el.getBox();
8329 var zIndex = Roo.bootstrap.Modal.zIndex++;
8332 this.maskEl.top.setStyle('position', 'absolute');
8333 this.maskEl.top.setStyle('z-index', zIndex);
8334 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
8335 this.maskEl.top.setLeft(0);
8336 this.maskEl.top.setTop(0);
8337 this.maskEl.top.show();
8339 this.maskEl.left.setStyle('position', 'absolute');
8340 this.maskEl.left.setStyle('z-index', zIndex);
8341 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
8342 this.maskEl.left.setLeft(0);
8343 this.maskEl.left.setTop(box.y - this.padding);
8344 this.maskEl.left.show();
8346 this.maskEl.bottom.setStyle('position', 'absolute');
8347 this.maskEl.bottom.setStyle('z-index', zIndex);
8348 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
8349 this.maskEl.bottom.setLeft(0);
8350 this.maskEl.bottom.setTop(box.bottom + this.padding);
8351 this.maskEl.bottom.show();
8353 this.maskEl.right.setStyle('position', 'absolute');
8354 this.maskEl.right.setStyle('z-index', zIndex);
8355 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
8356 this.maskEl.right.setLeft(box.right + this.padding);
8357 this.maskEl.right.setTop(box.y - this.padding);
8358 this.maskEl.right.show();
8360 this.toolTip.bindEl = this.target.el;
8362 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
8364 var tip = this.target.blankText;
8366 if(this.target.getValue() !== '' ) {
8368 if (this.target.invalidText.length) {
8369 tip = this.target.invalidText;
8370 } else if (this.target.regexText.length){
8371 tip = this.target.regexText;
8375 this.toolTip.show(tip);
8377 this.intervalID = window.setInterval(function() {
8378 Roo.bootstrap.Form.popover.unmask();
8381 window.onwheel = function(){ return false;};
8383 (function(){ this.isMasked = true; }).defer(500, this);
8389 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
8393 this.maskEl.top.setStyle('position', 'absolute');
8394 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
8395 this.maskEl.top.hide();
8397 this.maskEl.left.setStyle('position', 'absolute');
8398 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
8399 this.maskEl.left.hide();
8401 this.maskEl.bottom.setStyle('position', 'absolute');
8402 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
8403 this.maskEl.bottom.hide();
8405 this.maskEl.right.setStyle('position', 'absolute');
8406 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
8407 this.maskEl.right.hide();
8409 this.toolTip.hide();
8411 this.toolTip.el.hide();
8413 window.onwheel = function(){ return true;};
8415 if(this.intervalID){
8416 window.clearInterval(this.intervalID);
8417 this.intervalID = false;
8420 this.isMasked = false;
8430 * Ext JS Library 1.1.1
8431 * Copyright(c) 2006-2007, Ext JS, LLC.
8433 * Originally Released Under LGPL - original licence link has changed is not relivant.
8436 * <script type="text/javascript">
8439 * @class Roo.form.VTypes
8440 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
8443 Roo.form.VTypes = function(){
8444 // closure these in so they are only created once.
8445 var alpha = /^[a-zA-Z_]+$/;
8446 var alphanum = /^[a-zA-Z0-9_]+$/;
8447 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
8448 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
8450 // All these messages and functions are configurable
8453 * The function used to validate email addresses
8454 * @param {String} value The email address
8456 'email' : function(v){
8457 return email.test(v);
8460 * The error text to display when the email validation function returns false
8463 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
8465 * The keystroke filter mask to be applied on email input
8468 'emailMask' : /[a-z0-9_\.\-@]/i,
8471 * The function used to validate URLs
8472 * @param {String} value The URL
8474 'url' : function(v){
8478 * The error text to display when the url validation function returns false
8481 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
8484 * The function used to validate alpha values
8485 * @param {String} value The value
8487 'alpha' : function(v){
8488 return alpha.test(v);
8491 * The error text to display when the alpha validation function returns false
8494 'alphaText' : 'This field should only contain letters and _',
8496 * The keystroke filter mask to be applied on alpha input
8499 'alphaMask' : /[a-z_]/i,
8502 * The function used to validate alphanumeric values
8503 * @param {String} value The value
8505 'alphanum' : function(v){
8506 return alphanum.test(v);
8509 * The error text to display when the alphanumeric validation function returns false
8512 'alphanumText' : 'This field should only contain letters, numbers and _',
8514 * The keystroke filter mask to be applied on alphanumeric input
8517 'alphanumMask' : /[a-z0-9_]/i
8527 * @class Roo.bootstrap.Input
8528 * @extends Roo.bootstrap.Component
8529 * Bootstrap Input class
8530 * @cfg {Boolean} disabled is it disabled
8531 * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
8532 * @cfg {String} name name of the input
8533 * @cfg {string} fieldLabel - the label associated
8534 * @cfg {string} placeholder - placeholder to put in text.
8535 * @cfg {string} before - input group add on before
8536 * @cfg {string} after - input group add on after
8537 * @cfg {string} size - (lg|sm) or leave empty..
8538 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
8539 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
8540 * @cfg {Number} md colspan out of 12 for computer-sized screens
8541 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
8542 * @cfg {string} value default value of the input
8543 * @cfg {Number} labelWidth set the width of label
8544 * @cfg {Number} labellg set the width of label (1-12)
8545 * @cfg {Number} labelmd set the width of label (1-12)
8546 * @cfg {Number} labelsm set the width of label (1-12)
8547 * @cfg {Number} labelxs set the width of label (1-12)
8548 * @cfg {String} labelAlign (top|left)
8549 * @cfg {Boolean} readOnly Specifies that the field should be read-only
8550 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8551 * @cfg {String} indicatorpos (left|right) default left
8553 * @cfg {String} align (left|center|right) Default left
8554 * @cfg {Boolean} forceFeedback (true|false) Default false
8557 * Create a new Input
8558 * @param {Object} config The config object
8561 Roo.bootstrap.Input = function(config){
8563 Roo.bootstrap.Input.superclass.constructor.call(this, config);
8568 * Fires when this field receives input focus.
8569 * @param {Roo.form.Field} this
8574 * Fires when this field loses input focus.
8575 * @param {Roo.form.Field} this
8580 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8581 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8582 * @param {Roo.form.Field} this
8583 * @param {Roo.EventObject} e The event object
8588 * Fires just before the field blurs if the field value has changed.
8589 * @param {Roo.form.Field} this
8590 * @param {Mixed} newValue The new value
8591 * @param {Mixed} oldValue The original value
8596 * Fires after the field has been marked as invalid.
8597 * @param {Roo.form.Field} this
8598 * @param {String} msg The validation message
8603 * Fires after the field has been validated with no errors.
8604 * @param {Roo.form.Field} this
8609 * Fires after the key up
8610 * @param {Roo.form.Field} this
8611 * @param {Roo.EventObject} e The event Object
8617 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component, {
8619 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8620 automatic validation (defaults to "keyup").
8622 validationEvent : "keyup",
8624 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8626 validateOnBlur : true,
8628 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
8630 validationDelay : 250,
8632 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
8634 focusClass : "x-form-focus", // not needed???
8638 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
8640 invalidClass : "has-warning",
8643 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
8645 validClass : "has-success",
8648 * @cfg {Boolean} hasFeedback (true|false) default true
8653 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8655 invalidFeedbackClass : "glyphicon-warning-sign",
8658 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8660 validFeedbackClass : "glyphicon-ok",
8663 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
8665 selectOnFocus : false,
8668 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
8672 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
8677 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
8679 disableKeyFilter : false,
8682 * @cfg {Boolean} disabled True to disable the field (defaults to false).
8686 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
8690 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
8692 blankText : "Please complete this mandatory field",
8695 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
8699 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
8701 maxLength : Number.MAX_VALUE,
8703 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
8705 minLengthText : "The minimum length for this field is {0}",
8707 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
8709 maxLengthText : "The maximum length for this field is {0}",
8713 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
8714 * If available, this function will be called only after the basic validators all return true, and will be passed the
8715 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
8719 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
8720 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
8721 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
8725 * @cfg {String} regexText -- Depricated - use Invalid Text
8730 * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
8736 autocomplete: false,
8755 formatedValue : false,
8756 forceFeedback : false,
8758 indicatorpos : 'left',
8765 parentLabelAlign : function()
8768 while (parent.parent()) {
8769 parent = parent.parent();
8770 if (typeof(parent.labelAlign) !='undefined') {
8771 return parent.labelAlign;
8778 getAutoCreate : function()
8780 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8786 if(this.inputType != 'hidden'){
8787 cfg.cls = 'form-group' //input-group
8793 type : this.inputType,
8795 cls : 'form-control',
8796 placeholder : this.placeholder || '',
8797 autocomplete : this.autocomplete || 'new-password'
8801 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
8804 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
8805 input.maxLength = this.maxLength;
8808 if (this.disabled) {
8809 input.disabled=true;
8812 if (this.readOnly) {
8813 input.readonly=true;
8817 input.name = this.name;
8821 input.cls += ' input-' + this.size;
8825 ['xs','sm','md','lg'].map(function(size){
8826 if (settings[size]) {
8827 cfg.cls += ' col-' + size + '-' + settings[size];
8831 var inputblock = input;
8835 cls: 'glyphicon form-control-feedback'
8838 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8841 cls : 'has-feedback',
8849 if (this.before || this.after) {
8852 cls : 'input-group',
8856 if (this.before && typeof(this.before) == 'string') {
8858 inputblock.cn.push({
8860 cls : 'roo-input-before input-group-addon',
8864 if (this.before && typeof(this.before) == 'object') {
8865 this.before = Roo.factory(this.before);
8867 inputblock.cn.push({
8869 cls : 'roo-input-before input-group-' +
8870 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8874 inputblock.cn.push(input);
8876 if (this.after && typeof(this.after) == 'string') {
8877 inputblock.cn.push({
8879 cls : 'roo-input-after input-group-addon',
8883 if (this.after && typeof(this.after) == 'object') {
8884 this.after = Roo.factory(this.after);
8886 inputblock.cn.push({
8888 cls : 'roo-input-after input-group-' +
8889 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8893 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8894 inputblock.cls += ' has-feedback';
8895 inputblock.cn.push(feedback);
8899 if (align ==='left' && this.fieldLabel.length) {
8901 cfg.cls += ' roo-form-group-label-left';
8906 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
8907 tooltip : 'This field is required'
8912 cls : 'control-label',
8913 html : this.fieldLabel
8924 var labelCfg = cfg.cn[1];
8925 var contentCfg = cfg.cn[2];
8927 if(this.indicatorpos == 'right'){
8932 cls : 'control-label',
8936 html : this.fieldLabel
8940 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
8941 tooltip : 'This field is required'
8954 labelCfg = cfg.cn[0];
8955 contentCfg = cfg.cn[1];
8959 if(this.labelWidth > 12){
8960 labelCfg.style = "width: " + this.labelWidth + 'px';
8963 if(this.labelWidth < 13 && this.labelmd == 0){
8964 this.labelmd = this.labelWidth;
8967 if(this.labellg > 0){
8968 labelCfg.cls += ' col-lg-' + this.labellg;
8969 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
8972 if(this.labelmd > 0){
8973 labelCfg.cls += ' col-md-' + this.labelmd;
8974 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
8977 if(this.labelsm > 0){
8978 labelCfg.cls += ' col-sm-' + this.labelsm;
8979 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
8982 if(this.labelxs > 0){
8983 labelCfg.cls += ' col-xs-' + this.labelxs;
8984 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
8988 } else if ( this.fieldLabel.length) {
8993 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
8994 tooltip : 'This field is required'
8998 //cls : 'input-group-addon',
8999 html : this.fieldLabel
9007 if(this.indicatorpos == 'right'){
9012 //cls : 'input-group-addon',
9013 html : this.fieldLabel
9018 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9019 tooltip : 'This field is required'
9039 if (this.parentType === 'Navbar' && this.parent().bar) {
9040 cfg.cls += ' navbar-form';
9043 if (this.parentType === 'NavGroup') {
9044 cfg.cls += ' navbar-form';
9052 * return the real input element.
9054 inputEl: function ()
9056 return this.el.select('input.form-control',true).first();
9059 tooltipEl : function()
9061 return this.inputEl();
9064 indicatorEl : function()
9066 var indicator = this.el.select('i.roo-required-indicator',true).first();
9076 setDisabled : function(v)
9078 var i = this.inputEl().dom;
9080 i.removeAttribute('disabled');
9084 i.setAttribute('disabled','true');
9086 initEvents : function()
9089 this.inputEl().on("keydown" , this.fireKey, this);
9090 this.inputEl().on("focus", this.onFocus, this);
9091 this.inputEl().on("blur", this.onBlur, this);
9093 this.inputEl().relayEvent('keyup', this);
9095 this.indicator = this.indicatorEl();
9098 this.indicator.addClass('invisible');
9101 // reference to original value for reset
9102 this.originalValue = this.getValue();
9103 //Roo.form.TextField.superclass.initEvents.call(this);
9104 if(this.validationEvent == 'keyup'){
9105 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
9106 this.inputEl().on('keyup', this.filterValidation, this);
9108 else if(this.validationEvent !== false){
9109 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
9112 if(this.selectOnFocus){
9113 this.on("focus", this.preFocus, this);
9116 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
9117 this.inputEl().on("keypress", this.filterKeys, this);
9119 this.inputEl().relayEvent('keypress', this);
9122 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
9123 this.el.on("click", this.autoSize, this);
9126 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
9127 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
9130 if (typeof(this.before) == 'object') {
9131 this.before.render(this.el.select('.roo-input-before',true).first());
9133 if (typeof(this.after) == 'object') {
9134 this.after.render(this.el.select('.roo-input-after',true).first());
9139 filterValidation : function(e){
9140 if(!e.isNavKeyPress()){
9141 this.validationTask.delay(this.validationDelay);
9145 * Validates the field value
9146 * @return {Boolean} True if the value is valid, else false
9148 validate : function(){
9149 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
9150 if(this.disabled || this.validateValue(this.getRawValue())){
9161 * Validates a value according to the field's validation rules and marks the field as invalid
9162 * if the validation fails
9163 * @param {Mixed} value The value to validate
9164 * @return {Boolean} True if the value is valid, else false
9166 validateValue : function(value)
9168 if(this.getVisibilityEl().hasClass('hidden')){
9172 if(value.length < 1) { // if it's blank
9173 if(this.allowBlank){
9179 if(value.length < this.minLength){
9182 if(value.length > this.maxLength){
9186 var vt = Roo.form.VTypes;
9187 if(!vt[this.vtype](value, this)){
9191 if(typeof this.validator == "function"){
9192 var msg = this.validator(value);
9196 if (typeof(msg) == 'string') {
9197 this.invalidText = msg;
9201 if(this.regex && !this.regex.test(value)){
9209 fireKey : function(e){
9210 //Roo.log('field ' + e.getKey());
9211 if(e.isNavKeyPress()){
9212 this.fireEvent("specialkey", this, e);
9215 focus : function (selectText){
9217 this.inputEl().focus();
9218 if(selectText === true){
9219 this.inputEl().dom.select();
9225 onFocus : function(){
9226 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9227 // this.el.addClass(this.focusClass);
9230 this.hasFocus = true;
9231 this.startValue = this.getValue();
9232 this.fireEvent("focus", this);
9236 beforeBlur : Roo.emptyFn,
9240 onBlur : function(){
9242 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9243 //this.el.removeClass(this.focusClass);
9245 this.hasFocus = false;
9246 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
9249 var v = this.getValue();
9250 if(String(v) !== String(this.startValue)){
9251 this.fireEvent('change', this, v, this.startValue);
9253 this.fireEvent("blur", this);
9257 * Resets the current field value to the originally loaded value and clears any validation messages
9260 this.setValue(this.originalValue);
9264 * Returns the name of the field
9265 * @return {Mixed} name The name field
9267 getName: function(){
9271 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
9272 * @return {Mixed} value The field value
9274 getValue : function(){
9276 var v = this.inputEl().getValue();
9281 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
9282 * @return {Mixed} value The field value
9284 getRawValue : function(){
9285 var v = this.inputEl().getValue();
9291 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
9292 * @param {Mixed} value The value to set
9294 setRawValue : function(v){
9295 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9298 selectText : function(start, end){
9299 var v = this.getRawValue();
9301 start = start === undefined ? 0 : start;
9302 end = end === undefined ? v.length : end;
9303 var d = this.inputEl().dom;
9304 if(d.setSelectionRange){
9305 d.setSelectionRange(start, end);
9306 }else if(d.createTextRange){
9307 var range = d.createTextRange();
9308 range.moveStart("character", start);
9309 range.moveEnd("character", v.length-end);
9316 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
9317 * @param {Mixed} value The value to set
9319 setValue : function(v){
9322 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9328 processValue : function(value){
9329 if(this.stripCharsRe){
9330 var newValue = value.replace(this.stripCharsRe, '');
9331 if(newValue !== value){
9332 this.setRawValue(newValue);
9339 preFocus : function(){
9341 if(this.selectOnFocus){
9342 this.inputEl().dom.select();
9345 filterKeys : function(e){
9347 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
9350 var c = e.getCharCode(), cc = String.fromCharCode(c);
9351 if(Roo.isIE && (e.isSpecialKey() || !cc)){
9354 if(!this.maskRe.test(cc)){
9359 * Clear any invalid styles/messages for this field
9361 clearInvalid : function(){
9363 if(!this.el || this.preventMark){ // not rendered
9368 this.el.removeClass(this.invalidClass);
9370 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9372 var feedback = this.el.select('.form-control-feedback', true).first();
9375 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9380 this.fireEvent('valid', this);
9384 * Mark this field as valid
9386 markValid : function()
9388 if(!this.el || this.preventMark){ // not rendered...
9392 this.el.removeClass([this.invalidClass, this.validClass]);
9394 var feedback = this.el.select('.form-control-feedback', true).first();
9397 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9401 this.indicator.removeClass('visible');
9402 this.indicator.addClass('invisible');
9409 if(this.allowBlank && !this.getRawValue().length){
9413 this.el.addClass(this.validClass);
9415 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9417 var feedback = this.el.select('.form-control-feedback', true).first();
9420 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9421 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9426 this.fireEvent('valid', this);
9430 * Mark this field as invalid
9431 * @param {String} msg The validation message
9433 markInvalid : function(msg)
9435 if(!this.el || this.preventMark){ // not rendered
9439 this.el.removeClass([this.invalidClass, this.validClass]);
9441 var feedback = this.el.select('.form-control-feedback', true).first();
9444 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9451 if(this.allowBlank && !this.getRawValue().length){
9456 this.indicator.removeClass('invisible');
9457 this.indicator.addClass('visible');
9460 this.el.addClass(this.invalidClass);
9462 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9464 var feedback = this.el.select('.form-control-feedback', true).first();
9467 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9469 if(this.getValue().length || this.forceFeedback){
9470 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9477 this.fireEvent('invalid', this, msg);
9480 SafariOnKeyDown : function(event)
9482 // this is a workaround for a password hang bug on chrome/ webkit.
9483 if (this.inputEl().dom.type != 'password') {
9487 var isSelectAll = false;
9489 if(this.inputEl().dom.selectionEnd > 0){
9490 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
9492 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
9493 event.preventDefault();
9498 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
9500 event.preventDefault();
9501 // this is very hacky as keydown always get's upper case.
9503 var cc = String.fromCharCode(event.getCharCode());
9504 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
9508 adjustWidth : function(tag, w){
9509 tag = tag.toLowerCase();
9510 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
9511 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
9515 if(tag == 'textarea'){
9518 }else if(Roo.isOpera){
9522 if(tag == 'textarea'){
9530 setFieldLabel : function(v)
9537 var ar = this.el.select('label > span',true);
9539 if (ar.elements.length) {
9540 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9541 this.fieldLabel = v;
9545 var br = this.el.select('label',true);
9547 if(br.elements.length) {
9548 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9549 this.fieldLabel = v;
9553 Roo.log('Cannot Found any of label > span || label in input');
9557 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9558 this.fieldLabel = v;
9573 * @class Roo.bootstrap.TextArea
9574 * @extends Roo.bootstrap.Input
9575 * Bootstrap TextArea class
9576 * @cfg {Number} cols Specifies the visible width of a text area
9577 * @cfg {Number} rows Specifies the visible number of lines in a text area
9578 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
9579 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
9580 * @cfg {string} html text
9583 * Create a new TextArea
9584 * @param {Object} config The config object
9587 Roo.bootstrap.TextArea = function(config){
9588 Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
9592 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input, {
9602 getAutoCreate : function(){
9604 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
9610 if(this.inputType != 'hidden'){
9611 cfg.cls = 'form-group' //input-group
9619 value : this.value || '',
9620 html: this.html || '',
9621 cls : 'form-control',
9622 placeholder : this.placeholder || ''
9626 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9627 input.maxLength = this.maxLength;
9631 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
9635 input.cols = this.cols;
9638 if (this.readOnly) {
9639 input.readonly = true;
9643 input.name = this.name;
9647 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
9651 ['xs','sm','md','lg'].map(function(size){
9652 if (settings[size]) {
9653 cfg.cls += ' col-' + size + '-' + settings[size];
9657 var inputblock = input;
9659 if(this.hasFeedback && !this.allowBlank){
9663 cls: 'glyphicon form-control-feedback'
9667 cls : 'has-feedback',
9676 if (this.before || this.after) {
9679 cls : 'input-group',
9683 inputblock.cn.push({
9685 cls : 'input-group-addon',
9690 inputblock.cn.push(input);
9692 if(this.hasFeedback && !this.allowBlank){
9693 inputblock.cls += ' has-feedback';
9694 inputblock.cn.push(feedback);
9698 inputblock.cn.push({
9700 cls : 'input-group-addon',
9707 if (align ==='left' && this.fieldLabel.length) {
9712 cls : 'control-label',
9713 html : this.fieldLabel
9724 if(this.labelWidth > 12){
9725 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
9728 if(this.labelWidth < 13 && this.labelmd == 0){
9729 this.labelmd = this.labelWidth;
9732 if(this.labellg > 0){
9733 cfg.cn[0].cls += ' col-lg-' + this.labellg;
9734 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
9737 if(this.labelmd > 0){
9738 cfg.cn[0].cls += ' col-md-' + this.labelmd;
9739 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
9742 if(this.labelsm > 0){
9743 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
9744 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
9747 if(this.labelxs > 0){
9748 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
9749 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
9752 } else if ( this.fieldLabel.length) {
9757 //cls : 'input-group-addon',
9758 html : this.fieldLabel
9776 if (this.disabled) {
9777 input.disabled=true;
9784 * return the real textarea element.
9786 inputEl: function ()
9788 return this.el.select('textarea.form-control',true).first();
9792 * Clear any invalid styles/messages for this field
9794 clearInvalid : function()
9797 if(!this.el || this.preventMark){ // not rendered
9801 var label = this.el.select('label', true).first();
9802 var icon = this.el.select('i.fa-star', true).first();
9808 this.el.removeClass(this.invalidClass);
9810 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9812 var feedback = this.el.select('.form-control-feedback', true).first();
9815 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9820 this.fireEvent('valid', this);
9824 * Mark this field as valid
9826 markValid : function()
9828 if(!this.el || this.preventMark){ // not rendered
9832 this.el.removeClass([this.invalidClass, this.validClass]);
9834 var feedback = this.el.select('.form-control-feedback', true).first();
9837 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9840 if(this.disabled || this.allowBlank){
9844 var label = this.el.select('label', true).first();
9845 var icon = this.el.select('i.fa-star', true).first();
9851 this.el.addClass(this.validClass);
9853 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9855 var feedback = this.el.select('.form-control-feedback', true).first();
9858 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9859 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9864 this.fireEvent('valid', this);
9868 * Mark this field as invalid
9869 * @param {String} msg The validation message
9871 markInvalid : function(msg)
9873 if(!this.el || this.preventMark){ // not rendered
9877 this.el.removeClass([this.invalidClass, this.validClass]);
9879 var feedback = this.el.select('.form-control-feedback', true).first();
9882 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9885 if(this.disabled || this.allowBlank){
9889 var label = this.el.select('label', true).first();
9890 var icon = this.el.select('i.fa-star', true).first();
9892 if(!this.getValue().length && label && !icon){
9893 this.el.createChild({
9895 cls : 'text-danger fa fa-lg fa-star',
9896 tooltip : 'This field is required',
9897 style : 'margin-right:5px;'
9901 this.el.addClass(this.invalidClass);
9903 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9905 var feedback = this.el.select('.form-control-feedback', true).first();
9908 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9910 if(this.getValue().length || this.forceFeedback){
9911 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9918 this.fireEvent('invalid', this, msg);
9926 * trigger field - base class for combo..
9931 * @class Roo.bootstrap.TriggerField
9932 * @extends Roo.bootstrap.Input
9933 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
9934 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
9935 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
9936 * for which you can provide a custom implementation. For example:
9938 var trigger = new Roo.bootstrap.TriggerField();
9939 trigger.onTriggerClick = myTriggerFn;
9940 trigger.applyTo('my-field');
9943 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
9944 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
9945 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
9946 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
9947 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
9950 * Create a new TriggerField.
9951 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
9952 * to the base TextField)
9954 Roo.bootstrap.TriggerField = function(config){
9955 this.mimicing = false;
9956 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
9959 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
9961 * @cfg {String} triggerClass A CSS class to apply to the trigger
9964 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
9969 * @cfg {Boolean} removable (true|false) special filter default false
9973 /** @cfg {Boolean} grow @hide */
9974 /** @cfg {Number} growMin @hide */
9975 /** @cfg {Number} growMax @hide */
9981 autoSize: Roo.emptyFn,
9988 actionMode : 'wrap',
9993 getAutoCreate : function(){
9995 var align = this.labelAlign || this.parentLabelAlign();
10000 cls: 'form-group' //input-group
10007 type : this.inputType,
10008 cls : 'form-control',
10009 autocomplete: 'new-password',
10010 placeholder : this.placeholder || ''
10014 input.name = this.name;
10017 input.cls += ' input-' + this.size;
10020 if (this.disabled) {
10021 input.disabled=true;
10024 var inputblock = input;
10026 if(this.hasFeedback && !this.allowBlank){
10030 cls: 'glyphicon form-control-feedback'
10033 if(this.removable && !this.editable && !this.tickable){
10035 cls : 'has-feedback',
10041 cls : 'roo-combo-removable-btn close'
10048 cls : 'has-feedback',
10057 if(this.removable && !this.editable && !this.tickable){
10059 cls : 'roo-removable',
10065 cls : 'roo-combo-removable-btn close'
10072 if (this.before || this.after) {
10075 cls : 'input-group',
10079 inputblock.cn.push({
10081 cls : 'input-group-addon',
10086 inputblock.cn.push(input);
10088 if(this.hasFeedback && !this.allowBlank){
10089 inputblock.cls += ' has-feedback';
10090 inputblock.cn.push(feedback);
10094 inputblock.cn.push({
10096 cls : 'input-group-addon',
10109 cls: 'form-hidden-field'
10123 cls: 'form-hidden-field'
10127 cls: 'roo-select2-choices',
10131 cls: 'roo-select2-search-field',
10144 cls: 'roo-select2-container input-group',
10149 // cls: 'typeahead typeahead-long dropdown-menu',
10150 // style: 'display:none'
10155 if(!this.multiple && this.showToggleBtn){
10161 if (this.caret != false) {
10164 cls: 'fa fa-' + this.caret
10171 cls : 'input-group-addon btn dropdown-toggle',
10176 cls: 'combobox-clear',
10190 combobox.cls += ' roo-select2-container-multi';
10193 if (align ==='left' && this.fieldLabel.length) {
10195 cfg.cls += ' roo-form-group-label-left';
10200 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10201 tooltip : 'This field is required'
10206 cls : 'control-label',
10207 html : this.fieldLabel
10219 var labelCfg = cfg.cn[1];
10220 var contentCfg = cfg.cn[2];
10222 if(this.indicatorpos == 'right'){
10227 cls : 'control-label',
10231 html : this.fieldLabel
10235 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10236 tooltip : 'This field is required'
10249 labelCfg = cfg.cn[0];
10250 contentCfg = cfg.cn[1];
10253 if(this.labelWidth > 12){
10254 labelCfg.style = "width: " + this.labelWidth + 'px';
10257 if(this.labelWidth < 13 && this.labelmd == 0){
10258 this.labelmd = this.labelWidth;
10261 if(this.labellg > 0){
10262 labelCfg.cls += ' col-lg-' + this.labellg;
10263 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
10266 if(this.labelmd > 0){
10267 labelCfg.cls += ' col-md-' + this.labelmd;
10268 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
10271 if(this.labelsm > 0){
10272 labelCfg.cls += ' col-sm-' + this.labelsm;
10273 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
10276 if(this.labelxs > 0){
10277 labelCfg.cls += ' col-xs-' + this.labelxs;
10278 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
10281 } else if ( this.fieldLabel.length) {
10282 // Roo.log(" label");
10286 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10287 tooltip : 'This field is required'
10291 //cls : 'input-group-addon',
10292 html : this.fieldLabel
10300 if(this.indicatorpos == 'right'){
10308 html : this.fieldLabel
10312 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10313 tooltip : 'This field is required'
10326 // Roo.log(" no label && no align");
10333 ['xs','sm','md','lg'].map(function(size){
10334 if (settings[size]) {
10335 cfg.cls += ' col-' + size + '-' + settings[size];
10346 onResize : function(w, h){
10347 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
10348 // if(typeof w == 'number'){
10349 // var x = w - this.trigger.getWidth();
10350 // this.inputEl().setWidth(this.adjustWidth('input', x));
10351 // this.trigger.setStyle('left', x+'px');
10356 adjustSize : Roo.BoxComponent.prototype.adjustSize,
10359 getResizeEl : function(){
10360 return this.inputEl();
10364 getPositionEl : function(){
10365 return this.inputEl();
10369 alignErrorIcon : function(){
10370 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
10374 initEvents : function(){
10378 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
10379 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
10380 if(!this.multiple && this.showToggleBtn){
10381 this.trigger = this.el.select('span.dropdown-toggle',true).first();
10382 if(this.hideTrigger){
10383 this.trigger.setDisplayed(false);
10385 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
10389 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
10392 if(this.removable && !this.editable && !this.tickable){
10393 var close = this.closeTriggerEl();
10396 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
10397 close.on('click', this.removeBtnClick, this, close);
10401 //this.trigger.addClassOnOver('x-form-trigger-over');
10402 //this.trigger.addClassOnClick('x-form-trigger-click');
10405 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
10409 closeTriggerEl : function()
10411 var close = this.el.select('.roo-combo-removable-btn', true).first();
10412 return close ? close : false;
10415 removeBtnClick : function(e, h, el)
10417 e.preventDefault();
10419 if(this.fireEvent("remove", this) !== false){
10421 this.fireEvent("afterremove", this)
10425 createList : function()
10427 this.list = Roo.get(document.body).createChild({
10429 cls: 'typeahead typeahead-long dropdown-menu',
10430 style: 'display:none'
10433 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
10438 initTrigger : function(){
10443 onDestroy : function(){
10445 this.trigger.removeAllListeners();
10446 // this.trigger.remove();
10449 // this.wrap.remove();
10451 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
10455 onFocus : function(){
10456 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
10458 if(!this.mimicing){
10459 this.wrap.addClass('x-trigger-wrap-focus');
10460 this.mimicing = true;
10461 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
10462 if(this.monitorTab){
10463 this.el.on("keydown", this.checkTab, this);
10470 checkTab : function(e){
10471 if(e.getKey() == e.TAB){
10472 this.triggerBlur();
10477 onBlur : function(){
10482 mimicBlur : function(e, t){
10484 if(!this.wrap.contains(t) && this.validateBlur()){
10485 this.triggerBlur();
10491 triggerBlur : function(){
10492 this.mimicing = false;
10493 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
10494 if(this.monitorTab){
10495 this.el.un("keydown", this.checkTab, this);
10497 //this.wrap.removeClass('x-trigger-wrap-focus');
10498 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
10502 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
10503 validateBlur : function(e, t){
10508 onDisable : function(){
10509 this.inputEl().dom.disabled = true;
10510 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
10512 // this.wrap.addClass('x-item-disabled');
10517 onEnable : function(){
10518 this.inputEl().dom.disabled = false;
10519 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
10521 // this.el.removeClass('x-item-disabled');
10526 onShow : function(){
10527 var ae = this.getActionEl();
10530 ae.dom.style.display = '';
10531 ae.dom.style.visibility = 'visible';
10537 onHide : function(){
10538 var ae = this.getActionEl();
10539 ae.dom.style.display = 'none';
10543 * The function that should handle the trigger's click event. This method does nothing by default until overridden
10544 * by an implementing function.
10546 * @param {EventObject} e
10548 onTriggerClick : Roo.emptyFn
10552 * Ext JS Library 1.1.1
10553 * Copyright(c) 2006-2007, Ext JS, LLC.
10555 * Originally Released Under LGPL - original licence link has changed is not relivant.
10558 * <script type="text/javascript">
10563 * @class Roo.data.SortTypes
10565 * Defines the default sorting (casting?) comparison functions used when sorting data.
10567 Roo.data.SortTypes = {
10569 * Default sort that does nothing
10570 * @param {Mixed} s The value being converted
10571 * @return {Mixed} The comparison value
10573 none : function(s){
10578 * The regular expression used to strip tags
10582 stripTagsRE : /<\/?[^>]+>/gi,
10585 * Strips all HTML tags to sort on text only
10586 * @param {Mixed} s The value being converted
10587 * @return {String} The comparison value
10589 asText : function(s){
10590 return String(s).replace(this.stripTagsRE, "");
10594 * Strips all HTML tags to sort on text only - Case insensitive
10595 * @param {Mixed} s The value being converted
10596 * @return {String} The comparison value
10598 asUCText : function(s){
10599 return String(s).toUpperCase().replace(this.stripTagsRE, "");
10603 * Case insensitive string
10604 * @param {Mixed} s The value being converted
10605 * @return {String} The comparison value
10607 asUCString : function(s) {
10608 return String(s).toUpperCase();
10613 * @param {Mixed} s The value being converted
10614 * @return {Number} The comparison value
10616 asDate : function(s) {
10620 if(s instanceof Date){
10621 return s.getTime();
10623 return Date.parse(String(s));
10628 * @param {Mixed} s The value being converted
10629 * @return {Float} The comparison value
10631 asFloat : function(s) {
10632 var val = parseFloat(String(s).replace(/,/g, ""));
10641 * @param {Mixed} s The value being converted
10642 * @return {Number} The comparison value
10644 asInt : function(s) {
10645 var val = parseInt(String(s).replace(/,/g, ""));
10653 * Ext JS Library 1.1.1
10654 * Copyright(c) 2006-2007, Ext JS, LLC.
10656 * Originally Released Under LGPL - original licence link has changed is not relivant.
10659 * <script type="text/javascript">
10663 * @class Roo.data.Record
10664 * Instances of this class encapsulate both record <em>definition</em> information, and record
10665 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
10666 * to access Records cached in an {@link Roo.data.Store} object.<br>
10668 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
10669 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
10672 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
10674 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
10675 * {@link #create}. The parameters are the same.
10676 * @param {Array} data An associative Array of data values keyed by the field name.
10677 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
10678 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
10679 * not specified an integer id is generated.
10681 Roo.data.Record = function(data, id){
10682 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
10687 * Generate a constructor for a specific record layout.
10688 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
10689 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
10690 * Each field definition object may contain the following properties: <ul>
10691 * <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,
10692 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
10693 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
10694 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
10695 * is being used, then this is a string containing the javascript expression to reference the data relative to
10696 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
10697 * to the data item relative to the record element. If the mapping expression is the same as the field name,
10698 * this may be omitted.</p></li>
10699 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
10700 * <ul><li>auto (Default, implies no conversion)</li>
10705 * <li>date</li></ul></p></li>
10706 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
10707 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
10708 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
10709 * by the Reader into an object that will be stored in the Record. It is passed the
10710 * following parameters:<ul>
10711 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
10713 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
10715 * <br>usage:<br><pre><code>
10716 var TopicRecord = Roo.data.Record.create(
10717 {name: 'title', mapping: 'topic_title'},
10718 {name: 'author', mapping: 'username'},
10719 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
10720 {name: 'lastPost', mapping: 'post_time', type: 'date'},
10721 {name: 'lastPoster', mapping: 'user2'},
10722 {name: 'excerpt', mapping: 'post_text'}
10725 var myNewRecord = new TopicRecord({
10726 title: 'Do my job please',
10729 lastPost: new Date(),
10730 lastPoster: 'Animal',
10731 excerpt: 'No way dude!'
10733 myStore.add(myNewRecord);
10738 Roo.data.Record.create = function(o){
10739 var f = function(){
10740 f.superclass.constructor.apply(this, arguments);
10742 Roo.extend(f, Roo.data.Record);
10743 var p = f.prototype;
10744 p.fields = new Roo.util.MixedCollection(false, function(field){
10747 for(var i = 0, len = o.length; i < len; i++){
10748 p.fields.add(new Roo.data.Field(o[i]));
10750 f.getField = function(name){
10751 return p.fields.get(name);
10756 Roo.data.Record.AUTO_ID = 1000;
10757 Roo.data.Record.EDIT = 'edit';
10758 Roo.data.Record.REJECT = 'reject';
10759 Roo.data.Record.COMMIT = 'commit';
10761 Roo.data.Record.prototype = {
10763 * Readonly flag - true if this record has been modified.
10772 join : function(store){
10773 this.store = store;
10777 * Set the named field to the specified value.
10778 * @param {String} name The name of the field to set.
10779 * @param {Object} value The value to set the field to.
10781 set : function(name, value){
10782 if(this.data[name] == value){
10786 if(!this.modified){
10787 this.modified = {};
10789 if(typeof this.modified[name] == 'undefined'){
10790 this.modified[name] = this.data[name];
10792 this.data[name] = value;
10793 if(!this.editing && this.store){
10794 this.store.afterEdit(this);
10799 * Get the value of the named field.
10800 * @param {String} name The name of the field to get the value of.
10801 * @return {Object} The value of the field.
10803 get : function(name){
10804 return this.data[name];
10808 beginEdit : function(){
10809 this.editing = true;
10810 this.modified = {};
10814 cancelEdit : function(){
10815 this.editing = false;
10816 delete this.modified;
10820 endEdit : function(){
10821 this.editing = false;
10822 if(this.dirty && this.store){
10823 this.store.afterEdit(this);
10828 * Usually called by the {@link Roo.data.Store} which owns the Record.
10829 * Rejects all changes made to the Record since either creation, or the last commit operation.
10830 * Modified fields are reverted to their original values.
10832 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10833 * of reject operations.
10835 reject : function(){
10836 var m = this.modified;
10838 if(typeof m[n] != "function"){
10839 this.data[n] = m[n];
10842 this.dirty = false;
10843 delete this.modified;
10844 this.editing = false;
10846 this.store.afterReject(this);
10851 * Usually called by the {@link Roo.data.Store} which owns the Record.
10852 * Commits all changes made to the Record since either creation, or the last commit operation.
10854 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10855 * of commit operations.
10857 commit : function(){
10858 this.dirty = false;
10859 delete this.modified;
10860 this.editing = false;
10862 this.store.afterCommit(this);
10867 hasError : function(){
10868 return this.error != null;
10872 clearError : function(){
10877 * Creates a copy of this record.
10878 * @param {String} id (optional) A new record id if you don't want to use this record's id
10881 copy : function(newId) {
10882 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
10886 * Ext JS Library 1.1.1
10887 * Copyright(c) 2006-2007, Ext JS, LLC.
10889 * Originally Released Under LGPL - original licence link has changed is not relivant.
10892 * <script type="text/javascript">
10898 * @class Roo.data.Store
10899 * @extends Roo.util.Observable
10900 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
10901 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
10903 * 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
10904 * has no knowledge of the format of the data returned by the Proxy.<br>
10906 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
10907 * instances from the data object. These records are cached and made available through accessor functions.
10909 * Creates a new Store.
10910 * @param {Object} config A config object containing the objects needed for the Store to access data,
10911 * and read the data into Records.
10913 Roo.data.Store = function(config){
10914 this.data = new Roo.util.MixedCollection(false);
10915 this.data.getKey = function(o){
10918 this.baseParams = {};
10920 this.paramNames = {
10925 "multisort" : "_multisort"
10928 if(config && config.data){
10929 this.inlineData = config.data;
10930 delete config.data;
10933 Roo.apply(this, config);
10935 if(this.reader){ // reader passed
10936 this.reader = Roo.factory(this.reader, Roo.data);
10937 this.reader.xmodule = this.xmodule || false;
10938 if(!this.recordType){
10939 this.recordType = this.reader.recordType;
10941 if(this.reader.onMetaChange){
10942 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
10946 if(this.recordType){
10947 this.fields = this.recordType.prototype.fields;
10949 this.modified = [];
10953 * @event datachanged
10954 * Fires when the data cache has changed, and a widget which is using this Store
10955 * as a Record cache should refresh its view.
10956 * @param {Store} this
10958 datachanged : true,
10960 * @event metachange
10961 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
10962 * @param {Store} this
10963 * @param {Object} meta The JSON metadata
10968 * Fires when Records have been added to the Store
10969 * @param {Store} this
10970 * @param {Roo.data.Record[]} records The array of Records added
10971 * @param {Number} index The index at which the record(s) were added
10976 * Fires when a Record has been removed from the Store
10977 * @param {Store} this
10978 * @param {Roo.data.Record} record The Record that was removed
10979 * @param {Number} index The index at which the record was removed
10984 * Fires when a Record has been updated
10985 * @param {Store} this
10986 * @param {Roo.data.Record} record The Record that was updated
10987 * @param {String} operation The update operation being performed. Value may be one of:
10989 Roo.data.Record.EDIT
10990 Roo.data.Record.REJECT
10991 Roo.data.Record.COMMIT
10997 * Fires when the data cache has been cleared.
10998 * @param {Store} this
11002 * @event beforeload
11003 * Fires before a request is made for a new data object. If the beforeload handler returns false
11004 * the load action will be canceled.
11005 * @param {Store} this
11006 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11010 * @event beforeloadadd
11011 * Fires after a new set of Records has been loaded.
11012 * @param {Store} this
11013 * @param {Roo.data.Record[]} records The Records that were loaded
11014 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11016 beforeloadadd : true,
11019 * Fires after a new set of Records has been loaded, before they are added to the store.
11020 * @param {Store} this
11021 * @param {Roo.data.Record[]} records The Records that were loaded
11022 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11023 * @params {Object} return from reader
11027 * @event loadexception
11028 * Fires if an exception occurs in the Proxy during loading.
11029 * Called with the signature of the Proxy's "loadexception" event.
11030 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
11033 * @param {Object} return from JsonData.reader() - success, totalRecords, records
11034 * @param {Object} load options
11035 * @param {Object} jsonData from your request (normally this contains the Exception)
11037 loadexception : true
11041 this.proxy = Roo.factory(this.proxy, Roo.data);
11042 this.proxy.xmodule = this.xmodule || false;
11043 this.relayEvents(this.proxy, ["loadexception"]);
11045 this.sortToggle = {};
11046 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
11048 Roo.data.Store.superclass.constructor.call(this);
11050 if(this.inlineData){
11051 this.loadData(this.inlineData);
11052 delete this.inlineData;
11056 Roo.extend(Roo.data.Store, Roo.util.Observable, {
11058 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
11059 * without a remote query - used by combo/forms at present.
11063 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
11066 * @cfg {Array} data Inline data to be loaded when the store is initialized.
11069 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
11070 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
11073 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
11074 * on any HTTP request
11077 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
11080 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
11084 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
11085 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
11087 remoteSort : false,
11090 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
11091 * loaded or when a record is removed. (defaults to false).
11093 pruneModifiedRecords : false,
11096 lastOptions : null,
11099 * Add Records to the Store and fires the add event.
11100 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11102 add : function(records){
11103 records = [].concat(records);
11104 for(var i = 0, len = records.length; i < len; i++){
11105 records[i].join(this);
11107 var index = this.data.length;
11108 this.data.addAll(records);
11109 this.fireEvent("add", this, records, index);
11113 * Remove a Record from the Store and fires the remove event.
11114 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
11116 remove : function(record){
11117 var index = this.data.indexOf(record);
11118 this.data.removeAt(index);
11119 if(this.pruneModifiedRecords){
11120 this.modified.remove(record);
11122 this.fireEvent("remove", this, record, index);
11126 * Remove all Records from the Store and fires the clear event.
11128 removeAll : function(){
11130 if(this.pruneModifiedRecords){
11131 this.modified = [];
11133 this.fireEvent("clear", this);
11137 * Inserts Records to the Store at the given index and fires the add event.
11138 * @param {Number} index The start index at which to insert the passed Records.
11139 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11141 insert : function(index, records){
11142 records = [].concat(records);
11143 for(var i = 0, len = records.length; i < len; i++){
11144 this.data.insert(index, records[i]);
11145 records[i].join(this);
11147 this.fireEvent("add", this, records, index);
11151 * Get the index within the cache of the passed Record.
11152 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
11153 * @return {Number} The index of the passed Record. Returns -1 if not found.
11155 indexOf : function(record){
11156 return this.data.indexOf(record);
11160 * Get the index within the cache of the Record with the passed id.
11161 * @param {String} id The id of the Record to find.
11162 * @return {Number} The index of the Record. Returns -1 if not found.
11164 indexOfId : function(id){
11165 return this.data.indexOfKey(id);
11169 * Get the Record with the specified id.
11170 * @param {String} id The id of the Record to find.
11171 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
11173 getById : function(id){
11174 return this.data.key(id);
11178 * Get the Record at the specified index.
11179 * @param {Number} index The index of the Record to find.
11180 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
11182 getAt : function(index){
11183 return this.data.itemAt(index);
11187 * Returns a range of Records between specified indices.
11188 * @param {Number} startIndex (optional) The starting index (defaults to 0)
11189 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
11190 * @return {Roo.data.Record[]} An array of Records
11192 getRange : function(start, end){
11193 return this.data.getRange(start, end);
11197 storeOptions : function(o){
11198 o = Roo.apply({}, o);
11201 this.lastOptions = o;
11205 * Loads the Record cache from the configured Proxy using the configured Reader.
11207 * If using remote paging, then the first load call must specify the <em>start</em>
11208 * and <em>limit</em> properties in the options.params property to establish the initial
11209 * position within the dataset, and the number of Records to cache on each read from the Proxy.
11211 * <strong>It is important to note that for remote data sources, loading is asynchronous,
11212 * and this call will return before the new data has been loaded. Perform any post-processing
11213 * in a callback function, or in a "load" event handler.</strong>
11215 * @param {Object} options An object containing properties which control loading options:<ul>
11216 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
11217 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
11218 * passed the following arguments:<ul>
11219 * <li>r : Roo.data.Record[]</li>
11220 * <li>options: Options object from the load call</li>
11221 * <li>success: Boolean success indicator</li></ul></li>
11222 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
11223 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
11226 load : function(options){
11227 options = options || {};
11228 if(this.fireEvent("beforeload", this, options) !== false){
11229 this.storeOptions(options);
11230 var p = Roo.apply(options.params || {}, this.baseParams);
11231 // if meta was not loaded from remote source.. try requesting it.
11232 if (!this.reader.metaFromRemote) {
11233 p._requestMeta = 1;
11235 if(this.sortInfo && this.remoteSort){
11236 var pn = this.paramNames;
11237 p[pn["sort"]] = this.sortInfo.field;
11238 p[pn["dir"]] = this.sortInfo.direction;
11240 if (this.multiSort) {
11241 var pn = this.paramNames;
11242 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
11245 this.proxy.load(p, this.reader, this.loadRecords, this, options);
11250 * Reloads the Record cache from the configured Proxy using the configured Reader and
11251 * the options from the last load operation performed.
11252 * @param {Object} options (optional) An object containing properties which may override the options
11253 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
11254 * the most recently used options are reused).
11256 reload : function(options){
11257 this.load(Roo.applyIf(options||{}, this.lastOptions));
11261 // Called as a callback by the Reader during a load operation.
11262 loadRecords : function(o, options, success){
11263 if(!o || success === false){
11264 if(success !== false){
11265 this.fireEvent("load", this, [], options, o);
11267 if(options.callback){
11268 options.callback.call(options.scope || this, [], options, false);
11272 // if data returned failure - throw an exception.
11273 if (o.success === false) {
11274 // show a message if no listener is registered.
11275 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
11276 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
11278 // loadmask wil be hooked into this..
11279 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
11282 var r = o.records, t = o.totalRecords || r.length;
11284 this.fireEvent("beforeloadadd", this, r, options, o);
11286 if(!options || options.add !== true){
11287 if(this.pruneModifiedRecords){
11288 this.modified = [];
11290 for(var i = 0, len = r.length; i < len; i++){
11294 this.data = this.snapshot;
11295 delete this.snapshot;
11298 this.data.addAll(r);
11299 this.totalLength = t;
11301 this.fireEvent("datachanged", this);
11303 this.totalLength = Math.max(t, this.data.length+r.length);
11307 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
11309 var e = new Roo.data.Record({});
11311 e.set(this.parent.displayField, this.parent.emptyTitle);
11312 e.set(this.parent.valueField, '');
11317 this.fireEvent("load", this, r, options, o);
11318 if(options.callback){
11319 options.callback.call(options.scope || this, r, options, true);
11325 * Loads data from a passed data block. A Reader which understands the format of the data
11326 * must have been configured in the constructor.
11327 * @param {Object} data The data block from which to read the Records. The format of the data expected
11328 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
11329 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
11331 loadData : function(o, append){
11332 var r = this.reader.readRecords(o);
11333 this.loadRecords(r, {add: append}, true);
11337 * Gets the number of cached records.
11339 * <em>If using paging, this may not be the total size of the dataset. If the data object
11340 * used by the Reader contains the dataset size, then the getTotalCount() function returns
11341 * the data set size</em>
11343 getCount : function(){
11344 return this.data.length || 0;
11348 * Gets the total number of records in the dataset as returned by the server.
11350 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
11351 * the dataset size</em>
11353 getTotalCount : function(){
11354 return this.totalLength || 0;
11358 * Returns the sort state of the Store as an object with two properties:
11360 field {String} The name of the field by which the Records are sorted
11361 direction {String} The sort order, "ASC" or "DESC"
11364 getSortState : function(){
11365 return this.sortInfo;
11369 applySort : function(){
11370 if(this.sortInfo && !this.remoteSort){
11371 var s = this.sortInfo, f = s.field;
11372 var st = this.fields.get(f).sortType;
11373 var fn = function(r1, r2){
11374 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
11375 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
11377 this.data.sort(s.direction, fn);
11378 if(this.snapshot && this.snapshot != this.data){
11379 this.snapshot.sort(s.direction, fn);
11385 * Sets the default sort column and order to be used by the next load operation.
11386 * @param {String} fieldName The name of the field to sort by.
11387 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11389 setDefaultSort : function(field, dir){
11390 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
11394 * Sort the Records.
11395 * If remote sorting is used, the sort is performed on the server, and the cache is
11396 * reloaded. If local sorting is used, the cache is sorted internally.
11397 * @param {String} fieldName The name of the field to sort by.
11398 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11400 sort : function(fieldName, dir){
11401 var f = this.fields.get(fieldName);
11403 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
11405 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
11406 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
11411 this.sortToggle[f.name] = dir;
11412 this.sortInfo = {field: f.name, direction: dir};
11413 if(!this.remoteSort){
11415 this.fireEvent("datachanged", this);
11417 this.load(this.lastOptions);
11422 * Calls the specified function for each of the Records in the cache.
11423 * @param {Function} fn The function to call. The Record is passed as the first parameter.
11424 * Returning <em>false</em> aborts and exits the iteration.
11425 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
11427 each : function(fn, scope){
11428 this.data.each(fn, scope);
11432 * Gets all records modified since the last commit. Modified records are persisted across load operations
11433 * (e.g., during paging).
11434 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
11436 getModifiedRecords : function(){
11437 return this.modified;
11441 createFilterFn : function(property, value, anyMatch){
11442 if(!value.exec){ // not a regex
11443 value = String(value);
11444 if(value.length == 0){
11447 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
11449 return function(r){
11450 return value.test(r.data[property]);
11455 * Sums the value of <i>property</i> for each record between start and end and returns the result.
11456 * @param {String} property A field on your records
11457 * @param {Number} start The record index to start at (defaults to 0)
11458 * @param {Number} end The last record index to include (defaults to length - 1)
11459 * @return {Number} The sum
11461 sum : function(property, start, end){
11462 var rs = this.data.items, v = 0;
11463 start = start || 0;
11464 end = (end || end === 0) ? end : rs.length-1;
11466 for(var i = start; i <= end; i++){
11467 v += (rs[i].data[property] || 0);
11473 * Filter the records by a specified property.
11474 * @param {String} field A field on your records
11475 * @param {String/RegExp} value Either a string that the field
11476 * should start with or a RegExp to test against the field
11477 * @param {Boolean} anyMatch True to match any part not just the beginning
11479 filter : function(property, value, anyMatch){
11480 var fn = this.createFilterFn(property, value, anyMatch);
11481 return fn ? this.filterBy(fn) : this.clearFilter();
11485 * Filter by a function. The specified function will be called with each
11486 * record in this data source. If the function returns true the record is included,
11487 * otherwise it is filtered.
11488 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11489 * @param {Object} scope (optional) The scope of the function (defaults to this)
11491 filterBy : function(fn, scope){
11492 this.snapshot = this.snapshot || this.data;
11493 this.data = this.queryBy(fn, scope||this);
11494 this.fireEvent("datachanged", this);
11498 * Query the records by a specified property.
11499 * @param {String} field A field on your records
11500 * @param {String/RegExp} value Either a string that the field
11501 * should start with or a RegExp to test against the field
11502 * @param {Boolean} anyMatch True to match any part not just the beginning
11503 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11505 query : function(property, value, anyMatch){
11506 var fn = this.createFilterFn(property, value, anyMatch);
11507 return fn ? this.queryBy(fn) : this.data.clone();
11511 * Query by a function. The specified function will be called with each
11512 * record in this data source. If the function returns true the record is included
11514 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11515 * @param {Object} scope (optional) The scope of the function (defaults to this)
11516 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11518 queryBy : function(fn, scope){
11519 var data = this.snapshot || this.data;
11520 return data.filterBy(fn, scope||this);
11524 * Collects unique values for a particular dataIndex from this store.
11525 * @param {String} dataIndex The property to collect
11526 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
11527 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
11528 * @return {Array} An array of the unique values
11530 collect : function(dataIndex, allowNull, bypassFilter){
11531 var d = (bypassFilter === true && this.snapshot) ?
11532 this.snapshot.items : this.data.items;
11533 var v, sv, r = [], l = {};
11534 for(var i = 0, len = d.length; i < len; i++){
11535 v = d[i].data[dataIndex];
11537 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
11546 * Revert to a view of the Record cache with no filtering applied.
11547 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
11549 clearFilter : function(suppressEvent){
11550 if(this.snapshot && this.snapshot != this.data){
11551 this.data = this.snapshot;
11552 delete this.snapshot;
11553 if(suppressEvent !== true){
11554 this.fireEvent("datachanged", this);
11560 afterEdit : function(record){
11561 if(this.modified.indexOf(record) == -1){
11562 this.modified.push(record);
11564 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
11568 afterReject : function(record){
11569 this.modified.remove(record);
11570 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
11574 afterCommit : function(record){
11575 this.modified.remove(record);
11576 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
11580 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
11581 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
11583 commitChanges : function(){
11584 var m = this.modified.slice(0);
11585 this.modified = [];
11586 for(var i = 0, len = m.length; i < len; i++){
11592 * Cancel outstanding changes on all changed records.
11594 rejectChanges : function(){
11595 var m = this.modified.slice(0);
11596 this.modified = [];
11597 for(var i = 0, len = m.length; i < len; i++){
11602 onMetaChange : function(meta, rtype, o){
11603 this.recordType = rtype;
11604 this.fields = rtype.prototype.fields;
11605 delete this.snapshot;
11606 this.sortInfo = meta.sortInfo || this.sortInfo;
11607 this.modified = [];
11608 this.fireEvent('metachange', this, this.reader.meta);
11611 moveIndex : function(data, type)
11613 var index = this.indexOf(data);
11615 var newIndex = index + type;
11619 this.insert(newIndex, data);
11624 * Ext JS Library 1.1.1
11625 * Copyright(c) 2006-2007, Ext JS, LLC.
11627 * Originally Released Under LGPL - original licence link has changed is not relivant.
11630 * <script type="text/javascript">
11634 * @class Roo.data.SimpleStore
11635 * @extends Roo.data.Store
11636 * Small helper class to make creating Stores from Array data easier.
11637 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
11638 * @cfg {Array} fields An array of field definition objects, or field name strings.
11639 * @cfg {Array} data The multi-dimensional array of data
11641 * @param {Object} config
11643 Roo.data.SimpleStore = function(config){
11644 Roo.data.SimpleStore.superclass.constructor.call(this, {
11646 reader: new Roo.data.ArrayReader({
11649 Roo.data.Record.create(config.fields)
11651 proxy : new Roo.data.MemoryProxy(config.data)
11655 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
11657 * Ext JS Library 1.1.1
11658 * Copyright(c) 2006-2007, Ext JS, LLC.
11660 * Originally Released Under LGPL - original licence link has changed is not relivant.
11663 * <script type="text/javascript">
11668 * @extends Roo.data.Store
11669 * @class Roo.data.JsonStore
11670 * Small helper class to make creating Stores for JSON data easier. <br/>
11672 var store = new Roo.data.JsonStore({
11673 url: 'get-images.php',
11675 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
11678 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
11679 * JsonReader and HttpProxy (unless inline data is provided).</b>
11680 * @cfg {Array} fields An array of field definition objects, or field name strings.
11682 * @param {Object} config
11684 Roo.data.JsonStore = function(c){
11685 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
11686 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
11687 reader: new Roo.data.JsonReader(c, c.fields)
11690 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
11692 * Ext JS Library 1.1.1
11693 * Copyright(c) 2006-2007, Ext JS, LLC.
11695 * Originally Released Under LGPL - original licence link has changed is not relivant.
11698 * <script type="text/javascript">
11702 Roo.data.Field = function(config){
11703 if(typeof config == "string"){
11704 config = {name: config};
11706 Roo.apply(this, config);
11709 this.type = "auto";
11712 var st = Roo.data.SortTypes;
11713 // named sortTypes are supported, here we look them up
11714 if(typeof this.sortType == "string"){
11715 this.sortType = st[this.sortType];
11718 // set default sortType for strings and dates
11719 if(!this.sortType){
11722 this.sortType = st.asUCString;
11725 this.sortType = st.asDate;
11728 this.sortType = st.none;
11733 var stripRe = /[\$,%]/g;
11735 // prebuilt conversion function for this field, instead of
11736 // switching every time we're reading a value
11738 var cv, dateFormat = this.dateFormat;
11743 cv = function(v){ return v; };
11746 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
11750 return v !== undefined && v !== null && v !== '' ?
11751 parseInt(String(v).replace(stripRe, ""), 10) : '';
11756 return v !== undefined && v !== null && v !== '' ?
11757 parseFloat(String(v).replace(stripRe, ""), 10) : '';
11762 cv = function(v){ return v === true || v === "true" || v == 1; };
11769 if(v instanceof Date){
11773 if(dateFormat == "timestamp"){
11774 return new Date(v*1000);
11776 return Date.parseDate(v, dateFormat);
11778 var parsed = Date.parse(v);
11779 return parsed ? new Date(parsed) : null;
11788 Roo.data.Field.prototype = {
11796 * Ext JS Library 1.1.1
11797 * Copyright(c) 2006-2007, Ext JS, LLC.
11799 * Originally Released Under LGPL - original licence link has changed is not relivant.
11802 * <script type="text/javascript">
11805 // Base class for reading structured data from a data source. This class is intended to be
11806 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
11809 * @class Roo.data.DataReader
11810 * Base class for reading structured data from a data source. This class is intended to be
11811 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
11814 Roo.data.DataReader = function(meta, recordType){
11818 this.recordType = recordType instanceof Array ?
11819 Roo.data.Record.create(recordType) : recordType;
11822 Roo.data.DataReader.prototype = {
11824 * Create an empty record
11825 * @param {Object} data (optional) - overlay some values
11826 * @return {Roo.data.Record} record created.
11828 newRow : function(d) {
11830 this.recordType.prototype.fields.each(function(c) {
11832 case 'int' : da[c.name] = 0; break;
11833 case 'date' : da[c.name] = new Date(); break;
11834 case 'float' : da[c.name] = 0.0; break;
11835 case 'boolean' : da[c.name] = false; break;
11836 default : da[c.name] = ""; break;
11840 return new this.recordType(Roo.apply(da, d));
11845 * Ext JS Library 1.1.1
11846 * Copyright(c) 2006-2007, Ext JS, LLC.
11848 * Originally Released Under LGPL - original licence link has changed is not relivant.
11851 * <script type="text/javascript">
11855 * @class Roo.data.DataProxy
11856 * @extends Roo.data.Observable
11857 * This class is an abstract base class for implementations which provide retrieval of
11858 * unformatted data objects.<br>
11860 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
11861 * (of the appropriate type which knows how to parse the data object) to provide a block of
11862 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
11864 * Custom implementations must implement the load method as described in
11865 * {@link Roo.data.HttpProxy#load}.
11867 Roo.data.DataProxy = function(){
11870 * @event beforeload
11871 * Fires before a network request is made to retrieve a data object.
11872 * @param {Object} This DataProxy object.
11873 * @param {Object} params The params parameter to the load function.
11878 * Fires before the load method's callback is called.
11879 * @param {Object} This DataProxy object.
11880 * @param {Object} o The data object.
11881 * @param {Object} arg The callback argument object passed to the load function.
11885 * @event loadexception
11886 * Fires if an Exception occurs during data retrieval.
11887 * @param {Object} This DataProxy object.
11888 * @param {Object} o The data object.
11889 * @param {Object} arg The callback argument object passed to the load function.
11890 * @param {Object} e The Exception.
11892 loadexception : true
11894 Roo.data.DataProxy.superclass.constructor.call(this);
11897 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
11900 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
11904 * Ext JS Library 1.1.1
11905 * Copyright(c) 2006-2007, Ext JS, LLC.
11907 * Originally Released Under LGPL - original licence link has changed is not relivant.
11910 * <script type="text/javascript">
11913 * @class Roo.data.MemoryProxy
11914 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
11915 * to the Reader when its load method is called.
11917 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
11919 Roo.data.MemoryProxy = function(data){
11923 Roo.data.MemoryProxy.superclass.constructor.call(this);
11927 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
11930 * Load data from the requested source (in this case an in-memory
11931 * data object passed to the constructor), read the data object into
11932 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
11933 * process that block using the passed callback.
11934 * @param {Object} params This parameter is not used by the MemoryProxy class.
11935 * @param {Roo.data.DataReader} reader The Reader object which converts the data
11936 * object into a block of Roo.data.Records.
11937 * @param {Function} callback The function into which to pass the block of Roo.data.records.
11938 * The function must be passed <ul>
11939 * <li>The Record block object</li>
11940 * <li>The "arg" argument from the load function</li>
11941 * <li>A boolean success indicator</li>
11943 * @param {Object} scope The scope in which to call the callback
11944 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
11946 load : function(params, reader, callback, scope, arg){
11947 params = params || {};
11950 result = reader.readRecords(this.data);
11952 this.fireEvent("loadexception", this, arg, null, e);
11953 callback.call(scope, null, arg, false);
11956 callback.call(scope, result, arg, true);
11960 update : function(params, records){
11965 * Ext JS Library 1.1.1
11966 * Copyright(c) 2006-2007, Ext JS, LLC.
11968 * Originally Released Under LGPL - original licence link has changed is not relivant.
11971 * <script type="text/javascript">
11974 * @class Roo.data.HttpProxy
11975 * @extends Roo.data.DataProxy
11976 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
11977 * configured to reference a certain URL.<br><br>
11979 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
11980 * from which the running page was served.<br><br>
11982 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
11984 * Be aware that to enable the browser to parse an XML document, the server must set
11985 * the Content-Type header in the HTTP response to "text/xml".
11987 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
11988 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
11989 * will be used to make the request.
11991 Roo.data.HttpProxy = function(conn){
11992 Roo.data.HttpProxy.superclass.constructor.call(this);
11993 // is conn a conn config or a real conn?
11995 this.useAjax = !conn || !conn.events;
11999 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
12000 // thse are take from connection...
12003 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
12006 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
12007 * extra parameters to each request made by this object. (defaults to undefined)
12010 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
12011 * to each request made by this object. (defaults to undefined)
12014 * @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)
12017 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
12020 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
12026 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
12030 * Return the {@link Roo.data.Connection} object being used by this Proxy.
12031 * @return {Connection} The Connection object. This object may be used to subscribe to events on
12032 * a finer-grained basis than the DataProxy events.
12034 getConnection : function(){
12035 return this.useAjax ? Roo.Ajax : this.conn;
12039 * Load data from the configured {@link Roo.data.Connection}, read the data object into
12040 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
12041 * process that block using the passed callback.
12042 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12043 * for the request to the remote server.
12044 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12045 * object into a block of Roo.data.Records.
12046 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12047 * The function must be passed <ul>
12048 * <li>The Record block object</li>
12049 * <li>The "arg" argument from the load function</li>
12050 * <li>A boolean success indicator</li>
12052 * @param {Object} scope The scope in which to call the callback
12053 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12055 load : function(params, reader, callback, scope, arg){
12056 if(this.fireEvent("beforeload", this, params) !== false){
12058 params : params || {},
12060 callback : callback,
12065 callback : this.loadResponse,
12069 Roo.applyIf(o, this.conn);
12070 if(this.activeRequest){
12071 Roo.Ajax.abort(this.activeRequest);
12073 this.activeRequest = Roo.Ajax.request(o);
12075 this.conn.request(o);
12078 callback.call(scope||this, null, arg, false);
12083 loadResponse : function(o, success, response){
12084 delete this.activeRequest;
12086 this.fireEvent("loadexception", this, o, response);
12087 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12092 result = o.reader.read(response);
12094 this.fireEvent("loadexception", this, o, response, e);
12095 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12099 this.fireEvent("load", this, o, o.request.arg);
12100 o.request.callback.call(o.request.scope, result, o.request.arg, true);
12104 update : function(dataSet){
12109 updateResponse : function(dataSet){
12114 * Ext JS Library 1.1.1
12115 * Copyright(c) 2006-2007, Ext JS, LLC.
12117 * Originally Released Under LGPL - original licence link has changed is not relivant.
12120 * <script type="text/javascript">
12124 * @class Roo.data.ScriptTagProxy
12125 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
12126 * other than the originating domain of the running page.<br><br>
12128 * <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
12129 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
12131 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
12132 * source code that is used as the source inside a <script> tag.<br><br>
12134 * In order for the browser to process the returned data, the server must wrap the data object
12135 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
12136 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
12137 * depending on whether the callback name was passed:
12140 boolean scriptTag = false;
12141 String cb = request.getParameter("callback");
12144 response.setContentType("text/javascript");
12146 response.setContentType("application/x-json");
12148 Writer out = response.getWriter();
12150 out.write(cb + "(");
12152 out.print(dataBlock.toJsonString());
12159 * @param {Object} config A configuration object.
12161 Roo.data.ScriptTagProxy = function(config){
12162 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
12163 Roo.apply(this, config);
12164 this.head = document.getElementsByTagName("head")[0];
12167 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
12169 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
12171 * @cfg {String} url The URL from which to request the data object.
12174 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
12178 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
12179 * the server the name of the callback function set up by the load call to process the returned data object.
12180 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
12181 * javascript output which calls this named function passing the data object as its only parameter.
12183 callbackParam : "callback",
12185 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
12186 * name to the request.
12191 * Load data from the configured URL, read the data object into
12192 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12193 * process that block using the passed callback.
12194 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12195 * for the request to the remote server.
12196 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12197 * object into a block of Roo.data.Records.
12198 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12199 * The function must be passed <ul>
12200 * <li>The Record block object</li>
12201 * <li>The "arg" argument from the load function</li>
12202 * <li>A boolean success indicator</li>
12204 * @param {Object} scope The scope in which to call the callback
12205 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12207 load : function(params, reader, callback, scope, arg){
12208 if(this.fireEvent("beforeload", this, params) !== false){
12210 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
12212 var url = this.url;
12213 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
12215 url += "&_dc=" + (new Date().getTime());
12217 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
12220 cb : "stcCallback"+transId,
12221 scriptId : "stcScript"+transId,
12225 callback : callback,
12231 window[trans.cb] = function(o){
12232 conn.handleResponse(o, trans);
12235 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
12237 if(this.autoAbort !== false){
12241 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
12243 var script = document.createElement("script");
12244 script.setAttribute("src", url);
12245 script.setAttribute("type", "text/javascript");
12246 script.setAttribute("id", trans.scriptId);
12247 this.head.appendChild(script);
12249 this.trans = trans;
12251 callback.call(scope||this, null, arg, false);
12256 isLoading : function(){
12257 return this.trans ? true : false;
12261 * Abort the current server request.
12263 abort : function(){
12264 if(this.isLoading()){
12265 this.destroyTrans(this.trans);
12270 destroyTrans : function(trans, isLoaded){
12271 this.head.removeChild(document.getElementById(trans.scriptId));
12272 clearTimeout(trans.timeoutId);
12274 window[trans.cb] = undefined;
12276 delete window[trans.cb];
12279 // if hasn't been loaded, wait for load to remove it to prevent script error
12280 window[trans.cb] = function(){
12281 window[trans.cb] = undefined;
12283 delete window[trans.cb];
12290 handleResponse : function(o, trans){
12291 this.trans = false;
12292 this.destroyTrans(trans, true);
12295 result = trans.reader.readRecords(o);
12297 this.fireEvent("loadexception", this, o, trans.arg, e);
12298 trans.callback.call(trans.scope||window, null, trans.arg, false);
12301 this.fireEvent("load", this, o, trans.arg);
12302 trans.callback.call(trans.scope||window, result, trans.arg, true);
12306 handleFailure : function(trans){
12307 this.trans = false;
12308 this.destroyTrans(trans, false);
12309 this.fireEvent("loadexception", this, null, trans.arg);
12310 trans.callback.call(trans.scope||window, null, trans.arg, false);
12314 * Ext JS Library 1.1.1
12315 * Copyright(c) 2006-2007, Ext JS, LLC.
12317 * Originally Released Under LGPL - original licence link has changed is not relivant.
12320 * <script type="text/javascript">
12324 * @class Roo.data.JsonReader
12325 * @extends Roo.data.DataReader
12326 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
12327 * based on mappings in a provided Roo.data.Record constructor.
12329 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
12330 * in the reply previously.
12335 var RecordDef = Roo.data.Record.create([
12336 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
12337 {name: 'occupation'} // This field will use "occupation" as the mapping.
12339 var myReader = new Roo.data.JsonReader({
12340 totalProperty: "results", // The property which contains the total dataset size (optional)
12341 root: "rows", // The property which contains an Array of row objects
12342 id: "id" // The property within each row object that provides an ID for the record (optional)
12346 * This would consume a JSON file like this:
12348 { 'results': 2, 'rows': [
12349 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
12350 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
12353 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
12354 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
12355 * paged from the remote server.
12356 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
12357 * @cfg {String} root name of the property which contains the Array of row objects.
12358 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
12359 * @cfg {Array} fields Array of field definition objects
12361 * Create a new JsonReader
12362 * @param {Object} meta Metadata configuration options
12363 * @param {Object} recordType Either an Array of field definition objects,
12364 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
12366 Roo.data.JsonReader = function(meta, recordType){
12369 // set some defaults:
12370 Roo.applyIf(meta, {
12371 totalProperty: 'total',
12372 successProperty : 'success',
12377 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
12379 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
12382 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
12383 * Used by Store query builder to append _requestMeta to params.
12386 metaFromRemote : false,
12388 * This method is only used by a DataProxy which has retrieved data from a remote server.
12389 * @param {Object} response The XHR object which contains the JSON data in its responseText.
12390 * @return {Object} data A data block which is used by an Roo.data.Store object as
12391 * a cache of Roo.data.Records.
12393 read : function(response){
12394 var json = response.responseText;
12396 var o = /* eval:var:o */ eval("("+json+")");
12398 throw {message: "JsonReader.read: Json object not found"};
12404 this.metaFromRemote = true;
12405 this.meta = o.metaData;
12406 this.recordType = Roo.data.Record.create(o.metaData.fields);
12407 this.onMetaChange(this.meta, this.recordType, o);
12409 return this.readRecords(o);
12412 // private function a store will implement
12413 onMetaChange : function(meta, recordType, o){
12420 simpleAccess: function(obj, subsc) {
12427 getJsonAccessor: function(){
12429 return function(expr) {
12431 return(re.test(expr))
12432 ? new Function("obj", "return obj." + expr)
12437 return Roo.emptyFn;
12442 * Create a data block containing Roo.data.Records from an XML document.
12443 * @param {Object} o An object which contains an Array of row objects in the property specified
12444 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
12445 * which contains the total size of the dataset.
12446 * @return {Object} data A data block which is used by an Roo.data.Store object as
12447 * a cache of Roo.data.Records.
12449 readRecords : function(o){
12451 * After any data loads, the raw JSON data is available for further custom processing.
12455 var s = this.meta, Record = this.recordType,
12456 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
12458 // Generate extraction functions for the totalProperty, the root, the id, and for each field
12460 if(s.totalProperty) {
12461 this.getTotal = this.getJsonAccessor(s.totalProperty);
12463 if(s.successProperty) {
12464 this.getSuccess = this.getJsonAccessor(s.successProperty);
12466 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
12468 var g = this.getJsonAccessor(s.id);
12469 this.getId = function(rec) {
12471 return (r === undefined || r === "") ? null : r;
12474 this.getId = function(){return null;};
12477 for(var jj = 0; jj < fl; jj++){
12479 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
12480 this.ef[jj] = this.getJsonAccessor(map);
12484 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
12485 if(s.totalProperty){
12486 var vt = parseInt(this.getTotal(o), 10);
12491 if(s.successProperty){
12492 var vs = this.getSuccess(o);
12493 if(vs === false || vs === 'false'){
12498 for(var i = 0; i < c; i++){
12501 var id = this.getId(n);
12502 for(var j = 0; j < fl; j++){
12504 var v = this.ef[j](n);
12506 Roo.log('missing convert for ' + f.name);
12510 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
12512 var record = new Record(values, id);
12514 records[i] = record;
12520 totalRecords : totalRecords
12525 * Ext JS Library 1.1.1
12526 * Copyright(c) 2006-2007, Ext JS, LLC.
12528 * Originally Released Under LGPL - original licence link has changed is not relivant.
12531 * <script type="text/javascript">
12535 * @class Roo.data.ArrayReader
12536 * @extends Roo.data.DataReader
12537 * Data reader class to create an Array of Roo.data.Record objects from an Array.
12538 * Each element of that Array represents a row of data fields. The
12539 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
12540 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
12544 var RecordDef = Roo.data.Record.create([
12545 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
12546 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
12548 var myReader = new Roo.data.ArrayReader({
12549 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
12553 * This would consume an Array like this:
12555 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
12557 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
12559 * Create a new JsonReader
12560 * @param {Object} meta Metadata configuration options.
12561 * @param {Object} recordType Either an Array of field definition objects
12562 * as specified to {@link Roo.data.Record#create},
12563 * or an {@link Roo.data.Record} object
12564 * created using {@link Roo.data.Record#create}.
12566 Roo.data.ArrayReader = function(meta, recordType){
12567 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
12570 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
12572 * Create a data block containing Roo.data.Records from an XML document.
12573 * @param {Object} o An Array of row objects which represents the dataset.
12574 * @return {Object} data A data block which is used by an Roo.data.Store object as
12575 * a cache of Roo.data.Records.
12577 readRecords : function(o){
12578 var sid = this.meta ? this.meta.id : null;
12579 var recordType = this.recordType, fields = recordType.prototype.fields;
12582 for(var i = 0; i < root.length; i++){
12585 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
12586 for(var j = 0, jlen = fields.length; j < jlen; j++){
12587 var f = fields.items[j];
12588 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
12589 var v = n[k] !== undefined ? n[k] : f.defaultValue;
12591 values[f.name] = v;
12593 var record = new recordType(values, id);
12595 records[records.length] = record;
12599 totalRecords : records.length
12608 * @class Roo.bootstrap.ComboBox
12609 * @extends Roo.bootstrap.TriggerField
12610 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
12611 * @cfg {Boolean} append (true|false) default false
12612 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12613 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
12614 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
12615 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
12616 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
12617 * @cfg {Boolean} animate default true
12618 * @cfg {Boolean} emptyResultText only for touch device
12619 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
12620 * @cfg {String} emptyTitle default ''
12622 * Create a new ComboBox.
12623 * @param {Object} config Configuration options
12625 Roo.bootstrap.ComboBox = function(config){
12626 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
12630 * Fires when the dropdown list is expanded
12631 * @param {Roo.bootstrap.ComboBox} combo This combo box
12636 * Fires when the dropdown list is collapsed
12637 * @param {Roo.bootstrap.ComboBox} combo This combo box
12641 * @event beforeselect
12642 * Fires before a list item is selected. Return false to cancel the selection.
12643 * @param {Roo.bootstrap.ComboBox} combo This combo box
12644 * @param {Roo.data.Record} record The data record returned from the underlying store
12645 * @param {Number} index The index of the selected item in the dropdown list
12647 'beforeselect' : true,
12650 * Fires when a list item is selected
12651 * @param {Roo.bootstrap.ComboBox} combo This combo box
12652 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
12653 * @param {Number} index The index of the selected item in the dropdown list
12657 * @event beforequery
12658 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
12659 * The event object passed has these properties:
12660 * @param {Roo.bootstrap.ComboBox} combo This combo box
12661 * @param {String} query The query
12662 * @param {Boolean} forceAll true to force "all" query
12663 * @param {Boolean} cancel true to cancel the query
12664 * @param {Object} e The query event object
12666 'beforequery': true,
12669 * Fires when the 'add' icon is pressed (add a listener to enable add button)
12670 * @param {Roo.bootstrap.ComboBox} combo This combo box
12675 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
12676 * @param {Roo.bootstrap.ComboBox} combo This combo box
12677 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
12682 * Fires when the remove value from the combobox array
12683 * @param {Roo.bootstrap.ComboBox} combo This combo box
12687 * @event afterremove
12688 * Fires when the remove value from the combobox array
12689 * @param {Roo.bootstrap.ComboBox} combo This combo box
12691 'afterremove' : true,
12693 * @event specialfilter
12694 * Fires when specialfilter
12695 * @param {Roo.bootstrap.ComboBox} combo This combo box
12697 'specialfilter' : true,
12700 * Fires when tick the element
12701 * @param {Roo.bootstrap.ComboBox} combo This combo box
12705 * @event touchviewdisplay
12706 * Fires when touch view require special display (default is using displayField)
12707 * @param {Roo.bootstrap.ComboBox} combo This combo box
12708 * @param {Object} cfg set html .
12710 'touchviewdisplay' : true
12715 this.tickItems = [];
12717 this.selectedIndex = -1;
12718 if(this.mode == 'local'){
12719 if(config.queryDelay === undefined){
12720 this.queryDelay = 10;
12722 if(config.minChars === undefined){
12728 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
12731 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
12732 * rendering into an Roo.Editor, defaults to false)
12735 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
12736 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
12739 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
12742 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
12743 * the dropdown list (defaults to undefined, with no header element)
12747 * @cfg {String/Roo.Template} tpl The template to use to render the output
12751 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
12753 listWidth: undefined,
12755 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
12756 * mode = 'remote' or 'text' if mode = 'local')
12758 displayField: undefined,
12761 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
12762 * mode = 'remote' or 'value' if mode = 'local').
12763 * Note: use of a valueField requires the user make a selection
12764 * in order for a value to be mapped.
12766 valueField: undefined,
12768 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
12773 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
12774 * field's data value (defaults to the underlying DOM element's name)
12776 hiddenName: undefined,
12778 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
12782 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
12784 selectedClass: 'active',
12787 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
12791 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
12792 * anchor positions (defaults to 'tl-bl')
12794 listAlign: 'tl-bl?',
12796 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
12800 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
12801 * query specified by the allQuery config option (defaults to 'query')
12803 triggerAction: 'query',
12805 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
12806 * (defaults to 4, does not apply if editable = false)
12810 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
12811 * delay (typeAheadDelay) if it matches a known value (defaults to false)
12815 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
12816 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
12820 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
12821 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
12825 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
12826 * when editable = true (defaults to false)
12828 selectOnFocus:false,
12830 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
12832 queryParam: 'query',
12834 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
12835 * when mode = 'remote' (defaults to 'Loading...')
12837 loadingText: 'Loading...',
12839 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
12843 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
12847 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
12848 * traditional select (defaults to true)
12852 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
12856 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
12860 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
12861 * listWidth has a higher value)
12865 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
12866 * allow the user to set arbitrary text into the field (defaults to false)
12868 forceSelection:false,
12870 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
12871 * if typeAhead = true (defaults to 250)
12873 typeAheadDelay : 250,
12875 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
12876 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
12878 valueNotFoundText : undefined,
12880 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
12882 blockFocus : false,
12885 * @cfg {Boolean} disableClear Disable showing of clear button.
12887 disableClear : false,
12889 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
12891 alwaysQuery : false,
12894 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
12899 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
12901 invalidClass : "has-warning",
12904 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
12906 validClass : "has-success",
12909 * @cfg {Boolean} specialFilter (true|false) special filter default false
12911 specialFilter : false,
12914 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
12916 mobileTouchView : true,
12919 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
12921 useNativeIOS : false,
12923 ios_options : false,
12935 btnPosition : 'right',
12936 triggerList : true,
12937 showToggleBtn : true,
12939 emptyResultText: 'Empty',
12940 triggerText : 'Select',
12943 // element that contains real text value.. (when hidden is used..)
12945 getAutoCreate : function()
12950 * Render classic select for iso
12953 if(Roo.isIOS && this.useNativeIOS){
12954 cfg = this.getAutoCreateNativeIOS();
12962 if(Roo.isTouch && this.mobileTouchView){
12963 cfg = this.getAutoCreateTouchView();
12970 if(!this.tickable){
12971 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
12976 * ComboBox with tickable selections
12979 var align = this.labelAlign || this.parentLabelAlign();
12982 cls : 'form-group roo-combobox-tickable' //input-group
12985 var btn_text_select = '';
12986 var btn_text_done = '';
12987 var btn_text_cancel = '';
12989 if (this.btn_text_show) {
12990 btn_text_select = 'Select';
12991 btn_text_done = 'Done';
12992 btn_text_cancel = 'Cancel';
12997 cls : 'tickable-buttons',
13002 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
13003 //html : this.triggerText
13004 html: btn_text_select
13010 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
13012 html: btn_text_done
13018 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
13020 html: btn_text_cancel
13026 buttons.cn.unshift({
13028 cls: 'roo-select2-search-field-input'
13034 Roo.each(buttons.cn, function(c){
13036 c.cls += ' btn-' + _this.size;
13039 if (_this.disabled) {
13050 cls: 'form-hidden-field'
13054 cls: 'roo-select2-choices',
13058 cls: 'roo-select2-search-field',
13069 cls: 'roo-select2-container input-group roo-select2-container-multi',
13074 // cls: 'typeahead typeahead-long dropdown-menu',
13075 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
13080 if(this.hasFeedback && !this.allowBlank){
13084 cls: 'glyphicon form-control-feedback'
13087 combobox.cn.push(feedback);
13091 if (align ==='left' && this.fieldLabel.length) {
13093 cfg.cls += ' roo-form-group-label-left';
13098 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13099 tooltip : 'This field is required'
13104 cls : 'control-label',
13105 html : this.fieldLabel
13117 var labelCfg = cfg.cn[1];
13118 var contentCfg = cfg.cn[2];
13121 if(this.indicatorpos == 'right'){
13127 cls : 'control-label',
13131 html : this.fieldLabel
13135 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13136 tooltip : 'This field is required'
13151 labelCfg = cfg.cn[0];
13152 contentCfg = cfg.cn[1];
13156 if(this.labelWidth > 12){
13157 labelCfg.style = "width: " + this.labelWidth + 'px';
13160 if(this.labelWidth < 13 && this.labelmd == 0){
13161 this.labelmd = this.labelWidth;
13164 if(this.labellg > 0){
13165 labelCfg.cls += ' col-lg-' + this.labellg;
13166 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
13169 if(this.labelmd > 0){
13170 labelCfg.cls += ' col-md-' + this.labelmd;
13171 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
13174 if(this.labelsm > 0){
13175 labelCfg.cls += ' col-sm-' + this.labelsm;
13176 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
13179 if(this.labelxs > 0){
13180 labelCfg.cls += ' col-xs-' + this.labelxs;
13181 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
13185 } else if ( this.fieldLabel.length) {
13186 // Roo.log(" label");
13190 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13191 tooltip : 'This field is required'
13195 //cls : 'input-group-addon',
13196 html : this.fieldLabel
13201 if(this.indicatorpos == 'right'){
13205 //cls : 'input-group-addon',
13206 html : this.fieldLabel
13210 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13211 tooltip : 'This field is required'
13220 // Roo.log(" no label && no align");
13227 ['xs','sm','md','lg'].map(function(size){
13228 if (settings[size]) {
13229 cfg.cls += ' col-' + size + '-' + settings[size];
13237 _initEventsCalled : false,
13240 initEvents: function()
13242 if (this._initEventsCalled) { // as we call render... prevent looping...
13245 this._initEventsCalled = true;
13248 throw "can not find store for combo";
13251 this.indicator = this.indicatorEl();
13253 this.store = Roo.factory(this.store, Roo.data);
13254 this.store.parent = this;
13256 // if we are building from html. then this element is so complex, that we can not really
13257 // use the rendered HTML.
13258 // so we have to trash and replace the previous code.
13259 if (Roo.XComponent.build_from_html) {
13260 // remove this element....
13261 var e = this.el.dom, k=0;
13262 while (e ) { e = e.previousSibling; ++k;}
13267 this.rendered = false;
13269 this.render(this.parent().getChildContainer(true), k);
13272 if(Roo.isIOS && this.useNativeIOS){
13273 this.initIOSView();
13281 if(Roo.isTouch && this.mobileTouchView){
13282 this.initTouchView();
13287 this.initTickableEvents();
13291 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
13293 if(this.hiddenName){
13295 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13297 this.hiddenField.dom.value =
13298 this.hiddenValue !== undefined ? this.hiddenValue :
13299 this.value !== undefined ? this.value : '';
13301 // prevent input submission
13302 this.el.dom.removeAttribute('name');
13303 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13308 // this.el.dom.setAttribute('autocomplete', 'off');
13311 var cls = 'x-combo-list';
13313 //this.list = new Roo.Layer({
13314 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
13320 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13321 _this.list.setWidth(lw);
13324 this.list.on('mouseover', this.onViewOver, this);
13325 this.list.on('mousemove', this.onViewMove, this);
13326 this.list.on('scroll', this.onViewScroll, this);
13329 this.list.swallowEvent('mousewheel');
13330 this.assetHeight = 0;
13333 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
13334 this.assetHeight += this.header.getHeight();
13337 this.innerList = this.list.createChild({cls:cls+'-inner'});
13338 this.innerList.on('mouseover', this.onViewOver, this);
13339 this.innerList.on('mousemove', this.onViewMove, this);
13340 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13342 if(this.allowBlank && !this.pageSize && !this.disableClear){
13343 this.footer = this.list.createChild({cls:cls+'-ft'});
13344 this.pageTb = new Roo.Toolbar(this.footer);
13348 this.footer = this.list.createChild({cls:cls+'-ft'});
13349 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
13350 {pageSize: this.pageSize});
13354 if (this.pageTb && this.allowBlank && !this.disableClear) {
13356 this.pageTb.add(new Roo.Toolbar.Fill(), {
13357 cls: 'x-btn-icon x-btn-clear',
13359 handler: function()
13362 _this.clearValue();
13363 _this.onSelect(false, -1);
13368 this.assetHeight += this.footer.getHeight();
13373 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
13376 this.view = new Roo.View(this.list, this.tpl, {
13377 singleSelect:true, store: this.store, selectedClass: this.selectedClass
13379 //this.view.wrapEl.setDisplayed(false);
13380 this.view.on('click', this.onViewClick, this);
13383 this.store.on('beforeload', this.onBeforeLoad, this);
13384 this.store.on('load', this.onLoad, this);
13385 this.store.on('loadexception', this.onLoadException, this);
13387 if(this.resizable){
13388 this.resizer = new Roo.Resizable(this.list, {
13389 pinned:true, handles:'se'
13391 this.resizer.on('resize', function(r, w, h){
13392 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
13393 this.listWidth = w;
13394 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
13395 this.restrictHeight();
13397 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
13400 if(!this.editable){
13401 this.editable = true;
13402 this.setEditable(false);
13407 if (typeof(this.events.add.listeners) != 'undefined') {
13409 this.addicon = this.wrap.createChild(
13410 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
13412 this.addicon.on('click', function(e) {
13413 this.fireEvent('add', this);
13416 if (typeof(this.events.edit.listeners) != 'undefined') {
13418 this.editicon = this.wrap.createChild(
13419 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
13420 if (this.addicon) {
13421 this.editicon.setStyle('margin-left', '40px');
13423 this.editicon.on('click', function(e) {
13425 // we fire even if inothing is selected..
13426 this.fireEvent('edit', this, this.lastData );
13432 this.keyNav = new Roo.KeyNav(this.inputEl(), {
13433 "up" : function(e){
13434 this.inKeyMode = true;
13438 "down" : function(e){
13439 if(!this.isExpanded()){
13440 this.onTriggerClick();
13442 this.inKeyMode = true;
13447 "enter" : function(e){
13448 // this.onViewClick();
13452 if(this.fireEvent("specialkey", this, e)){
13453 this.onViewClick(false);
13459 "esc" : function(e){
13463 "tab" : function(e){
13466 if(this.fireEvent("specialkey", this, e)){
13467 this.onViewClick(false);
13475 doRelay : function(foo, bar, hname){
13476 if(hname == 'down' || this.scope.isExpanded()){
13477 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13486 this.queryDelay = Math.max(this.queryDelay || 10,
13487 this.mode == 'local' ? 10 : 250);
13490 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13492 if(this.typeAhead){
13493 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13495 if(this.editable !== false){
13496 this.inputEl().on("keyup", this.onKeyUp, this);
13498 if(this.forceSelection){
13499 this.inputEl().on('blur', this.doForce, this);
13503 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13504 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13508 initTickableEvents: function()
13512 if(this.hiddenName){
13514 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13516 this.hiddenField.dom.value =
13517 this.hiddenValue !== undefined ? this.hiddenValue :
13518 this.value !== undefined ? this.value : '';
13520 // prevent input submission
13521 this.el.dom.removeAttribute('name');
13522 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13527 // this.list = this.el.select('ul.dropdown-menu',true).first();
13529 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13530 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13531 if(this.triggerList){
13532 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
13535 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
13536 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
13538 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
13539 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
13541 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
13542 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
13544 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
13545 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
13546 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
13549 this.cancelBtn.hide();
13554 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13555 _this.list.setWidth(lw);
13558 this.list.on('mouseover', this.onViewOver, this);
13559 this.list.on('mousemove', this.onViewMove, this);
13561 this.list.on('scroll', this.onViewScroll, this);
13564 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}" type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
13567 this.view = new Roo.View(this.list, this.tpl, {
13568 singleSelect:true, tickable:true, parent:this, store: this.store, selectedClass: this.selectedClass
13571 //this.view.wrapEl.setDisplayed(false);
13572 this.view.on('click', this.onViewClick, this);
13576 this.store.on('beforeload', this.onBeforeLoad, this);
13577 this.store.on('load', this.onLoad, this);
13578 this.store.on('loadexception', this.onLoadException, this);
13581 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
13582 "up" : function(e){
13583 this.inKeyMode = true;
13587 "down" : function(e){
13588 this.inKeyMode = true;
13592 "enter" : function(e){
13593 if(this.fireEvent("specialkey", this, e)){
13594 this.onViewClick(false);
13600 "esc" : function(e){
13601 this.onTickableFooterButtonClick(e, false, false);
13604 "tab" : function(e){
13605 this.fireEvent("specialkey", this, e);
13607 this.onTickableFooterButtonClick(e, false, false);
13614 doRelay : function(e, fn, key){
13615 if(this.scope.isExpanded()){
13616 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13625 this.queryDelay = Math.max(this.queryDelay || 10,
13626 this.mode == 'local' ? 10 : 250);
13629 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13631 if(this.typeAhead){
13632 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13635 if(this.editable !== false){
13636 this.tickableInputEl().on("keyup", this.onKeyUp, this);
13639 this.indicator = this.indicatorEl();
13641 if(this.indicator){
13642 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
13643 this.indicator.hide();
13648 onDestroy : function(){
13650 this.view.setStore(null);
13651 this.view.el.removeAllListeners();
13652 this.view.el.remove();
13653 this.view.purgeListeners();
13656 this.list.dom.innerHTML = '';
13660 this.store.un('beforeload', this.onBeforeLoad, this);
13661 this.store.un('load', this.onLoad, this);
13662 this.store.un('loadexception', this.onLoadException, this);
13664 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
13668 fireKey : function(e){
13669 if(e.isNavKeyPress() && !this.list.isVisible()){
13670 this.fireEvent("specialkey", this, e);
13675 onResize: function(w, h){
13676 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
13678 // if(typeof w != 'number'){
13679 // // we do not handle it!?!?
13682 // var tw = this.trigger.getWidth();
13683 // // tw += this.addicon ? this.addicon.getWidth() : 0;
13684 // // tw += this.editicon ? this.editicon.getWidth() : 0;
13686 // this.inputEl().setWidth( this.adjustWidth('input', x));
13688 // //this.trigger.setStyle('left', x+'px');
13690 // if(this.list && this.listWidth === undefined){
13691 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
13692 // this.list.setWidth(lw);
13693 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13701 * Allow or prevent the user from directly editing the field text. If false is passed,
13702 * the user will only be able to select from the items defined in the dropdown list. This method
13703 * is the runtime equivalent of setting the 'editable' config option at config time.
13704 * @param {Boolean} value True to allow the user to directly edit the field text
13706 setEditable : function(value){
13707 if(value == this.editable){
13710 this.editable = value;
13712 this.inputEl().dom.setAttribute('readOnly', true);
13713 this.inputEl().on('mousedown', this.onTriggerClick, this);
13714 this.inputEl().addClass('x-combo-noedit');
13716 this.inputEl().dom.setAttribute('readOnly', false);
13717 this.inputEl().un('mousedown', this.onTriggerClick, this);
13718 this.inputEl().removeClass('x-combo-noedit');
13724 onBeforeLoad : function(combo,opts){
13725 if(!this.hasFocus){
13729 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
13731 this.restrictHeight();
13732 this.selectedIndex = -1;
13736 onLoad : function(){
13738 this.hasQuery = false;
13740 if(!this.hasFocus){
13744 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13745 this.loading.hide();
13748 if(this.store.getCount() > 0){
13751 this.restrictHeight();
13752 if(this.lastQuery == this.allQuery){
13753 if(this.editable && !this.tickable){
13754 this.inputEl().dom.select();
13758 !this.selectByValue(this.value, true) &&
13761 !this.store.lastOptions ||
13762 typeof(this.store.lastOptions.add) == 'undefined' ||
13763 this.store.lastOptions.add != true
13766 this.select(0, true);
13769 if(this.autoFocus){
13772 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
13773 this.taTask.delay(this.typeAheadDelay);
13777 this.onEmptyResults();
13783 onLoadException : function()
13785 this.hasQuery = false;
13787 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13788 this.loading.hide();
13791 if(this.tickable && this.editable){
13796 // only causes errors at present
13797 //Roo.log(this.store.reader.jsonData);
13798 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
13800 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
13806 onTypeAhead : function(){
13807 if(this.store.getCount() > 0){
13808 var r = this.store.getAt(0);
13809 var newValue = r.data[this.displayField];
13810 var len = newValue.length;
13811 var selStart = this.getRawValue().length;
13813 if(selStart != len){
13814 this.setRawValue(newValue);
13815 this.selectText(selStart, newValue.length);
13821 onSelect : function(record, index){
13823 if(this.fireEvent('beforeselect', this, record, index) !== false){
13825 this.setFromData(index > -1 ? record.data : false);
13828 this.fireEvent('select', this, record, index);
13833 * Returns the currently selected field value or empty string if no value is set.
13834 * @return {String} value The selected value
13836 getValue : function()
13838 if(Roo.isIOS && this.useNativeIOS){
13839 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
13843 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
13846 if(this.valueField){
13847 return typeof this.value != 'undefined' ? this.value : '';
13849 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
13853 getRawValue : function()
13855 if(Roo.isIOS && this.useNativeIOS){
13856 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
13859 var v = this.inputEl().getValue();
13865 * Clears any text/value currently set in the field
13867 clearValue : function(){
13869 if(this.hiddenField){
13870 this.hiddenField.dom.value = '';
13873 this.setRawValue('');
13874 this.lastSelectionText = '';
13875 this.lastData = false;
13877 var close = this.closeTriggerEl();
13888 * Sets the specified value into the field. If the value finds a match, the corresponding record text
13889 * will be displayed in the field. If the value does not match the data value of an existing item,
13890 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
13891 * Otherwise the field will be blank (although the value will still be set).
13892 * @param {String} value The value to match
13894 setValue : function(v)
13896 if(Roo.isIOS && this.useNativeIOS){
13897 this.setIOSValue(v);
13907 if(this.valueField){
13908 var r = this.findRecord(this.valueField, v);
13910 text = r.data[this.displayField];
13911 }else if(this.valueNotFoundText !== undefined){
13912 text = this.valueNotFoundText;
13915 this.lastSelectionText = text;
13916 if(this.hiddenField){
13917 this.hiddenField.dom.value = v;
13919 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
13922 var close = this.closeTriggerEl();
13925 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
13931 * @property {Object} the last set data for the element
13936 * Sets the value of the field based on a object which is related to the record format for the store.
13937 * @param {Object} value the value to set as. or false on reset?
13939 setFromData : function(o){
13946 var dv = ''; // display value
13947 var vv = ''; // value value..
13949 if (this.displayField) {
13950 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
13952 // this is an error condition!!!
13953 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
13956 if(this.valueField){
13957 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
13960 var close = this.closeTriggerEl();
13963 if(dv.length || vv * 1 > 0){
13965 this.blockFocus=true;
13971 if(this.hiddenField){
13972 this.hiddenField.dom.value = vv;
13974 this.lastSelectionText = dv;
13975 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
13979 // no hidden field.. - we store the value in 'value', but still display
13980 // display field!!!!
13981 this.lastSelectionText = dv;
13982 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
13989 reset : function(){
13990 // overridden so that last data is reset..
13997 this.setValue(this.originalValue);
13998 //this.clearInvalid();
13999 this.lastData = false;
14001 this.view.clearSelections();
14007 findRecord : function(prop, value){
14009 if(this.store.getCount() > 0){
14010 this.store.each(function(r){
14011 if(r.data[prop] == value){
14021 getName: function()
14023 // returns hidden if it's set..
14024 if (!this.rendered) {return ''};
14025 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
14029 onViewMove : function(e, t){
14030 this.inKeyMode = false;
14034 onViewOver : function(e, t){
14035 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
14038 var item = this.view.findItemFromChild(t);
14041 var index = this.view.indexOf(item);
14042 this.select(index, false);
14047 onViewClick : function(view, doFocus, el, e)
14049 var index = this.view.getSelectedIndexes()[0];
14051 var r = this.store.getAt(index);
14055 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
14062 Roo.each(this.tickItems, function(v,k){
14064 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
14066 _this.tickItems.splice(k, 1);
14068 if(typeof(e) == 'undefined' && view == false){
14069 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
14081 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
14082 this.tickItems.push(r.data);
14085 if(typeof(e) == 'undefined' && view == false){
14086 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
14093 this.onSelect(r, index);
14095 if(doFocus !== false && !this.blockFocus){
14096 this.inputEl().focus();
14101 restrictHeight : function(){
14102 //this.innerList.dom.style.height = '';
14103 //var inner = this.innerList.dom;
14104 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
14105 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
14106 //this.list.beginUpdate();
14107 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
14108 this.list.alignTo(this.inputEl(), this.listAlign);
14109 this.list.alignTo(this.inputEl(), this.listAlign);
14110 //this.list.endUpdate();
14114 onEmptyResults : function(){
14116 if(this.tickable && this.editable){
14117 this.hasFocus = false;
14118 this.restrictHeight();
14126 * Returns true if the dropdown list is expanded, else false.
14128 isExpanded : function(){
14129 return this.list.isVisible();
14133 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
14134 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14135 * @param {String} value The data value of the item to select
14136 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14137 * selected item if it is not currently in view (defaults to true)
14138 * @return {Boolean} True if the value matched an item in the list, else false
14140 selectByValue : function(v, scrollIntoView){
14141 if(v !== undefined && v !== null){
14142 var r = this.findRecord(this.valueField || this.displayField, v);
14144 this.select(this.store.indexOf(r), scrollIntoView);
14152 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
14153 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14154 * @param {Number} index The zero-based index of the list item to select
14155 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14156 * selected item if it is not currently in view (defaults to true)
14158 select : function(index, scrollIntoView){
14159 this.selectedIndex = index;
14160 this.view.select(index);
14161 if(scrollIntoView !== false){
14162 var el = this.view.getNode(index);
14164 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
14167 this.list.scrollChildIntoView(el, false);
14173 selectNext : function(){
14174 var ct = this.store.getCount();
14176 if(this.selectedIndex == -1){
14178 }else if(this.selectedIndex < ct-1){
14179 this.select(this.selectedIndex+1);
14185 selectPrev : function(){
14186 var ct = this.store.getCount();
14188 if(this.selectedIndex == -1){
14190 }else if(this.selectedIndex != 0){
14191 this.select(this.selectedIndex-1);
14197 onKeyUp : function(e){
14198 if(this.editable !== false && !e.isSpecialKey()){
14199 this.lastKey = e.getKey();
14200 this.dqTask.delay(this.queryDelay);
14205 validateBlur : function(){
14206 return !this.list || !this.list.isVisible();
14210 initQuery : function(){
14212 var v = this.getRawValue();
14214 if(this.tickable && this.editable){
14215 v = this.tickableInputEl().getValue();
14222 doForce : function(){
14223 if(this.inputEl().dom.value.length > 0){
14224 this.inputEl().dom.value =
14225 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
14231 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
14232 * query allowing the query action to be canceled if needed.
14233 * @param {String} query The SQL query to execute
14234 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
14235 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
14236 * saved in the current store (defaults to false)
14238 doQuery : function(q, forceAll){
14240 if(q === undefined || q === null){
14245 forceAll: forceAll,
14249 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
14254 forceAll = qe.forceAll;
14255 if(forceAll === true || (q.length >= this.minChars)){
14257 this.hasQuery = true;
14259 if(this.lastQuery != q || this.alwaysQuery){
14260 this.lastQuery = q;
14261 if(this.mode == 'local'){
14262 this.selectedIndex = -1;
14264 this.store.clearFilter();
14267 if(this.specialFilter){
14268 this.fireEvent('specialfilter', this);
14273 this.store.filter(this.displayField, q);
14276 this.store.fireEvent("datachanged", this.store);
14283 this.store.baseParams[this.queryParam] = q;
14285 var options = {params : this.getParams(q)};
14288 options.add = true;
14289 options.params.start = this.page * this.pageSize;
14292 this.store.load(options);
14295 * this code will make the page width larger, at the beginning, the list not align correctly,
14296 * we should expand the list on onLoad
14297 * so command out it
14302 this.selectedIndex = -1;
14307 this.loadNext = false;
14311 getParams : function(q){
14313 //p[this.queryParam] = q;
14317 p.limit = this.pageSize;
14323 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
14325 collapse : function(){
14326 if(!this.isExpanded()){
14332 this.hasFocus = false;
14336 this.cancelBtn.hide();
14337 this.trigger.show();
14340 this.tickableInputEl().dom.value = '';
14341 this.tickableInputEl().blur();
14346 Roo.get(document).un('mousedown', this.collapseIf, this);
14347 Roo.get(document).un('mousewheel', this.collapseIf, this);
14348 if (!this.editable) {
14349 Roo.get(document).un('keydown', this.listKeyPress, this);
14351 this.fireEvent('collapse', this);
14357 collapseIf : function(e){
14358 var in_combo = e.within(this.el);
14359 var in_list = e.within(this.list);
14360 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
14362 if (in_combo || in_list || is_list) {
14363 //e.stopPropagation();
14368 this.onTickableFooterButtonClick(e, false, false);
14376 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
14378 expand : function(){
14380 if(this.isExpanded() || !this.hasFocus){
14384 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
14385 this.list.setWidth(lw);
14391 this.restrictHeight();
14395 this.tickItems = Roo.apply([], this.item);
14398 this.cancelBtn.show();
14399 this.trigger.hide();
14402 this.tickableInputEl().focus();
14407 Roo.get(document).on('mousedown', this.collapseIf, this);
14408 Roo.get(document).on('mousewheel', this.collapseIf, this);
14409 if (!this.editable) {
14410 Roo.get(document).on('keydown', this.listKeyPress, this);
14413 this.fireEvent('expand', this);
14417 // Implements the default empty TriggerField.onTriggerClick function
14418 onTriggerClick : function(e)
14420 Roo.log('trigger click');
14422 if(this.disabled || !this.triggerList){
14427 this.loadNext = false;
14429 if(this.isExpanded()){
14431 if (!this.blockFocus) {
14432 this.inputEl().focus();
14436 this.hasFocus = true;
14437 if(this.triggerAction == 'all') {
14438 this.doQuery(this.allQuery, true);
14440 this.doQuery(this.getRawValue());
14442 if (!this.blockFocus) {
14443 this.inputEl().focus();
14448 onTickableTriggerClick : function(e)
14455 this.loadNext = false;
14456 this.hasFocus = true;
14458 if(this.triggerAction == 'all') {
14459 this.doQuery(this.allQuery, true);
14461 this.doQuery(this.getRawValue());
14465 onSearchFieldClick : function(e)
14467 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
14468 this.onTickableFooterButtonClick(e, false, false);
14472 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
14477 this.loadNext = false;
14478 this.hasFocus = true;
14480 if(this.triggerAction == 'all') {
14481 this.doQuery(this.allQuery, true);
14483 this.doQuery(this.getRawValue());
14487 listKeyPress : function(e)
14489 //Roo.log('listkeypress');
14490 // scroll to first matching element based on key pres..
14491 if (e.isSpecialKey()) {
14494 var k = String.fromCharCode(e.getKey()).toUpperCase();
14497 var csel = this.view.getSelectedNodes();
14498 var cselitem = false;
14500 var ix = this.view.indexOf(csel[0]);
14501 cselitem = this.store.getAt(ix);
14502 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
14508 this.store.each(function(v) {
14510 // start at existing selection.
14511 if (cselitem.id == v.id) {
14517 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
14518 match = this.store.indexOf(v);
14524 if (match === false) {
14525 return true; // no more action?
14528 this.view.select(match);
14529 var sn = Roo.get(this.view.getSelectedNodes()[0]);
14530 sn.scrollIntoView(sn.dom.parentNode, false);
14533 onViewScroll : function(e, t){
14535 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){
14539 this.hasQuery = true;
14541 this.loading = this.list.select('.loading', true).first();
14543 if(this.loading === null){
14544 this.list.createChild({
14546 cls: 'loading roo-select2-more-results roo-select2-active',
14547 html: 'Loading more results...'
14550 this.loading = this.list.select('.loading', true).first();
14552 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
14554 this.loading.hide();
14557 this.loading.show();
14562 this.loadNext = true;
14564 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
14569 addItem : function(o)
14571 var dv = ''; // display value
14573 if (this.displayField) {
14574 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14576 // this is an error condition!!!
14577 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14584 var choice = this.choices.createChild({
14586 cls: 'roo-select2-search-choice',
14595 cls: 'roo-select2-search-choice-close fa fa-times',
14600 }, this.searchField);
14602 var close = choice.select('a.roo-select2-search-choice-close', true).first();
14604 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
14612 this.inputEl().dom.value = '';
14617 onRemoveItem : function(e, _self, o)
14619 e.preventDefault();
14621 this.lastItem = Roo.apply([], this.item);
14623 var index = this.item.indexOf(o.data) * 1;
14626 Roo.log('not this item?!');
14630 this.item.splice(index, 1);
14635 this.fireEvent('remove', this, e);
14641 syncValue : function()
14643 if(!this.item.length){
14650 Roo.each(this.item, function(i){
14651 if(_this.valueField){
14652 value.push(i[_this.valueField]);
14659 this.value = value.join(',');
14661 if(this.hiddenField){
14662 this.hiddenField.dom.value = this.value;
14665 this.store.fireEvent("datachanged", this.store);
14670 clearItem : function()
14672 if(!this.multiple){
14678 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
14686 if(this.tickable && !Roo.isTouch){
14687 this.view.refresh();
14691 inputEl: function ()
14693 if(Roo.isIOS && this.useNativeIOS){
14694 return this.el.select('select.roo-ios-select', true).first();
14697 if(Roo.isTouch && this.mobileTouchView){
14698 return this.el.select('input.form-control',true).first();
14702 return this.searchField;
14705 return this.el.select('input.form-control',true).first();
14708 onTickableFooterButtonClick : function(e, btn, el)
14710 e.preventDefault();
14712 this.lastItem = Roo.apply([], this.item);
14714 if(btn && btn.name == 'cancel'){
14715 this.tickItems = Roo.apply([], this.item);
14724 Roo.each(this.tickItems, function(o){
14732 validate : function()
14734 if(this.getVisibilityEl().hasClass('hidden')){
14738 var v = this.getRawValue();
14741 v = this.getValue();
14744 if(this.disabled || this.allowBlank || v.length){
14749 this.markInvalid();
14753 tickableInputEl : function()
14755 if(!this.tickable || !this.editable){
14756 return this.inputEl();
14759 return this.inputEl().select('.roo-select2-search-field-input', true).first();
14763 getAutoCreateTouchView : function()
14768 cls: 'form-group' //input-group
14774 type : this.inputType,
14775 cls : 'form-control x-combo-noedit',
14776 autocomplete: 'new-password',
14777 placeholder : this.placeholder || '',
14782 input.name = this.name;
14786 input.cls += ' input-' + this.size;
14789 if (this.disabled) {
14790 input.disabled = true;
14801 inputblock.cls += ' input-group';
14803 inputblock.cn.unshift({
14805 cls : 'input-group-addon',
14810 if(this.removable && !this.multiple){
14811 inputblock.cls += ' roo-removable';
14813 inputblock.cn.push({
14816 cls : 'roo-combo-removable-btn close'
14820 if(this.hasFeedback && !this.allowBlank){
14822 inputblock.cls += ' has-feedback';
14824 inputblock.cn.push({
14826 cls: 'glyphicon form-control-feedback'
14833 inputblock.cls += (this.before) ? '' : ' input-group';
14835 inputblock.cn.push({
14837 cls : 'input-group-addon',
14848 cls: 'form-hidden-field'
14862 cls: 'form-hidden-field'
14866 cls: 'roo-select2-choices',
14870 cls: 'roo-select2-search-field',
14883 cls: 'roo-select2-container input-group roo-touchview-combobox ',
14889 if(!this.multiple && this.showToggleBtn){
14896 if (this.caret != false) {
14899 cls: 'fa fa-' + this.caret
14906 cls : 'input-group-addon btn dropdown-toggle',
14911 cls: 'combobox-clear',
14925 combobox.cls += ' roo-select2-container-multi';
14928 var align = this.labelAlign || this.parentLabelAlign();
14930 if (align ==='left' && this.fieldLabel.length) {
14935 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
14936 tooltip : 'This field is required'
14940 cls : 'control-label',
14941 html : this.fieldLabel
14952 var labelCfg = cfg.cn[1];
14953 var contentCfg = cfg.cn[2];
14956 if(this.indicatorpos == 'right'){
14961 cls : 'control-label',
14965 html : this.fieldLabel
14969 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
14970 tooltip : 'This field is required'
14983 labelCfg = cfg.cn[0];
14984 contentCfg = cfg.cn[1];
14989 if(this.labelWidth > 12){
14990 labelCfg.style = "width: " + this.labelWidth + 'px';
14993 if(this.labelWidth < 13 && this.labelmd == 0){
14994 this.labelmd = this.labelWidth;
14997 if(this.labellg > 0){
14998 labelCfg.cls += ' col-lg-' + this.labellg;
14999 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
15002 if(this.labelmd > 0){
15003 labelCfg.cls += ' col-md-' + this.labelmd;
15004 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
15007 if(this.labelsm > 0){
15008 labelCfg.cls += ' col-sm-' + this.labelsm;
15009 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
15012 if(this.labelxs > 0){
15013 labelCfg.cls += ' col-xs-' + this.labelxs;
15014 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
15018 } else if ( this.fieldLabel.length) {
15022 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15023 tooltip : 'This field is required'
15027 cls : 'control-label',
15028 html : this.fieldLabel
15039 if(this.indicatorpos == 'right'){
15043 cls : 'control-label',
15044 html : this.fieldLabel,
15048 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15049 tooltip : 'This field is required'
15066 var settings = this;
15068 ['xs','sm','md','lg'].map(function(size){
15069 if (settings[size]) {
15070 cfg.cls += ' col-' + size + '-' + settings[size];
15077 initTouchView : function()
15079 this.renderTouchView();
15081 this.touchViewEl.on('scroll', function(){
15082 this.el.dom.scrollTop = 0;
15085 this.originalValue = this.getValue();
15087 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
15089 this.inputEl().on("click", this.showTouchView, this);
15090 if (this.triggerEl) {
15091 this.triggerEl.on("click", this.showTouchView, this);
15095 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
15096 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
15098 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
15100 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
15101 this.store.on('load', this.onTouchViewLoad, this);
15102 this.store.on('loadexception', this.onTouchViewLoadException, this);
15104 if(this.hiddenName){
15106 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
15108 this.hiddenField.dom.value =
15109 this.hiddenValue !== undefined ? this.hiddenValue :
15110 this.value !== undefined ? this.value : '';
15112 this.el.dom.removeAttribute('name');
15113 this.hiddenField.dom.setAttribute('name', this.hiddenName);
15117 this.choices = this.el.select('ul.roo-select2-choices', true).first();
15118 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
15121 if(this.removable && !this.multiple){
15122 var close = this.closeTriggerEl();
15124 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
15125 close.on('click', this.removeBtnClick, this, close);
15129 * fix the bug in Safari iOS8
15131 this.inputEl().on("focus", function(e){
15132 document.activeElement.blur();
15140 renderTouchView : function()
15142 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
15143 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15145 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
15146 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15148 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
15149 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15150 this.touchViewBodyEl.setStyle('overflow', 'auto');
15152 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
15153 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15155 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
15156 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15160 showTouchView : function()
15166 this.touchViewHeaderEl.hide();
15168 if(this.modalTitle.length){
15169 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
15170 this.touchViewHeaderEl.show();
15173 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
15174 this.touchViewEl.show();
15176 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
15178 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
15179 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15181 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15183 if(this.modalTitle.length){
15184 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15187 this.touchViewBodyEl.setHeight(bodyHeight);
15191 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
15193 this.touchViewEl.addClass('in');
15196 this.doTouchViewQuery();
15200 hideTouchView : function()
15202 this.touchViewEl.removeClass('in');
15206 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
15208 this.touchViewEl.setStyle('display', 'none');
15213 setTouchViewValue : function()
15220 Roo.each(this.tickItems, function(o){
15225 this.hideTouchView();
15228 doTouchViewQuery : function()
15237 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
15241 if(!this.alwaysQuery || this.mode == 'local'){
15242 this.onTouchViewLoad();
15249 onTouchViewBeforeLoad : function(combo,opts)
15255 onTouchViewLoad : function()
15257 if(this.store.getCount() < 1){
15258 this.onTouchViewEmptyResults();
15262 this.clearTouchView();
15264 var rawValue = this.getRawValue();
15266 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
15268 this.tickItems = [];
15270 this.store.data.each(function(d, rowIndex){
15271 var row = this.touchViewListGroup.createChild(template);
15273 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
15274 row.addClass(d.data.cls);
15277 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15280 html : d.data[this.displayField]
15283 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
15284 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
15287 row.removeClass('selected');
15288 if(!this.multiple && this.valueField &&
15289 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
15292 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15293 row.addClass('selected');
15296 if(this.multiple && this.valueField &&
15297 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
15301 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15302 this.tickItems.push(d.data);
15305 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
15309 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
15311 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15313 if(this.modalTitle.length){
15314 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15317 var listHeight = this.touchViewListGroup.getHeight();
15321 if(firstChecked && listHeight > bodyHeight){
15322 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
15327 onTouchViewLoadException : function()
15329 this.hideTouchView();
15332 onTouchViewEmptyResults : function()
15334 this.clearTouchView();
15336 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
15338 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
15342 clearTouchView : function()
15344 this.touchViewListGroup.dom.innerHTML = '';
15347 onTouchViewClick : function(e, el, o)
15349 e.preventDefault();
15352 var rowIndex = o.rowIndex;
15354 var r = this.store.getAt(rowIndex);
15356 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
15358 if(!this.multiple){
15359 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
15360 c.dom.removeAttribute('checked');
15363 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15365 this.setFromData(r.data);
15367 var close = this.closeTriggerEl();
15373 this.hideTouchView();
15375 this.fireEvent('select', this, r, rowIndex);
15380 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
15381 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
15382 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
15386 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15387 this.addItem(r.data);
15388 this.tickItems.push(r.data);
15392 getAutoCreateNativeIOS : function()
15395 cls: 'form-group' //input-group,
15400 cls : 'roo-ios-select'
15404 combobox.name = this.name;
15407 if (this.disabled) {
15408 combobox.disabled = true;
15411 var settings = this;
15413 ['xs','sm','md','lg'].map(function(size){
15414 if (settings[size]) {
15415 cfg.cls += ' col-' + size + '-' + settings[size];
15425 initIOSView : function()
15427 this.store.on('load', this.onIOSViewLoad, this);
15432 onIOSViewLoad : function()
15434 if(this.store.getCount() < 1){
15438 this.clearIOSView();
15440 if(this.allowBlank) {
15442 var default_text = '-- SELECT --';
15444 if(this.placeholder.length){
15445 default_text = this.placeholder;
15448 if(this.emptyTitle.length){
15449 default_text += ' - ' + this.emptyTitle + ' -';
15452 var opt = this.inputEl().createChild({
15455 html : default_text
15459 o[this.valueField] = 0;
15460 o[this.displayField] = default_text;
15462 this.ios_options.push({
15469 this.store.data.each(function(d, rowIndex){
15473 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15474 html = d.data[this.displayField];
15479 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
15480 value = d.data[this.valueField];
15489 if(this.value == d.data[this.valueField]){
15490 option['selected'] = true;
15493 var opt = this.inputEl().createChild(option);
15495 this.ios_options.push({
15502 this.inputEl().on('change', function(){
15503 this.fireEvent('select', this);
15508 clearIOSView: function()
15510 this.inputEl().dom.innerHTML = '';
15512 this.ios_options = [];
15515 setIOSValue: function(v)
15519 if(!this.ios_options){
15523 Roo.each(this.ios_options, function(opts){
15525 opts.el.dom.removeAttribute('selected');
15527 if(opts.data[this.valueField] != v){
15531 opts.el.dom.setAttribute('selected', true);
15537 * @cfg {Boolean} grow
15541 * @cfg {Number} growMin
15545 * @cfg {Number} growMax
15554 Roo.apply(Roo.bootstrap.ComboBox, {
15558 cls: 'modal-header',
15580 cls: 'list-group-item',
15584 cls: 'roo-combobox-list-group-item-value'
15588 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
15602 listItemCheckbox : {
15604 cls: 'list-group-item',
15608 cls: 'roo-combobox-list-group-item-value'
15612 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
15628 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
15633 cls: 'modal-footer',
15641 cls: 'col-xs-6 text-left',
15644 cls: 'btn btn-danger roo-touch-view-cancel',
15650 cls: 'col-xs-6 text-right',
15653 cls: 'btn btn-success roo-touch-view-ok',
15664 Roo.apply(Roo.bootstrap.ComboBox, {
15666 touchViewTemplate : {
15668 cls: 'modal fade roo-combobox-touch-view',
15672 cls: 'modal-dialog',
15673 style : 'position:fixed', // we have to fix position....
15677 cls: 'modal-content',
15679 Roo.bootstrap.ComboBox.header,
15680 Roo.bootstrap.ComboBox.body,
15681 Roo.bootstrap.ComboBox.footer
15690 * Ext JS Library 1.1.1
15691 * Copyright(c) 2006-2007, Ext JS, LLC.
15693 * Originally Released Under LGPL - original licence link has changed is not relivant.
15696 * <script type="text/javascript">
15701 * @extends Roo.util.Observable
15702 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
15703 * This class also supports single and multi selection modes. <br>
15704 * Create a data model bound view:
15706 var store = new Roo.data.Store(...);
15708 var view = new Roo.View({
15710 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
15712 singleSelect: true,
15713 selectedClass: "ydataview-selected",
15717 // listen for node click?
15718 view.on("click", function(vw, index, node, e){
15719 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
15723 dataModel.load("foobar.xml");
15725 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
15727 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
15728 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
15730 * Note: old style constructor is still suported (container, template, config)
15733 * Create a new View
15734 * @param {Object} config The config object
15737 Roo.View = function(config, depreciated_tpl, depreciated_config){
15739 this.parent = false;
15741 if (typeof(depreciated_tpl) == 'undefined') {
15742 // new way.. - universal constructor.
15743 Roo.apply(this, config);
15744 this.el = Roo.get(this.el);
15747 this.el = Roo.get(config);
15748 this.tpl = depreciated_tpl;
15749 Roo.apply(this, depreciated_config);
15751 this.wrapEl = this.el.wrap().wrap();
15752 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
15755 if(typeof(this.tpl) == "string"){
15756 this.tpl = new Roo.Template(this.tpl);
15758 // support xtype ctors..
15759 this.tpl = new Roo.factory(this.tpl, Roo);
15763 this.tpl.compile();
15768 * @event beforeclick
15769 * Fires before a click is processed. Returns false to cancel the default action.
15770 * @param {Roo.View} this
15771 * @param {Number} index The index of the target node
15772 * @param {HTMLElement} node The target node
15773 * @param {Roo.EventObject} e The raw event object
15775 "beforeclick" : true,
15778 * Fires when a template node is clicked.
15779 * @param {Roo.View} this
15780 * @param {Number} index The index of the target node
15781 * @param {HTMLElement} node The target node
15782 * @param {Roo.EventObject} e The raw event object
15787 * Fires when a template node is double clicked.
15788 * @param {Roo.View} this
15789 * @param {Number} index The index of the target node
15790 * @param {HTMLElement} node The target node
15791 * @param {Roo.EventObject} e The raw event object
15795 * @event contextmenu
15796 * Fires when a template node is right clicked.
15797 * @param {Roo.View} this
15798 * @param {Number} index The index of the target node
15799 * @param {HTMLElement} node The target node
15800 * @param {Roo.EventObject} e The raw event object
15802 "contextmenu" : true,
15804 * @event selectionchange
15805 * Fires when the selected nodes change.
15806 * @param {Roo.View} this
15807 * @param {Array} selections Array of the selected nodes
15809 "selectionchange" : true,
15812 * @event beforeselect
15813 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
15814 * @param {Roo.View} this
15815 * @param {HTMLElement} node The node to be selected
15816 * @param {Array} selections Array of currently selected nodes
15818 "beforeselect" : true,
15820 * @event preparedata
15821 * Fires on every row to render, to allow you to change the data.
15822 * @param {Roo.View} this
15823 * @param {Object} data to be rendered (change this)
15825 "preparedata" : true
15833 "click": this.onClick,
15834 "dblclick": this.onDblClick,
15835 "contextmenu": this.onContextMenu,
15839 this.selections = [];
15841 this.cmp = new Roo.CompositeElementLite([]);
15843 this.store = Roo.factory(this.store, Roo.data);
15844 this.setStore(this.store, true);
15847 if ( this.footer && this.footer.xtype) {
15849 var fctr = this.wrapEl.appendChild(document.createElement("div"));
15851 this.footer.dataSource = this.store;
15852 this.footer.container = fctr;
15853 this.footer = Roo.factory(this.footer, Roo);
15854 fctr.insertFirst(this.el);
15856 // this is a bit insane - as the paging toolbar seems to detach the el..
15857 // dom.parentNode.parentNode.parentNode
15858 // they get detached?
15862 Roo.View.superclass.constructor.call(this);
15867 Roo.extend(Roo.View, Roo.util.Observable, {
15870 * @cfg {Roo.data.Store} store Data store to load data from.
15875 * @cfg {String|Roo.Element} el The container element.
15880 * @cfg {String|Roo.Template} tpl The template used by this View
15884 * @cfg {String} dataName the named area of the template to use as the data area
15885 * Works with domtemplates roo-name="name"
15889 * @cfg {String} selectedClass The css class to add to selected nodes
15891 selectedClass : "x-view-selected",
15893 * @cfg {String} emptyText The empty text to show when nothing is loaded.
15898 * @cfg {String} text to display on mask (default Loading)
15902 * @cfg {Boolean} multiSelect Allow multiple selection
15904 multiSelect : false,
15906 * @cfg {Boolean} singleSelect Allow single selection
15908 singleSelect: false,
15911 * @cfg {Boolean} toggleSelect - selecting
15913 toggleSelect : false,
15916 * @cfg {Boolean} tickable - selecting
15921 * Returns the element this view is bound to.
15922 * @return {Roo.Element}
15924 getEl : function(){
15925 return this.wrapEl;
15931 * Refreshes the view. - called by datachanged on the store. - do not call directly.
15933 refresh : function(){
15934 //Roo.log('refresh');
15937 // if we are using something like 'domtemplate', then
15938 // the what gets used is:
15939 // t.applySubtemplate(NAME, data, wrapping data..)
15940 // the outer template then get' applied with
15941 // the store 'extra data'
15942 // and the body get's added to the
15943 // roo-name="data" node?
15944 // <span class='roo-tpl-{name}'></span> ?????
15948 this.clearSelections();
15949 this.el.update("");
15951 var records = this.store.getRange();
15952 if(records.length < 1) {
15954 // is this valid?? = should it render a template??
15956 this.el.update(this.emptyText);
15960 if (this.dataName) {
15961 this.el.update(t.apply(this.store.meta)); //????
15962 el = this.el.child('.roo-tpl-' + this.dataName);
15965 for(var i = 0, len = records.length; i < len; i++){
15966 var data = this.prepareData(records[i].data, i, records[i]);
15967 this.fireEvent("preparedata", this, data, i, records[i]);
15969 var d = Roo.apply({}, data);
15972 Roo.apply(d, {'roo-id' : Roo.id()});
15976 Roo.each(this.parent.item, function(item){
15977 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
15980 Roo.apply(d, {'roo-data-checked' : 'checked'});
15984 html[html.length] = Roo.util.Format.trim(
15986 t.applySubtemplate(this.dataName, d, this.store.meta) :
15993 el.update(html.join(""));
15994 this.nodes = el.dom.childNodes;
15995 this.updateIndexes(0);
16000 * Function to override to reformat the data that is sent to
16001 * the template for each node.
16002 * DEPRICATED - use the preparedata event handler.
16003 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
16004 * a JSON object for an UpdateManager bound view).
16006 prepareData : function(data, index, record)
16008 this.fireEvent("preparedata", this, data, index, record);
16012 onUpdate : function(ds, record){
16013 // Roo.log('on update');
16014 this.clearSelections();
16015 var index = this.store.indexOf(record);
16016 var n = this.nodes[index];
16017 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
16018 n.parentNode.removeChild(n);
16019 this.updateIndexes(index, index);
16025 onAdd : function(ds, records, index)
16027 //Roo.log(['on Add', ds, records, index] );
16028 this.clearSelections();
16029 if(this.nodes.length == 0){
16033 var n = this.nodes[index];
16034 for(var i = 0, len = records.length; i < len; i++){
16035 var d = this.prepareData(records[i].data, i, records[i]);
16037 this.tpl.insertBefore(n, d);
16040 this.tpl.append(this.el, d);
16043 this.updateIndexes(index);
16046 onRemove : function(ds, record, index){
16047 // Roo.log('onRemove');
16048 this.clearSelections();
16049 var el = this.dataName ?
16050 this.el.child('.roo-tpl-' + this.dataName) :
16053 el.dom.removeChild(this.nodes[index]);
16054 this.updateIndexes(index);
16058 * Refresh an individual node.
16059 * @param {Number} index
16061 refreshNode : function(index){
16062 this.onUpdate(this.store, this.store.getAt(index));
16065 updateIndexes : function(startIndex, endIndex){
16066 var ns = this.nodes;
16067 startIndex = startIndex || 0;
16068 endIndex = endIndex || ns.length - 1;
16069 for(var i = startIndex; i <= endIndex; i++){
16070 ns[i].nodeIndex = i;
16075 * Changes the data store this view uses and refresh the view.
16076 * @param {Store} store
16078 setStore : function(store, initial){
16079 if(!initial && this.store){
16080 this.store.un("datachanged", this.refresh);
16081 this.store.un("add", this.onAdd);
16082 this.store.un("remove", this.onRemove);
16083 this.store.un("update", this.onUpdate);
16084 this.store.un("clear", this.refresh);
16085 this.store.un("beforeload", this.onBeforeLoad);
16086 this.store.un("load", this.onLoad);
16087 this.store.un("loadexception", this.onLoad);
16091 store.on("datachanged", this.refresh, this);
16092 store.on("add", this.onAdd, this);
16093 store.on("remove", this.onRemove, this);
16094 store.on("update", this.onUpdate, this);
16095 store.on("clear", this.refresh, this);
16096 store.on("beforeload", this.onBeforeLoad, this);
16097 store.on("load", this.onLoad, this);
16098 store.on("loadexception", this.onLoad, this);
16106 * onbeforeLoad - masks the loading area.
16109 onBeforeLoad : function(store,opts)
16111 //Roo.log('onBeforeLoad');
16113 this.el.update("");
16115 this.el.mask(this.mask ? this.mask : "Loading" );
16117 onLoad : function ()
16124 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
16125 * @param {HTMLElement} node
16126 * @return {HTMLElement} The template node
16128 findItemFromChild : function(node){
16129 var el = this.dataName ?
16130 this.el.child('.roo-tpl-' + this.dataName,true) :
16133 if(!node || node.parentNode == el){
16136 var p = node.parentNode;
16137 while(p && p != el){
16138 if(p.parentNode == el){
16147 onClick : function(e){
16148 var item = this.findItemFromChild(e.getTarget());
16150 var index = this.indexOf(item);
16151 if(this.onItemClick(item, index, e) !== false){
16152 this.fireEvent("click", this, index, item, e);
16155 this.clearSelections();
16160 onContextMenu : function(e){
16161 var item = this.findItemFromChild(e.getTarget());
16163 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
16168 onDblClick : function(e){
16169 var item = this.findItemFromChild(e.getTarget());
16171 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
16175 onItemClick : function(item, index, e)
16177 if(this.fireEvent("beforeclick", this, index, item, e) === false){
16180 if (this.toggleSelect) {
16181 var m = this.isSelected(item) ? 'unselect' : 'select';
16184 _t[m](item, true, false);
16187 if(this.multiSelect || this.singleSelect){
16188 if(this.multiSelect && e.shiftKey && this.lastSelection){
16189 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
16191 this.select(item, this.multiSelect && e.ctrlKey);
16192 this.lastSelection = item;
16195 if(!this.tickable){
16196 e.preventDefault();
16204 * Get the number of selected nodes.
16207 getSelectionCount : function(){
16208 return this.selections.length;
16212 * Get the currently selected nodes.
16213 * @return {Array} An array of HTMLElements
16215 getSelectedNodes : function(){
16216 return this.selections;
16220 * Get the indexes of the selected nodes.
16223 getSelectedIndexes : function(){
16224 var indexes = [], s = this.selections;
16225 for(var i = 0, len = s.length; i < len; i++){
16226 indexes.push(s[i].nodeIndex);
16232 * Clear all selections
16233 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
16235 clearSelections : function(suppressEvent){
16236 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
16237 this.cmp.elements = this.selections;
16238 this.cmp.removeClass(this.selectedClass);
16239 this.selections = [];
16240 if(!suppressEvent){
16241 this.fireEvent("selectionchange", this, this.selections);
16247 * Returns true if the passed node is selected
16248 * @param {HTMLElement/Number} node The node or node index
16249 * @return {Boolean}
16251 isSelected : function(node){
16252 var s = this.selections;
16256 node = this.getNode(node);
16257 return s.indexOf(node) !== -1;
16262 * @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
16263 * @param {Boolean} keepExisting (optional) true to keep existing selections
16264 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16266 select : function(nodeInfo, keepExisting, suppressEvent){
16267 if(nodeInfo instanceof Array){
16269 this.clearSelections(true);
16271 for(var i = 0, len = nodeInfo.length; i < len; i++){
16272 this.select(nodeInfo[i], true, true);
16276 var node = this.getNode(nodeInfo);
16277 if(!node || this.isSelected(node)){
16278 return; // already selected.
16281 this.clearSelections(true);
16284 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
16285 Roo.fly(node).addClass(this.selectedClass);
16286 this.selections.push(node);
16287 if(!suppressEvent){
16288 this.fireEvent("selectionchange", this, this.selections);
16296 * @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
16297 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
16298 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16300 unselect : function(nodeInfo, keepExisting, suppressEvent)
16302 if(nodeInfo instanceof Array){
16303 Roo.each(this.selections, function(s) {
16304 this.unselect(s, nodeInfo);
16308 var node = this.getNode(nodeInfo);
16309 if(!node || !this.isSelected(node)){
16310 //Roo.log("not selected");
16311 return; // not selected.
16315 Roo.each(this.selections, function(s) {
16317 Roo.fly(node).removeClass(this.selectedClass);
16324 this.selections= ns;
16325 this.fireEvent("selectionchange", this, this.selections);
16329 * Gets a template node.
16330 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16331 * @return {HTMLElement} The node or null if it wasn't found
16333 getNode : function(nodeInfo){
16334 if(typeof nodeInfo == "string"){
16335 return document.getElementById(nodeInfo);
16336 }else if(typeof nodeInfo == "number"){
16337 return this.nodes[nodeInfo];
16343 * Gets a range template nodes.
16344 * @param {Number} startIndex
16345 * @param {Number} endIndex
16346 * @return {Array} An array of nodes
16348 getNodes : function(start, end){
16349 var ns = this.nodes;
16350 start = start || 0;
16351 end = typeof end == "undefined" ? ns.length - 1 : end;
16354 for(var i = start; i <= end; i++){
16358 for(var i = start; i >= end; i--){
16366 * Finds the index of the passed node
16367 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16368 * @return {Number} The index of the node or -1
16370 indexOf : function(node){
16371 node = this.getNode(node);
16372 if(typeof node.nodeIndex == "number"){
16373 return node.nodeIndex;
16375 var ns = this.nodes;
16376 for(var i = 0, len = ns.length; i < len; i++){
16387 * based on jquery fullcalendar
16391 Roo.bootstrap = Roo.bootstrap || {};
16393 * @class Roo.bootstrap.Calendar
16394 * @extends Roo.bootstrap.Component
16395 * Bootstrap Calendar class
16396 * @cfg {Boolean} loadMask (true|false) default false
16397 * @cfg {Object} header generate the user specific header of the calendar, default false
16400 * Create a new Container
16401 * @param {Object} config The config object
16406 Roo.bootstrap.Calendar = function(config){
16407 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
16411 * Fires when a date is selected
16412 * @param {DatePicker} this
16413 * @param {Date} date The selected date
16417 * @event monthchange
16418 * Fires when the displayed month changes
16419 * @param {DatePicker} this
16420 * @param {Date} date The selected month
16422 'monthchange': true,
16424 * @event evententer
16425 * Fires when mouse over an event
16426 * @param {Calendar} this
16427 * @param {event} Event
16429 'evententer': true,
16431 * @event eventleave
16432 * Fires when the mouse leaves an
16433 * @param {Calendar} this
16436 'eventleave': true,
16438 * @event eventclick
16439 * Fires when the mouse click an
16440 * @param {Calendar} this
16449 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
16452 * @cfg {Number} startDay
16453 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
16461 getAutoCreate : function(){
16464 var fc_button = function(name, corner, style, content ) {
16465 return Roo.apply({},{
16467 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
16469 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
16472 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
16483 style : 'width:100%',
16490 cls : 'fc-header-left',
16492 fc_button('prev', 'left', 'arrow', '‹' ),
16493 fc_button('next', 'right', 'arrow', '›' ),
16494 { tag: 'span', cls: 'fc-header-space' },
16495 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
16503 cls : 'fc-header-center',
16507 cls: 'fc-header-title',
16510 html : 'month / year'
16518 cls : 'fc-header-right',
16520 /* fc_button('month', 'left', '', 'month' ),
16521 fc_button('week', '', '', 'week' ),
16522 fc_button('day', 'right', '', 'day' )
16534 header = this.header;
16537 var cal_heads = function() {
16539 // fixme - handle this.
16541 for (var i =0; i < Date.dayNames.length; i++) {
16542 var d = Date.dayNames[i];
16545 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
16546 html : d.substring(0,3)
16550 ret[0].cls += ' fc-first';
16551 ret[6].cls += ' fc-last';
16554 var cal_cell = function(n) {
16557 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
16562 cls: 'fc-day-number',
16566 cls: 'fc-day-content',
16570 style: 'position: relative;' // height: 17px;
16582 var cal_rows = function() {
16585 for (var r = 0; r < 6; r++) {
16592 for (var i =0; i < Date.dayNames.length; i++) {
16593 var d = Date.dayNames[i];
16594 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
16597 row.cn[0].cls+=' fc-first';
16598 row.cn[0].cn[0].style = 'min-height:90px';
16599 row.cn[6].cls+=' fc-last';
16603 ret[0].cls += ' fc-first';
16604 ret[4].cls += ' fc-prev-last';
16605 ret[5].cls += ' fc-last';
16612 cls: 'fc-border-separate',
16613 style : 'width:100%',
16621 cls : 'fc-first fc-last',
16639 cls : 'fc-content',
16640 style : "position: relative;",
16643 cls : 'fc-view fc-view-month fc-grid',
16644 style : 'position: relative',
16645 unselectable : 'on',
16648 cls : 'fc-event-container',
16649 style : 'position:absolute;z-index:8;top:0;left:0;'
16667 initEvents : function()
16670 throw "can not find store for calendar";
16676 style: "text-align:center",
16680 style: "background-color:white;width:50%;margin:250 auto",
16684 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
16695 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
16697 var size = this.el.select('.fc-content', true).first().getSize();
16698 this.maskEl.setSize(size.width, size.height);
16699 this.maskEl.enableDisplayMode("block");
16700 if(!this.loadMask){
16701 this.maskEl.hide();
16704 this.store = Roo.factory(this.store, Roo.data);
16705 this.store.on('load', this.onLoad, this);
16706 this.store.on('beforeload', this.onBeforeLoad, this);
16710 this.cells = this.el.select('.fc-day',true);
16711 //Roo.log(this.cells);
16712 this.textNodes = this.el.query('.fc-day-number');
16713 this.cells.addClassOnOver('fc-state-hover');
16715 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
16716 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
16717 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
16718 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
16720 this.on('monthchange', this.onMonthChange, this);
16722 this.update(new Date().clearTime());
16725 resize : function() {
16726 var sz = this.el.getSize();
16728 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
16729 this.el.select('.fc-day-content div',true).setHeight(34);
16734 showPrevMonth : function(e){
16735 this.update(this.activeDate.add("mo", -1));
16737 showToday : function(e){
16738 this.update(new Date().clearTime());
16741 showNextMonth : function(e){
16742 this.update(this.activeDate.add("mo", 1));
16746 showPrevYear : function(){
16747 this.update(this.activeDate.add("y", -1));
16751 showNextYear : function(){
16752 this.update(this.activeDate.add("y", 1));
16757 update : function(date)
16759 var vd = this.activeDate;
16760 this.activeDate = date;
16761 // if(vd && this.el){
16762 // var t = date.getTime();
16763 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
16764 // Roo.log('using add remove');
16766 // this.fireEvent('monthchange', this, date);
16768 // this.cells.removeClass("fc-state-highlight");
16769 // this.cells.each(function(c){
16770 // if(c.dateValue == t){
16771 // c.addClass("fc-state-highlight");
16772 // setTimeout(function(){
16773 // try{c.dom.firstChild.focus();}catch(e){}
16783 var days = date.getDaysInMonth();
16785 var firstOfMonth = date.getFirstDateOfMonth();
16786 var startingPos = firstOfMonth.getDay()-this.startDay;
16788 if(startingPos < this.startDay){
16792 var pm = date.add(Date.MONTH, -1);
16793 var prevStart = pm.getDaysInMonth()-startingPos;
16795 this.cells = this.el.select('.fc-day',true);
16796 this.textNodes = this.el.query('.fc-day-number');
16797 this.cells.addClassOnOver('fc-state-hover');
16799 var cells = this.cells.elements;
16800 var textEls = this.textNodes;
16802 Roo.each(cells, function(cell){
16803 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
16806 days += startingPos;
16808 // convert everything to numbers so it's fast
16809 var day = 86400000;
16810 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
16813 //Roo.log(prevStart);
16815 var today = new Date().clearTime().getTime();
16816 var sel = date.clearTime().getTime();
16817 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
16818 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
16819 var ddMatch = this.disabledDatesRE;
16820 var ddText = this.disabledDatesText;
16821 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
16822 var ddaysText = this.disabledDaysText;
16823 var format = this.format;
16825 var setCellClass = function(cal, cell){
16829 //Roo.log('set Cell Class');
16831 var t = d.getTime();
16835 cell.dateValue = t;
16837 cell.className += " fc-today";
16838 cell.className += " fc-state-highlight";
16839 cell.title = cal.todayText;
16842 // disable highlight in other month..
16843 //cell.className += " fc-state-highlight";
16848 cell.className = " fc-state-disabled";
16849 cell.title = cal.minText;
16853 cell.className = " fc-state-disabled";
16854 cell.title = cal.maxText;
16858 if(ddays.indexOf(d.getDay()) != -1){
16859 cell.title = ddaysText;
16860 cell.className = " fc-state-disabled";
16863 if(ddMatch && format){
16864 var fvalue = d.dateFormat(format);
16865 if(ddMatch.test(fvalue)){
16866 cell.title = ddText.replace("%0", fvalue);
16867 cell.className = " fc-state-disabled";
16871 if (!cell.initialClassName) {
16872 cell.initialClassName = cell.dom.className;
16875 cell.dom.className = cell.initialClassName + ' ' + cell.className;
16880 for(; i < startingPos; i++) {
16881 textEls[i].innerHTML = (++prevStart);
16882 d.setDate(d.getDate()+1);
16884 cells[i].className = "fc-past fc-other-month";
16885 setCellClass(this, cells[i]);
16890 for(; i < days; i++){
16891 intDay = i - startingPos + 1;
16892 textEls[i].innerHTML = (intDay);
16893 d.setDate(d.getDate()+1);
16895 cells[i].className = ''; // "x-date-active";
16896 setCellClass(this, cells[i]);
16900 for(; i < 42; i++) {
16901 textEls[i].innerHTML = (++extraDays);
16902 d.setDate(d.getDate()+1);
16904 cells[i].className = "fc-future fc-other-month";
16905 setCellClass(this, cells[i]);
16908 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
16910 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
16912 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
16913 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
16915 if(totalRows != 6){
16916 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
16917 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
16920 this.fireEvent('monthchange', this, date);
16924 if(!this.internalRender){
16925 var main = this.el.dom.firstChild;
16926 var w = main.offsetWidth;
16927 this.el.setWidth(w + this.el.getBorderWidth("lr"));
16928 Roo.fly(main).setWidth(w);
16929 this.internalRender = true;
16930 // opera does not respect the auto grow header center column
16931 // then, after it gets a width opera refuses to recalculate
16932 // without a second pass
16933 if(Roo.isOpera && !this.secondPass){
16934 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
16935 this.secondPass = true;
16936 this.update.defer(10, this, [date]);
16943 findCell : function(dt) {
16944 dt = dt.clearTime().getTime();
16946 this.cells.each(function(c){
16947 //Roo.log("check " +c.dateValue + '?=' + dt);
16948 if(c.dateValue == dt){
16958 findCells : function(ev) {
16959 var s = ev.start.clone().clearTime().getTime();
16961 var e= ev.end.clone().clearTime().getTime();
16964 this.cells.each(function(c){
16965 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
16967 if(c.dateValue > e){
16970 if(c.dateValue < s){
16979 // findBestRow: function(cells)
16983 // for (var i =0 ; i < cells.length;i++) {
16984 // ret = Math.max(cells[i].rows || 0,ret);
16991 addItem : function(ev)
16993 // look for vertical location slot in
16994 var cells = this.findCells(ev);
16996 // ev.row = this.findBestRow(cells);
16998 // work out the location.
17002 for(var i =0; i < cells.length; i++) {
17004 cells[i].row = cells[0].row;
17007 cells[i].row = cells[i].row + 1;
17017 if (crow.start.getY() == cells[i].getY()) {
17019 crow.end = cells[i];
17036 cells[0].events.push(ev);
17038 this.calevents.push(ev);
17041 clearEvents: function() {
17043 if(!this.calevents){
17047 Roo.each(this.cells.elements, function(c){
17053 Roo.each(this.calevents, function(e) {
17054 Roo.each(e.els, function(el) {
17055 el.un('mouseenter' ,this.onEventEnter, this);
17056 el.un('mouseleave' ,this.onEventLeave, this);
17061 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
17067 renderEvents: function()
17071 this.cells.each(function(c) {
17080 if(c.row != c.events.length){
17081 r = 4 - (4 - (c.row - c.events.length));
17084 c.events = ev.slice(0, r);
17085 c.more = ev.slice(r);
17087 if(c.more.length && c.more.length == 1){
17088 c.events.push(c.more.pop());
17091 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
17095 this.cells.each(function(c) {
17097 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
17100 for (var e = 0; e < c.events.length; e++){
17101 var ev = c.events[e];
17102 var rows = ev.rows;
17104 for(var i = 0; i < rows.length; i++) {
17106 // how many rows should it span..
17109 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
17110 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
17112 unselectable : "on",
17115 cls: 'fc-event-inner',
17119 // cls: 'fc-event-time',
17120 // html : cells.length > 1 ? '' : ev.time
17124 cls: 'fc-event-title',
17125 html : String.format('{0}', ev.title)
17132 cls: 'ui-resizable-handle ui-resizable-e',
17133 html : '  '
17140 cfg.cls += ' fc-event-start';
17142 if ((i+1) == rows.length) {
17143 cfg.cls += ' fc-event-end';
17146 var ctr = _this.el.select('.fc-event-container',true).first();
17147 var cg = ctr.createChild(cfg);
17149 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
17150 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
17152 var r = (c.more.length) ? 1 : 0;
17153 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
17154 cg.setWidth(ebox.right - sbox.x -2);
17156 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
17157 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
17158 cg.on('click', _this.onEventClick, _this, ev);
17169 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
17170 style : 'position: absolute',
17171 unselectable : "on",
17174 cls: 'fc-event-inner',
17178 cls: 'fc-event-title',
17186 cls: 'ui-resizable-handle ui-resizable-e',
17187 html : '  '
17193 var ctr = _this.el.select('.fc-event-container',true).first();
17194 var cg = ctr.createChild(cfg);
17196 var sbox = c.select('.fc-day-content',true).first().getBox();
17197 var ebox = c.select('.fc-day-content',true).first().getBox();
17199 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
17200 cg.setWidth(ebox.right - sbox.x -2);
17202 cg.on('click', _this.onMoreEventClick, _this, c.more);
17212 onEventEnter: function (e, el,event,d) {
17213 this.fireEvent('evententer', this, el, event);
17216 onEventLeave: function (e, el,event,d) {
17217 this.fireEvent('eventleave', this, el, event);
17220 onEventClick: function (e, el,event,d) {
17221 this.fireEvent('eventclick', this, el, event);
17224 onMonthChange: function () {
17228 onMoreEventClick: function(e, el, more)
17232 this.calpopover.placement = 'right';
17233 this.calpopover.setTitle('More');
17235 this.calpopover.setContent('');
17237 var ctr = this.calpopover.el.select('.popover-content', true).first();
17239 Roo.each(more, function(m){
17241 cls : 'fc-event-hori fc-event-draggable',
17244 var cg = ctr.createChild(cfg);
17246 cg.on('click', _this.onEventClick, _this, m);
17249 this.calpopover.show(el);
17254 onLoad: function ()
17256 this.calevents = [];
17259 if(this.store.getCount() > 0){
17260 this.store.data.each(function(d){
17263 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
17264 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
17265 time : d.data.start_time,
17266 title : d.data.title,
17267 description : d.data.description,
17268 venue : d.data.venue
17273 this.renderEvents();
17275 if(this.calevents.length && this.loadMask){
17276 this.maskEl.hide();
17280 onBeforeLoad: function()
17282 this.clearEvents();
17284 this.maskEl.show();
17298 * @class Roo.bootstrap.Popover
17299 * @extends Roo.bootstrap.Component
17300 * Bootstrap Popover class
17301 * @cfg {String} html contents of the popover (or false to use children..)
17302 * @cfg {String} title of popover (or false to hide)
17303 * @cfg {String} placement how it is placed
17304 * @cfg {String} trigger click || hover (or false to trigger manually)
17305 * @cfg {String} over what (parent or false to trigger manually.)
17306 * @cfg {Number} delay - delay before showing
17309 * Create a new Popover
17310 * @param {Object} config The config object
17313 Roo.bootstrap.Popover = function(config){
17314 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
17320 * After the popover show
17322 * @param {Roo.bootstrap.Popover} this
17327 * After the popover hide
17329 * @param {Roo.bootstrap.Popover} this
17335 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
17337 title: 'Fill in a title',
17340 placement : 'right',
17341 trigger : 'hover', // hover
17347 can_build_overlaid : false,
17349 getChildContainer : function()
17351 return this.el.select('.popover-content',true).first();
17354 getAutoCreate : function(){
17357 cls : 'popover roo-dynamic',
17358 style: 'display:block',
17364 cls : 'popover-inner',
17368 cls: 'popover-title',
17372 cls : 'popover-content',
17383 setTitle: function(str)
17386 this.el.select('.popover-title',true).first().dom.innerHTML = str;
17388 setContent: function(str)
17391 this.el.select('.popover-content',true).first().dom.innerHTML = str;
17393 // as it get's added to the bottom of the page.
17394 onRender : function(ct, position)
17396 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
17398 var cfg = Roo.apply({}, this.getAutoCreate());
17402 cfg.cls += ' ' + this.cls;
17405 cfg.style = this.style;
17407 //Roo.log("adding to ");
17408 this.el = Roo.get(document.body).createChild(cfg, position);
17409 // Roo.log(this.el);
17414 initEvents : function()
17416 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
17417 this.el.enableDisplayMode('block');
17419 if (this.over === false) {
17422 if (this.triggers === false) {
17425 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17426 var triggers = this.trigger ? this.trigger.split(' ') : [];
17427 Roo.each(triggers, function(trigger) {
17429 if (trigger == 'click') {
17430 on_el.on('click', this.toggle, this);
17431 } else if (trigger != 'manual') {
17432 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
17433 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
17435 on_el.on(eventIn ,this.enter, this);
17436 on_el.on(eventOut, this.leave, this);
17447 toggle : function () {
17448 this.hoverState == 'in' ? this.leave() : this.enter();
17451 enter : function () {
17453 clearTimeout(this.timeout);
17455 this.hoverState = 'in';
17457 if (!this.delay || !this.delay.show) {
17462 this.timeout = setTimeout(function () {
17463 if (_t.hoverState == 'in') {
17466 }, this.delay.show)
17469 leave : function() {
17470 clearTimeout(this.timeout);
17472 this.hoverState = 'out';
17474 if (!this.delay || !this.delay.hide) {
17479 this.timeout = setTimeout(function () {
17480 if (_t.hoverState == 'out') {
17483 }, this.delay.hide)
17486 show : function (on_el)
17489 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17493 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
17494 if (this.html !== false) {
17495 this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
17497 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
17498 if (!this.title.length) {
17499 this.el.select('.popover-title',true).hide();
17502 var placement = typeof this.placement == 'function' ?
17503 this.placement.call(this, this.el, on_el) :
17506 var autoToken = /\s?auto?\s?/i;
17507 var autoPlace = autoToken.test(placement);
17509 placement = placement.replace(autoToken, '') || 'top';
17513 //this.el.setXY([0,0]);
17515 this.el.dom.style.display='block';
17516 this.el.addClass(placement);
17518 //this.el.appendTo(on_el);
17520 var p = this.getPosition();
17521 var box = this.el.getBox();
17526 var align = Roo.bootstrap.Popover.alignment[placement];
17529 this.el.alignTo(on_el, align[0],align[1]);
17530 //var arrow = this.el.select('.arrow',true).first();
17531 //arrow.set(align[2],
17533 this.el.addClass('in');
17536 if (this.el.hasClass('fade')) {
17540 this.hoverState = 'in';
17542 this.fireEvent('show', this);
17547 this.el.setXY([0,0]);
17548 this.el.removeClass('in');
17550 this.hoverState = null;
17552 this.fireEvent('hide', this);
17557 Roo.bootstrap.Popover.alignment = {
17558 'left' : ['r-l', [-10,0], 'right'],
17559 'right' : ['l-r', [10,0], 'left'],
17560 'bottom' : ['t-b', [0,10], 'top'],
17561 'top' : [ 'b-t', [0,-10], 'bottom']
17572 * @class Roo.bootstrap.Progress
17573 * @extends Roo.bootstrap.Component
17574 * Bootstrap Progress class
17575 * @cfg {Boolean} striped striped of the progress bar
17576 * @cfg {Boolean} active animated of the progress bar
17580 * Create a new Progress
17581 * @param {Object} config The config object
17584 Roo.bootstrap.Progress = function(config){
17585 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
17588 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
17593 getAutoCreate : function(){
17601 cfg.cls += ' progress-striped';
17605 cfg.cls += ' active';
17624 * @class Roo.bootstrap.ProgressBar
17625 * @extends Roo.bootstrap.Component
17626 * Bootstrap ProgressBar class
17627 * @cfg {Number} aria_valuenow aria-value now
17628 * @cfg {Number} aria_valuemin aria-value min
17629 * @cfg {Number} aria_valuemax aria-value max
17630 * @cfg {String} label label for the progress bar
17631 * @cfg {String} panel (success | info | warning | danger )
17632 * @cfg {String} role role of the progress bar
17633 * @cfg {String} sr_only text
17637 * Create a new ProgressBar
17638 * @param {Object} config The config object
17641 Roo.bootstrap.ProgressBar = function(config){
17642 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
17645 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
17649 aria_valuemax : 100,
17655 getAutoCreate : function()
17660 cls: 'progress-bar',
17661 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
17673 cfg.role = this.role;
17676 if(this.aria_valuenow){
17677 cfg['aria-valuenow'] = this.aria_valuenow;
17680 if(this.aria_valuemin){
17681 cfg['aria-valuemin'] = this.aria_valuemin;
17684 if(this.aria_valuemax){
17685 cfg['aria-valuemax'] = this.aria_valuemax;
17688 if(this.label && !this.sr_only){
17689 cfg.html = this.label;
17693 cfg.cls += ' progress-bar-' + this.panel;
17699 update : function(aria_valuenow)
17701 this.aria_valuenow = aria_valuenow;
17703 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
17718 * @class Roo.bootstrap.TabGroup
17719 * @extends Roo.bootstrap.Column
17720 * Bootstrap Column class
17721 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
17722 * @cfg {Boolean} carousel true to make the group behave like a carousel
17723 * @cfg {Boolean} bullets show bullets for the panels
17724 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
17725 * @cfg {Number} timer auto slide timer .. default 0 millisecond
17726 * @cfg {Boolean} showarrow (true|false) show arrow default true
17729 * Create a new TabGroup
17730 * @param {Object} config The config object
17733 Roo.bootstrap.TabGroup = function(config){
17734 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
17736 this.navId = Roo.id();
17739 Roo.bootstrap.TabGroup.register(this);
17743 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
17746 transition : false,
17751 slideOnTouch : false,
17754 getAutoCreate : function()
17756 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
17758 cfg.cls += ' tab-content';
17760 if (this.carousel) {
17761 cfg.cls += ' carousel slide';
17764 cls : 'carousel-inner',
17768 if(this.bullets && !Roo.isTouch){
17771 cls : 'carousel-bullets',
17775 if(this.bullets_cls){
17776 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
17783 cfg.cn[0].cn.push(bullets);
17786 if(this.showarrow){
17787 cfg.cn[0].cn.push({
17789 class : 'carousel-arrow',
17793 class : 'carousel-prev',
17797 class : 'fa fa-chevron-left'
17803 class : 'carousel-next',
17807 class : 'fa fa-chevron-right'
17820 initEvents: function()
17822 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
17823 // this.el.on("touchstart", this.onTouchStart, this);
17826 if(this.autoslide){
17829 this.slideFn = window.setInterval(function() {
17830 _this.showPanelNext();
17834 if(this.showarrow){
17835 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
17836 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
17842 // onTouchStart : function(e, el, o)
17844 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
17848 // this.showPanelNext();
17852 getChildContainer : function()
17854 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
17858 * register a Navigation item
17859 * @param {Roo.bootstrap.NavItem} the navitem to add
17861 register : function(item)
17863 this.tabs.push( item);
17864 item.navId = this.navId; // not really needed..
17869 getActivePanel : function()
17872 Roo.each(this.tabs, function(t) {
17882 getPanelByName : function(n)
17885 Roo.each(this.tabs, function(t) {
17886 if (t.tabId == n) {
17894 indexOfPanel : function(p)
17897 Roo.each(this.tabs, function(t,i) {
17898 if (t.tabId == p.tabId) {
17907 * show a specific panel
17908 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
17909 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
17911 showPanel : function (pan)
17913 if(this.transition || typeof(pan) == 'undefined'){
17914 Roo.log("waiting for the transitionend");
17918 if (typeof(pan) == 'number') {
17919 pan = this.tabs[pan];
17922 if (typeof(pan) == 'string') {
17923 pan = this.getPanelByName(pan);
17926 var cur = this.getActivePanel();
17929 Roo.log('pan or acitve pan is undefined');
17933 if (pan.tabId == this.getActivePanel().tabId) {
17937 if (false === cur.fireEvent('beforedeactivate')) {
17941 if(this.bullets > 0 && !Roo.isTouch){
17942 this.setActiveBullet(this.indexOfPanel(pan));
17945 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
17947 this.transition = true;
17948 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
17949 var lr = dir == 'next' ? 'left' : 'right';
17950 pan.el.addClass(dir); // or prev
17951 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
17952 cur.el.addClass(lr); // or right
17953 pan.el.addClass(lr);
17956 cur.el.on('transitionend', function() {
17957 Roo.log("trans end?");
17959 pan.el.removeClass([lr,dir]);
17960 pan.setActive(true);
17962 cur.el.removeClass([lr]);
17963 cur.setActive(false);
17965 _this.transition = false;
17967 }, this, { single: true } );
17972 cur.setActive(false);
17973 pan.setActive(true);
17978 showPanelNext : function()
17980 var i = this.indexOfPanel(this.getActivePanel());
17982 if (i >= this.tabs.length - 1 && !this.autoslide) {
17986 if (i >= this.tabs.length - 1 && this.autoslide) {
17990 this.showPanel(this.tabs[i+1]);
17993 showPanelPrev : function()
17995 var i = this.indexOfPanel(this.getActivePanel());
17997 if (i < 1 && !this.autoslide) {
18001 if (i < 1 && this.autoslide) {
18002 i = this.tabs.length;
18005 this.showPanel(this.tabs[i-1]);
18009 addBullet: function()
18011 if(!this.bullets || Roo.isTouch){
18014 var ctr = this.el.select('.carousel-bullets',true).first();
18015 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
18016 var bullet = ctr.createChild({
18017 cls : 'bullet bullet-' + i
18018 },ctr.dom.lastChild);
18023 bullet.on('click', (function(e, el, o, ii, t){
18025 e.preventDefault();
18027 this.showPanel(ii);
18029 if(this.autoslide && this.slideFn){
18030 clearInterval(this.slideFn);
18031 this.slideFn = window.setInterval(function() {
18032 _this.showPanelNext();
18036 }).createDelegate(this, [i, bullet], true));
18041 setActiveBullet : function(i)
18047 Roo.each(this.el.select('.bullet', true).elements, function(el){
18048 el.removeClass('selected');
18051 var bullet = this.el.select('.bullet-' + i, true).first();
18057 bullet.addClass('selected');
18068 Roo.apply(Roo.bootstrap.TabGroup, {
18072 * register a Navigation Group
18073 * @param {Roo.bootstrap.NavGroup} the navgroup to add
18075 register : function(navgrp)
18077 this.groups[navgrp.navId] = navgrp;
18081 * fetch a Navigation Group based on the navigation ID
18082 * if one does not exist , it will get created.
18083 * @param {string} the navgroup to add
18084 * @returns {Roo.bootstrap.NavGroup} the navgroup
18086 get: function(navId) {
18087 if (typeof(this.groups[navId]) == 'undefined') {
18088 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
18090 return this.groups[navId] ;
18105 * @class Roo.bootstrap.TabPanel
18106 * @extends Roo.bootstrap.Component
18107 * Bootstrap TabPanel class
18108 * @cfg {Boolean} active panel active
18109 * @cfg {String} html panel content
18110 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
18111 * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
18112 * @cfg {String} href click to link..
18116 * Create a new TabPanel
18117 * @param {Object} config The config object
18120 Roo.bootstrap.TabPanel = function(config){
18121 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
18125 * Fires when the active status changes
18126 * @param {Roo.bootstrap.TabPanel} this
18127 * @param {Boolean} state the new state
18132 * @event beforedeactivate
18133 * Fires before a tab is de-activated - can be used to do validation on a form.
18134 * @param {Roo.bootstrap.TabPanel} this
18135 * @return {Boolean} false if there is an error
18138 'beforedeactivate': true
18141 this.tabId = this.tabId || Roo.id();
18145 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
18153 getAutoCreate : function(){
18156 // item is needed for carousel - not sure if it has any effect otherwise
18157 cls: 'tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
18158 html: this.html || ''
18162 cfg.cls += ' active';
18166 cfg.tabId = this.tabId;
18173 initEvents: function()
18175 var p = this.parent();
18177 this.navId = this.navId || p.navId;
18179 if (typeof(this.navId) != 'undefined') {
18180 // not really needed.. but just in case.. parent should be a NavGroup.
18181 var tg = Roo.bootstrap.TabGroup.get(this.navId);
18185 var i = tg.tabs.length - 1;
18187 if(this.active && tg.bullets > 0 && i < tg.bullets){
18188 tg.setActiveBullet(i);
18192 this.el.on('click', this.onClick, this);
18195 this.el.on("touchstart", this.onTouchStart, this);
18196 this.el.on("touchmove", this.onTouchMove, this);
18197 this.el.on("touchend", this.onTouchEnd, this);
18202 onRender : function(ct, position)
18204 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
18207 setActive : function(state)
18209 Roo.log("panel - set active " + this.tabId + "=" + state);
18211 this.active = state;
18213 this.el.removeClass('active');
18215 } else if (!this.el.hasClass('active')) {
18216 this.el.addClass('active');
18219 this.fireEvent('changed', this, state);
18222 onClick : function(e)
18224 e.preventDefault();
18226 if(!this.href.length){
18230 window.location.href = this.href;
18239 onTouchStart : function(e)
18241 this.swiping = false;
18243 this.startX = e.browserEvent.touches[0].clientX;
18244 this.startY = e.browserEvent.touches[0].clientY;
18247 onTouchMove : function(e)
18249 this.swiping = true;
18251 this.endX = e.browserEvent.touches[0].clientX;
18252 this.endY = e.browserEvent.touches[0].clientY;
18255 onTouchEnd : function(e)
18262 var tabGroup = this.parent();
18264 if(this.endX > this.startX){ // swiping right
18265 tabGroup.showPanelPrev();
18269 if(this.startX > this.endX){ // swiping left
18270 tabGroup.showPanelNext();
18289 * @class Roo.bootstrap.DateField
18290 * @extends Roo.bootstrap.Input
18291 * Bootstrap DateField class
18292 * @cfg {Number} weekStart default 0
18293 * @cfg {String} viewMode default empty, (months|years)
18294 * @cfg {String} minViewMode default empty, (months|years)
18295 * @cfg {Number} startDate default -Infinity
18296 * @cfg {Number} endDate default Infinity
18297 * @cfg {Boolean} todayHighlight default false
18298 * @cfg {Boolean} todayBtn default false
18299 * @cfg {Boolean} calendarWeeks default false
18300 * @cfg {Object} daysOfWeekDisabled default empty
18301 * @cfg {Boolean} singleMode default false (true | false)
18303 * @cfg {Boolean} keyboardNavigation default true
18304 * @cfg {String} language default en
18307 * Create a new DateField
18308 * @param {Object} config The config object
18311 Roo.bootstrap.DateField = function(config){
18312 Roo.bootstrap.DateField.superclass.constructor.call(this, config);
18316 * Fires when this field show.
18317 * @param {Roo.bootstrap.DateField} this
18318 * @param {Mixed} date The date value
18323 * Fires when this field hide.
18324 * @param {Roo.bootstrap.DateField} this
18325 * @param {Mixed} date The date value
18330 * Fires when select a date.
18331 * @param {Roo.bootstrap.DateField} this
18332 * @param {Mixed} date The date value
18336 * @event beforeselect
18337 * Fires when before select a date.
18338 * @param {Roo.bootstrap.DateField} this
18339 * @param {Mixed} date The date value
18341 beforeselect : true
18345 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, {
18348 * @cfg {String} format
18349 * The default date format string which can be overriden for localization support. The format must be
18350 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18354 * @cfg {String} altFormats
18355 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18356 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18358 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
18366 todayHighlight : false,
18372 keyboardNavigation: true,
18374 calendarWeeks: false,
18376 startDate: -Infinity,
18380 daysOfWeekDisabled: [],
18384 singleMode : false,
18386 UTCDate: function()
18388 return new Date(Date.UTC.apply(Date, arguments));
18391 UTCToday: function()
18393 var today = new Date();
18394 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
18397 getDate: function() {
18398 var d = this.getUTCDate();
18399 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
18402 getUTCDate: function() {
18406 setDate: function(d) {
18407 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
18410 setUTCDate: function(d) {
18412 this.setValue(this.formatDate(this.date));
18415 onRender: function(ct, position)
18418 Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
18420 this.language = this.language || 'en';
18421 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
18422 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
18424 this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
18425 this.format = this.format || 'm/d/y';
18426 this.isInline = false;
18427 this.isInput = true;
18428 this.component = this.el.select('.add-on', true).first() || false;
18429 this.component = (this.component && this.component.length === 0) ? false : this.component;
18430 this.hasInput = this.component && this.inputEl().length;
18432 if (typeof(this.minViewMode === 'string')) {
18433 switch (this.minViewMode) {
18435 this.minViewMode = 1;
18438 this.minViewMode = 2;
18441 this.minViewMode = 0;
18446 if (typeof(this.viewMode === 'string')) {
18447 switch (this.viewMode) {
18460 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
18462 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
18464 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18466 this.picker().on('mousedown', this.onMousedown, this);
18467 this.picker().on('click', this.onClick, this);
18469 this.picker().addClass('datepicker-dropdown');
18471 this.startViewMode = this.viewMode;
18473 if(this.singleMode){
18474 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
18475 v.setVisibilityMode(Roo.Element.DISPLAY);
18479 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18480 v.setStyle('width', '189px');
18484 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
18485 if(!this.calendarWeeks){
18490 v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18491 v.attr('colspan', function(i, val){
18492 return parseInt(val) + 1;
18497 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
18499 this.setStartDate(this.startDate);
18500 this.setEndDate(this.endDate);
18502 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
18509 if(this.isInline) {
18514 picker : function()
18516 return this.pickerEl;
18517 // return this.el.select('.datepicker', true).first();
18520 fillDow: function()
18522 var dowCnt = this.weekStart;
18531 if(this.calendarWeeks){
18539 while (dowCnt < this.weekStart + 7) {
18543 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
18547 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
18550 fillMonths: function()
18553 var months = this.picker().select('>.datepicker-months td', true).first();
18555 months.dom.innerHTML = '';
18561 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
18564 months.createChild(month);
18571 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;
18573 if (this.date < this.startDate) {
18574 this.viewDate = new Date(this.startDate);
18575 } else if (this.date > this.endDate) {
18576 this.viewDate = new Date(this.endDate);
18578 this.viewDate = new Date(this.date);
18586 var d = new Date(this.viewDate),
18587 year = d.getUTCFullYear(),
18588 month = d.getUTCMonth(),
18589 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
18590 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
18591 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
18592 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
18593 currentDate = this.date && this.date.valueOf(),
18594 today = this.UTCToday();
18596 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
18598 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18600 // this.picker.select('>tfoot th.today').
18601 // .text(dates[this.language].today)
18602 // .toggle(this.todayBtn !== false);
18604 this.updateNavArrows();
18607 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
18609 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
18611 prevMonth.setUTCDate(day);
18613 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
18615 var nextMonth = new Date(prevMonth);
18617 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
18619 nextMonth = nextMonth.valueOf();
18621 var fillMonths = false;
18623 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
18625 while(prevMonth.valueOf() < nextMonth) {
18628 if (prevMonth.getUTCDay() === this.weekStart) {
18630 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
18638 if(this.calendarWeeks){
18639 // ISO 8601: First week contains first thursday.
18640 // ISO also states week starts on Monday, but we can be more abstract here.
18642 // Start of current week: based on weekstart/current date
18643 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
18644 // Thursday of this week
18645 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
18646 // First Thursday of year, year from thursday
18647 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
18648 // Calendar week: ms between thursdays, div ms per day, div 7 days
18649 calWeek = (th - yth) / 864e5 / 7 + 1;
18651 fillMonths.cn.push({
18659 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
18661 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
18664 if (this.todayHighlight &&
18665 prevMonth.getUTCFullYear() == today.getFullYear() &&
18666 prevMonth.getUTCMonth() == today.getMonth() &&
18667 prevMonth.getUTCDate() == today.getDate()) {
18668 clsName += ' today';
18671 if (currentDate && prevMonth.valueOf() === currentDate) {
18672 clsName += ' active';
18675 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
18676 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
18677 clsName += ' disabled';
18680 fillMonths.cn.push({
18682 cls: 'day ' + clsName,
18683 html: prevMonth.getDate()
18686 prevMonth.setDate(prevMonth.getDate()+1);
18689 var currentYear = this.date && this.date.getUTCFullYear();
18690 var currentMonth = this.date && this.date.getUTCMonth();
18692 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
18694 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
18695 v.removeClass('active');
18697 if(currentYear === year && k === currentMonth){
18698 v.addClass('active');
18701 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
18702 v.addClass('disabled');
18708 year = parseInt(year/10, 10) * 10;
18710 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
18712 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
18715 for (var i = -1; i < 11; i++) {
18716 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
18718 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
18726 showMode: function(dir)
18729 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
18732 Roo.each(this.picker().select('>div',true).elements, function(v){
18733 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18736 this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
18741 if(this.isInline) {
18745 this.picker().removeClass(['bottom', 'top']);
18747 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
18749 * place to the top of element!
18753 this.picker().addClass('top');
18754 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
18759 this.picker().addClass('bottom');
18761 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
18764 parseDate : function(value)
18766 if(!value || value instanceof Date){
18769 var v = Date.parseDate(value, this.format);
18770 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
18771 v = Date.parseDate(value, 'Y-m-d');
18773 if(!v && this.altFormats){
18774 if(!this.altFormatsArray){
18775 this.altFormatsArray = this.altFormats.split("|");
18777 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18778 v = Date.parseDate(value, this.altFormatsArray[i]);
18784 formatDate : function(date, fmt)
18786 return (!date || !(date instanceof Date)) ?
18787 date : date.dateFormat(fmt || this.format);
18790 onFocus : function()
18792 Roo.bootstrap.DateField.superclass.onFocus.call(this);
18796 onBlur : function()
18798 Roo.bootstrap.DateField.superclass.onBlur.call(this);
18800 var d = this.inputEl().getValue();
18809 this.picker().show();
18813 this.fireEvent('show', this, this.date);
18818 if(this.isInline) {
18821 this.picker().hide();
18822 this.viewMode = this.startViewMode;
18825 this.fireEvent('hide', this, this.date);
18829 onMousedown: function(e)
18831 e.stopPropagation();
18832 e.preventDefault();
18837 Roo.bootstrap.DateField.superclass.keyup.call(this);
18841 setValue: function(v)
18843 if(this.fireEvent('beforeselect', this, v) !== false){
18844 var d = new Date(this.parseDate(v) ).clearTime();
18846 if(isNaN(d.getTime())){
18847 this.date = this.viewDate = '';
18848 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
18852 v = this.formatDate(d);
18854 Roo.bootstrap.DateField.superclass.setValue.call(this, v);
18856 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
18860 this.fireEvent('select', this, this.date);
18864 getValue: function()
18866 return this.formatDate(this.date);
18869 fireKey: function(e)
18871 if (!this.picker().isVisible()){
18872 if (e.keyCode == 27) { // allow escape to hide and re-show picker
18878 var dateChanged = false,
18880 newDate, newViewDate;
18885 e.preventDefault();
18889 if (!this.keyboardNavigation) {
18892 dir = e.keyCode == 37 ? -1 : 1;
18895 newDate = this.moveYear(this.date, dir);
18896 newViewDate = this.moveYear(this.viewDate, dir);
18897 } else if (e.shiftKey){
18898 newDate = this.moveMonth(this.date, dir);
18899 newViewDate = this.moveMonth(this.viewDate, dir);
18901 newDate = new Date(this.date);
18902 newDate.setUTCDate(this.date.getUTCDate() + dir);
18903 newViewDate = new Date(this.viewDate);
18904 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
18906 if (this.dateWithinRange(newDate)){
18907 this.date = newDate;
18908 this.viewDate = newViewDate;
18909 this.setValue(this.formatDate(this.date));
18911 e.preventDefault();
18912 dateChanged = true;
18917 if (!this.keyboardNavigation) {
18920 dir = e.keyCode == 38 ? -1 : 1;
18922 newDate = this.moveYear(this.date, dir);
18923 newViewDate = this.moveYear(this.viewDate, dir);
18924 } else if (e.shiftKey){
18925 newDate = this.moveMonth(this.date, dir);
18926 newViewDate = this.moveMonth(this.viewDate, dir);
18928 newDate = new Date(this.date);
18929 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
18930 newViewDate = new Date(this.viewDate);
18931 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
18933 if (this.dateWithinRange(newDate)){
18934 this.date = newDate;
18935 this.viewDate = newViewDate;
18936 this.setValue(this.formatDate(this.date));
18938 e.preventDefault();
18939 dateChanged = true;
18943 this.setValue(this.formatDate(this.date));
18945 e.preventDefault();
18948 this.setValue(this.formatDate(this.date));
18962 onClick: function(e)
18964 e.stopPropagation();
18965 e.preventDefault();
18967 var target = e.getTarget();
18969 if(target.nodeName.toLowerCase() === 'i'){
18970 target = Roo.get(target).dom.parentNode;
18973 var nodeName = target.nodeName;
18974 var className = target.className;
18975 var html = target.innerHTML;
18976 //Roo.log(nodeName);
18978 switch(nodeName.toLowerCase()) {
18980 switch(className) {
18986 var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
18987 switch(this.viewMode){
18989 this.viewDate = this.moveMonth(this.viewDate, dir);
18993 this.viewDate = this.moveYear(this.viewDate, dir);
18999 var date = new Date();
19000 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
19002 this.setValue(this.formatDate(this.date));
19009 if (className.indexOf('disabled') < 0) {
19010 this.viewDate.setUTCDate(1);
19011 if (className.indexOf('month') > -1) {
19012 this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
19014 var year = parseInt(html, 10) || 0;
19015 this.viewDate.setUTCFullYear(year);
19019 if(this.singleMode){
19020 this.setValue(this.formatDate(this.viewDate));
19031 //Roo.log(className);
19032 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
19033 var day = parseInt(html, 10) || 1;
19034 var year = this.viewDate.getUTCFullYear(),
19035 month = this.viewDate.getUTCMonth();
19037 if (className.indexOf('old') > -1) {
19044 } else if (className.indexOf('new') > -1) {
19052 //Roo.log([year,month,day]);
19053 this.date = this.UTCDate(year, month, day,0,0,0,0);
19054 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
19056 //Roo.log(this.formatDate(this.date));
19057 this.setValue(this.formatDate(this.date));
19064 setStartDate: function(startDate)
19066 this.startDate = startDate || -Infinity;
19067 if (this.startDate !== -Infinity) {
19068 this.startDate = this.parseDate(this.startDate);
19071 this.updateNavArrows();
19074 setEndDate: function(endDate)
19076 this.endDate = endDate || Infinity;
19077 if (this.endDate !== Infinity) {
19078 this.endDate = this.parseDate(this.endDate);
19081 this.updateNavArrows();
19084 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
19086 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
19087 if (typeof(this.daysOfWeekDisabled) !== 'object') {
19088 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
19090 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
19091 return parseInt(d, 10);
19094 this.updateNavArrows();
19097 updateNavArrows: function()
19099 if(this.singleMode){
19103 var d = new Date(this.viewDate),
19104 year = d.getUTCFullYear(),
19105 month = d.getUTCMonth();
19107 Roo.each(this.picker().select('.prev', true).elements, function(v){
19109 switch (this.viewMode) {
19112 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
19118 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
19125 Roo.each(this.picker().select('.next', true).elements, function(v){
19127 switch (this.viewMode) {
19130 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
19136 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
19144 moveMonth: function(date, dir)
19149 var new_date = new Date(date.valueOf()),
19150 day = new_date.getUTCDate(),
19151 month = new_date.getUTCMonth(),
19152 mag = Math.abs(dir),
19154 dir = dir > 0 ? 1 : -1;
19157 // If going back one month, make sure month is not current month
19158 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
19160 return new_date.getUTCMonth() == month;
19162 // If going forward one month, make sure month is as expected
19163 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
19165 return new_date.getUTCMonth() != new_month;
19167 new_month = month + dir;
19168 new_date.setUTCMonth(new_month);
19169 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
19170 if (new_month < 0 || new_month > 11) {
19171 new_month = (new_month + 12) % 12;
19174 // For magnitudes >1, move one month at a time...
19175 for (var i=0; i<mag; i++) {
19176 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
19177 new_date = this.moveMonth(new_date, dir);
19179 // ...then reset the day, keeping it in the new month
19180 new_month = new_date.getUTCMonth();
19181 new_date.setUTCDate(day);
19183 return new_month != new_date.getUTCMonth();
19186 // Common date-resetting loop -- if date is beyond end of month, make it
19189 new_date.setUTCDate(--day);
19190 new_date.setUTCMonth(new_month);
19195 moveYear: function(date, dir)
19197 return this.moveMonth(date, dir*12);
19200 dateWithinRange: function(date)
19202 return date >= this.startDate && date <= this.endDate;
19208 this.picker().remove();
19211 validateValue : function(value)
19213 if(this.getVisibilityEl().hasClass('hidden')){
19217 if(value.length < 1) {
19218 if(this.allowBlank){
19224 if(value.length < this.minLength){
19227 if(value.length > this.maxLength){
19231 var vt = Roo.form.VTypes;
19232 if(!vt[this.vtype](value, this)){
19236 if(typeof this.validator == "function"){
19237 var msg = this.validator(value);
19243 if(this.regex && !this.regex.test(value)){
19247 if(typeof(this.parseDate(value)) == 'undefined'){
19251 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
19255 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
19263 setVisible : function(visible)
19269 this.getEl().removeClass('hidden');
19275 this.getEl().addClass('hidden');
19280 Roo.apply(Roo.bootstrap.DateField, {
19291 html: '<i class="fa fa-arrow-left"/>'
19301 html: '<i class="fa fa-arrow-right"/>'
19343 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
19344 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
19345 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
19346 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19347 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
19360 navFnc: 'FullYear',
19365 navFnc: 'FullYear',
19370 Roo.apply(Roo.bootstrap.DateField, {
19374 cls: 'datepicker dropdown-menu roo-dynamic',
19378 cls: 'datepicker-days',
19382 cls: 'table-condensed',
19384 Roo.bootstrap.DateField.head,
19388 Roo.bootstrap.DateField.footer
19395 cls: 'datepicker-months',
19399 cls: 'table-condensed',
19401 Roo.bootstrap.DateField.head,
19402 Roo.bootstrap.DateField.content,
19403 Roo.bootstrap.DateField.footer
19410 cls: 'datepicker-years',
19414 cls: 'table-condensed',
19416 Roo.bootstrap.DateField.head,
19417 Roo.bootstrap.DateField.content,
19418 Roo.bootstrap.DateField.footer
19437 * @class Roo.bootstrap.TimeField
19438 * @extends Roo.bootstrap.Input
19439 * Bootstrap DateField class
19443 * Create a new TimeField
19444 * @param {Object} config The config object
19447 Roo.bootstrap.TimeField = function(config){
19448 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
19452 * Fires when this field show.
19453 * @param {Roo.bootstrap.DateField} thisthis
19454 * @param {Mixed} date The date value
19459 * Fires when this field hide.
19460 * @param {Roo.bootstrap.DateField} this
19461 * @param {Mixed} date The date value
19466 * Fires when select a date.
19467 * @param {Roo.bootstrap.DateField} this
19468 * @param {Mixed} date The date value
19474 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
19477 * @cfg {String} format
19478 * The default time format string which can be overriden for localization support. The format must be
19479 * valid according to {@link Date#parseDate} (defaults to 'H:i').
19483 onRender: function(ct, position)
19486 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
19488 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
19490 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19492 this.pop = this.picker().select('>.datepicker-time',true).first();
19493 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19495 this.picker().on('mousedown', this.onMousedown, this);
19496 this.picker().on('click', this.onClick, this);
19498 this.picker().addClass('datepicker-dropdown');
19503 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
19504 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
19505 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
19506 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
19507 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
19508 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
19512 fireKey: function(e){
19513 if (!this.picker().isVisible()){
19514 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19520 e.preventDefault();
19528 this.onTogglePeriod();
19531 this.onIncrementMinutes();
19534 this.onDecrementMinutes();
19543 onClick: function(e) {
19544 e.stopPropagation();
19545 e.preventDefault();
19548 picker : function()
19550 return this.el.select('.datepicker', true).first();
19553 fillTime: function()
19555 var time = this.pop.select('tbody', true).first();
19557 time.dom.innerHTML = '';
19572 cls: 'hours-up glyphicon glyphicon-chevron-up'
19592 cls: 'minutes-up glyphicon glyphicon-chevron-up'
19613 cls: 'timepicker-hour',
19628 cls: 'timepicker-minute',
19643 cls: 'btn btn-primary period',
19665 cls: 'hours-down glyphicon glyphicon-chevron-down'
19685 cls: 'minutes-down glyphicon glyphicon-chevron-down'
19703 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
19710 var hours = this.time.getHours();
19711 var minutes = this.time.getMinutes();
19724 hours = hours - 12;
19728 hours = '0' + hours;
19732 minutes = '0' + minutes;
19735 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
19736 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
19737 this.pop.select('button', true).first().dom.innerHTML = period;
19743 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
19745 var cls = ['bottom'];
19747 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
19754 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
19759 this.picker().addClass(cls.join('-'));
19763 Roo.each(cls, function(c){
19765 _this.picker().setTop(_this.inputEl().getHeight());
19769 _this.picker().setTop(0 - _this.picker().getHeight());
19774 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
19778 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
19785 onFocus : function()
19787 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
19791 onBlur : function()
19793 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
19799 this.picker().show();
19804 this.fireEvent('show', this, this.date);
19809 this.picker().hide();
19812 this.fireEvent('hide', this, this.date);
19815 setTime : function()
19818 this.setValue(this.time.format(this.format));
19820 this.fireEvent('select', this, this.date);
19825 onMousedown: function(e){
19826 e.stopPropagation();
19827 e.preventDefault();
19830 onIncrementHours: function()
19832 Roo.log('onIncrementHours');
19833 this.time = this.time.add(Date.HOUR, 1);
19838 onDecrementHours: function()
19840 Roo.log('onDecrementHours');
19841 this.time = this.time.add(Date.HOUR, -1);
19845 onIncrementMinutes: function()
19847 Roo.log('onIncrementMinutes');
19848 this.time = this.time.add(Date.MINUTE, 1);
19852 onDecrementMinutes: function()
19854 Roo.log('onDecrementMinutes');
19855 this.time = this.time.add(Date.MINUTE, -1);
19859 onTogglePeriod: function()
19861 Roo.log('onTogglePeriod');
19862 this.time = this.time.add(Date.HOUR, 12);
19869 Roo.apply(Roo.bootstrap.TimeField, {
19899 cls: 'btn btn-info ok',
19911 Roo.apply(Roo.bootstrap.TimeField, {
19915 cls: 'datepicker dropdown-menu',
19919 cls: 'datepicker-time',
19923 cls: 'table-condensed',
19925 Roo.bootstrap.TimeField.content,
19926 Roo.bootstrap.TimeField.footer
19945 * @class Roo.bootstrap.MonthField
19946 * @extends Roo.bootstrap.Input
19947 * Bootstrap MonthField class
19949 * @cfg {String} language default en
19952 * Create a new MonthField
19953 * @param {Object} config The config object
19956 Roo.bootstrap.MonthField = function(config){
19957 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
19962 * Fires when this field show.
19963 * @param {Roo.bootstrap.MonthField} this
19964 * @param {Mixed} date The date value
19969 * Fires when this field hide.
19970 * @param {Roo.bootstrap.MonthField} this
19971 * @param {Mixed} date The date value
19976 * Fires when select a date.
19977 * @param {Roo.bootstrap.MonthField} this
19978 * @param {String} oldvalue The old value
19979 * @param {String} newvalue The new value
19985 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
19987 onRender: function(ct, position)
19990 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
19992 this.language = this.language || 'en';
19993 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
19994 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
19996 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
19997 this.isInline = false;
19998 this.isInput = true;
19999 this.component = this.el.select('.add-on', true).first() || false;
20000 this.component = (this.component && this.component.length === 0) ? false : this.component;
20001 this.hasInput = this.component && this.inputEL().length;
20003 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
20005 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
20007 this.picker().on('mousedown', this.onMousedown, this);
20008 this.picker().on('click', this.onClick, this);
20010 this.picker().addClass('datepicker-dropdown');
20012 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
20013 v.setStyle('width', '189px');
20020 if(this.isInline) {
20026 setValue: function(v, suppressEvent)
20028 var o = this.getValue();
20030 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
20034 if(suppressEvent !== true){
20035 this.fireEvent('select', this, o, v);
20040 getValue: function()
20045 onClick: function(e)
20047 e.stopPropagation();
20048 e.preventDefault();
20050 var target = e.getTarget();
20052 if(target.nodeName.toLowerCase() === 'i'){
20053 target = Roo.get(target).dom.parentNode;
20056 var nodeName = target.nodeName;
20057 var className = target.className;
20058 var html = target.innerHTML;
20060 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
20064 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
20066 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20072 picker : function()
20074 return this.pickerEl;
20077 fillMonths: function()
20080 var months = this.picker().select('>.datepicker-months td', true).first();
20082 months.dom.innerHTML = '';
20088 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
20091 months.createChild(month);
20100 if(typeof(this.vIndex) == 'undefined' && this.value.length){
20101 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
20104 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
20105 e.removeClass('active');
20107 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
20108 e.addClass('active');
20115 if(this.isInline) {
20119 this.picker().removeClass(['bottom', 'top']);
20121 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
20123 * place to the top of element!
20127 this.picker().addClass('top');
20128 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
20133 this.picker().addClass('bottom');
20135 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
20138 onFocus : function()
20140 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
20144 onBlur : function()
20146 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
20148 var d = this.inputEl().getValue();
20157 this.picker().show();
20158 this.picker().select('>.datepicker-months', true).first().show();
20162 this.fireEvent('show', this, this.date);
20167 if(this.isInline) {
20170 this.picker().hide();
20171 this.fireEvent('hide', this, this.date);
20175 onMousedown: function(e)
20177 e.stopPropagation();
20178 e.preventDefault();
20183 Roo.bootstrap.MonthField.superclass.keyup.call(this);
20187 fireKey: function(e)
20189 if (!this.picker().isVisible()){
20190 if (e.keyCode == 27) {// allow escape to hide and re-show picker
20201 e.preventDefault();
20205 dir = e.keyCode == 37 ? -1 : 1;
20207 this.vIndex = this.vIndex + dir;
20209 if(this.vIndex < 0){
20213 if(this.vIndex > 11){
20217 if(isNaN(this.vIndex)){
20221 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20227 dir = e.keyCode == 38 ? -1 : 1;
20229 this.vIndex = this.vIndex + dir * 4;
20231 if(this.vIndex < 0){
20235 if(this.vIndex > 11){
20239 if(isNaN(this.vIndex)){
20243 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20248 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20249 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20253 e.preventDefault();
20256 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20257 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20273 this.picker().remove();
20278 Roo.apply(Roo.bootstrap.MonthField, {
20297 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
20298 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
20303 Roo.apply(Roo.bootstrap.MonthField, {
20307 cls: 'datepicker dropdown-menu roo-dynamic',
20311 cls: 'datepicker-months',
20315 cls: 'table-condensed',
20317 Roo.bootstrap.DateField.content
20337 * @class Roo.bootstrap.CheckBox
20338 * @extends Roo.bootstrap.Input
20339 * Bootstrap CheckBox class
20341 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20342 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
20343 * @cfg {String} boxLabel The text that appears beside the checkbox
20344 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
20345 * @cfg {Boolean} checked initnal the element
20346 * @cfg {Boolean} inline inline the element (default false)
20347 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
20348 * @cfg {String} tooltip label tooltip
20351 * Create a new CheckBox
20352 * @param {Object} config The config object
20355 Roo.bootstrap.CheckBox = function(config){
20356 Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
20361 * Fires when the element is checked or unchecked.
20362 * @param {Roo.bootstrap.CheckBox} this This input
20363 * @param {Boolean} checked The new checked value
20368 * Fires when the element is click.
20369 * @param {Roo.bootstrap.CheckBox} this This input
20376 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input, {
20378 inputType: 'checkbox',
20387 getAutoCreate : function()
20389 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
20395 cfg.cls = 'form-group ' + this.inputType; //input-group
20398 cfg.cls += ' ' + this.inputType + '-inline';
20404 type : this.inputType,
20405 value : this.inputValue,
20406 cls : 'roo-' + this.inputType, //'form-box',
20407 placeholder : this.placeholder || ''
20411 if(this.inputType != 'radio'){
20415 cls : 'roo-hidden-value',
20416 value : this.checked ? this.inputValue : this.valueOff
20421 if (this.weight) { // Validity check?
20422 cfg.cls += " " + this.inputType + "-" + this.weight;
20425 if (this.disabled) {
20426 input.disabled=true;
20430 input.checked = this.checked;
20435 input.name = this.name;
20437 if(this.inputType != 'radio'){
20438 hidden.name = this.name;
20439 input.name = '_hidden_' + this.name;
20444 input.cls += ' input-' + this.size;
20449 ['xs','sm','md','lg'].map(function(size){
20450 if (settings[size]) {
20451 cfg.cls += ' col-' + size + '-' + settings[size];
20455 var inputblock = input;
20457 if (this.before || this.after) {
20460 cls : 'input-group',
20465 inputblock.cn.push({
20467 cls : 'input-group-addon',
20472 inputblock.cn.push(input);
20474 if(this.inputType != 'radio'){
20475 inputblock.cn.push(hidden);
20479 inputblock.cn.push({
20481 cls : 'input-group-addon',
20488 if (align ==='left' && this.fieldLabel.length) {
20489 // Roo.log("left and has label");
20494 cls : 'control-label',
20495 html : this.fieldLabel
20505 if(this.labelWidth > 12){
20506 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
20509 if(this.labelWidth < 13 && this.labelmd == 0){
20510 this.labelmd = this.labelWidth;
20513 if(this.labellg > 0){
20514 cfg.cn[0].cls += ' col-lg-' + this.labellg;
20515 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
20518 if(this.labelmd > 0){
20519 cfg.cn[0].cls += ' col-md-' + this.labelmd;
20520 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
20523 if(this.labelsm > 0){
20524 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
20525 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
20528 if(this.labelxs > 0){
20529 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
20530 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
20533 } else if ( this.fieldLabel.length) {
20534 // Roo.log(" label");
20538 tag: this.boxLabel ? 'span' : 'label',
20540 cls: 'control-label box-input-label',
20541 //cls : 'input-group-addon',
20542 html : this.fieldLabel
20551 // Roo.log(" no label && no align");
20552 cfg.cn = [ inputblock ] ;
20558 var boxLabelCfg = {
20560 //'for': id, // box label is handled by onclick - so no for...
20562 html: this.boxLabel
20566 boxLabelCfg.tooltip = this.tooltip;
20569 cfg.cn.push(boxLabelCfg);
20572 if(this.inputType != 'radio'){
20573 cfg.cn.push(hidden);
20581 * return the real input element.
20583 inputEl: function ()
20585 return this.el.select('input.roo-' + this.inputType,true).first();
20587 hiddenEl: function ()
20589 return this.el.select('input.roo-hidden-value',true).first();
20592 labelEl: function()
20594 return this.el.select('label.control-label',true).first();
20596 /* depricated... */
20600 return this.labelEl();
20603 boxLabelEl: function()
20605 return this.el.select('label.box-label',true).first();
20608 initEvents : function()
20610 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
20612 this.inputEl().on('click', this.onClick, this);
20614 if (this.boxLabel) {
20615 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
20618 this.startValue = this.getValue();
20621 Roo.bootstrap.CheckBox.register(this);
20625 onClick : function(e)
20627 if(this.fireEvent('click', this, e) !== false){
20628 this.setChecked(!this.checked);
20633 setChecked : function(state,suppressEvent)
20635 this.startValue = this.getValue();
20637 if(this.inputType == 'radio'){
20639 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20640 e.dom.checked = false;
20643 this.inputEl().dom.checked = true;
20645 this.inputEl().dom.value = this.inputValue;
20647 if(suppressEvent !== true){
20648 this.fireEvent('check', this, true);
20656 this.checked = state;
20658 this.inputEl().dom.checked = state;
20661 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
20663 if(suppressEvent !== true){
20664 this.fireEvent('check', this, state);
20670 getValue : function()
20672 if(this.inputType == 'radio'){
20673 return this.getGroupValue();
20676 return this.hiddenEl().dom.value;
20680 getGroupValue : function()
20682 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
20686 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
20689 setValue : function(v,suppressEvent)
20691 if(this.inputType == 'radio'){
20692 this.setGroupValue(v, suppressEvent);
20696 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
20701 setGroupValue : function(v, suppressEvent)
20703 this.startValue = this.getValue();
20705 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20706 e.dom.checked = false;
20708 if(e.dom.value == v){
20709 e.dom.checked = true;
20713 if(suppressEvent !== true){
20714 this.fireEvent('check', this, true);
20722 validate : function()
20724 if(this.getVisibilityEl().hasClass('hidden')){
20730 (this.inputType == 'radio' && this.validateRadio()) ||
20731 (this.inputType == 'checkbox' && this.validateCheckbox())
20737 this.markInvalid();
20741 validateRadio : function()
20743 if(this.getVisibilityEl().hasClass('hidden')){
20747 if(this.allowBlank){
20753 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20754 if(!e.dom.checked){
20766 validateCheckbox : function()
20769 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
20770 //return (this.getValue() == this.inputValue) ? true : false;
20773 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20781 for(var i in group){
20782 if(group[i].el.isVisible(true)){
20790 for(var i in group){
20795 r = (group[i].getValue() == group[i].inputValue) ? true : false;
20802 * Mark this field as valid
20804 markValid : function()
20808 this.fireEvent('valid', this);
20810 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20813 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
20820 if(this.inputType == 'radio'){
20821 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20822 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
20823 e.findParent('.form-group', false, true).addClass(_this.validClass);
20830 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20831 this.el.findParent('.form-group', false, true).addClass(this.validClass);
20835 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20841 for(var i in group){
20842 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20843 group[i].el.findParent('.form-group', false, true).addClass(this.validClass);
20848 * Mark this field as invalid
20849 * @param {String} msg The validation message
20851 markInvalid : function(msg)
20853 if(this.allowBlank){
20859 this.fireEvent('invalid', this, msg);
20861 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20864 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
20868 label.markInvalid();
20871 if(this.inputType == 'radio'){
20872 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20873 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
20874 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
20881 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20882 this.el.findParent('.form-group', false, true).addClass(this.invalidClass);
20886 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20892 for(var i in group){
20893 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20894 group[i].el.findParent('.form-group', false, true).addClass(this.invalidClass);
20899 clearInvalid : function()
20901 Roo.bootstrap.Input.prototype.clearInvalid.call(this);
20903 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20905 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20907 if (label && label.iconEl) {
20908 label.iconEl.removeClass(label.validClass);
20909 label.iconEl.removeClass(label.invalidClass);
20913 disable : function()
20915 if(this.inputType != 'radio'){
20916 Roo.bootstrap.CheckBox.superclass.disable.call(this);
20923 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20924 _this.getActionEl().addClass(this.disabledClass);
20925 e.dom.disabled = true;
20929 this.disabled = true;
20930 this.fireEvent("disable", this);
20934 enable : function()
20936 if(this.inputType != 'radio'){
20937 Roo.bootstrap.CheckBox.superclass.enable.call(this);
20944 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20945 _this.getActionEl().removeClass(this.disabledClass);
20946 e.dom.disabled = false;
20950 this.disabled = false;
20951 this.fireEvent("enable", this);
20955 setBoxLabel : function(v)
20960 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
20966 Roo.apply(Roo.bootstrap.CheckBox, {
20971 * register a CheckBox Group
20972 * @param {Roo.bootstrap.CheckBox} the CheckBox to add
20974 register : function(checkbox)
20976 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
20977 this.groups[checkbox.groupId] = {};
20980 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
20984 this.groups[checkbox.groupId][checkbox.name] = checkbox;
20988 * fetch a CheckBox Group based on the group ID
20989 * @param {string} the group ID
20990 * @returns {Roo.bootstrap.CheckBox} the CheckBox group
20992 get: function(groupId) {
20993 if (typeof(this.groups[groupId]) == 'undefined') {
20997 return this.groups[groupId] ;
21010 * @class Roo.bootstrap.Radio
21011 * @extends Roo.bootstrap.Component
21012 * Bootstrap Radio class
21013 * @cfg {String} boxLabel - the label associated
21014 * @cfg {String} value - the value of radio
21017 * Create a new Radio
21018 * @param {Object} config The config object
21020 Roo.bootstrap.Radio = function(config){
21021 Roo.bootstrap.Radio.superclass.constructor.call(this, config);
21025 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.Component, {
21031 getAutoCreate : function()
21035 cls : 'form-group radio',
21040 html : this.boxLabel
21048 initEvents : function()
21050 this.parent().register(this);
21052 this.el.on('click', this.onClick, this);
21056 onClick : function(e)
21058 if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
21059 this.setChecked(true);
21063 setChecked : function(state, suppressEvent)
21065 this.parent().setValue(this.value, suppressEvent);
21069 setBoxLabel : function(v)
21074 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21089 * @class Roo.bootstrap.SecurePass
21090 * @extends Roo.bootstrap.Input
21091 * Bootstrap SecurePass class
21095 * Create a new SecurePass
21096 * @param {Object} config The config object
21099 Roo.bootstrap.SecurePass = function (config) {
21100 // these go here, so the translation tool can replace them..
21102 PwdEmpty: "Please type a password, and then retype it to confirm.",
21103 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21104 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21105 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21106 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21107 FNInPwd: "Your password can't contain your first name. Please type a different password.",
21108 LNInPwd: "Your password can't contain your last name. Please type a different password.",
21109 TooWeak: "Your password is Too Weak."
21111 this.meterLabel = "Password strength:";
21112 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
21113 this.meterClass = [
21114 "roo-password-meter-tooweak",
21115 "roo-password-meter-weak",
21116 "roo-password-meter-medium",
21117 "roo-password-meter-strong",
21118 "roo-password-meter-grey"
21123 Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
21126 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
21128 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
21130 * PwdEmpty: "Please type a password, and then retype it to confirm.",
21131 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21132 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21133 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21134 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21135 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
21136 * LNInPwd: "Your password can't contain your last name. Please type a different password."
21146 * @cfg {String/Object} Label for the strength meter (defaults to
21147 * 'Password strength:')
21152 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
21153 * ['Weak', 'Medium', 'Strong'])
21156 pwdStrengths: false,
21169 initEvents: function ()
21171 Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
21173 if (this.el.is('input[type=password]') && Roo.isSafari) {
21174 this.el.on('keydown', this.SafariOnKeyDown, this);
21177 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
21180 onRender: function (ct, position)
21182 Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
21183 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
21184 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
21186 this.trigger.createChild({
21191 cls: 'roo-password-meter-grey col-xs-12',
21194 //width: this.meterWidth + 'px'
21198 cls: 'roo-password-meter-text'
21204 if (this.hideTrigger) {
21205 this.trigger.setDisplayed(false);
21207 this.setSize(this.width || '', this.height || '');
21210 onDestroy: function ()
21212 if (this.trigger) {
21213 this.trigger.removeAllListeners();
21214 this.trigger.remove();
21217 this.wrap.remove();
21219 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
21222 checkStrength: function ()
21224 var pwd = this.inputEl().getValue();
21225 if (pwd == this._lastPwd) {
21230 if (this.ClientSideStrongPassword(pwd)) {
21232 } else if (this.ClientSideMediumPassword(pwd)) {
21234 } else if (this.ClientSideWeakPassword(pwd)) {
21240 Roo.log('strength1: ' + strength);
21242 //var pm = this.trigger.child('div/div/div').dom;
21243 var pm = this.trigger.child('div/div');
21244 pm.removeClass(this.meterClass);
21245 pm.addClass(this.meterClass[strength]);
21248 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21250 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21252 this._lastPwd = pwd;
21256 Roo.bootstrap.SecurePass.superclass.reset.call(this);
21258 this._lastPwd = '';
21260 var pm = this.trigger.child('div/div');
21261 pm.removeClass(this.meterClass);
21262 pm.addClass('roo-password-meter-grey');
21265 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21268 this.inputEl().dom.type='password';
21271 validateValue: function (value)
21274 if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
21277 if (value.length == 0) {
21278 if (this.allowBlank) {
21279 this.clearInvalid();
21283 this.markInvalid(this.errors.PwdEmpty);
21284 this.errorMsg = this.errors.PwdEmpty;
21292 if ('[\x21-\x7e]*'.match(value)) {
21293 this.markInvalid(this.errors.PwdBadChar);
21294 this.errorMsg = this.errors.PwdBadChar;
21297 if (value.length < 6) {
21298 this.markInvalid(this.errors.PwdShort);
21299 this.errorMsg = this.errors.PwdShort;
21302 if (value.length > 16) {
21303 this.markInvalid(this.errors.PwdLong);
21304 this.errorMsg = this.errors.PwdLong;
21308 if (this.ClientSideStrongPassword(value)) {
21310 } else if (this.ClientSideMediumPassword(value)) {
21312 } else if (this.ClientSideWeakPassword(value)) {
21319 if (strength < 2) {
21320 //this.markInvalid(this.errors.TooWeak);
21321 this.errorMsg = this.errors.TooWeak;
21326 console.log('strength2: ' + strength);
21328 //var pm = this.trigger.child('div/div/div').dom;
21330 var pm = this.trigger.child('div/div');
21331 pm.removeClass(this.meterClass);
21332 pm.addClass(this.meterClass[strength]);
21334 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21336 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21338 this.errorMsg = '';
21342 CharacterSetChecks: function (type)
21345 this.fResult = false;
21348 isctype: function (character, type)
21351 case this.kCapitalLetter:
21352 if (character >= 'A' && character <= 'Z') {
21357 case this.kSmallLetter:
21358 if (character >= 'a' && character <= 'z') {
21364 if (character >= '0' && character <= '9') {
21369 case this.kPunctuation:
21370 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
21381 IsLongEnough: function (pwd, size)
21383 return !(pwd == null || isNaN(size) || pwd.length < size);
21386 SpansEnoughCharacterSets: function (word, nb)
21388 if (!this.IsLongEnough(word, nb))
21393 var characterSetChecks = new Array(
21394 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
21395 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
21398 for (var index = 0; index < word.length; ++index) {
21399 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21400 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
21401 characterSetChecks[nCharSet].fResult = true;
21408 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21409 if (characterSetChecks[nCharSet].fResult) {
21414 if (nCharSets < nb) {
21420 ClientSideStrongPassword: function (pwd)
21422 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
21425 ClientSideMediumPassword: function (pwd)
21427 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
21430 ClientSideWeakPassword: function (pwd)
21432 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
21435 })//<script type="text/javascript">
21438 * Based Ext JS Library 1.1.1
21439 * Copyright(c) 2006-2007, Ext JS, LLC.
21445 * @class Roo.HtmlEditorCore
21446 * @extends Roo.Component
21447 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
21449 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
21452 Roo.HtmlEditorCore = function(config){
21455 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
21460 * @event initialize
21461 * Fires when the editor is fully initialized (including the iframe)
21462 * @param {Roo.HtmlEditorCore} this
21467 * Fires when the editor is first receives the focus. Any insertion must wait
21468 * until after this event.
21469 * @param {Roo.HtmlEditorCore} this
21473 * @event beforesync
21474 * Fires before the textarea is updated with content from the editor iframe. Return false
21475 * to cancel the sync.
21476 * @param {Roo.HtmlEditorCore} this
21477 * @param {String} html
21481 * @event beforepush
21482 * Fires before the iframe editor is updated with content from the textarea. Return false
21483 * to cancel the push.
21484 * @param {Roo.HtmlEditorCore} this
21485 * @param {String} html
21490 * Fires when the textarea is updated with content from the editor iframe.
21491 * @param {Roo.HtmlEditorCore} this
21492 * @param {String} html
21497 * Fires when the iframe editor is updated with content from the textarea.
21498 * @param {Roo.HtmlEditorCore} this
21499 * @param {String} html
21504 * @event editorevent
21505 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21506 * @param {Roo.HtmlEditorCore} this
21512 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
21514 // defaults : white / black...
21515 this.applyBlacklists();
21522 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
21526 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
21532 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
21537 * @cfg {Number} height (in pixels)
21541 * @cfg {Number} width (in pixels)
21546 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21549 stylesheets: false,
21554 // private properties
21555 validationEvent : false,
21557 initialized : false,
21559 sourceEditMode : false,
21560 onFocus : Roo.emptyFn,
21562 hideMode:'offsets',
21566 // blacklist + whitelisted elements..
21573 * Protected method that will not generally be called directly. It
21574 * is called when the editor initializes the iframe with HTML contents. Override this method if you
21575 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
21577 getDocMarkup : function(){
21581 // inherit styels from page...??
21582 if (this.stylesheets === false) {
21584 Roo.get(document.head).select('style').each(function(node) {
21585 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21588 Roo.get(document.head).select('link').each(function(node) {
21589 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21592 } else if (!this.stylesheets.length) {
21594 st = '<style type="text/css">' +
21595 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21598 st = '<style type="text/css">' +
21603 st += '<style type="text/css">' +
21604 'IMG { cursor: pointer } ' +
21607 var cls = 'roo-htmleditor-body';
21609 if(this.bodyCls.length){
21610 cls += ' ' + this.bodyCls;
21613 return '<html><head>' + st +
21614 //<style type="text/css">' +
21615 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21617 ' </head><body class="' + cls + '"></body></html>';
21621 onRender : function(ct, position)
21624 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
21625 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
21628 this.el.dom.style.border = '0 none';
21629 this.el.dom.setAttribute('tabIndex', -1);
21630 this.el.addClass('x-hidden hide');
21634 if(Roo.isIE){ // fix IE 1px bogus margin
21635 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
21639 this.frameId = Roo.id();
21643 var iframe = this.owner.wrap.createChild({
21645 cls: 'form-control', // bootstrap..
21647 name: this.frameId,
21648 frameBorder : 'no',
21649 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
21654 this.iframe = iframe.dom;
21656 this.assignDocWin();
21658 this.doc.designMode = 'on';
21661 this.doc.write(this.getDocMarkup());
21665 var task = { // must defer to wait for browser to be ready
21667 //console.log("run task?" + this.doc.readyState);
21668 this.assignDocWin();
21669 if(this.doc.body || this.doc.readyState == 'complete'){
21671 this.doc.designMode="on";
21675 Roo.TaskMgr.stop(task);
21676 this.initEditor.defer(10, this);
21683 Roo.TaskMgr.start(task);
21688 onResize : function(w, h)
21690 Roo.log('resize: ' +w + ',' + h );
21691 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
21695 if(typeof w == 'number'){
21697 this.iframe.style.width = w + 'px';
21699 if(typeof h == 'number'){
21701 this.iframe.style.height = h + 'px';
21703 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
21710 * Toggles the editor between standard and source edit mode.
21711 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21713 toggleSourceEdit : function(sourceEditMode){
21715 this.sourceEditMode = sourceEditMode === true;
21717 if(this.sourceEditMode){
21719 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
21722 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
21723 //this.iframe.className = '';
21726 //this.setSize(this.owner.wrap.getSize());
21727 //this.fireEvent('editmodechange', this, this.sourceEditMode);
21734 * Protected method that will not generally be called directly. If you need/want
21735 * custom HTML cleanup, this is the method you should override.
21736 * @param {String} html The HTML to be cleaned
21737 * return {String} The cleaned HTML
21739 cleanHtml : function(html){
21740 html = String(html);
21741 if(html.length > 5){
21742 if(Roo.isSafari){ // strip safari nonsense
21743 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
21746 if(html == ' '){
21753 * HTML Editor -> Textarea
21754 * Protected method that will not generally be called directly. Syncs the contents
21755 * of the editor iframe with the textarea.
21757 syncValue : function(){
21758 if(this.initialized){
21759 var bd = (this.doc.body || this.doc.documentElement);
21760 //this.cleanUpPaste(); -- this is done else where and causes havoc..
21761 var html = bd.innerHTML;
21763 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
21764 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
21766 html = '<div style="'+m[0]+'">' + html + '</div>';
21769 html = this.cleanHtml(html);
21770 // fix up the special chars.. normaly like back quotes in word...
21771 // however we do not want to do this with chinese..
21772 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
21773 var cc = b.charCodeAt();
21775 (cc >= 0x4E00 && cc < 0xA000 ) ||
21776 (cc >= 0x3400 && cc < 0x4E00 ) ||
21777 (cc >= 0xf900 && cc < 0xfb00 )
21783 if(this.owner.fireEvent('beforesync', this, html) !== false){
21784 this.el.dom.value = html;
21785 this.owner.fireEvent('sync', this, html);
21791 * Protected method that will not generally be called directly. Pushes the value of the textarea
21792 * into the iframe editor.
21794 pushValue : function(){
21795 if(this.initialized){
21796 var v = this.el.dom.value.trim();
21798 // if(v.length < 1){
21802 if(this.owner.fireEvent('beforepush', this, v) !== false){
21803 var d = (this.doc.body || this.doc.documentElement);
21805 this.cleanUpPaste();
21806 this.el.dom.value = d.innerHTML;
21807 this.owner.fireEvent('push', this, v);
21813 deferFocus : function(){
21814 this.focus.defer(10, this);
21818 focus : function(){
21819 if(this.win && !this.sourceEditMode){
21826 assignDocWin: function()
21828 var iframe = this.iframe;
21831 this.doc = iframe.contentWindow.document;
21832 this.win = iframe.contentWindow;
21834 // if (!Roo.get(this.frameId)) {
21837 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21838 // this.win = Roo.get(this.frameId).dom.contentWindow;
21840 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
21844 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21845 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
21850 initEditor : function(){
21851 //console.log("INIT EDITOR");
21852 this.assignDocWin();
21856 this.doc.designMode="on";
21858 this.doc.write(this.getDocMarkup());
21861 var dbody = (this.doc.body || this.doc.documentElement);
21862 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
21863 // this copies styles from the containing element into thsi one..
21864 // not sure why we need all of this..
21865 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
21867 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
21868 //ss['background-attachment'] = 'fixed'; // w3c
21869 dbody.bgProperties = 'fixed'; // ie
21870 //Roo.DomHelper.applyStyles(dbody, ss);
21871 Roo.EventManager.on(this.doc, {
21872 //'mousedown': this.onEditorEvent,
21873 'mouseup': this.onEditorEvent,
21874 'dblclick': this.onEditorEvent,
21875 'click': this.onEditorEvent,
21876 'keyup': this.onEditorEvent,
21881 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
21883 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
21884 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
21886 this.initialized = true;
21888 this.owner.fireEvent('initialize', this);
21893 onDestroy : function(){
21899 //for (var i =0; i < this.toolbars.length;i++) {
21900 // // fixme - ask toolbars for heights?
21901 // this.toolbars[i].onDestroy();
21904 //this.wrap.dom.innerHTML = '';
21905 //this.wrap.remove();
21910 onFirstFocus : function(){
21912 this.assignDocWin();
21915 this.activated = true;
21918 if(Roo.isGecko){ // prevent silly gecko errors
21920 var s = this.win.getSelection();
21921 if(!s.focusNode || s.focusNode.nodeType != 3){
21922 var r = s.getRangeAt(0);
21923 r.selectNodeContents((this.doc.body || this.doc.documentElement));
21928 this.execCmd('useCSS', true);
21929 this.execCmd('styleWithCSS', false);
21932 this.owner.fireEvent('activate', this);
21936 adjustFont: function(btn){
21937 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
21938 //if(Roo.isSafari){ // safari
21941 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
21942 if(Roo.isSafari){ // safari
21943 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
21944 v = (v < 10) ? 10 : v;
21945 v = (v > 48) ? 48 : v;
21946 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
21951 v = Math.max(1, v+adjust);
21953 this.execCmd('FontSize', v );
21956 onEditorEvent : function(e)
21958 this.owner.fireEvent('editorevent', this, e);
21959 // this.updateToolbar();
21960 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
21963 insertTag : function(tg)
21965 // could be a bit smarter... -> wrap the current selected tRoo..
21966 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
21968 range = this.createRange(this.getSelection());
21969 var wrappingNode = this.doc.createElement(tg.toLowerCase());
21970 wrappingNode.appendChild(range.extractContents());
21971 range.insertNode(wrappingNode);
21978 this.execCmd("formatblock", tg);
21982 insertText : function(txt)
21986 var range = this.createRange();
21987 range.deleteContents();
21988 //alert(Sender.getAttribute('label'));
21990 range.insertNode(this.doc.createTextNode(txt));
21996 * Executes a Midas editor command on the editor document and performs necessary focus and
21997 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
21998 * @param {String} cmd The Midas command
21999 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22001 relayCmd : function(cmd, value){
22003 this.execCmd(cmd, value);
22004 this.owner.fireEvent('editorevent', this);
22005 //this.updateToolbar();
22006 this.owner.deferFocus();
22010 * Executes a Midas editor command directly on the editor document.
22011 * For visual commands, you should use {@link #relayCmd} instead.
22012 * <b>This should only be called after the editor is initialized.</b>
22013 * @param {String} cmd The Midas command
22014 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22016 execCmd : function(cmd, value){
22017 this.doc.execCommand(cmd, false, value === undefined ? null : value);
22024 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
22026 * @param {String} text | dom node..
22028 insertAtCursor : function(text)
22031 if(!this.activated){
22037 var r = this.doc.selection.createRange();
22048 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
22052 // from jquery ui (MIT licenced)
22054 var win = this.win;
22056 if (win.getSelection && win.getSelection().getRangeAt) {
22057 range = win.getSelection().getRangeAt(0);
22058 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
22059 range.insertNode(node);
22060 } else if (win.document.selection && win.document.selection.createRange) {
22061 // no firefox support
22062 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22063 win.document.selection.createRange().pasteHTML(txt);
22065 // no firefox support
22066 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22067 this.execCmd('InsertHTML', txt);
22076 mozKeyPress : function(e){
22078 var c = e.getCharCode(), cmd;
22081 c = String.fromCharCode(c).toLowerCase();
22095 this.cleanUpPaste.defer(100, this);
22103 e.preventDefault();
22111 fixKeys : function(){ // load time branching for fastest keydown performance
22113 return function(e){
22114 var k = e.getKey(), r;
22117 r = this.doc.selection.createRange();
22120 r.pasteHTML('    ');
22127 r = this.doc.selection.createRange();
22129 var target = r.parentElement();
22130 if(!target || target.tagName.toLowerCase() != 'li'){
22132 r.pasteHTML('<br />');
22138 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22139 this.cleanUpPaste.defer(100, this);
22145 }else if(Roo.isOpera){
22146 return function(e){
22147 var k = e.getKey();
22151 this.execCmd('InsertHTML','    ');
22154 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22155 this.cleanUpPaste.defer(100, this);
22160 }else if(Roo.isSafari){
22161 return function(e){
22162 var k = e.getKey();
22166 this.execCmd('InsertText','\t');
22170 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22171 this.cleanUpPaste.defer(100, this);
22179 getAllAncestors: function()
22181 var p = this.getSelectedNode();
22184 a.push(p); // push blank onto stack..
22185 p = this.getParentElement();
22189 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
22193 a.push(this.doc.body);
22197 lastSelNode : false,
22200 getSelection : function()
22202 this.assignDocWin();
22203 return Roo.isIE ? this.doc.selection : this.win.getSelection();
22206 getSelectedNode: function()
22208 // this may only work on Gecko!!!
22210 // should we cache this!!!!
22215 var range = this.createRange(this.getSelection()).cloneRange();
22218 var parent = range.parentElement();
22220 var testRange = range.duplicate();
22221 testRange.moveToElementText(parent);
22222 if (testRange.inRange(range)) {
22225 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
22228 parent = parent.parentElement;
22233 // is ancestor a text element.
22234 var ac = range.commonAncestorContainer;
22235 if (ac.nodeType == 3) {
22236 ac = ac.parentNode;
22239 var ar = ac.childNodes;
22242 var other_nodes = [];
22243 var has_other_nodes = false;
22244 for (var i=0;i<ar.length;i++) {
22245 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
22248 // fullly contained node.
22250 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
22255 // probably selected..
22256 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
22257 other_nodes.push(ar[i]);
22261 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
22266 has_other_nodes = true;
22268 if (!nodes.length && other_nodes.length) {
22269 nodes= other_nodes;
22271 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
22277 createRange: function(sel)
22279 // this has strange effects when using with
22280 // top toolbar - not sure if it's a great idea.
22281 //this.editor.contentWindow.focus();
22282 if (typeof sel != "undefined") {
22284 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
22286 return this.doc.createRange();
22289 return this.doc.createRange();
22292 getParentElement: function()
22295 this.assignDocWin();
22296 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
22298 var range = this.createRange(sel);
22301 var p = range.commonAncestorContainer;
22302 while (p.nodeType == 3) { // text node
22313 * Range intersection.. the hard stuff...
22317 * [ -- selected range --- ]
22321 * if end is before start or hits it. fail.
22322 * if start is after end or hits it fail.
22324 * if either hits (but other is outside. - then it's not
22330 // @see http://www.thismuchiknow.co.uk/?p=64.
22331 rangeIntersectsNode : function(range, node)
22333 var nodeRange = node.ownerDocument.createRange();
22335 nodeRange.selectNode(node);
22337 nodeRange.selectNodeContents(node);
22340 var rangeStartRange = range.cloneRange();
22341 rangeStartRange.collapse(true);
22343 var rangeEndRange = range.cloneRange();
22344 rangeEndRange.collapse(false);
22346 var nodeStartRange = nodeRange.cloneRange();
22347 nodeStartRange.collapse(true);
22349 var nodeEndRange = nodeRange.cloneRange();
22350 nodeEndRange.collapse(false);
22352 return rangeStartRange.compareBoundaryPoints(
22353 Range.START_TO_START, nodeEndRange) == -1 &&
22354 rangeEndRange.compareBoundaryPoints(
22355 Range.START_TO_START, nodeStartRange) == 1;
22359 rangeCompareNode : function(range, node)
22361 var nodeRange = node.ownerDocument.createRange();
22363 nodeRange.selectNode(node);
22365 nodeRange.selectNodeContents(node);
22369 range.collapse(true);
22371 nodeRange.collapse(true);
22373 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
22374 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
22376 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
22378 var nodeIsBefore = ss == 1;
22379 var nodeIsAfter = ee == -1;
22381 if (nodeIsBefore && nodeIsAfter) {
22384 if (!nodeIsBefore && nodeIsAfter) {
22385 return 1; //right trailed.
22388 if (nodeIsBefore && !nodeIsAfter) {
22389 return 2; // left trailed.
22395 // private? - in a new class?
22396 cleanUpPaste : function()
22398 // cleans up the whole document..
22399 Roo.log('cleanuppaste');
22401 this.cleanUpChildren(this.doc.body);
22402 var clean = this.cleanWordChars(this.doc.body.innerHTML);
22403 if (clean != this.doc.body.innerHTML) {
22404 this.doc.body.innerHTML = clean;
22409 cleanWordChars : function(input) {// change the chars to hex code
22410 var he = Roo.HtmlEditorCore;
22412 var output = input;
22413 Roo.each(he.swapCodes, function(sw) {
22414 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
22416 output = output.replace(swapper, sw[1]);
22423 cleanUpChildren : function (n)
22425 if (!n.childNodes.length) {
22428 for (var i = n.childNodes.length-1; i > -1 ; i--) {
22429 this.cleanUpChild(n.childNodes[i]);
22436 cleanUpChild : function (node)
22439 //console.log(node);
22440 if (node.nodeName == "#text") {
22441 // clean up silly Windows -- stuff?
22444 if (node.nodeName == "#comment") {
22445 node.parentNode.removeChild(node);
22446 // clean up silly Windows -- stuff?
22449 var lcname = node.tagName.toLowerCase();
22450 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
22451 // whitelist of tags..
22453 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
22455 node.parentNode.removeChild(node);
22460 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
22462 // remove <a name=....> as rendering on yahoo mailer is borked with this.
22463 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
22465 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
22466 // remove_keep_children = true;
22469 if (remove_keep_children) {
22470 this.cleanUpChildren(node);
22471 // inserts everything just before this node...
22472 while (node.childNodes.length) {
22473 var cn = node.childNodes[0];
22474 node.removeChild(cn);
22475 node.parentNode.insertBefore(cn, node);
22477 node.parentNode.removeChild(node);
22481 if (!node.attributes || !node.attributes.length) {
22482 this.cleanUpChildren(node);
22486 function cleanAttr(n,v)
22489 if (v.match(/^\./) || v.match(/^\//)) {
22492 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) {
22495 if (v.match(/^#/)) {
22498 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
22499 node.removeAttribute(n);
22503 var cwhite = this.cwhite;
22504 var cblack = this.cblack;
22506 function cleanStyle(n,v)
22508 if (v.match(/expression/)) { //XSS?? should we even bother..
22509 node.removeAttribute(n);
22513 var parts = v.split(/;/);
22516 Roo.each(parts, function(p) {
22517 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
22521 var l = p.split(':').shift().replace(/\s+/g,'');
22522 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
22524 if ( cwhite.length && cblack.indexOf(l) > -1) {
22525 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22526 //node.removeAttribute(n);
22530 // only allow 'c whitelisted system attributes'
22531 if ( cwhite.length && cwhite.indexOf(l) < 0) {
22532 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22533 //node.removeAttribute(n);
22543 if (clean.length) {
22544 node.setAttribute(n, clean.join(';'));
22546 node.removeAttribute(n);
22552 for (var i = node.attributes.length-1; i > -1 ; i--) {
22553 var a = node.attributes[i];
22556 if (a.name.toLowerCase().substr(0,2)=='on') {
22557 node.removeAttribute(a.name);
22560 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
22561 node.removeAttribute(a.name);
22564 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
22565 cleanAttr(a.name,a.value); // fixme..
22568 if (a.name == 'style') {
22569 cleanStyle(a.name,a.value);
22572 /// clean up MS crap..
22573 // tecnically this should be a list of valid class'es..
22576 if (a.name == 'class') {
22577 if (a.value.match(/^Mso/)) {
22578 node.className = '';
22581 if (a.value.match(/^body$/)) {
22582 node.className = '';
22593 this.cleanUpChildren(node);
22599 * Clean up MS wordisms...
22601 cleanWord : function(node)
22606 this.cleanWord(this.doc.body);
22609 if (node.nodeName == "#text") {
22610 // clean up silly Windows -- stuff?
22613 if (node.nodeName == "#comment") {
22614 node.parentNode.removeChild(node);
22615 // clean up silly Windows -- stuff?
22619 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
22620 node.parentNode.removeChild(node);
22624 // remove - but keep children..
22625 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
22626 while (node.childNodes.length) {
22627 var cn = node.childNodes[0];
22628 node.removeChild(cn);
22629 node.parentNode.insertBefore(cn, node);
22631 node.parentNode.removeChild(node);
22632 this.iterateChildren(node, this.cleanWord);
22636 if (node.className.length) {
22638 var cn = node.className.split(/\W+/);
22640 Roo.each(cn, function(cls) {
22641 if (cls.match(/Mso[a-zA-Z]+/)) {
22646 node.className = cna.length ? cna.join(' ') : '';
22648 node.removeAttribute("class");
22652 if (node.hasAttribute("lang")) {
22653 node.removeAttribute("lang");
22656 if (node.hasAttribute("style")) {
22658 var styles = node.getAttribute("style").split(";");
22660 Roo.each(styles, function(s) {
22661 if (!s.match(/:/)) {
22664 var kv = s.split(":");
22665 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
22668 // what ever is left... we allow.
22671 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22672 if (!nstyle.length) {
22673 node.removeAttribute('style');
22676 this.iterateChildren(node, this.cleanWord);
22682 * iterateChildren of a Node, calling fn each time, using this as the scole..
22683 * @param {DomNode} node node to iterate children of.
22684 * @param {Function} fn method of this class to call on each item.
22686 iterateChildren : function(node, fn)
22688 if (!node.childNodes.length) {
22691 for (var i = node.childNodes.length-1; i > -1 ; i--) {
22692 fn.call(this, node.childNodes[i])
22698 * cleanTableWidths.
22700 * Quite often pasting from word etc.. results in tables with column and widths.
22701 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
22704 cleanTableWidths : function(node)
22709 this.cleanTableWidths(this.doc.body);
22714 if (node.nodeName == "#text" || node.nodeName == "#comment") {
22717 Roo.log(node.tagName);
22718 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
22719 this.iterateChildren(node, this.cleanTableWidths);
22722 if (node.hasAttribute('width')) {
22723 node.removeAttribute('width');
22727 if (node.hasAttribute("style")) {
22730 var styles = node.getAttribute("style").split(";");
22732 Roo.each(styles, function(s) {
22733 if (!s.match(/:/)) {
22736 var kv = s.split(":");
22737 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
22740 // what ever is left... we allow.
22743 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22744 if (!nstyle.length) {
22745 node.removeAttribute('style');
22749 this.iterateChildren(node, this.cleanTableWidths);
22757 domToHTML : function(currentElement, depth, nopadtext) {
22759 depth = depth || 0;
22760 nopadtext = nopadtext || false;
22762 if (!currentElement) {
22763 return this.domToHTML(this.doc.body);
22766 //Roo.log(currentElement);
22768 var allText = false;
22769 var nodeName = currentElement.nodeName;
22770 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
22772 if (nodeName == '#text') {
22774 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
22779 if (nodeName != 'BODY') {
22782 // Prints the node tagName, such as <A>, <IMG>, etc
22785 for(i = 0; i < currentElement.attributes.length;i++) {
22787 var aname = currentElement.attributes.item(i).name;
22788 if (!currentElement.attributes.item(i).value.length) {
22791 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
22794 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
22803 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
22806 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
22811 // Traverse the tree
22813 var currentElementChild = currentElement.childNodes.item(i);
22814 var allText = true;
22815 var innerHTML = '';
22817 while (currentElementChild) {
22818 // Formatting code (indent the tree so it looks nice on the screen)
22819 var nopad = nopadtext;
22820 if (lastnode == 'SPAN') {
22824 if (currentElementChild.nodeName == '#text') {
22825 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
22826 toadd = nopadtext ? toadd : toadd.trim();
22827 if (!nopad && toadd.length > 80) {
22828 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
22830 innerHTML += toadd;
22833 currentElementChild = currentElement.childNodes.item(i);
22839 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
22841 // Recursively traverse the tree structure of the child node
22842 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
22843 lastnode = currentElementChild.nodeName;
22845 currentElementChild=currentElement.childNodes.item(i);
22851 // The remaining code is mostly for formatting the tree
22852 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
22857 ret+= "</"+tagName+">";
22863 applyBlacklists : function()
22865 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
22866 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
22870 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
22871 if (b.indexOf(tag) > -1) {
22874 this.white.push(tag);
22878 Roo.each(w, function(tag) {
22879 if (b.indexOf(tag) > -1) {
22882 if (this.white.indexOf(tag) > -1) {
22885 this.white.push(tag);
22890 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
22891 if (w.indexOf(tag) > -1) {
22894 this.black.push(tag);
22898 Roo.each(b, function(tag) {
22899 if (w.indexOf(tag) > -1) {
22902 if (this.black.indexOf(tag) > -1) {
22905 this.black.push(tag);
22910 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
22911 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
22915 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
22916 if (b.indexOf(tag) > -1) {
22919 this.cwhite.push(tag);
22923 Roo.each(w, function(tag) {
22924 if (b.indexOf(tag) > -1) {
22927 if (this.cwhite.indexOf(tag) > -1) {
22930 this.cwhite.push(tag);
22935 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
22936 if (w.indexOf(tag) > -1) {
22939 this.cblack.push(tag);
22943 Roo.each(b, function(tag) {
22944 if (w.indexOf(tag) > -1) {
22947 if (this.cblack.indexOf(tag) > -1) {
22950 this.cblack.push(tag);
22955 setStylesheets : function(stylesheets)
22957 if(typeof(stylesheets) == 'string'){
22958 Roo.get(this.iframe.contentDocument.head).createChild({
22960 rel : 'stylesheet',
22969 Roo.each(stylesheets, function(s) {
22974 Roo.get(_this.iframe.contentDocument.head).createChild({
22976 rel : 'stylesheet',
22985 removeStylesheets : function()
22989 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
22994 setStyle : function(style)
22996 Roo.get(this.iframe.contentDocument.head).createChild({
23005 // hide stuff that is not compatible
23019 * @event specialkey
23023 * @cfg {String} fieldClass @hide
23026 * @cfg {String} focusClass @hide
23029 * @cfg {String} autoCreate @hide
23032 * @cfg {String} inputType @hide
23035 * @cfg {String} invalidClass @hide
23038 * @cfg {String} invalidText @hide
23041 * @cfg {String} msgFx @hide
23044 * @cfg {String} validateOnBlur @hide
23048 Roo.HtmlEditorCore.white = [
23049 'area', 'br', 'img', 'input', 'hr', 'wbr',
23051 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
23052 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
23053 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
23054 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
23055 'table', 'ul', 'xmp',
23057 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
23060 'dir', 'menu', 'ol', 'ul', 'dl',
23066 Roo.HtmlEditorCore.black = [
23067 // 'embed', 'object', // enable - backend responsiblity to clean thiese
23069 'base', 'basefont', 'bgsound', 'blink', 'body',
23070 'frame', 'frameset', 'head', 'html', 'ilayer',
23071 'iframe', 'layer', 'link', 'meta', 'object',
23072 'script', 'style' ,'title', 'xml' // clean later..
23074 Roo.HtmlEditorCore.clean = [
23075 'script', 'style', 'title', 'xml'
23077 Roo.HtmlEditorCore.remove = [
23082 Roo.HtmlEditorCore.ablack = [
23086 Roo.HtmlEditorCore.aclean = [
23087 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
23091 Roo.HtmlEditorCore.pwhite= [
23092 'http', 'https', 'mailto'
23095 // white listed style attributes.
23096 Roo.HtmlEditorCore.cwhite= [
23097 // 'text-align', /// default is to allow most things..
23103 // black listed style attributes.
23104 Roo.HtmlEditorCore.cblack= [
23105 // 'font-size' -- this can be set by the project
23109 Roo.HtmlEditorCore.swapCodes =[
23128 * @class Roo.bootstrap.HtmlEditor
23129 * @extends Roo.bootstrap.TextArea
23130 * Bootstrap HtmlEditor class
23133 * Create a new HtmlEditor
23134 * @param {Object} config The config object
23137 Roo.bootstrap.HtmlEditor = function(config){
23138 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
23139 if (!this.toolbars) {
23140 this.toolbars = [];
23143 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
23146 * @event initialize
23147 * Fires when the editor is fully initialized (including the iframe)
23148 * @param {HtmlEditor} this
23153 * Fires when the editor is first receives the focus. Any insertion must wait
23154 * until after this event.
23155 * @param {HtmlEditor} this
23159 * @event beforesync
23160 * Fires before the textarea is updated with content from the editor iframe. Return false
23161 * to cancel the sync.
23162 * @param {HtmlEditor} this
23163 * @param {String} html
23167 * @event beforepush
23168 * Fires before the iframe editor is updated with content from the textarea. Return false
23169 * to cancel the push.
23170 * @param {HtmlEditor} this
23171 * @param {String} html
23176 * Fires when the textarea is updated with content from the editor iframe.
23177 * @param {HtmlEditor} this
23178 * @param {String} html
23183 * Fires when the iframe editor is updated with content from the textarea.
23184 * @param {HtmlEditor} this
23185 * @param {String} html
23189 * @event editmodechange
23190 * Fires when the editor switches edit modes
23191 * @param {HtmlEditor} this
23192 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
23194 editmodechange: true,
23196 * @event editorevent
23197 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
23198 * @param {HtmlEditor} this
23202 * @event firstfocus
23203 * Fires when on first focus - needed by toolbars..
23204 * @param {HtmlEditor} this
23209 * Auto save the htmlEditor value as a file into Events
23210 * @param {HtmlEditor} this
23214 * @event savedpreview
23215 * preview the saved version of htmlEditor
23216 * @param {HtmlEditor} this
23223 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
23227 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
23232 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
23237 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
23242 * @cfg {Number} height (in pixels)
23246 * @cfg {Number} width (in pixels)
23251 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
23254 stylesheets: false,
23259 // private properties
23260 validationEvent : false,
23262 initialized : false,
23265 onFocus : Roo.emptyFn,
23267 hideMode:'offsets',
23269 tbContainer : false,
23273 toolbarContainer :function() {
23274 return this.wrap.select('.x-html-editor-tb',true).first();
23278 * Protected method that will not generally be called directly. It
23279 * is called when the editor creates its toolbar. Override this method if you need to
23280 * add custom toolbar buttons.
23281 * @param {HtmlEditor} editor
23283 createToolbar : function(){
23284 Roo.log('renewing');
23285 Roo.log("create toolbars");
23287 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
23288 this.toolbars[0].render(this.toolbarContainer());
23292 // if (!editor.toolbars || !editor.toolbars.length) {
23293 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
23296 // for (var i =0 ; i < editor.toolbars.length;i++) {
23297 // editor.toolbars[i] = Roo.factory(
23298 // typeof(editor.toolbars[i]) == 'string' ?
23299 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
23300 // Roo.bootstrap.HtmlEditor);
23301 // editor.toolbars[i].init(editor);
23307 onRender : function(ct, position)
23309 // Roo.log("Call onRender: " + this.xtype);
23311 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
23313 this.wrap = this.inputEl().wrap({
23314 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
23317 this.editorcore.onRender(ct, position);
23319 if (this.resizable) {
23320 this.resizeEl = new Roo.Resizable(this.wrap, {
23324 minHeight : this.height,
23325 height: this.height,
23326 handles : this.resizable,
23329 resize : function(r, w, h) {
23330 _t.onResize(w,h); // -something
23336 this.createToolbar(this);
23339 if(!this.width && this.resizable){
23340 this.setSize(this.wrap.getSize());
23342 if (this.resizeEl) {
23343 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
23344 // should trigger onReize..
23350 onResize : function(w, h)
23352 Roo.log('resize: ' +w + ',' + h );
23353 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
23357 if(this.inputEl() ){
23358 if(typeof w == 'number'){
23359 var aw = w - this.wrap.getFrameWidth('lr');
23360 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
23363 if(typeof h == 'number'){
23364 var tbh = -11; // fixme it needs to tool bar size!
23365 for (var i =0; i < this.toolbars.length;i++) {
23366 // fixme - ask toolbars for heights?
23367 tbh += this.toolbars[i].el.getHeight();
23368 //if (this.toolbars[i].footer) {
23369 // tbh += this.toolbars[i].footer.el.getHeight();
23377 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23378 ah -= 5; // knock a few pixes off for look..
23379 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
23383 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23384 this.editorcore.onResize(ew,eh);
23389 * Toggles the editor between standard and source edit mode.
23390 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23392 toggleSourceEdit : function(sourceEditMode)
23394 this.editorcore.toggleSourceEdit(sourceEditMode);
23396 if(this.editorcore.sourceEditMode){
23397 Roo.log('editor - showing textarea');
23400 // Roo.log(this.syncValue());
23402 this.inputEl().removeClass(['hide', 'x-hidden']);
23403 this.inputEl().dom.removeAttribute('tabIndex');
23404 this.inputEl().focus();
23406 Roo.log('editor - hiding textarea');
23408 // Roo.log(this.pushValue());
23411 this.inputEl().addClass(['hide', 'x-hidden']);
23412 this.inputEl().dom.setAttribute('tabIndex', -1);
23413 //this.deferFocus();
23416 if(this.resizable){
23417 this.setSize(this.wrap.getSize());
23420 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23423 // private (for BoxComponent)
23424 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23426 // private (for BoxComponent)
23427 getResizeEl : function(){
23431 // private (for BoxComponent)
23432 getPositionEl : function(){
23437 initEvents : function(){
23438 this.originalValue = this.getValue();
23442 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23445 // markInvalid : Roo.emptyFn,
23447 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23450 // clearInvalid : Roo.emptyFn,
23452 setValue : function(v){
23453 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
23454 this.editorcore.pushValue();
23459 deferFocus : function(){
23460 this.focus.defer(10, this);
23464 focus : function(){
23465 this.editorcore.focus();
23471 onDestroy : function(){
23477 for (var i =0; i < this.toolbars.length;i++) {
23478 // fixme - ask toolbars for heights?
23479 this.toolbars[i].onDestroy();
23482 this.wrap.dom.innerHTML = '';
23483 this.wrap.remove();
23488 onFirstFocus : function(){
23489 //Roo.log("onFirstFocus");
23490 this.editorcore.onFirstFocus();
23491 for (var i =0; i < this.toolbars.length;i++) {
23492 this.toolbars[i].onFirstFocus();
23498 syncValue : function()
23500 this.editorcore.syncValue();
23503 pushValue : function()
23505 this.editorcore.pushValue();
23509 // hide stuff that is not compatible
23523 * @event specialkey
23527 * @cfg {String} fieldClass @hide
23530 * @cfg {String} focusClass @hide
23533 * @cfg {String} autoCreate @hide
23536 * @cfg {String} inputType @hide
23539 * @cfg {String} invalidClass @hide
23542 * @cfg {String} invalidText @hide
23545 * @cfg {String} msgFx @hide
23548 * @cfg {String} validateOnBlur @hide
23557 Roo.namespace('Roo.bootstrap.htmleditor');
23559 * @class Roo.bootstrap.HtmlEditorToolbar1
23564 new Roo.bootstrap.HtmlEditor({
23567 new Roo.bootstrap.HtmlEditorToolbar1({
23568 disable : { fonts: 1 , format: 1, ..., ... , ...],
23574 * @cfg {Object} disable List of elements to disable..
23575 * @cfg {Array} btns List of additional buttons.
23579 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
23582 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
23585 Roo.apply(this, config);
23587 // default disabled, based on 'good practice'..
23588 this.disable = this.disable || {};
23589 Roo.applyIf(this.disable, {
23592 specialElements : true
23594 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
23596 this.editor = config.editor;
23597 this.editorcore = config.editor.editorcore;
23599 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
23601 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23602 // dont call parent... till later.
23604 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
23609 editorcore : false,
23614 "h1","h2","h3","h4","h5","h6",
23616 "abbr", "acronym", "address", "cite", "samp", "var",
23620 onRender : function(ct, position)
23622 // Roo.log("Call onRender: " + this.xtype);
23624 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
23626 this.el.dom.style.marginBottom = '0';
23628 var editorcore = this.editorcore;
23629 var editor= this.editor;
23632 var btn = function(id,cmd , toggle, handler, html){
23634 var event = toggle ? 'toggle' : 'click';
23639 xns: Roo.bootstrap,
23642 enableToggle:toggle !== false,
23644 pressed : toggle ? false : null,
23647 a.listeners[toggle ? 'toggle' : 'click'] = function() {
23648 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
23654 // var cb_box = function...
23659 xns: Roo.bootstrap,
23660 glyphicon : 'font',
23664 xns: Roo.bootstrap,
23668 Roo.each(this.formats, function(f) {
23669 style.menu.items.push({
23671 xns: Roo.bootstrap,
23672 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
23677 editorcore.insertTag(this.tagname);
23684 children.push(style);
23686 btn('bold',false,true);
23687 btn('italic',false,true);
23688 btn('align-left', 'justifyleft',true);
23689 btn('align-center', 'justifycenter',true);
23690 btn('align-right' , 'justifyright',true);
23691 btn('link', false, false, function(btn) {
23692 //Roo.log("create link?");
23693 var url = prompt(this.createLinkText, this.defaultLinkValue);
23694 if(url && url != 'http:/'+'/'){
23695 this.editorcore.relayCmd('createlink', url);
23698 btn('list','insertunorderedlist',true);
23699 btn('pencil', false,true, function(btn){
23701 this.toggleSourceEdit(btn.pressed);
23704 if (this.editor.btns.length > 0) {
23705 for (var i = 0; i<this.editor.btns.length; i++) {
23706 children.push(this.editor.btns[i]);
23714 xns: Roo.bootstrap,
23719 xns: Roo.bootstrap,
23724 cog.menu.items.push({
23726 xns: Roo.bootstrap,
23727 html : Clean styles,
23732 editorcore.insertTag(this.tagname);
23741 this.xtype = 'NavSimplebar';
23743 for(var i=0;i< children.length;i++) {
23745 this.buttons.add(this.addxtypeChild(children[i]));
23749 editor.on('editorevent', this.updateToolbar, this);
23751 onBtnClick : function(id)
23753 this.editorcore.relayCmd(id);
23754 this.editorcore.focus();
23758 * Protected method that will not generally be called directly. It triggers
23759 * a toolbar update by reading the markup state of the current selection in the editor.
23761 updateToolbar: function(){
23763 if(!this.editorcore.activated){
23764 this.editor.onFirstFocus(); // is this neeed?
23768 var btns = this.buttons;
23769 var doc = this.editorcore.doc;
23770 btns.get('bold').setActive(doc.queryCommandState('bold'));
23771 btns.get('italic').setActive(doc.queryCommandState('italic'));
23772 //btns.get('underline').setActive(doc.queryCommandState('underline'));
23774 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
23775 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
23776 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
23778 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
23779 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
23782 var ans = this.editorcore.getAllAncestors();
23783 if (this.formatCombo) {
23786 var store = this.formatCombo.store;
23787 this.formatCombo.setValue("");
23788 for (var i =0; i < ans.length;i++) {
23789 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
23791 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
23799 // hides menus... - so this cant be on a menu...
23800 Roo.bootstrap.MenuMgr.hideAll();
23802 Roo.bootstrap.MenuMgr.hideAll();
23803 //this.editorsyncValue();
23805 onFirstFocus: function() {
23806 this.buttons.each(function(item){
23810 toggleSourceEdit : function(sourceEditMode){
23813 if(sourceEditMode){
23814 Roo.log("disabling buttons");
23815 this.buttons.each( function(item){
23816 if(item.cmd != 'pencil'){
23822 Roo.log("enabling buttons");
23823 if(this.editorcore.initialized){
23824 this.buttons.each( function(item){
23830 Roo.log("calling toggole on editor");
23831 // tell the editor that it's been pressed..
23832 this.editor.toggleSourceEdit(sourceEditMode);
23842 * @class Roo.bootstrap.Table.AbstractSelectionModel
23843 * @extends Roo.util.Observable
23844 * Abstract base class for grid SelectionModels. It provides the interface that should be
23845 * implemented by descendant classes. This class should not be directly instantiated.
23848 Roo.bootstrap.Table.AbstractSelectionModel = function(){
23849 this.locked = false;
23850 Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
23854 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable, {
23855 /** @ignore Called by the grid automatically. Do not call directly. */
23856 init : function(grid){
23862 * Locks the selections.
23865 this.locked = true;
23869 * Unlocks the selections.
23871 unlock : function(){
23872 this.locked = false;
23876 * Returns true if the selections are locked.
23877 * @return {Boolean}
23879 isLocked : function(){
23880 return this.locked;
23884 * @extends Roo.bootstrap.Table.AbstractSelectionModel
23885 * @class Roo.bootstrap.Table.RowSelectionModel
23886 * The default SelectionModel used by {@link Roo.bootstrap.Table}.
23887 * It supports multiple selections and keyboard selection/navigation.
23889 * @param {Object} config
23892 Roo.bootstrap.Table.RowSelectionModel = function(config){
23893 Roo.apply(this, config);
23894 this.selections = new Roo.util.MixedCollection(false, function(o){
23899 this.lastActive = false;
23903 * @event selectionchange
23904 * Fires when the selection changes
23905 * @param {SelectionModel} this
23907 "selectionchange" : true,
23909 * @event afterselectionchange
23910 * Fires after the selection changes (eg. by key press or clicking)
23911 * @param {SelectionModel} this
23913 "afterselectionchange" : true,
23915 * @event beforerowselect
23916 * Fires when a row is selected being selected, return false to cancel.
23917 * @param {SelectionModel} this
23918 * @param {Number} rowIndex The selected index
23919 * @param {Boolean} keepExisting False if other selections will be cleared
23921 "beforerowselect" : true,
23924 * Fires when a row is selected.
23925 * @param {SelectionModel} this
23926 * @param {Number} rowIndex The selected index
23927 * @param {Roo.data.Record} r The record
23929 "rowselect" : true,
23931 * @event rowdeselect
23932 * Fires when a row is deselected.
23933 * @param {SelectionModel} this
23934 * @param {Number} rowIndex The selected index
23936 "rowdeselect" : true
23938 Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
23939 this.locked = false;
23942 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel, {
23944 * @cfg {Boolean} singleSelect
23945 * True to allow selection of only one row at a time (defaults to false)
23947 singleSelect : false,
23950 initEvents : function()
23953 //if(!this.grid.enableDragDrop && !this.grid.enableDrag){
23954 // this.growclickrid.on("mousedown", this.handleMouseDown, this);
23955 //}else{ // allow click to work like normal
23956 // this.grid.on("rowclick", this.handleDragableRowClick, this);
23958 //this.grid.on("rowdblclick", this.handleMouseDBClick, this);
23959 this.grid.on("rowclick", this.handleMouseDown, this);
23961 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
23962 "up" : function(e){
23964 this.selectPrevious(e.shiftKey);
23965 }else if(this.last !== false && this.lastActive !== false){
23966 var last = this.last;
23967 this.selectRange(this.last, this.lastActive-1);
23968 this.grid.getView().focusRow(this.lastActive);
23969 if(last !== false){
23973 this.selectFirstRow();
23975 this.fireEvent("afterselectionchange", this);
23977 "down" : function(e){
23979 this.selectNext(e.shiftKey);
23980 }else if(this.last !== false && this.lastActive !== false){
23981 var last = this.last;
23982 this.selectRange(this.last, this.lastActive+1);
23983 this.grid.getView().focusRow(this.lastActive);
23984 if(last !== false){
23988 this.selectFirstRow();
23990 this.fireEvent("afterselectionchange", this);
23994 this.grid.store.on('load', function(){
23995 this.selections.clear();
23998 var view = this.grid.view;
23999 view.on("refresh", this.onRefresh, this);
24000 view.on("rowupdated", this.onRowUpdated, this);
24001 view.on("rowremoved", this.onRemove, this);
24006 onRefresh : function()
24008 var ds = this.grid.store, i, v = this.grid.view;
24009 var s = this.selections;
24010 s.each(function(r){
24011 if((i = ds.indexOfId(r.id)) != -1){
24020 onRemove : function(v, index, r){
24021 this.selections.remove(r);
24025 onRowUpdated : function(v, index, r){
24026 if(this.isSelected(r)){
24027 v.onRowSelect(index);
24033 * @param {Array} records The records to select
24034 * @param {Boolean} keepExisting (optional) True to keep existing selections
24036 selectRecords : function(records, keepExisting)
24039 this.clearSelections();
24041 var ds = this.grid.store;
24042 for(var i = 0, len = records.length; i < len; i++){
24043 this.selectRow(ds.indexOf(records[i]), true);
24048 * Gets the number of selected rows.
24051 getCount : function(){
24052 return this.selections.length;
24056 * Selects the first row in the grid.
24058 selectFirstRow : function(){
24063 * Select the last row.
24064 * @param {Boolean} keepExisting (optional) True to keep existing selections
24066 selectLastRow : function(keepExisting){
24067 //this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
24068 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
24072 * Selects the row immediately following the last selected row.
24073 * @param {Boolean} keepExisting (optional) True to keep existing selections
24075 selectNext : function(keepExisting)
24077 if(this.last !== false && (this.last+1) < this.grid.store.getCount()){
24078 this.selectRow(this.last+1, keepExisting);
24079 this.grid.getView().focusRow(this.last);
24084 * Selects the row that precedes the last selected row.
24085 * @param {Boolean} keepExisting (optional) True to keep existing selections
24087 selectPrevious : function(keepExisting){
24089 this.selectRow(this.last-1, keepExisting);
24090 this.grid.getView().focusRow(this.last);
24095 * Returns the selected records
24096 * @return {Array} Array of selected records
24098 getSelections : function(){
24099 return [].concat(this.selections.items);
24103 * Returns the first selected record.
24106 getSelected : function(){
24107 return this.selections.itemAt(0);
24112 * Clears all selections.
24114 clearSelections : function(fast)
24120 var ds = this.grid.store;
24121 var s = this.selections;
24122 s.each(function(r){
24123 this.deselectRow(ds.indexOfId(r.id));
24127 this.selections.clear();
24134 * Selects all rows.
24136 selectAll : function(){
24140 this.selections.clear();
24141 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
24142 this.selectRow(i, true);
24147 * Returns True if there is a selection.
24148 * @return {Boolean}
24150 hasSelection : function(){
24151 return this.selections.length > 0;
24155 * Returns True if the specified row is selected.
24156 * @param {Number/Record} record The record or index of the record to check
24157 * @return {Boolean}
24159 isSelected : function(index){
24160 var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
24161 return (r && this.selections.key(r.id) ? true : false);
24165 * Returns True if the specified record id is selected.
24166 * @param {String} id The id of record to check
24167 * @return {Boolean}
24169 isIdSelected : function(id){
24170 return (this.selections.key(id) ? true : false);
24175 handleMouseDBClick : function(e, t){
24179 handleMouseDown : function(e, t)
24181 var rowIndex = this.grid.headerShow ? t.dom.rowIndex - 1 : t.dom.rowIndex ; // first row is header???
24182 if(this.isLocked() || rowIndex < 0 ){
24185 if(e.shiftKey && this.last !== false){
24186 var last = this.last;
24187 this.selectRange(last, rowIndex, e.ctrlKey);
24188 this.last = last; // reset the last
24192 var isSelected = this.isSelected(rowIndex);
24193 //Roo.log("select row:" + rowIndex);
24195 this.deselectRow(rowIndex);
24197 this.selectRow(rowIndex, true);
24201 if(e.button !== 0 && isSelected){
24202 alert('rowIndex 2: ' + rowIndex);
24203 view.focusRow(rowIndex);
24204 }else if(e.ctrlKey && isSelected){
24205 this.deselectRow(rowIndex);
24206 }else if(!isSelected){
24207 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
24208 view.focusRow(rowIndex);
24212 this.fireEvent("afterselectionchange", this);
24215 handleDragableRowClick : function(grid, rowIndex, e)
24217 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
24218 this.selectRow(rowIndex, false);
24219 grid.view.focusRow(rowIndex);
24220 this.fireEvent("afterselectionchange", this);
24225 * Selects multiple rows.
24226 * @param {Array} rows Array of the indexes of the row to select
24227 * @param {Boolean} keepExisting (optional) True to keep existing selections
24229 selectRows : function(rows, keepExisting){
24231 this.clearSelections();
24233 for(var i = 0, len = rows.length; i < len; i++){
24234 this.selectRow(rows[i], true);
24239 * Selects a range of rows. All rows in between startRow and endRow are also selected.
24240 * @param {Number} startRow The index of the first row in the range
24241 * @param {Number} endRow The index of the last row in the range
24242 * @param {Boolean} keepExisting (optional) True to retain existing selections
24244 selectRange : function(startRow, endRow, keepExisting){
24249 this.clearSelections();
24251 if(startRow <= endRow){
24252 for(var i = startRow; i <= endRow; i++){
24253 this.selectRow(i, true);
24256 for(var i = startRow; i >= endRow; i--){
24257 this.selectRow(i, true);
24263 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
24264 * @param {Number} startRow The index of the first row in the range
24265 * @param {Number} endRow The index of the last row in the range
24267 deselectRange : function(startRow, endRow, preventViewNotify){
24271 for(var i = startRow; i <= endRow; i++){
24272 this.deselectRow(i, preventViewNotify);
24278 * @param {Number} row The index of the row to select
24279 * @param {Boolean} keepExisting (optional) True to keep existing selections
24281 selectRow : function(index, keepExisting, preventViewNotify)
24283 if(this.locked || (index < 0 || index > this.grid.store.getCount())) {
24286 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
24287 if(!keepExisting || this.singleSelect){
24288 this.clearSelections();
24291 var r = this.grid.store.getAt(index);
24292 //console.log('selectRow - record id :' + r.id);
24294 this.selections.add(r);
24295 this.last = this.lastActive = index;
24296 if(!preventViewNotify){
24297 var proxy = new Roo.Element(
24298 this.grid.getRowDom(index)
24300 proxy.addClass('bg-info info');
24302 this.fireEvent("rowselect", this, index, r);
24303 this.fireEvent("selectionchange", this);
24309 * @param {Number} row The index of the row to deselect
24311 deselectRow : function(index, preventViewNotify)
24316 if(this.last == index){
24319 if(this.lastActive == index){
24320 this.lastActive = false;
24323 var r = this.grid.store.getAt(index);
24328 this.selections.remove(r);
24329 //.console.log('deselectRow - record id :' + r.id);
24330 if(!preventViewNotify){
24332 var proxy = new Roo.Element(
24333 this.grid.getRowDom(index)
24335 proxy.removeClass('bg-info info');
24337 this.fireEvent("rowdeselect", this, index);
24338 this.fireEvent("selectionchange", this);
24342 restoreLast : function(){
24344 this.last = this._last;
24349 acceptsNav : function(row, col, cm){
24350 return !cm.isHidden(col) && cm.isCellEditable(col, row);
24354 onEditorKey : function(field, e){
24355 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
24360 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
24362 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
24364 }else if(k == e.ENTER && !e.ctrlKey){
24368 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
24370 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
24372 }else if(k == e.ESC){
24376 g.startEditing(newCell[0], newCell[1]);
24382 * Ext JS Library 1.1.1
24383 * Copyright(c) 2006-2007, Ext JS, LLC.
24385 * Originally Released Under LGPL - original licence link has changed is not relivant.
24388 * <script type="text/javascript">
24392 * @class Roo.bootstrap.PagingToolbar
24393 * @extends Roo.bootstrap.NavSimplebar
24394 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
24396 * Create a new PagingToolbar
24397 * @param {Object} config The config object
24398 * @param {Roo.data.Store} store
24400 Roo.bootstrap.PagingToolbar = function(config)
24402 // old args format still supported... - xtype is prefered..
24403 // created from xtype...
24405 this.ds = config.dataSource;
24407 if (config.store && !this.ds) {
24408 this.store= Roo.factory(config.store, Roo.data);
24409 this.ds = this.store;
24410 this.ds.xmodule = this.xmodule || false;
24413 this.toolbarItems = [];
24414 if (config.items) {
24415 this.toolbarItems = config.items;
24418 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
24423 this.bind(this.ds);
24426 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
24430 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
24432 * @cfg {Roo.data.Store} dataSource
24433 * The underlying data store providing the paged data
24436 * @cfg {String/HTMLElement/Element} container
24437 * container The id or element that will contain the toolbar
24440 * @cfg {Boolean} displayInfo
24441 * True to display the displayMsg (defaults to false)
24444 * @cfg {Number} pageSize
24445 * The number of records to display per page (defaults to 20)
24449 * @cfg {String} displayMsg
24450 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
24452 displayMsg : 'Displaying {0} - {1} of {2}',
24454 * @cfg {String} emptyMsg
24455 * The message to display when no records are found (defaults to "No data to display")
24457 emptyMsg : 'No data to display',
24459 * Customizable piece of the default paging text (defaults to "Page")
24462 beforePageText : "Page",
24464 * Customizable piece of the default paging text (defaults to "of %0")
24467 afterPageText : "of {0}",
24469 * Customizable piece of the default paging text (defaults to "First Page")
24472 firstText : "First Page",
24474 * Customizable piece of the default paging text (defaults to "Previous Page")
24477 prevText : "Previous Page",
24479 * Customizable piece of the default paging text (defaults to "Next Page")
24482 nextText : "Next Page",
24484 * Customizable piece of the default paging text (defaults to "Last Page")
24487 lastText : "Last Page",
24489 * Customizable piece of the default paging text (defaults to "Refresh")
24492 refreshText : "Refresh",
24496 onRender : function(ct, position)
24498 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
24499 this.navgroup.parentId = this.id;
24500 this.navgroup.onRender(this.el, null);
24501 // add the buttons to the navgroup
24503 if(this.displayInfo){
24504 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
24505 this.displayEl = this.el.select('.x-paging-info', true).first();
24506 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
24507 // this.displayEl = navel.el.select('span',true).first();
24513 Roo.each(_this.buttons, function(e){ // this might need to use render????
24514 Roo.factory(e).onRender(_this.el, null);
24518 Roo.each(_this.toolbarItems, function(e) {
24519 _this.navgroup.addItem(e);
24523 this.first = this.navgroup.addItem({
24524 tooltip: this.firstText,
24526 icon : 'fa fa-backward',
24528 preventDefault: true,
24529 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
24532 this.prev = this.navgroup.addItem({
24533 tooltip: this.prevText,
24535 icon : 'fa fa-step-backward',
24537 preventDefault: true,
24538 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
24540 //this.addSeparator();
24543 var field = this.navgroup.addItem( {
24545 cls : 'x-paging-position',
24547 html : this.beforePageText +
24548 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
24549 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
24552 this.field = field.el.select('input', true).first();
24553 this.field.on("keydown", this.onPagingKeydown, this);
24554 this.field.on("focus", function(){this.dom.select();});
24557 this.afterTextEl = field.el.select('.x-paging-after',true).first();
24558 //this.field.setHeight(18);
24559 //this.addSeparator();
24560 this.next = this.navgroup.addItem({
24561 tooltip: this.nextText,
24563 html : ' <i class="fa fa-step-forward">',
24565 preventDefault: true,
24566 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
24568 this.last = this.navgroup.addItem({
24569 tooltip: this.lastText,
24570 icon : 'fa fa-forward',
24573 preventDefault: true,
24574 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
24576 //this.addSeparator();
24577 this.loading = this.navgroup.addItem({
24578 tooltip: this.refreshText,
24579 icon: 'fa fa-refresh',
24580 preventDefault: true,
24581 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
24587 updateInfo : function(){
24588 if(this.displayEl){
24589 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
24590 var msg = count == 0 ?
24594 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
24596 this.displayEl.update(msg);
24601 onLoad : function(ds, r, o)
24603 this.cursor = o.params.start ? o.params.start : 0;
24605 var d = this.getPageData(),
24610 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
24611 this.field.dom.value = ap;
24612 this.first.setDisabled(ap == 1);
24613 this.prev.setDisabled(ap == 1);
24614 this.next.setDisabled(ap == ps);
24615 this.last.setDisabled(ap == ps);
24616 this.loading.enable();
24621 getPageData : function(){
24622 var total = this.ds.getTotalCount();
24625 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
24626 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
24631 onLoadError : function(){
24632 this.loading.enable();
24636 onPagingKeydown : function(e){
24637 var k = e.getKey();
24638 var d = this.getPageData();
24640 var v = this.field.dom.value, pageNum;
24641 if(!v || isNaN(pageNum = parseInt(v, 10))){
24642 this.field.dom.value = d.activePage;
24645 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
24646 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24649 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))
24651 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
24652 this.field.dom.value = pageNum;
24653 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
24656 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
24658 var v = this.field.dom.value, pageNum;
24659 var increment = (e.shiftKey) ? 10 : 1;
24660 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
24663 if(!v || isNaN(pageNum = parseInt(v, 10))) {
24664 this.field.dom.value = d.activePage;
24667 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
24669 this.field.dom.value = parseInt(v, 10) + increment;
24670 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
24671 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24678 beforeLoad : function(){
24680 this.loading.disable();
24685 onClick : function(which){
24694 ds.load({params:{start: 0, limit: this.pageSize}});
24697 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
24700 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
24703 var total = ds.getTotalCount();
24704 var extra = total % this.pageSize;
24705 var lastStart = extra ? (total - extra) : total-this.pageSize;
24706 ds.load({params:{start: lastStart, limit: this.pageSize}});
24709 ds.load({params:{start: this.cursor, limit: this.pageSize}});
24715 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
24716 * @param {Roo.data.Store} store The data store to unbind
24718 unbind : function(ds){
24719 ds.un("beforeload", this.beforeLoad, this);
24720 ds.un("load", this.onLoad, this);
24721 ds.un("loadexception", this.onLoadError, this);
24722 ds.un("remove", this.updateInfo, this);
24723 ds.un("add", this.updateInfo, this);
24724 this.ds = undefined;
24728 * Binds the paging toolbar to the specified {@link Roo.data.Store}
24729 * @param {Roo.data.Store} store The data store to bind
24731 bind : function(ds){
24732 ds.on("beforeload", this.beforeLoad, this);
24733 ds.on("load", this.onLoad, this);
24734 ds.on("loadexception", this.onLoadError, this);
24735 ds.on("remove", this.updateInfo, this);
24736 ds.on("add", this.updateInfo, this);
24747 * @class Roo.bootstrap.MessageBar
24748 * @extends Roo.bootstrap.Component
24749 * Bootstrap MessageBar class
24750 * @cfg {String} html contents of the MessageBar
24751 * @cfg {String} weight (info | success | warning | danger) default info
24752 * @cfg {String} beforeClass insert the bar before the given class
24753 * @cfg {Boolean} closable (true | false) default false
24754 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
24757 * Create a new Element
24758 * @param {Object} config The config object
24761 Roo.bootstrap.MessageBar = function(config){
24762 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
24765 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
24771 beforeClass: 'bootstrap-sticky-wrap',
24773 getAutoCreate : function(){
24777 cls: 'alert alert-dismissable alert-' + this.weight,
24782 html: this.html || ''
24788 cfg.cls += ' alert-messages-fixed';
24802 onRender : function(ct, position)
24804 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
24807 var cfg = Roo.apply({}, this.getAutoCreate());
24811 cfg.cls += ' ' + this.cls;
24814 cfg.style = this.style;
24816 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
24818 this.el.setVisibilityMode(Roo.Element.DISPLAY);
24821 this.el.select('>button.close').on('click', this.hide, this);
24827 if (!this.rendered) {
24833 this.fireEvent('show', this);
24839 if (!this.rendered) {
24845 this.fireEvent('hide', this);
24848 update : function()
24850 // var e = this.el.dom.firstChild;
24852 // if(this.closable){
24853 // e = e.nextSibling;
24856 // e.data = this.html || '';
24858 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
24874 * @class Roo.bootstrap.Graph
24875 * @extends Roo.bootstrap.Component
24876 * Bootstrap Graph class
24880 @cfg {String} graphtype bar | vbar | pie
24881 @cfg {number} g_x coodinator | centre x (pie)
24882 @cfg {number} g_y coodinator | centre y (pie)
24883 @cfg {number} g_r radius (pie)
24884 @cfg {number} g_height height of the chart (respected by all elements in the set)
24885 @cfg {number} g_width width of the chart (respected by all elements in the set)
24886 @cfg {Object} title The title of the chart
24889 -opts (object) options for the chart
24891 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
24892 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
24894 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.
24895 o stacked (boolean) whether or not to tread values as in a stacked bar chart
24897 o stretch (boolean)
24899 -opts (object) options for the pie
24902 o startAngle (number)
24903 o endAngle (number)
24907 * Create a new Input
24908 * @param {Object} config The config object
24911 Roo.bootstrap.Graph = function(config){
24912 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
24918 * The img click event for the img.
24919 * @param {Roo.EventObject} e
24925 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
24936 //g_colors: this.colors,
24943 getAutoCreate : function(){
24954 onRender : function(ct,position){
24957 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
24959 if (typeof(Raphael) == 'undefined') {
24960 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
24964 this.raphael = Raphael(this.el.dom);
24966 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
24967 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
24968 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
24969 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
24971 r.text(160, 10, "Single Series Chart").attr(txtattr);
24972 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
24973 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
24974 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
24976 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
24977 r.barchart(330, 10, 300, 220, data1);
24978 r.barchart(10, 250, 300, 220, data2, {stacked: true});
24979 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
24982 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
24983 // r.barchart(30, 30, 560, 250, xdata, {
24984 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
24985 // axis : "0 0 1 1",
24986 // axisxlabels : xdata
24987 // //yvalues : cols,
24990 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
24992 // this.load(null,xdata,{
24993 // axis : "0 0 1 1",
24994 // axisxlabels : xdata
24999 load : function(graphtype,xdata,opts)
25001 this.raphael.clear();
25003 graphtype = this.graphtype;
25008 var r = this.raphael,
25009 fin = function () {
25010 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
25012 fout = function () {
25013 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
25015 pfin = function() {
25016 this.sector.stop();
25017 this.sector.scale(1.1, 1.1, this.cx, this.cy);
25020 this.label[0].stop();
25021 this.label[0].attr({ r: 7.5 });
25022 this.label[1].attr({ "font-weight": 800 });
25025 pfout = function() {
25026 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
25029 this.label[0].animate({ r: 5 }, 500, "bounce");
25030 this.label[1].attr({ "font-weight": 400 });
25036 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25039 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25042 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
25043 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
25045 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
25052 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
25057 setTitle: function(o)
25062 initEvents: function() {
25065 this.el.on('click', this.onClick, this);
25069 onClick : function(e)
25071 Roo.log('img onclick');
25072 this.fireEvent('click', this, e);
25084 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25087 * @class Roo.bootstrap.dash.NumberBox
25088 * @extends Roo.bootstrap.Component
25089 * Bootstrap NumberBox class
25090 * @cfg {String} headline Box headline
25091 * @cfg {String} content Box content
25092 * @cfg {String} icon Box icon
25093 * @cfg {String} footer Footer text
25094 * @cfg {String} fhref Footer href
25097 * Create a new NumberBox
25098 * @param {Object} config The config object
25102 Roo.bootstrap.dash.NumberBox = function(config){
25103 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
25107 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
25116 getAutoCreate : function(){
25120 cls : 'small-box ',
25128 cls : 'roo-headline',
25129 html : this.headline
25133 cls : 'roo-content',
25134 html : this.content
25148 cls : 'ion ' + this.icon
25157 cls : 'small-box-footer',
25158 href : this.fhref || '#',
25162 cfg.cn.push(footer);
25169 onRender : function(ct,position){
25170 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
25177 setHeadline: function (value)
25179 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
25182 setFooter: function (value, href)
25184 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
25187 this.el.select('a.small-box-footer',true).first().attr('href', href);
25192 setContent: function (value)
25194 this.el.select('.roo-content',true).first().dom.innerHTML = value;
25197 initEvents: function()
25211 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25214 * @class Roo.bootstrap.dash.TabBox
25215 * @extends Roo.bootstrap.Component
25216 * Bootstrap TabBox class
25217 * @cfg {String} title Title of the TabBox
25218 * @cfg {String} icon Icon of the TabBox
25219 * @cfg {Boolean} showtabs (true|false) show the tabs default true
25220 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
25223 * Create a new TabBox
25224 * @param {Object} config The config object
25228 Roo.bootstrap.dash.TabBox = function(config){
25229 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
25234 * When a pane is added
25235 * @param {Roo.bootstrap.dash.TabPane} pane
25239 * @event activatepane
25240 * When a pane is activated
25241 * @param {Roo.bootstrap.dash.TabPane} pane
25243 "activatepane" : true
25251 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
25256 tabScrollable : false,
25258 getChildContainer : function()
25260 return this.el.select('.tab-content', true).first();
25263 getAutoCreate : function(){
25267 cls: 'pull-left header',
25275 cls: 'fa ' + this.icon
25281 cls: 'nav nav-tabs pull-right',
25287 if(this.tabScrollable){
25294 cls: 'nav nav-tabs pull-right',
25305 cls: 'nav-tabs-custom',
25310 cls: 'tab-content no-padding',
25318 initEvents : function()
25320 //Roo.log('add add pane handler');
25321 this.on('addpane', this.onAddPane, this);
25324 * Updates the box title
25325 * @param {String} html to set the title to.
25327 setTitle : function(value)
25329 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
25331 onAddPane : function(pane)
25333 this.panes.push(pane);
25334 //Roo.log('addpane');
25336 // tabs are rendere left to right..
25337 if(!this.showtabs){
25341 var ctr = this.el.select('.nav-tabs', true).first();
25344 var existing = ctr.select('.nav-tab',true);
25345 var qty = existing.getCount();;
25348 var tab = ctr.createChild({
25350 cls : 'nav-tab' + (qty ? '' : ' active'),
25358 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
25361 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
25363 pane.el.addClass('active');
25368 onTabClick : function(ev,un,ob,pane)
25370 //Roo.log('tab - prev default');
25371 ev.preventDefault();
25374 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
25375 pane.tab.addClass('active');
25376 //Roo.log(pane.title);
25377 this.getChildContainer().select('.tab-pane',true).removeClass('active');
25378 // technically we should have a deactivate event.. but maybe add later.
25379 // and it should not de-activate the selected tab...
25380 this.fireEvent('activatepane', pane);
25381 pane.el.addClass('active');
25382 pane.fireEvent('activate');
25387 getActivePane : function()
25390 Roo.each(this.panes, function(p) {
25391 if(p.el.hasClass('active')){
25412 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25414 * @class Roo.bootstrap.TabPane
25415 * @extends Roo.bootstrap.Component
25416 * Bootstrap TabPane class
25417 * @cfg {Boolean} active (false | true) Default false
25418 * @cfg {String} title title of panel
25422 * Create a new TabPane
25423 * @param {Object} config The config object
25426 Roo.bootstrap.dash.TabPane = function(config){
25427 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
25433 * When a pane is activated
25434 * @param {Roo.bootstrap.dash.TabPane} pane
25441 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
25446 // the tabBox that this is attached to.
25449 getAutoCreate : function()
25457 cfg.cls += ' active';
25462 initEvents : function()
25464 //Roo.log('trigger add pane handler');
25465 this.parent().fireEvent('addpane', this)
25469 * Updates the tab title
25470 * @param {String} html to set the title to.
25472 setTitle: function(str)
25478 this.tab.select('a', true).first().dom.innerHTML = str;
25495 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25498 * @class Roo.bootstrap.menu.Menu
25499 * @extends Roo.bootstrap.Component
25500 * Bootstrap Menu class - container for Menu
25501 * @cfg {String} html Text of the menu
25502 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
25503 * @cfg {String} icon Font awesome icon
25504 * @cfg {String} pos Menu align to (top | bottom) default bottom
25508 * Create a new Menu
25509 * @param {Object} config The config object
25513 Roo.bootstrap.menu.Menu = function(config){
25514 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
25518 * @event beforeshow
25519 * Fires before this menu is displayed
25520 * @param {Roo.bootstrap.menu.Menu} this
25524 * @event beforehide
25525 * Fires before this menu is hidden
25526 * @param {Roo.bootstrap.menu.Menu} this
25531 * Fires after this menu is displayed
25532 * @param {Roo.bootstrap.menu.Menu} this
25537 * Fires after this menu is hidden
25538 * @param {Roo.bootstrap.menu.Menu} this
25543 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
25544 * @param {Roo.bootstrap.menu.Menu} this
25545 * @param {Roo.EventObject} e
25552 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
25556 weight : 'default',
25561 getChildContainer : function() {
25562 if(this.isSubMenu){
25566 return this.el.select('ul.dropdown-menu', true).first();
25569 getAutoCreate : function()
25574 cls : 'roo-menu-text',
25582 cls : 'fa ' + this.icon
25593 cls : 'dropdown-button btn btn-' + this.weight,
25598 cls : 'dropdown-toggle btn btn-' + this.weight,
25608 cls : 'dropdown-menu'
25614 if(this.pos == 'top'){
25615 cfg.cls += ' dropup';
25618 if(this.isSubMenu){
25621 cls : 'dropdown-menu'
25628 onRender : function(ct, position)
25630 this.isSubMenu = ct.hasClass('dropdown-submenu');
25632 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
25635 initEvents : function()
25637 if(this.isSubMenu){
25641 this.hidden = true;
25643 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
25644 this.triggerEl.on('click', this.onTriggerPress, this);
25646 this.buttonEl = this.el.select('button.dropdown-button', true).first();
25647 this.buttonEl.on('click', this.onClick, this);
25653 if(this.isSubMenu){
25657 return this.el.select('ul.dropdown-menu', true).first();
25660 onClick : function(e)
25662 this.fireEvent("click", this, e);
25665 onTriggerPress : function(e)
25667 if (this.isVisible()) {
25674 isVisible : function(){
25675 return !this.hidden;
25680 this.fireEvent("beforeshow", this);
25682 this.hidden = false;
25683 this.el.addClass('open');
25685 Roo.get(document).on("mouseup", this.onMouseUp, this);
25687 this.fireEvent("show", this);
25694 this.fireEvent("beforehide", this);
25696 this.hidden = true;
25697 this.el.removeClass('open');
25699 Roo.get(document).un("mouseup", this.onMouseUp);
25701 this.fireEvent("hide", this);
25704 onMouseUp : function()
25718 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25721 * @class Roo.bootstrap.menu.Item
25722 * @extends Roo.bootstrap.Component
25723 * Bootstrap MenuItem class
25724 * @cfg {Boolean} submenu (true | false) default false
25725 * @cfg {String} html text of the item
25726 * @cfg {String} href the link
25727 * @cfg {Boolean} disable (true | false) default false
25728 * @cfg {Boolean} preventDefault (true | false) default true
25729 * @cfg {String} icon Font awesome icon
25730 * @cfg {String} pos Submenu align to (left | right) default right
25734 * Create a new Item
25735 * @param {Object} config The config object
25739 Roo.bootstrap.menu.Item = function(config){
25740 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
25744 * Fires when the mouse is hovering over this menu
25745 * @param {Roo.bootstrap.menu.Item} this
25746 * @param {Roo.EventObject} e
25751 * Fires when the mouse exits this menu
25752 * @param {Roo.bootstrap.menu.Item} this
25753 * @param {Roo.EventObject} e
25759 * The raw click event for the entire grid.
25760 * @param {Roo.EventObject} e
25766 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
25771 preventDefault: true,
25776 getAutoCreate : function()
25781 cls : 'roo-menu-item-text',
25789 cls : 'fa ' + this.icon
25798 href : this.href || '#',
25805 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
25809 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
25811 if(this.pos == 'left'){
25812 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
25819 initEvents : function()
25821 this.el.on('mouseover', this.onMouseOver, this);
25822 this.el.on('mouseout', this.onMouseOut, this);
25824 this.el.select('a', true).first().on('click', this.onClick, this);
25828 onClick : function(e)
25830 if(this.preventDefault){
25831 e.preventDefault();
25834 this.fireEvent("click", this, e);
25837 onMouseOver : function(e)
25839 if(this.submenu && this.pos == 'left'){
25840 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
25843 this.fireEvent("mouseover", this, e);
25846 onMouseOut : function(e)
25848 this.fireEvent("mouseout", this, e);
25860 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25863 * @class Roo.bootstrap.menu.Separator
25864 * @extends Roo.bootstrap.Component
25865 * Bootstrap Separator class
25868 * Create a new Separator
25869 * @param {Object} config The config object
25873 Roo.bootstrap.menu.Separator = function(config){
25874 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
25877 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
25879 getAutoCreate : function(){
25900 * @class Roo.bootstrap.Tooltip
25901 * Bootstrap Tooltip class
25902 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
25903 * to determine which dom element triggers the tooltip.
25905 * It needs to add support for additional attributes like tooltip-position
25908 * Create a new Toolti
25909 * @param {Object} config The config object
25912 Roo.bootstrap.Tooltip = function(config){
25913 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
25915 this.alignment = Roo.bootstrap.Tooltip.alignment;
25917 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
25918 this.alignment = config.alignment;
25923 Roo.apply(Roo.bootstrap.Tooltip, {
25925 * @function init initialize tooltip monitoring.
25929 currentTip : false,
25930 currentRegion : false,
25936 Roo.get(document).on('mouseover', this.enter ,this);
25937 Roo.get(document).on('mouseout', this.leave, this);
25940 this.currentTip = new Roo.bootstrap.Tooltip();
25943 enter : function(ev)
25945 var dom = ev.getTarget();
25947 //Roo.log(['enter',dom]);
25948 var el = Roo.fly(dom);
25949 if (this.currentEl) {
25951 //Roo.log(this.currentEl);
25952 //Roo.log(this.currentEl.contains(dom));
25953 if (this.currentEl == el) {
25956 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
25962 if (this.currentTip.el) {
25963 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
25967 if(!el || el.dom == document){
25973 // you can not look for children, as if el is the body.. then everythign is the child..
25974 if (!el.attr('tooltip')) { //
25975 if (!el.select("[tooltip]").elements.length) {
25978 // is the mouse over this child...?
25979 bindEl = el.select("[tooltip]").first();
25980 var xy = ev.getXY();
25981 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
25982 //Roo.log("not in region.");
25985 //Roo.log("child element over..");
25988 this.currentEl = bindEl;
25989 this.currentTip.bind(bindEl);
25990 this.currentRegion = Roo.lib.Region.getRegion(dom);
25991 this.currentTip.enter();
25994 leave : function(ev)
25996 var dom = ev.getTarget();
25997 //Roo.log(['leave',dom]);
25998 if (!this.currentEl) {
26003 if (dom != this.currentEl.dom) {
26006 var xy = ev.getXY();
26007 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
26010 // only activate leave if mouse cursor is outside... bounding box..
26015 if (this.currentTip) {
26016 this.currentTip.leave();
26018 //Roo.log('clear currentEl');
26019 this.currentEl = false;
26024 'left' : ['r-l', [-2,0], 'right'],
26025 'right' : ['l-r', [2,0], 'left'],
26026 'bottom' : ['t-b', [0,2], 'top'],
26027 'top' : [ 'b-t', [0,-2], 'bottom']
26033 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
26038 delay : null, // can be { show : 300 , hide: 500}
26042 hoverState : null, //???
26044 placement : 'bottom',
26048 getAutoCreate : function(){
26055 cls : 'tooltip-arrow'
26058 cls : 'tooltip-inner'
26065 bind : function(el)
26071 enter : function () {
26073 if (this.timeout != null) {
26074 clearTimeout(this.timeout);
26077 this.hoverState = 'in';
26078 //Roo.log("enter - show");
26079 if (!this.delay || !this.delay.show) {
26084 this.timeout = setTimeout(function () {
26085 if (_t.hoverState == 'in') {
26088 }, this.delay.show);
26092 clearTimeout(this.timeout);
26094 this.hoverState = 'out';
26095 if (!this.delay || !this.delay.hide) {
26101 this.timeout = setTimeout(function () {
26102 //Roo.log("leave - timeout");
26104 if (_t.hoverState == 'out') {
26106 Roo.bootstrap.Tooltip.currentEl = false;
26111 show : function (msg)
26114 this.render(document.body);
26117 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
26119 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
26121 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
26123 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
26125 var placement = typeof this.placement == 'function' ?
26126 this.placement.call(this, this.el, on_el) :
26129 var autoToken = /\s?auto?\s?/i;
26130 var autoPlace = autoToken.test(placement);
26132 placement = placement.replace(autoToken, '') || 'top';
26136 //this.el.setXY([0,0]);
26138 //this.el.dom.style.display='block';
26140 //this.el.appendTo(on_el);
26142 var p = this.getPosition();
26143 var box = this.el.getBox();
26149 var align = this.alignment[placement];
26151 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
26153 if(placement == 'top' || placement == 'bottom'){
26155 placement = 'right';
26158 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
26159 placement = 'left';
26162 var scroll = Roo.select('body', true).first().getScroll();
26164 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
26170 this.el.alignTo(this.bindEl, align[0],align[1]);
26171 //var arrow = this.el.select('.arrow',true).first();
26172 //arrow.set(align[2],
26174 this.el.addClass(placement);
26176 this.el.addClass('in fade');
26178 this.hoverState = null;
26180 if (this.el.hasClass('fade')) {
26191 //this.el.setXY([0,0]);
26192 this.el.removeClass('in');
26208 * @class Roo.bootstrap.LocationPicker
26209 * @extends Roo.bootstrap.Component
26210 * Bootstrap LocationPicker class
26211 * @cfg {Number} latitude Position when init default 0
26212 * @cfg {Number} longitude Position when init default 0
26213 * @cfg {Number} zoom default 15
26214 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
26215 * @cfg {Boolean} mapTypeControl default false
26216 * @cfg {Boolean} disableDoubleClickZoom default false
26217 * @cfg {Boolean} scrollwheel default true
26218 * @cfg {Boolean} streetViewControl default false
26219 * @cfg {Number} radius default 0
26220 * @cfg {String} locationName
26221 * @cfg {Boolean} draggable default true
26222 * @cfg {Boolean} enableAutocomplete default false
26223 * @cfg {Boolean} enableReverseGeocode default true
26224 * @cfg {String} markerTitle
26227 * Create a new LocationPicker
26228 * @param {Object} config The config object
26232 Roo.bootstrap.LocationPicker = function(config){
26234 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
26239 * Fires when the picker initialized.
26240 * @param {Roo.bootstrap.LocationPicker} this
26241 * @param {Google Location} location
26245 * @event positionchanged
26246 * Fires when the picker position changed.
26247 * @param {Roo.bootstrap.LocationPicker} this
26248 * @param {Google Location} location
26250 positionchanged : true,
26253 * Fires when the map resize.
26254 * @param {Roo.bootstrap.LocationPicker} this
26259 * Fires when the map show.
26260 * @param {Roo.bootstrap.LocationPicker} this
26265 * Fires when the map hide.
26266 * @param {Roo.bootstrap.LocationPicker} this
26271 * Fires when click the map.
26272 * @param {Roo.bootstrap.LocationPicker} this
26273 * @param {Map event} e
26277 * @event mapRightClick
26278 * Fires when right click the map.
26279 * @param {Roo.bootstrap.LocationPicker} this
26280 * @param {Map event} e
26282 mapRightClick : true,
26284 * @event markerClick
26285 * Fires when click the marker.
26286 * @param {Roo.bootstrap.LocationPicker} this
26287 * @param {Map event} e
26289 markerClick : true,
26291 * @event markerRightClick
26292 * Fires when right click the marker.
26293 * @param {Roo.bootstrap.LocationPicker} this
26294 * @param {Map event} e
26296 markerRightClick : true,
26298 * @event OverlayViewDraw
26299 * Fires when OverlayView Draw
26300 * @param {Roo.bootstrap.LocationPicker} this
26302 OverlayViewDraw : true,
26304 * @event OverlayViewOnAdd
26305 * Fires when OverlayView Draw
26306 * @param {Roo.bootstrap.LocationPicker} this
26308 OverlayViewOnAdd : true,
26310 * @event OverlayViewOnRemove
26311 * Fires when OverlayView Draw
26312 * @param {Roo.bootstrap.LocationPicker} this
26314 OverlayViewOnRemove : true,
26316 * @event OverlayViewShow
26317 * Fires when OverlayView Draw
26318 * @param {Roo.bootstrap.LocationPicker} this
26319 * @param {Pixel} cpx
26321 OverlayViewShow : true,
26323 * @event OverlayViewHide
26324 * Fires when OverlayView Draw
26325 * @param {Roo.bootstrap.LocationPicker} this
26327 OverlayViewHide : true,
26329 * @event loadexception
26330 * Fires when load google lib failed.
26331 * @param {Roo.bootstrap.LocationPicker} this
26333 loadexception : true
26338 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
26340 gMapContext: false,
26346 mapTypeControl: false,
26347 disableDoubleClickZoom: false,
26349 streetViewControl: false,
26353 enableAutocomplete: false,
26354 enableReverseGeocode: true,
26357 getAutoCreate: function()
26362 cls: 'roo-location-picker'
26368 initEvents: function(ct, position)
26370 if(!this.el.getWidth() || this.isApplied()){
26374 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26379 initial: function()
26381 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
26382 this.fireEvent('loadexception', this);
26386 if(!this.mapTypeId){
26387 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
26390 this.gMapContext = this.GMapContext();
26392 this.initOverlayView();
26394 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
26398 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
26399 _this.setPosition(_this.gMapContext.marker.position);
26402 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
26403 _this.fireEvent('mapClick', this, event);
26407 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
26408 _this.fireEvent('mapRightClick', this, event);
26412 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
26413 _this.fireEvent('markerClick', this, event);
26417 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
26418 _this.fireEvent('markerRightClick', this, event);
26422 this.setPosition(this.gMapContext.location);
26424 this.fireEvent('initial', this, this.gMapContext.location);
26427 initOverlayView: function()
26431 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
26435 _this.fireEvent('OverlayViewDraw', _this);
26440 _this.fireEvent('OverlayViewOnAdd', _this);
26443 onRemove: function()
26445 _this.fireEvent('OverlayViewOnRemove', _this);
26448 show: function(cpx)
26450 _this.fireEvent('OverlayViewShow', _this, cpx);
26455 _this.fireEvent('OverlayViewHide', _this);
26461 fromLatLngToContainerPixel: function(event)
26463 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
26466 isApplied: function()
26468 return this.getGmapContext() == false ? false : true;
26471 getGmapContext: function()
26473 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
26476 GMapContext: function()
26478 var position = new google.maps.LatLng(this.latitude, this.longitude);
26480 var _map = new google.maps.Map(this.el.dom, {
26483 mapTypeId: this.mapTypeId,
26484 mapTypeControl: this.mapTypeControl,
26485 disableDoubleClickZoom: this.disableDoubleClickZoom,
26486 scrollwheel: this.scrollwheel,
26487 streetViewControl: this.streetViewControl,
26488 locationName: this.locationName,
26489 draggable: this.draggable,
26490 enableAutocomplete: this.enableAutocomplete,
26491 enableReverseGeocode: this.enableReverseGeocode
26494 var _marker = new google.maps.Marker({
26495 position: position,
26497 title: this.markerTitle,
26498 draggable: this.draggable
26505 location: position,
26506 radius: this.radius,
26507 locationName: this.locationName,
26508 addressComponents: {
26509 formatted_address: null,
26510 addressLine1: null,
26511 addressLine2: null,
26513 streetNumber: null,
26517 stateOrProvince: null
26520 domContainer: this.el.dom,
26521 geodecoder: new google.maps.Geocoder()
26525 drawCircle: function(center, radius, options)
26527 if (this.gMapContext.circle != null) {
26528 this.gMapContext.circle.setMap(null);
26532 options = Roo.apply({}, options, {
26533 strokeColor: "#0000FF",
26534 strokeOpacity: .35,
26536 fillColor: "#0000FF",
26540 options.map = this.gMapContext.map;
26541 options.radius = radius;
26542 options.center = center;
26543 this.gMapContext.circle = new google.maps.Circle(options);
26544 return this.gMapContext.circle;
26550 setPosition: function(location)
26552 this.gMapContext.location = location;
26553 this.gMapContext.marker.setPosition(location);
26554 this.gMapContext.map.panTo(location);
26555 this.drawCircle(location, this.gMapContext.radius, {});
26559 if (this.gMapContext.settings.enableReverseGeocode) {
26560 this.gMapContext.geodecoder.geocode({
26561 latLng: this.gMapContext.location
26562 }, function(results, status) {
26564 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
26565 _this.gMapContext.locationName = results[0].formatted_address;
26566 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
26568 _this.fireEvent('positionchanged', this, location);
26575 this.fireEvent('positionchanged', this, location);
26580 google.maps.event.trigger(this.gMapContext.map, "resize");
26582 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
26584 this.fireEvent('resize', this);
26587 setPositionByLatLng: function(latitude, longitude)
26589 this.setPosition(new google.maps.LatLng(latitude, longitude));
26592 getCurrentPosition: function()
26595 latitude: this.gMapContext.location.lat(),
26596 longitude: this.gMapContext.location.lng()
26600 getAddressName: function()
26602 return this.gMapContext.locationName;
26605 getAddressComponents: function()
26607 return this.gMapContext.addressComponents;
26610 address_component_from_google_geocode: function(address_components)
26614 for (var i = 0; i < address_components.length; i++) {
26615 var component = address_components[i];
26616 if (component.types.indexOf("postal_code") >= 0) {
26617 result.postalCode = component.short_name;
26618 } else if (component.types.indexOf("street_number") >= 0) {
26619 result.streetNumber = component.short_name;
26620 } else if (component.types.indexOf("route") >= 0) {
26621 result.streetName = component.short_name;
26622 } else if (component.types.indexOf("neighborhood") >= 0) {
26623 result.city = component.short_name;
26624 } else if (component.types.indexOf("locality") >= 0) {
26625 result.city = component.short_name;
26626 } else if (component.types.indexOf("sublocality") >= 0) {
26627 result.district = component.short_name;
26628 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
26629 result.stateOrProvince = component.short_name;
26630 } else if (component.types.indexOf("country") >= 0) {
26631 result.country = component.short_name;
26635 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
26636 result.addressLine2 = "";
26640 setZoomLevel: function(zoom)
26642 this.gMapContext.map.setZoom(zoom);
26655 this.fireEvent('show', this);
26666 this.fireEvent('hide', this);
26671 Roo.apply(Roo.bootstrap.LocationPicker, {
26673 OverlayView : function(map, options)
26675 options = options || {};
26689 * @class Roo.bootstrap.Alert
26690 * @extends Roo.bootstrap.Component
26691 * Bootstrap Alert class
26692 * @cfg {String} title The title of alert
26693 * @cfg {String} html The content of alert
26694 * @cfg {String} weight ( success | info | warning | danger )
26695 * @cfg {String} faicon font-awesomeicon
26698 * Create a new alert
26699 * @param {Object} config The config object
26703 Roo.bootstrap.Alert = function(config){
26704 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
26708 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
26715 getAutoCreate : function()
26724 cls : 'roo-alert-icon'
26729 cls : 'roo-alert-title',
26734 cls : 'roo-alert-text',
26741 cfg.cn[0].cls += ' fa ' + this.faicon;
26745 cfg.cls += ' alert-' + this.weight;
26751 initEvents: function()
26753 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26756 setTitle : function(str)
26758 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
26761 setText : function(str)
26763 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
26766 setWeight : function(weight)
26769 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
26772 this.weight = weight;
26774 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
26777 setIcon : function(icon)
26780 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
26783 this.faicon = icon;
26785 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
26806 * @class Roo.bootstrap.UploadCropbox
26807 * @extends Roo.bootstrap.Component
26808 * Bootstrap UploadCropbox class
26809 * @cfg {String} emptyText show when image has been loaded
26810 * @cfg {String} rotateNotify show when image too small to rotate
26811 * @cfg {Number} errorTimeout default 3000
26812 * @cfg {Number} minWidth default 300
26813 * @cfg {Number} minHeight default 300
26814 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
26815 * @cfg {Boolean} isDocument (true|false) default false
26816 * @cfg {String} url action url
26817 * @cfg {String} paramName default 'imageUpload'
26818 * @cfg {String} method default POST
26819 * @cfg {Boolean} loadMask (true|false) default true
26820 * @cfg {Boolean} loadingText default 'Loading...'
26823 * Create a new UploadCropbox
26824 * @param {Object} config The config object
26827 Roo.bootstrap.UploadCropbox = function(config){
26828 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
26832 * @event beforeselectfile
26833 * Fire before select file
26834 * @param {Roo.bootstrap.UploadCropbox} this
26836 "beforeselectfile" : true,
26839 * Fire after initEvent
26840 * @param {Roo.bootstrap.UploadCropbox} this
26845 * Fire after initEvent
26846 * @param {Roo.bootstrap.UploadCropbox} this
26847 * @param {String} data
26852 * Fire when preparing the file data
26853 * @param {Roo.bootstrap.UploadCropbox} this
26854 * @param {Object} file
26859 * Fire when get exception
26860 * @param {Roo.bootstrap.UploadCropbox} this
26861 * @param {XMLHttpRequest} xhr
26863 "exception" : true,
26865 * @event beforeloadcanvas
26866 * Fire before load the canvas
26867 * @param {Roo.bootstrap.UploadCropbox} this
26868 * @param {String} src
26870 "beforeloadcanvas" : true,
26873 * Fire when trash image
26874 * @param {Roo.bootstrap.UploadCropbox} this
26879 * Fire when download the image
26880 * @param {Roo.bootstrap.UploadCropbox} this
26884 * @event footerbuttonclick
26885 * Fire when footerbuttonclick
26886 * @param {Roo.bootstrap.UploadCropbox} this
26887 * @param {String} type
26889 "footerbuttonclick" : true,
26893 * @param {Roo.bootstrap.UploadCropbox} this
26898 * Fire when rotate the image
26899 * @param {Roo.bootstrap.UploadCropbox} this
26900 * @param {String} pos
26905 * Fire when inspect the file
26906 * @param {Roo.bootstrap.UploadCropbox} this
26907 * @param {Object} file
26912 * Fire when xhr upload the file
26913 * @param {Roo.bootstrap.UploadCropbox} this
26914 * @param {Object} data
26919 * Fire when arrange the file data
26920 * @param {Roo.bootstrap.UploadCropbox} this
26921 * @param {Object} formData
26926 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
26929 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
26931 emptyText : 'Click to upload image',
26932 rotateNotify : 'Image is too small to rotate',
26933 errorTimeout : 3000,
26947 cropType : 'image/jpeg',
26949 canvasLoaded : false,
26950 isDocument : false,
26952 paramName : 'imageUpload',
26954 loadingText : 'Loading...',
26957 getAutoCreate : function()
26961 cls : 'roo-upload-cropbox',
26965 cls : 'roo-upload-cropbox-selector',
26970 cls : 'roo-upload-cropbox-body',
26971 style : 'cursor:pointer',
26975 cls : 'roo-upload-cropbox-preview'
26979 cls : 'roo-upload-cropbox-thumb'
26983 cls : 'roo-upload-cropbox-empty-notify',
26984 html : this.emptyText
26988 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
26989 html : this.rotateNotify
26995 cls : 'roo-upload-cropbox-footer',
26998 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
27008 onRender : function(ct, position)
27010 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
27012 if (this.buttons.length) {
27014 Roo.each(this.buttons, function(bb) {
27016 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
27018 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
27024 this.maskEl = this.el;
27028 initEvents : function()
27030 this.urlAPI = (window.createObjectURL && window) ||
27031 (window.URL && URL.revokeObjectURL && URL) ||
27032 (window.webkitURL && webkitURL);
27034 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
27035 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27037 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
27038 this.selectorEl.hide();
27040 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
27041 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27043 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
27044 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27045 this.thumbEl.hide();
27047 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
27048 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27050 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
27051 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27052 this.errorEl.hide();
27054 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
27055 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27056 this.footerEl.hide();
27058 this.setThumbBoxSize();
27064 this.fireEvent('initial', this);
27071 window.addEventListener("resize", function() { _this.resize(); } );
27073 this.bodyEl.on('click', this.beforeSelectFile, this);
27076 this.bodyEl.on('touchstart', this.onTouchStart, this);
27077 this.bodyEl.on('touchmove', this.onTouchMove, this);
27078 this.bodyEl.on('touchend', this.onTouchEnd, this);
27082 this.bodyEl.on('mousedown', this.onMouseDown, this);
27083 this.bodyEl.on('mousemove', this.onMouseMove, this);
27084 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
27085 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
27086 Roo.get(document).on('mouseup', this.onMouseUp, this);
27089 this.selectorEl.on('change', this.onFileSelected, this);
27095 this.baseScale = 1;
27097 this.baseRotate = 1;
27098 this.dragable = false;
27099 this.pinching = false;
27102 this.cropData = false;
27103 this.notifyEl.dom.innerHTML = this.emptyText;
27105 this.selectorEl.dom.value = '';
27109 resize : function()
27111 if(this.fireEvent('resize', this) != false){
27112 this.setThumbBoxPosition();
27113 this.setCanvasPosition();
27117 onFooterButtonClick : function(e, el, o, type)
27120 case 'rotate-left' :
27121 this.onRotateLeft(e);
27123 case 'rotate-right' :
27124 this.onRotateRight(e);
27127 this.beforeSelectFile(e);
27142 this.fireEvent('footerbuttonclick', this, type);
27145 beforeSelectFile : function(e)
27147 e.preventDefault();
27149 if(this.fireEvent('beforeselectfile', this) != false){
27150 this.selectorEl.dom.click();
27154 onFileSelected : function(e)
27156 e.preventDefault();
27158 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
27162 var file = this.selectorEl.dom.files[0];
27164 if(this.fireEvent('inspect', this, file) != false){
27165 this.prepare(file);
27170 trash : function(e)
27172 this.fireEvent('trash', this);
27175 download : function(e)
27177 this.fireEvent('download', this);
27180 loadCanvas : function(src)
27182 if(this.fireEvent('beforeloadcanvas', this, src) != false){
27186 this.imageEl = document.createElement('img');
27190 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
27192 this.imageEl.src = src;
27196 onLoadCanvas : function()
27198 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
27199 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
27201 this.bodyEl.un('click', this.beforeSelectFile, this);
27203 this.notifyEl.hide();
27204 this.thumbEl.show();
27205 this.footerEl.show();
27207 this.baseRotateLevel();
27209 if(this.isDocument){
27210 this.setThumbBoxSize();
27213 this.setThumbBoxPosition();
27215 this.baseScaleLevel();
27221 this.canvasLoaded = true;
27224 this.maskEl.unmask();
27229 setCanvasPosition : function()
27231 if(!this.canvasEl){
27235 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
27236 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
27238 this.previewEl.setLeft(pw);
27239 this.previewEl.setTop(ph);
27243 onMouseDown : function(e)
27247 this.dragable = true;
27248 this.pinching = false;
27250 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
27251 this.dragable = false;
27255 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27256 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27260 onMouseMove : function(e)
27264 if(!this.canvasLoaded){
27268 if (!this.dragable){
27272 var minX = Math.ceil(this.thumbEl.getLeft(true));
27273 var minY = Math.ceil(this.thumbEl.getTop(true));
27275 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
27276 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
27278 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27279 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27281 x = x - this.mouseX;
27282 y = y - this.mouseY;
27284 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
27285 var bgY = Math.ceil(y + this.previewEl.getTop(true));
27287 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
27288 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
27290 this.previewEl.setLeft(bgX);
27291 this.previewEl.setTop(bgY);
27293 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27294 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27297 onMouseUp : function(e)
27301 this.dragable = false;
27304 onMouseWheel : function(e)
27308 this.startScale = this.scale;
27310 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
27312 if(!this.zoomable()){
27313 this.scale = this.startScale;
27322 zoomable : function()
27324 var minScale = this.thumbEl.getWidth() / this.minWidth;
27326 if(this.minWidth < this.minHeight){
27327 minScale = this.thumbEl.getHeight() / this.minHeight;
27330 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
27331 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
27335 (this.rotate == 0 || this.rotate == 180) &&
27337 width > this.imageEl.OriginWidth ||
27338 height > this.imageEl.OriginHeight ||
27339 (width < this.minWidth && height < this.minHeight)
27347 (this.rotate == 90 || this.rotate == 270) &&
27349 width > this.imageEl.OriginWidth ||
27350 height > this.imageEl.OriginHeight ||
27351 (width < this.minHeight && height < this.minWidth)
27358 !this.isDocument &&
27359 (this.rotate == 0 || this.rotate == 180) &&
27361 width < this.minWidth ||
27362 width > this.imageEl.OriginWidth ||
27363 height < this.minHeight ||
27364 height > this.imageEl.OriginHeight
27371 !this.isDocument &&
27372 (this.rotate == 90 || this.rotate == 270) &&
27374 width < this.minHeight ||
27375 width > this.imageEl.OriginWidth ||
27376 height < this.minWidth ||
27377 height > this.imageEl.OriginHeight
27387 onRotateLeft : function(e)
27389 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27391 var minScale = this.thumbEl.getWidth() / this.minWidth;
27393 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27394 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27396 this.startScale = this.scale;
27398 while (this.getScaleLevel() < minScale){
27400 this.scale = this.scale + 1;
27402 if(!this.zoomable()){
27407 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27408 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27413 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27420 this.scale = this.startScale;
27422 this.onRotateFail();
27427 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27429 if(this.isDocument){
27430 this.setThumbBoxSize();
27431 this.setThumbBoxPosition();
27432 this.setCanvasPosition();
27437 this.fireEvent('rotate', this, 'left');
27441 onRotateRight : function(e)
27443 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27445 var minScale = this.thumbEl.getWidth() / this.minWidth;
27447 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27448 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27450 this.startScale = this.scale;
27452 while (this.getScaleLevel() < minScale){
27454 this.scale = this.scale + 1;
27456 if(!this.zoomable()){
27461 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27462 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27467 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27474 this.scale = this.startScale;
27476 this.onRotateFail();
27481 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27483 if(this.isDocument){
27484 this.setThumbBoxSize();
27485 this.setThumbBoxPosition();
27486 this.setCanvasPosition();
27491 this.fireEvent('rotate', this, 'right');
27494 onRotateFail : function()
27496 this.errorEl.show(true);
27500 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
27505 this.previewEl.dom.innerHTML = '';
27507 var canvasEl = document.createElement("canvas");
27509 var contextEl = canvasEl.getContext("2d");
27511 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27512 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27513 var center = this.imageEl.OriginWidth / 2;
27515 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
27516 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27517 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27518 center = this.imageEl.OriginHeight / 2;
27521 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
27523 contextEl.translate(center, center);
27524 contextEl.rotate(this.rotate * Math.PI / 180);
27526 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27528 this.canvasEl = document.createElement("canvas");
27530 this.contextEl = this.canvasEl.getContext("2d");
27532 switch (this.rotate) {
27535 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27536 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27538 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27543 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27544 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27546 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27547 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);
27551 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27556 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27557 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27559 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27560 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);
27564 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);
27569 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27570 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27572 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27573 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27577 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);
27584 this.previewEl.appendChild(this.canvasEl);
27586 this.setCanvasPosition();
27591 if(!this.canvasLoaded){
27595 var imageCanvas = document.createElement("canvas");
27597 var imageContext = imageCanvas.getContext("2d");
27599 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27600 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27602 var center = imageCanvas.width / 2;
27604 imageContext.translate(center, center);
27606 imageContext.rotate(this.rotate * Math.PI / 180);
27608 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27610 var canvas = document.createElement("canvas");
27612 var context = canvas.getContext("2d");
27614 canvas.width = this.minWidth;
27615 canvas.height = this.minHeight;
27617 switch (this.rotate) {
27620 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27621 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27623 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27624 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27626 var targetWidth = this.minWidth - 2 * x;
27627 var targetHeight = this.minHeight - 2 * y;
27631 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27632 scale = targetWidth / width;
27635 if(x > 0 && y == 0){
27636 scale = targetHeight / height;
27639 if(x > 0 && y > 0){
27640 scale = targetWidth / width;
27642 if(width < height){
27643 scale = targetHeight / height;
27647 context.scale(scale, scale);
27649 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27650 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27652 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27653 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27655 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27660 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27661 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27663 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27664 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27666 var targetWidth = this.minWidth - 2 * x;
27667 var targetHeight = this.minHeight - 2 * y;
27671 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27672 scale = targetWidth / width;
27675 if(x > 0 && y == 0){
27676 scale = targetHeight / height;
27679 if(x > 0 && y > 0){
27680 scale = targetWidth / width;
27682 if(width < height){
27683 scale = targetHeight / height;
27687 context.scale(scale, scale);
27689 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27690 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27692 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27693 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27695 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27697 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27702 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27703 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27705 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27706 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27708 var targetWidth = this.minWidth - 2 * x;
27709 var targetHeight = this.minHeight - 2 * y;
27713 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27714 scale = targetWidth / width;
27717 if(x > 0 && y == 0){
27718 scale = targetHeight / height;
27721 if(x > 0 && y > 0){
27722 scale = targetWidth / width;
27724 if(width < height){
27725 scale = targetHeight / height;
27729 context.scale(scale, scale);
27731 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27732 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27734 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27735 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27737 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27738 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27740 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27745 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27746 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27748 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27749 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27751 var targetWidth = this.minWidth - 2 * x;
27752 var targetHeight = this.minHeight - 2 * y;
27756 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27757 scale = targetWidth / width;
27760 if(x > 0 && y == 0){
27761 scale = targetHeight / height;
27764 if(x > 0 && y > 0){
27765 scale = targetWidth / width;
27767 if(width < height){
27768 scale = targetHeight / height;
27772 context.scale(scale, scale);
27774 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27775 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27777 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27778 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27780 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27782 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27789 this.cropData = canvas.toDataURL(this.cropType);
27791 if(this.fireEvent('crop', this, this.cropData) !== false){
27792 this.process(this.file, this.cropData);
27799 setThumbBoxSize : function()
27803 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
27804 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
27805 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
27807 this.minWidth = width;
27808 this.minHeight = height;
27810 if(this.rotate == 90 || this.rotate == 270){
27811 this.minWidth = height;
27812 this.minHeight = width;
27817 width = Math.ceil(this.minWidth * height / this.minHeight);
27819 if(this.minWidth > this.minHeight){
27821 height = Math.ceil(this.minHeight * width / this.minWidth);
27824 this.thumbEl.setStyle({
27825 width : width + 'px',
27826 height : height + 'px'
27833 setThumbBoxPosition : function()
27835 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
27836 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
27838 this.thumbEl.setLeft(x);
27839 this.thumbEl.setTop(y);
27843 baseRotateLevel : function()
27845 this.baseRotate = 1;
27848 typeof(this.exif) != 'undefined' &&
27849 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
27850 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
27852 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
27855 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
27859 baseScaleLevel : function()
27863 if(this.isDocument){
27865 if(this.baseRotate == 6 || this.baseRotate == 8){
27867 height = this.thumbEl.getHeight();
27868 this.baseScale = height / this.imageEl.OriginWidth;
27870 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
27871 width = this.thumbEl.getWidth();
27872 this.baseScale = width / this.imageEl.OriginHeight;
27878 height = this.thumbEl.getHeight();
27879 this.baseScale = height / this.imageEl.OriginHeight;
27881 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
27882 width = this.thumbEl.getWidth();
27883 this.baseScale = width / this.imageEl.OriginWidth;
27889 if(this.baseRotate == 6 || this.baseRotate == 8){
27891 width = this.thumbEl.getHeight();
27892 this.baseScale = width / this.imageEl.OriginHeight;
27894 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
27895 height = this.thumbEl.getWidth();
27896 this.baseScale = height / this.imageEl.OriginHeight;
27899 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27900 height = this.thumbEl.getWidth();
27901 this.baseScale = height / this.imageEl.OriginHeight;
27903 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
27904 width = this.thumbEl.getHeight();
27905 this.baseScale = width / this.imageEl.OriginWidth;
27912 width = this.thumbEl.getWidth();
27913 this.baseScale = width / this.imageEl.OriginWidth;
27915 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
27916 height = this.thumbEl.getHeight();
27917 this.baseScale = height / this.imageEl.OriginHeight;
27920 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27922 height = this.thumbEl.getHeight();
27923 this.baseScale = height / this.imageEl.OriginHeight;
27925 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
27926 width = this.thumbEl.getWidth();
27927 this.baseScale = width / this.imageEl.OriginWidth;
27935 getScaleLevel : function()
27937 return this.baseScale * Math.pow(1.1, this.scale);
27940 onTouchStart : function(e)
27942 if(!this.canvasLoaded){
27943 this.beforeSelectFile(e);
27947 var touches = e.browserEvent.touches;
27953 if(touches.length == 1){
27954 this.onMouseDown(e);
27958 if(touches.length != 2){
27964 for(var i = 0, finger; finger = touches[i]; i++){
27965 coords.push(finger.pageX, finger.pageY);
27968 var x = Math.pow(coords[0] - coords[2], 2);
27969 var y = Math.pow(coords[1] - coords[3], 2);
27971 this.startDistance = Math.sqrt(x + y);
27973 this.startScale = this.scale;
27975 this.pinching = true;
27976 this.dragable = false;
27980 onTouchMove : function(e)
27982 if(!this.pinching && !this.dragable){
27986 var touches = e.browserEvent.touches;
27993 this.onMouseMove(e);
27999 for(var i = 0, finger; finger = touches[i]; i++){
28000 coords.push(finger.pageX, finger.pageY);
28003 var x = Math.pow(coords[0] - coords[2], 2);
28004 var y = Math.pow(coords[1] - coords[3], 2);
28006 this.endDistance = Math.sqrt(x + y);
28008 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
28010 if(!this.zoomable()){
28011 this.scale = this.startScale;
28019 onTouchEnd : function(e)
28021 this.pinching = false;
28022 this.dragable = false;
28026 process : function(file, crop)
28029 this.maskEl.mask(this.loadingText);
28032 this.xhr = new XMLHttpRequest();
28034 file.xhr = this.xhr;
28036 this.xhr.open(this.method, this.url, true);
28039 "Accept": "application/json",
28040 "Cache-Control": "no-cache",
28041 "X-Requested-With": "XMLHttpRequest"
28044 for (var headerName in headers) {
28045 var headerValue = headers[headerName];
28047 this.xhr.setRequestHeader(headerName, headerValue);
28053 this.xhr.onload = function()
28055 _this.xhrOnLoad(_this.xhr);
28058 this.xhr.onerror = function()
28060 _this.xhrOnError(_this.xhr);
28063 var formData = new FormData();
28065 formData.append('returnHTML', 'NO');
28068 formData.append('crop', crop);
28071 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
28072 formData.append(this.paramName, file, file.name);
28075 if(typeof(file.filename) != 'undefined'){
28076 formData.append('filename', file.filename);
28079 if(typeof(file.mimetype) != 'undefined'){
28080 formData.append('mimetype', file.mimetype);
28083 if(this.fireEvent('arrange', this, formData) != false){
28084 this.xhr.send(formData);
28088 xhrOnLoad : function(xhr)
28091 this.maskEl.unmask();
28094 if (xhr.readyState !== 4) {
28095 this.fireEvent('exception', this, xhr);
28099 var response = Roo.decode(xhr.responseText);
28101 if(!response.success){
28102 this.fireEvent('exception', this, xhr);
28106 var response = Roo.decode(xhr.responseText);
28108 this.fireEvent('upload', this, response);
28112 xhrOnError : function()
28115 this.maskEl.unmask();
28118 Roo.log('xhr on error');
28120 var response = Roo.decode(xhr.responseText);
28126 prepare : function(file)
28129 this.maskEl.mask(this.loadingText);
28135 if(typeof(file) === 'string'){
28136 this.loadCanvas(file);
28140 if(!file || !this.urlAPI){
28145 this.cropType = file.type;
28149 if(this.fireEvent('prepare', this, this.file) != false){
28151 var reader = new FileReader();
28153 reader.onload = function (e) {
28154 if (e.target.error) {
28155 Roo.log(e.target.error);
28159 var buffer = e.target.result,
28160 dataView = new DataView(buffer),
28162 maxOffset = dataView.byteLength - 4,
28166 if (dataView.getUint16(0) === 0xffd8) {
28167 while (offset < maxOffset) {
28168 markerBytes = dataView.getUint16(offset);
28170 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
28171 markerLength = dataView.getUint16(offset + 2) + 2;
28172 if (offset + markerLength > dataView.byteLength) {
28173 Roo.log('Invalid meta data: Invalid segment size.');
28177 if(markerBytes == 0xffe1){
28178 _this.parseExifData(
28185 offset += markerLength;
28195 var url = _this.urlAPI.createObjectURL(_this.file);
28197 _this.loadCanvas(url);
28202 reader.readAsArrayBuffer(this.file);
28208 parseExifData : function(dataView, offset, length)
28210 var tiffOffset = offset + 10,
28214 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28215 // No Exif data, might be XMP data instead
28219 // Check for the ASCII code for "Exif" (0x45786966):
28220 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28221 // No Exif data, might be XMP data instead
28224 if (tiffOffset + 8 > dataView.byteLength) {
28225 Roo.log('Invalid Exif data: Invalid segment size.');
28228 // Check for the two null bytes:
28229 if (dataView.getUint16(offset + 8) !== 0x0000) {
28230 Roo.log('Invalid Exif data: Missing byte alignment offset.');
28233 // Check the byte alignment:
28234 switch (dataView.getUint16(tiffOffset)) {
28236 littleEndian = true;
28239 littleEndian = false;
28242 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
28245 // Check for the TIFF tag marker (0x002A):
28246 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
28247 Roo.log('Invalid Exif data: Missing TIFF marker.');
28250 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
28251 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
28253 this.parseExifTags(
28256 tiffOffset + dirOffset,
28261 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
28266 if (dirOffset + 6 > dataView.byteLength) {
28267 Roo.log('Invalid Exif data: Invalid directory offset.');
28270 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
28271 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
28272 if (dirEndOffset + 4 > dataView.byteLength) {
28273 Roo.log('Invalid Exif data: Invalid directory size.');
28276 for (i = 0; i < tagsNumber; i += 1) {
28280 dirOffset + 2 + 12 * i, // tag offset
28284 // Return the offset to the next directory:
28285 return dataView.getUint32(dirEndOffset, littleEndian);
28288 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
28290 var tag = dataView.getUint16(offset, littleEndian);
28292 this.exif[tag] = this.getExifValue(
28296 dataView.getUint16(offset + 2, littleEndian), // tag type
28297 dataView.getUint32(offset + 4, littleEndian), // tag length
28302 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
28304 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
28313 Roo.log('Invalid Exif data: Invalid tag type.');
28317 tagSize = tagType.size * length;
28318 // Determine if the value is contained in the dataOffset bytes,
28319 // or if the value at the dataOffset is a pointer to the actual data:
28320 dataOffset = tagSize > 4 ?
28321 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
28322 if (dataOffset + tagSize > dataView.byteLength) {
28323 Roo.log('Invalid Exif data: Invalid data offset.');
28326 if (length === 1) {
28327 return tagType.getValue(dataView, dataOffset, littleEndian);
28330 for (i = 0; i < length; i += 1) {
28331 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
28334 if (tagType.ascii) {
28336 // Concatenate the chars:
28337 for (i = 0; i < values.length; i += 1) {
28339 // Ignore the terminating NULL byte(s):
28340 if (c === '\u0000') {
28352 Roo.apply(Roo.bootstrap.UploadCropbox, {
28354 'Orientation': 0x0112
28358 1: 0, //'top-left',
28360 3: 180, //'bottom-right',
28361 // 4: 'bottom-left',
28363 6: 90, //'right-top',
28364 // 7: 'right-bottom',
28365 8: 270 //'left-bottom'
28369 // byte, 8-bit unsigned int:
28371 getValue: function (dataView, dataOffset) {
28372 return dataView.getUint8(dataOffset);
28376 // ascii, 8-bit byte:
28378 getValue: function (dataView, dataOffset) {
28379 return String.fromCharCode(dataView.getUint8(dataOffset));
28384 // short, 16 bit int:
28386 getValue: function (dataView, dataOffset, littleEndian) {
28387 return dataView.getUint16(dataOffset, littleEndian);
28391 // long, 32 bit int:
28393 getValue: function (dataView, dataOffset, littleEndian) {
28394 return dataView.getUint32(dataOffset, littleEndian);
28398 // rational = two long values, first is numerator, second is denominator:
28400 getValue: function (dataView, dataOffset, littleEndian) {
28401 return dataView.getUint32(dataOffset, littleEndian) /
28402 dataView.getUint32(dataOffset + 4, littleEndian);
28406 // slong, 32 bit signed int:
28408 getValue: function (dataView, dataOffset, littleEndian) {
28409 return dataView.getInt32(dataOffset, littleEndian);
28413 // srational, two slongs, first is numerator, second is denominator:
28415 getValue: function (dataView, dataOffset, littleEndian) {
28416 return dataView.getInt32(dataOffset, littleEndian) /
28417 dataView.getInt32(dataOffset + 4, littleEndian);
28427 cls : 'btn-group roo-upload-cropbox-rotate-left',
28428 action : 'rotate-left',
28432 cls : 'btn btn-default',
28433 html : '<i class="fa fa-undo"></i>'
28439 cls : 'btn-group roo-upload-cropbox-picture',
28440 action : 'picture',
28444 cls : 'btn btn-default',
28445 html : '<i class="fa fa-picture-o"></i>'
28451 cls : 'btn-group roo-upload-cropbox-rotate-right',
28452 action : 'rotate-right',
28456 cls : 'btn btn-default',
28457 html : '<i class="fa fa-repeat"></i>'
28465 cls : 'btn-group roo-upload-cropbox-rotate-left',
28466 action : 'rotate-left',
28470 cls : 'btn btn-default',
28471 html : '<i class="fa fa-undo"></i>'
28477 cls : 'btn-group roo-upload-cropbox-download',
28478 action : 'download',
28482 cls : 'btn btn-default',
28483 html : '<i class="fa fa-download"></i>'
28489 cls : 'btn-group roo-upload-cropbox-crop',
28494 cls : 'btn btn-default',
28495 html : '<i class="fa fa-crop"></i>'
28501 cls : 'btn-group roo-upload-cropbox-trash',
28506 cls : 'btn btn-default',
28507 html : '<i class="fa fa-trash"></i>'
28513 cls : 'btn-group roo-upload-cropbox-rotate-right',
28514 action : 'rotate-right',
28518 cls : 'btn btn-default',
28519 html : '<i class="fa fa-repeat"></i>'
28527 cls : 'btn-group roo-upload-cropbox-rotate-left',
28528 action : 'rotate-left',
28532 cls : 'btn btn-default',
28533 html : '<i class="fa fa-undo"></i>'
28539 cls : 'btn-group roo-upload-cropbox-rotate-right',
28540 action : 'rotate-right',
28544 cls : 'btn btn-default',
28545 html : '<i class="fa fa-repeat"></i>'
28558 * @class Roo.bootstrap.DocumentManager
28559 * @extends Roo.bootstrap.Component
28560 * Bootstrap DocumentManager class
28561 * @cfg {String} paramName default 'imageUpload'
28562 * @cfg {String} toolTipName default 'filename'
28563 * @cfg {String} method default POST
28564 * @cfg {String} url action url
28565 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
28566 * @cfg {Boolean} multiple multiple upload default true
28567 * @cfg {Number} thumbSize default 300
28568 * @cfg {String} fieldLabel
28569 * @cfg {Number} labelWidth default 4
28570 * @cfg {String} labelAlign (left|top) default left
28571 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
28572 * @cfg {Number} labellg set the width of label (1-12)
28573 * @cfg {Number} labelmd set the width of label (1-12)
28574 * @cfg {Number} labelsm set the width of label (1-12)
28575 * @cfg {Number} labelxs set the width of label (1-12)
28578 * Create a new DocumentManager
28579 * @param {Object} config The config object
28582 Roo.bootstrap.DocumentManager = function(config){
28583 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
28586 this.delegates = [];
28591 * Fire when initial the DocumentManager
28592 * @param {Roo.bootstrap.DocumentManager} this
28597 * inspect selected file
28598 * @param {Roo.bootstrap.DocumentManager} this
28599 * @param {File} file
28604 * Fire when xhr load exception
28605 * @param {Roo.bootstrap.DocumentManager} this
28606 * @param {XMLHttpRequest} xhr
28608 "exception" : true,
28610 * @event afterupload
28611 * Fire when xhr load exception
28612 * @param {Roo.bootstrap.DocumentManager} this
28613 * @param {XMLHttpRequest} xhr
28615 "afterupload" : true,
28618 * prepare the form data
28619 * @param {Roo.bootstrap.DocumentManager} this
28620 * @param {Object} formData
28625 * Fire when remove the file
28626 * @param {Roo.bootstrap.DocumentManager} this
28627 * @param {Object} file
28632 * Fire after refresh the file
28633 * @param {Roo.bootstrap.DocumentManager} this
28638 * Fire after click the image
28639 * @param {Roo.bootstrap.DocumentManager} this
28640 * @param {Object} file
28645 * Fire when upload a image and editable set to true
28646 * @param {Roo.bootstrap.DocumentManager} this
28647 * @param {Object} file
28651 * @event beforeselectfile
28652 * Fire before select file
28653 * @param {Roo.bootstrap.DocumentManager} this
28655 "beforeselectfile" : true,
28658 * Fire before process file
28659 * @param {Roo.bootstrap.DocumentManager} this
28660 * @param {Object} file
28664 * @event previewrendered
28665 * Fire when preview rendered
28666 * @param {Roo.bootstrap.DocumentManager} this
28667 * @param {Object} file
28669 "previewrendered" : true
28674 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
28683 paramName : 'imageUpload',
28684 toolTipName : 'filename',
28687 labelAlign : 'left',
28697 getAutoCreate : function()
28699 var managerWidget = {
28701 cls : 'roo-document-manager',
28705 cls : 'roo-document-manager-selector',
28710 cls : 'roo-document-manager-uploader',
28714 cls : 'roo-document-manager-upload-btn',
28715 html : '<i class="fa fa-plus"></i>'
28726 cls : 'column col-md-12',
28731 if(this.fieldLabel.length){
28736 cls : 'column col-md-12',
28737 html : this.fieldLabel
28741 cls : 'column col-md-12',
28746 if(this.labelAlign == 'left'){
28751 html : this.fieldLabel
28760 if(this.labelWidth > 12){
28761 content[0].style = "width: " + this.labelWidth + 'px';
28764 if(this.labelWidth < 13 && this.labelmd == 0){
28765 this.labelmd = this.labelWidth;
28768 if(this.labellg > 0){
28769 content[0].cls += ' col-lg-' + this.labellg;
28770 content[1].cls += ' col-lg-' + (12 - this.labellg);
28773 if(this.labelmd > 0){
28774 content[0].cls += ' col-md-' + this.labelmd;
28775 content[1].cls += ' col-md-' + (12 - this.labelmd);
28778 if(this.labelsm > 0){
28779 content[0].cls += ' col-sm-' + this.labelsm;
28780 content[1].cls += ' col-sm-' + (12 - this.labelsm);
28783 if(this.labelxs > 0){
28784 content[0].cls += ' col-xs-' + this.labelxs;
28785 content[1].cls += ' col-xs-' + (12 - this.labelxs);
28793 cls : 'row clearfix',
28801 initEvents : function()
28803 this.managerEl = this.el.select('.roo-document-manager', true).first();
28804 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28806 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
28807 this.selectorEl.hide();
28810 this.selectorEl.attr('multiple', 'multiple');
28813 this.selectorEl.on('change', this.onFileSelected, this);
28815 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
28816 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28818 this.uploader.on('click', this.onUploaderClick, this);
28820 this.renderProgressDialog();
28824 window.addEventListener("resize", function() { _this.refresh(); } );
28826 this.fireEvent('initial', this);
28829 renderProgressDialog : function()
28833 this.progressDialog = new Roo.bootstrap.Modal({
28834 cls : 'roo-document-manager-progress-dialog',
28835 allow_close : false,
28845 btnclick : function() {
28846 _this.uploadCancel();
28852 this.progressDialog.render(Roo.get(document.body));
28854 this.progress = new Roo.bootstrap.Progress({
28855 cls : 'roo-document-manager-progress',
28860 this.progress.render(this.progressDialog.getChildContainer());
28862 this.progressBar = new Roo.bootstrap.ProgressBar({
28863 cls : 'roo-document-manager-progress-bar',
28866 aria_valuemax : 12,
28870 this.progressBar.render(this.progress.getChildContainer());
28873 onUploaderClick : function(e)
28875 e.preventDefault();
28877 if(this.fireEvent('beforeselectfile', this) != false){
28878 this.selectorEl.dom.click();
28883 onFileSelected : function(e)
28885 e.preventDefault();
28887 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
28891 Roo.each(this.selectorEl.dom.files, function(file){
28892 if(this.fireEvent('inspect', this, file) != false){
28893 this.files.push(file);
28903 this.selectorEl.dom.value = '';
28905 if(!this.files || !this.files.length){
28909 if(this.boxes > 0 && this.files.length > this.boxes){
28910 this.files = this.files.slice(0, this.boxes);
28913 this.uploader.show();
28915 if(this.boxes > 0 && this.files.length > this.boxes - 1){
28916 this.uploader.hide();
28925 Roo.each(this.files, function(file){
28927 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
28928 var f = this.renderPreview(file);
28933 if(file.type.indexOf('image') != -1){
28934 this.delegates.push(
28936 _this.process(file);
28937 }).createDelegate(this)
28945 _this.process(file);
28946 }).createDelegate(this)
28951 this.files = files;
28953 this.delegates = this.delegates.concat(docs);
28955 if(!this.delegates.length){
28960 this.progressBar.aria_valuemax = this.delegates.length;
28967 arrange : function()
28969 if(!this.delegates.length){
28970 this.progressDialog.hide();
28975 var delegate = this.delegates.shift();
28977 this.progressDialog.show();
28979 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
28981 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
28986 refresh : function()
28988 this.uploader.show();
28990 if(this.boxes > 0 && this.files.length > this.boxes - 1){
28991 this.uploader.hide();
28994 Roo.isTouch ? this.closable(false) : this.closable(true);
28996 this.fireEvent('refresh', this);
28999 onRemove : function(e, el, o)
29001 e.preventDefault();
29003 this.fireEvent('remove', this, o);
29007 remove : function(o)
29011 Roo.each(this.files, function(file){
29012 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
29021 this.files = files;
29028 Roo.each(this.files, function(file){
29033 file.target.remove();
29042 onClick : function(e, el, o)
29044 e.preventDefault();
29046 this.fireEvent('click', this, o);
29050 closable : function(closable)
29052 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
29054 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29066 xhrOnLoad : function(xhr)
29068 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29072 if (xhr.readyState !== 4) {
29074 this.fireEvent('exception', this, xhr);
29078 var response = Roo.decode(xhr.responseText);
29080 if(!response.success){
29082 this.fireEvent('exception', this, xhr);
29086 var file = this.renderPreview(response.data);
29088 this.files.push(file);
29092 this.fireEvent('afterupload', this, xhr);
29096 xhrOnError : function(xhr)
29098 Roo.log('xhr on error');
29100 var response = Roo.decode(xhr.responseText);
29107 process : function(file)
29109 if(this.fireEvent('process', this, file) !== false){
29110 if(this.editable && file.type.indexOf('image') != -1){
29111 this.fireEvent('edit', this, file);
29115 this.uploadStart(file, false);
29122 uploadStart : function(file, crop)
29124 this.xhr = new XMLHttpRequest();
29126 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29131 file.xhr = this.xhr;
29133 this.managerEl.createChild({
29135 cls : 'roo-document-manager-loading',
29139 tooltip : file.name,
29140 cls : 'roo-document-manager-thumb',
29141 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29147 this.xhr.open(this.method, this.url, true);
29150 "Accept": "application/json",
29151 "Cache-Control": "no-cache",
29152 "X-Requested-With": "XMLHttpRequest"
29155 for (var headerName in headers) {
29156 var headerValue = headers[headerName];
29158 this.xhr.setRequestHeader(headerName, headerValue);
29164 this.xhr.onload = function()
29166 _this.xhrOnLoad(_this.xhr);
29169 this.xhr.onerror = function()
29171 _this.xhrOnError(_this.xhr);
29174 var formData = new FormData();
29176 formData.append('returnHTML', 'NO');
29179 formData.append('crop', crop);
29182 formData.append(this.paramName, file, file.name);
29189 if(this.fireEvent('prepare', this, formData, options) != false){
29191 if(options.manually){
29195 this.xhr.send(formData);
29199 this.uploadCancel();
29202 uploadCancel : function()
29208 this.delegates = [];
29210 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29217 renderPreview : function(file)
29219 if(typeof(file.target) != 'undefined' && file.target){
29223 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
29225 var previewEl = this.managerEl.createChild({
29227 cls : 'roo-document-manager-preview',
29231 tooltip : file[this.toolTipName],
29232 cls : 'roo-document-manager-thumb',
29233 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
29238 html : '<i class="fa fa-times-circle"></i>'
29243 var close = previewEl.select('button.close', true).first();
29245 close.on('click', this.onRemove, this, file);
29247 file.target = previewEl;
29249 var image = previewEl.select('img', true).first();
29253 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
29255 image.on('click', this.onClick, this, file);
29257 this.fireEvent('previewrendered', this, file);
29263 onPreviewLoad : function(file, image)
29265 if(typeof(file.target) == 'undefined' || !file.target){
29269 var width = image.dom.naturalWidth || image.dom.width;
29270 var height = image.dom.naturalHeight || image.dom.height;
29272 if(width > height){
29273 file.target.addClass('wide');
29277 file.target.addClass('tall');
29282 uploadFromSource : function(file, crop)
29284 this.xhr = new XMLHttpRequest();
29286 this.managerEl.createChild({
29288 cls : 'roo-document-manager-loading',
29292 tooltip : file.name,
29293 cls : 'roo-document-manager-thumb',
29294 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29300 this.xhr.open(this.method, this.url, true);
29303 "Accept": "application/json",
29304 "Cache-Control": "no-cache",
29305 "X-Requested-With": "XMLHttpRequest"
29308 for (var headerName in headers) {
29309 var headerValue = headers[headerName];
29311 this.xhr.setRequestHeader(headerName, headerValue);
29317 this.xhr.onload = function()
29319 _this.xhrOnLoad(_this.xhr);
29322 this.xhr.onerror = function()
29324 _this.xhrOnError(_this.xhr);
29327 var formData = new FormData();
29329 formData.append('returnHTML', 'NO');
29331 formData.append('crop', crop);
29333 if(typeof(file.filename) != 'undefined'){
29334 formData.append('filename', file.filename);
29337 if(typeof(file.mimetype) != 'undefined'){
29338 formData.append('mimetype', file.mimetype);
29343 if(this.fireEvent('prepare', this, formData) != false){
29344 this.xhr.send(formData);
29354 * @class Roo.bootstrap.DocumentViewer
29355 * @extends Roo.bootstrap.Component
29356 * Bootstrap DocumentViewer class
29357 * @cfg {Boolean} showDownload (true|false) show download button (default true)
29358 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
29361 * Create a new DocumentViewer
29362 * @param {Object} config The config object
29365 Roo.bootstrap.DocumentViewer = function(config){
29366 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
29371 * Fire after initEvent
29372 * @param {Roo.bootstrap.DocumentViewer} this
29378 * @param {Roo.bootstrap.DocumentViewer} this
29383 * Fire after download button
29384 * @param {Roo.bootstrap.DocumentViewer} this
29389 * Fire after trash button
29390 * @param {Roo.bootstrap.DocumentViewer} this
29397 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
29399 showDownload : true,
29403 getAutoCreate : function()
29407 cls : 'roo-document-viewer',
29411 cls : 'roo-document-viewer-body',
29415 cls : 'roo-document-viewer-thumb',
29419 cls : 'roo-document-viewer-image'
29427 cls : 'roo-document-viewer-footer',
29430 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
29434 cls : 'btn-group roo-document-viewer-download',
29438 cls : 'btn btn-default',
29439 html : '<i class="fa fa-download"></i>'
29445 cls : 'btn-group roo-document-viewer-trash',
29449 cls : 'btn btn-default',
29450 html : '<i class="fa fa-trash"></i>'
29463 initEvents : function()
29465 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
29466 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
29468 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
29469 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
29471 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
29472 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
29474 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
29475 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
29477 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
29478 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
29480 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
29481 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
29483 this.bodyEl.on('click', this.onClick, this);
29484 this.downloadBtn.on('click', this.onDownload, this);
29485 this.trashBtn.on('click', this.onTrash, this);
29487 this.downloadBtn.hide();
29488 this.trashBtn.hide();
29490 if(this.showDownload){
29491 this.downloadBtn.show();
29494 if(this.showTrash){
29495 this.trashBtn.show();
29498 if(!this.showDownload && !this.showTrash) {
29499 this.footerEl.hide();
29504 initial : function()
29506 this.fireEvent('initial', this);
29510 onClick : function(e)
29512 e.preventDefault();
29514 this.fireEvent('click', this);
29517 onDownload : function(e)
29519 e.preventDefault();
29521 this.fireEvent('download', this);
29524 onTrash : function(e)
29526 e.preventDefault();
29528 this.fireEvent('trash', this);
29540 * @class Roo.bootstrap.NavProgressBar
29541 * @extends Roo.bootstrap.Component
29542 * Bootstrap NavProgressBar class
29545 * Create a new nav progress bar
29546 * @param {Object} config The config object
29549 Roo.bootstrap.NavProgressBar = function(config){
29550 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
29552 this.bullets = this.bullets || [];
29554 // Roo.bootstrap.NavProgressBar.register(this);
29558 * Fires when the active item changes
29559 * @param {Roo.bootstrap.NavProgressBar} this
29560 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
29561 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
29568 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
29573 getAutoCreate : function()
29575 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
29579 cls : 'roo-navigation-bar-group',
29583 cls : 'roo-navigation-top-bar'
29587 cls : 'roo-navigation-bullets-bar',
29591 cls : 'roo-navigation-bar'
29598 cls : 'roo-navigation-bottom-bar'
29608 initEvents: function()
29613 onRender : function(ct, position)
29615 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
29617 if(this.bullets.length){
29618 Roo.each(this.bullets, function(b){
29627 addItem : function(cfg)
29629 var item = new Roo.bootstrap.NavProgressItem(cfg);
29631 item.parentId = this.id;
29632 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
29635 var top = new Roo.bootstrap.Element({
29637 cls : 'roo-navigation-bar-text'
29640 var bottom = new Roo.bootstrap.Element({
29642 cls : 'roo-navigation-bar-text'
29645 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
29646 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
29648 var topText = new Roo.bootstrap.Element({
29650 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
29653 var bottomText = new Roo.bootstrap.Element({
29655 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
29658 topText.onRender(top.el, null);
29659 bottomText.onRender(bottom.el, null);
29662 item.bottomEl = bottom;
29665 this.barItems.push(item);
29670 getActive : function()
29672 var active = false;
29674 Roo.each(this.barItems, function(v){
29676 if (!v.isActive()) {
29688 setActiveItem : function(item)
29692 Roo.each(this.barItems, function(v){
29693 if (v.rid == item.rid) {
29697 if (v.isActive()) {
29698 v.setActive(false);
29703 item.setActive(true);
29705 this.fireEvent('changed', this, item, prev);
29708 getBarItem: function(rid)
29712 Roo.each(this.barItems, function(e) {
29713 if (e.rid != rid) {
29724 indexOfItem : function(item)
29728 Roo.each(this.barItems, function(v, i){
29730 if (v.rid != item.rid) {
29741 setActiveNext : function()
29743 var i = this.indexOfItem(this.getActive());
29745 if (i > this.barItems.length) {
29749 this.setActiveItem(this.barItems[i+1]);
29752 setActivePrev : function()
29754 var i = this.indexOfItem(this.getActive());
29760 this.setActiveItem(this.barItems[i-1]);
29763 format : function()
29765 if(!this.barItems.length){
29769 var width = 100 / this.barItems.length;
29771 Roo.each(this.barItems, function(i){
29772 i.el.setStyle('width', width + '%');
29773 i.topEl.el.setStyle('width', width + '%');
29774 i.bottomEl.el.setStyle('width', width + '%');
29783 * Nav Progress Item
29788 * @class Roo.bootstrap.NavProgressItem
29789 * @extends Roo.bootstrap.Component
29790 * Bootstrap NavProgressItem class
29791 * @cfg {String} rid the reference id
29792 * @cfg {Boolean} active (true|false) Is item active default false
29793 * @cfg {Boolean} disabled (true|false) Is item active default false
29794 * @cfg {String} html
29795 * @cfg {String} position (top|bottom) text position default bottom
29796 * @cfg {String} icon show icon instead of number
29799 * Create a new NavProgressItem
29800 * @param {Object} config The config object
29802 Roo.bootstrap.NavProgressItem = function(config){
29803 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
29808 * The raw click event for the entire grid.
29809 * @param {Roo.bootstrap.NavProgressItem} this
29810 * @param {Roo.EventObject} e
29817 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
29823 position : 'bottom',
29826 getAutoCreate : function()
29828 var iconCls = 'roo-navigation-bar-item-icon';
29830 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
29834 cls: 'roo-navigation-bar-item',
29844 cfg.cls += ' active';
29847 cfg.cls += ' disabled';
29853 disable : function()
29855 this.setDisabled(true);
29858 enable : function()
29860 this.setDisabled(false);
29863 initEvents: function()
29865 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
29867 this.iconEl.on('click', this.onClick, this);
29870 onClick : function(e)
29872 e.preventDefault();
29878 if(this.fireEvent('click', this, e) === false){
29882 this.parent().setActiveItem(this);
29885 isActive: function ()
29887 return this.active;
29890 setActive : function(state)
29892 if(this.active == state){
29896 this.active = state;
29899 this.el.addClass('active');
29903 this.el.removeClass('active');
29908 setDisabled : function(state)
29910 if(this.disabled == state){
29914 this.disabled = state;
29917 this.el.addClass('disabled');
29921 this.el.removeClass('disabled');
29924 tooltipEl : function()
29926 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
29939 * @class Roo.bootstrap.FieldLabel
29940 * @extends Roo.bootstrap.Component
29941 * Bootstrap FieldLabel class
29942 * @cfg {String} html contents of the element
29943 * @cfg {String} tag tag of the element default label
29944 * @cfg {String} cls class of the element
29945 * @cfg {String} target label target
29946 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
29947 * @cfg {String} invalidClass default "text-warning"
29948 * @cfg {String} validClass default "text-success"
29949 * @cfg {String} iconTooltip default "This field is required"
29950 * @cfg {String} indicatorpos (left|right) default left
29953 * Create a new FieldLabel
29954 * @param {Object} config The config object
29957 Roo.bootstrap.FieldLabel = function(config){
29958 Roo.bootstrap.Element.superclass.constructor.call(this, config);
29963 * Fires after the field has been marked as invalid.
29964 * @param {Roo.form.FieldLabel} this
29965 * @param {String} msg The validation message
29970 * Fires after the field has been validated with no errors.
29971 * @param {Roo.form.FieldLabel} this
29977 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
29984 invalidClass : 'has-warning',
29985 validClass : 'has-success',
29986 iconTooltip : 'This field is required',
29987 indicatorpos : 'left',
29989 getAutoCreate : function(){
29993 cls : 'roo-bootstrap-field-label ' + this.cls,
29998 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
29999 tooltip : this.iconTooltip
30008 if(this.indicatorpos == 'right'){
30011 cls : 'roo-bootstrap-field-label ' + this.cls,
30020 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
30021 tooltip : this.iconTooltip
30030 initEvents: function()
30032 Roo.bootstrap.Element.superclass.initEvents.call(this);
30034 this.indicator = this.indicatorEl();
30036 if(this.indicator){
30037 this.indicator.removeClass('visible');
30038 this.indicator.addClass('invisible');
30041 Roo.bootstrap.FieldLabel.register(this);
30044 indicatorEl : function()
30046 var indicator = this.el.select('i.roo-required-indicator',true).first();
30057 * Mark this field as valid
30059 markValid : function()
30061 if(this.indicator){
30062 this.indicator.removeClass('visible');
30063 this.indicator.addClass('invisible');
30066 this.el.removeClass(this.invalidClass);
30068 this.el.addClass(this.validClass);
30070 this.fireEvent('valid', this);
30074 * Mark this field as invalid
30075 * @param {String} msg The validation message
30077 markInvalid : function(msg)
30079 if(this.indicator){
30080 this.indicator.removeClass('invisible');
30081 this.indicator.addClass('visible');
30084 this.el.removeClass(this.validClass);
30086 this.el.addClass(this.invalidClass);
30088 this.fireEvent('invalid', this, msg);
30094 Roo.apply(Roo.bootstrap.FieldLabel, {
30099 * register a FieldLabel Group
30100 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
30102 register : function(label)
30104 if(this.groups.hasOwnProperty(label.target)){
30108 this.groups[label.target] = label;
30112 * fetch a FieldLabel Group based on the target
30113 * @param {string} target
30114 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
30116 get: function(target) {
30117 if (typeof(this.groups[target]) == 'undefined') {
30121 return this.groups[target] ;
30130 * page DateSplitField.
30136 * @class Roo.bootstrap.DateSplitField
30137 * @extends Roo.bootstrap.Component
30138 * Bootstrap DateSplitField class
30139 * @cfg {string} fieldLabel - the label associated
30140 * @cfg {Number} labelWidth set the width of label (0-12)
30141 * @cfg {String} labelAlign (top|left)
30142 * @cfg {Boolean} dayAllowBlank (true|false) default false
30143 * @cfg {Boolean} monthAllowBlank (true|false) default false
30144 * @cfg {Boolean} yearAllowBlank (true|false) default false
30145 * @cfg {string} dayPlaceholder
30146 * @cfg {string} monthPlaceholder
30147 * @cfg {string} yearPlaceholder
30148 * @cfg {string} dayFormat default 'd'
30149 * @cfg {string} monthFormat default 'm'
30150 * @cfg {string} yearFormat default 'Y'
30151 * @cfg {Number} labellg set the width of label (1-12)
30152 * @cfg {Number} labelmd set the width of label (1-12)
30153 * @cfg {Number} labelsm set the width of label (1-12)
30154 * @cfg {Number} labelxs set the width of label (1-12)
30158 * Create a new DateSplitField
30159 * @param {Object} config The config object
30162 Roo.bootstrap.DateSplitField = function(config){
30163 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
30169 * getting the data of years
30170 * @param {Roo.bootstrap.DateSplitField} this
30171 * @param {Object} years
30176 * getting the data of days
30177 * @param {Roo.bootstrap.DateSplitField} this
30178 * @param {Object} days
30183 * Fires after the field has been marked as invalid.
30184 * @param {Roo.form.Field} this
30185 * @param {String} msg The validation message
30190 * Fires after the field has been validated with no errors.
30191 * @param {Roo.form.Field} this
30197 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
30200 labelAlign : 'top',
30202 dayAllowBlank : false,
30203 monthAllowBlank : false,
30204 yearAllowBlank : false,
30205 dayPlaceholder : '',
30206 monthPlaceholder : '',
30207 yearPlaceholder : '',
30211 isFormField : true,
30217 getAutoCreate : function()
30221 cls : 'row roo-date-split-field-group',
30226 cls : 'form-hidden-field roo-date-split-field-group-value',
30232 var labelCls = 'col-md-12';
30233 var contentCls = 'col-md-4';
30235 if(this.fieldLabel){
30239 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
30243 html : this.fieldLabel
30248 if(this.labelAlign == 'left'){
30250 if(this.labelWidth > 12){
30251 label.style = "width: " + this.labelWidth + 'px';
30254 if(this.labelWidth < 13 && this.labelmd == 0){
30255 this.labelmd = this.labelWidth;
30258 if(this.labellg > 0){
30259 labelCls = ' col-lg-' + this.labellg;
30260 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
30263 if(this.labelmd > 0){
30264 labelCls = ' col-md-' + this.labelmd;
30265 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
30268 if(this.labelsm > 0){
30269 labelCls = ' col-sm-' + this.labelsm;
30270 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
30273 if(this.labelxs > 0){
30274 labelCls = ' col-xs-' + this.labelxs;
30275 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
30279 label.cls += ' ' + labelCls;
30281 cfg.cn.push(label);
30284 Roo.each(['day', 'month', 'year'], function(t){
30287 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
30294 inputEl: function ()
30296 return this.el.select('.roo-date-split-field-group-value', true).first();
30299 onRender : function(ct, position)
30303 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
30305 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
30307 this.dayField = new Roo.bootstrap.ComboBox({
30308 allowBlank : this.dayAllowBlank,
30309 alwaysQuery : true,
30310 displayField : 'value',
30313 forceSelection : true,
30315 placeholder : this.dayPlaceholder,
30316 selectOnFocus : true,
30317 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30318 triggerAction : 'all',
30320 valueField : 'value',
30321 store : new Roo.data.SimpleStore({
30322 data : (function() {
30324 _this.fireEvent('days', _this, days);
30327 fields : [ 'value' ]
30330 select : function (_self, record, index)
30332 _this.setValue(_this.getValue());
30337 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
30339 this.monthField = new Roo.bootstrap.MonthField({
30340 after : '<i class=\"fa fa-calendar\"></i>',
30341 allowBlank : this.monthAllowBlank,
30342 placeholder : this.monthPlaceholder,
30345 render : function (_self)
30347 this.el.select('span.input-group-addon', true).first().on('click', function(e){
30348 e.preventDefault();
30352 select : function (_self, oldvalue, newvalue)
30354 _this.setValue(_this.getValue());
30359 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
30361 this.yearField = new Roo.bootstrap.ComboBox({
30362 allowBlank : this.yearAllowBlank,
30363 alwaysQuery : true,
30364 displayField : 'value',
30367 forceSelection : true,
30369 placeholder : this.yearPlaceholder,
30370 selectOnFocus : true,
30371 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30372 triggerAction : 'all',
30374 valueField : 'value',
30375 store : new Roo.data.SimpleStore({
30376 data : (function() {
30378 _this.fireEvent('years', _this, years);
30381 fields : [ 'value' ]
30384 select : function (_self, record, index)
30386 _this.setValue(_this.getValue());
30391 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
30394 setValue : function(v, format)
30396 this.inputEl.dom.value = v;
30398 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
30400 var d = Date.parseDate(v, f);
30407 this.setDay(d.format(this.dayFormat));
30408 this.setMonth(d.format(this.monthFormat));
30409 this.setYear(d.format(this.yearFormat));
30416 setDay : function(v)
30418 this.dayField.setValue(v);
30419 this.inputEl.dom.value = this.getValue();
30424 setMonth : function(v)
30426 this.monthField.setValue(v, true);
30427 this.inputEl.dom.value = this.getValue();
30432 setYear : function(v)
30434 this.yearField.setValue(v);
30435 this.inputEl.dom.value = this.getValue();
30440 getDay : function()
30442 return this.dayField.getValue();
30445 getMonth : function()
30447 return this.monthField.getValue();
30450 getYear : function()
30452 return this.yearField.getValue();
30455 getValue : function()
30457 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
30459 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
30469 this.inputEl.dom.value = '';
30474 validate : function()
30476 var d = this.dayField.validate();
30477 var m = this.monthField.validate();
30478 var y = this.yearField.validate();
30483 (!this.dayAllowBlank && !d) ||
30484 (!this.monthAllowBlank && !m) ||
30485 (!this.yearAllowBlank && !y)
30490 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
30499 this.markInvalid();
30504 markValid : function()
30507 var label = this.el.select('label', true).first();
30508 var icon = this.el.select('i.fa-star', true).first();
30514 this.fireEvent('valid', this);
30518 * Mark this field as invalid
30519 * @param {String} msg The validation message
30521 markInvalid : function(msg)
30524 var label = this.el.select('label', true).first();
30525 var icon = this.el.select('i.fa-star', true).first();
30527 if(label && !icon){
30528 this.el.select('.roo-date-split-field-label', true).createChild({
30530 cls : 'text-danger fa fa-lg fa-star',
30531 tooltip : 'This field is required',
30532 style : 'margin-right:5px;'
30536 this.fireEvent('invalid', this, msg);
30539 clearInvalid : function()
30541 var label = this.el.select('label', true).first();
30542 var icon = this.el.select('i.fa-star', true).first();
30548 this.fireEvent('valid', this);
30551 getName: function()
30561 * http://masonry.desandro.com
30563 * The idea is to render all the bricks based on vertical width...
30565 * The original code extends 'outlayer' - we might need to use that....
30571 * @class Roo.bootstrap.LayoutMasonry
30572 * @extends Roo.bootstrap.Component
30573 * Bootstrap Layout Masonry class
30576 * Create a new Element
30577 * @param {Object} config The config object
30580 Roo.bootstrap.LayoutMasonry = function(config){
30582 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
30586 Roo.bootstrap.LayoutMasonry.register(this);
30592 * Fire after layout the items
30593 * @param {Roo.bootstrap.LayoutMasonry} this
30594 * @param {Roo.EventObject} e
30601 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
30604 * @cfg {Boolean} isLayoutInstant = no animation?
30606 isLayoutInstant : false, // needed?
30609 * @cfg {Number} boxWidth width of the columns
30614 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
30619 * @cfg {Number} padWidth padding below box..
30624 * @cfg {Number} gutter gutter width..
30629 * @cfg {Number} maxCols maximum number of columns
30635 * @cfg {Boolean} isAutoInitial defalut true
30637 isAutoInitial : true,
30642 * @cfg {Boolean} isHorizontal defalut false
30644 isHorizontal : false,
30646 currentSize : null,
30652 bricks: null, //CompositeElement
30656 _isLayoutInited : false,
30658 // isAlternative : false, // only use for vertical layout...
30661 * @cfg {Number} alternativePadWidth padding below box..
30663 alternativePadWidth : 50,
30665 selectedBrick : [],
30667 getAutoCreate : function(){
30669 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
30673 cls: 'blog-masonary-wrapper ' + this.cls,
30675 cls : 'mas-boxes masonary'
30682 getChildContainer: function( )
30684 if (this.boxesEl) {
30685 return this.boxesEl;
30688 this.boxesEl = this.el.select('.mas-boxes').first();
30690 return this.boxesEl;
30694 initEvents : function()
30698 if(this.isAutoInitial){
30699 Roo.log('hook children rendered');
30700 this.on('childrenrendered', function() {
30701 Roo.log('children rendered');
30707 initial : function()
30709 this.selectedBrick = [];
30711 this.currentSize = this.el.getBox(true);
30713 Roo.EventManager.onWindowResize(this.resize, this);
30715 if(!this.isAutoInitial){
30723 //this.layout.defer(500,this);
30727 resize : function()
30729 var cs = this.el.getBox(true);
30732 this.currentSize.width == cs.width &&
30733 this.currentSize.x == cs.x &&
30734 this.currentSize.height == cs.height &&
30735 this.currentSize.y == cs.y
30737 Roo.log("no change in with or X or Y");
30741 this.currentSize = cs;
30747 layout : function()
30749 this._resetLayout();
30751 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
30753 this.layoutItems( isInstant );
30755 this._isLayoutInited = true;
30757 this.fireEvent('layout', this);
30761 _resetLayout : function()
30763 if(this.isHorizontal){
30764 this.horizontalMeasureColumns();
30768 this.verticalMeasureColumns();
30772 verticalMeasureColumns : function()
30774 this.getContainerWidth();
30776 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30777 // this.colWidth = Math.floor(this.containerWidth * 0.8);
30781 var boxWidth = this.boxWidth + this.padWidth;
30783 if(this.containerWidth < this.boxWidth){
30784 boxWidth = this.containerWidth
30787 var containerWidth = this.containerWidth;
30789 var cols = Math.floor(containerWidth / boxWidth);
30791 this.cols = Math.max( cols, 1 );
30793 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
30795 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
30797 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
30799 this.colWidth = boxWidth + avail - this.padWidth;
30801 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
30802 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
30805 horizontalMeasureColumns : function()
30807 this.getContainerWidth();
30809 var boxWidth = this.boxWidth;
30811 if(this.containerWidth < boxWidth){
30812 boxWidth = this.containerWidth;
30815 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
30817 this.el.setHeight(boxWidth);
30821 getContainerWidth : function()
30823 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
30826 layoutItems : function( isInstant )
30828 Roo.log(this.bricks);
30830 var items = Roo.apply([], this.bricks);
30832 if(this.isHorizontal){
30833 this._horizontalLayoutItems( items , isInstant );
30837 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30838 // this._verticalAlternativeLayoutItems( items , isInstant );
30842 this._verticalLayoutItems( items , isInstant );
30846 _verticalLayoutItems : function ( items , isInstant)
30848 if ( !items || !items.length ) {
30853 ['xs', 'xs', 'xs', 'tall'],
30854 ['xs', 'xs', 'tall'],
30855 ['xs', 'xs', 'sm'],
30856 ['xs', 'xs', 'xs'],
30862 ['sm', 'xs', 'xs'],
30866 ['tall', 'xs', 'xs', 'xs'],
30867 ['tall', 'xs', 'xs'],
30879 Roo.each(items, function(item, k){
30881 switch (item.size) {
30882 // these layouts take up a full box,
30893 boxes.push([item]);
30916 var filterPattern = function(box, length)
30924 var pattern = box.slice(0, length);
30928 Roo.each(pattern, function(i){
30929 format.push(i.size);
30932 Roo.each(standard, function(s){
30934 if(String(s) != String(format)){
30943 if(!match && length == 1){
30948 filterPattern(box, length - 1);
30952 queue.push(pattern);
30954 box = box.slice(length, box.length);
30956 filterPattern(box, 4);
30962 Roo.each(boxes, function(box, k){
30968 if(box.length == 1){
30973 filterPattern(box, 4);
30977 this._processVerticalLayoutQueue( queue, isInstant );
30981 // _verticalAlternativeLayoutItems : function( items , isInstant )
30983 // if ( !items || !items.length ) {
30987 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
30991 _horizontalLayoutItems : function ( items , isInstant)
30993 if ( !items || !items.length || items.length < 3) {
30999 var eItems = items.slice(0, 3);
31001 items = items.slice(3, items.length);
31004 ['xs', 'xs', 'xs', 'wide'],
31005 ['xs', 'xs', 'wide'],
31006 ['xs', 'xs', 'sm'],
31007 ['xs', 'xs', 'xs'],
31013 ['sm', 'xs', 'xs'],
31017 ['wide', 'xs', 'xs', 'xs'],
31018 ['wide', 'xs', 'xs'],
31031 Roo.each(items, function(item, k){
31033 switch (item.size) {
31044 boxes.push([item]);
31068 var filterPattern = function(box, length)
31076 var pattern = box.slice(0, length);
31080 Roo.each(pattern, function(i){
31081 format.push(i.size);
31084 Roo.each(standard, function(s){
31086 if(String(s) != String(format)){
31095 if(!match && length == 1){
31100 filterPattern(box, length - 1);
31104 queue.push(pattern);
31106 box = box.slice(length, box.length);
31108 filterPattern(box, 4);
31114 Roo.each(boxes, function(box, k){
31120 if(box.length == 1){
31125 filterPattern(box, 4);
31132 var pos = this.el.getBox(true);
31136 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31138 var hit_end = false;
31140 Roo.each(queue, function(box){
31144 Roo.each(box, function(b){
31146 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31156 Roo.each(box, function(b){
31158 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31161 mx = Math.max(mx, b.x);
31165 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
31169 Roo.each(box, function(b){
31171 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31185 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
31188 /** Sets position of item in DOM
31189 * @param {Element} item
31190 * @param {Number} x - horizontal position
31191 * @param {Number} y - vertical position
31192 * @param {Boolean} isInstant - disables transitions
31194 _processVerticalLayoutQueue : function( queue, isInstant )
31196 var pos = this.el.getBox(true);
31201 for (var i = 0; i < this.cols; i++){
31205 Roo.each(queue, function(box, k){
31207 var col = k % this.cols;
31209 Roo.each(box, function(b,kk){
31211 b.el.position('absolute');
31213 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31214 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31216 if(b.size == 'md-left' || b.size == 'md-right'){
31217 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31218 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31221 b.el.setWidth(width);
31222 b.el.setHeight(height);
31224 b.el.select('iframe',true).setSize(width,height);
31228 for (var i = 0; i < this.cols; i++){
31230 if(maxY[i] < maxY[col]){
31235 col = Math.min(col, i);
31239 x = pos.x + col * (this.colWidth + this.padWidth);
31243 var positions = [];
31245 switch (box.length){
31247 positions = this.getVerticalOneBoxColPositions(x, y, box);
31250 positions = this.getVerticalTwoBoxColPositions(x, y, box);
31253 positions = this.getVerticalThreeBoxColPositions(x, y, box);
31256 positions = this.getVerticalFourBoxColPositions(x, y, box);
31262 Roo.each(box, function(b,kk){
31264 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31266 var sz = b.el.getSize();
31268 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
31276 for (var i = 0; i < this.cols; i++){
31277 mY = Math.max(mY, maxY[i]);
31280 this.el.setHeight(mY - pos.y);
31284 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
31286 // var pos = this.el.getBox(true);
31289 // var maxX = pos.right;
31291 // var maxHeight = 0;
31293 // Roo.each(items, function(item, k){
31297 // item.el.position('absolute');
31299 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
31301 // item.el.setWidth(width);
31303 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
31305 // item.el.setHeight(height);
31308 // item.el.setXY([x, y], isInstant ? false : true);
31310 // item.el.setXY([maxX - width, y], isInstant ? false : true);
31313 // y = y + height + this.alternativePadWidth;
31315 // maxHeight = maxHeight + height + this.alternativePadWidth;
31319 // this.el.setHeight(maxHeight);
31323 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
31325 var pos = this.el.getBox(true);
31330 var maxX = pos.right;
31332 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
31334 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31336 Roo.each(queue, function(box, k){
31338 Roo.each(box, function(b, kk){
31340 b.el.position('absolute');
31342 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31343 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31345 if(b.size == 'md-left' || b.size == 'md-right'){
31346 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31347 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31350 b.el.setWidth(width);
31351 b.el.setHeight(height);
31359 var positions = [];
31361 switch (box.length){
31363 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
31366 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
31369 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
31372 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
31378 Roo.each(box, function(b,kk){
31380 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31382 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
31390 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
31392 Roo.each(eItems, function(b,k){
31394 b.size = (k == 0) ? 'sm' : 'xs';
31395 b.x = (k == 0) ? 2 : 1;
31396 b.y = (k == 0) ? 2 : 1;
31398 b.el.position('absolute');
31400 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31402 b.el.setWidth(width);
31404 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31406 b.el.setHeight(height);
31410 var positions = [];
31413 x : maxX - this.unitWidth * 2 - this.gutter,
31418 x : maxX - this.unitWidth,
31419 y : minY + (this.unitWidth + this.gutter) * 2
31423 x : maxX - this.unitWidth * 3 - this.gutter * 2,
31427 Roo.each(eItems, function(b,k){
31429 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
31435 getVerticalOneBoxColPositions : function(x, y, box)
31439 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
31441 if(box[0].size == 'md-left'){
31445 if(box[0].size == 'md-right'){
31450 x : x + (this.unitWidth + this.gutter) * rand,
31457 getVerticalTwoBoxColPositions : function(x, y, box)
31461 if(box[0].size == 'xs'){
31465 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
31469 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
31483 x : x + (this.unitWidth + this.gutter) * 2,
31484 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
31491 getVerticalThreeBoxColPositions : function(x, y, box)
31495 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31503 x : x + (this.unitWidth + this.gutter) * 1,
31508 x : x + (this.unitWidth + this.gutter) * 2,
31516 if(box[0].size == 'xs' && box[1].size == 'xs'){
31525 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
31529 x : x + (this.unitWidth + this.gutter) * 1,
31543 x : x + (this.unitWidth + this.gutter) * 2,
31548 x : x + (this.unitWidth + this.gutter) * 2,
31549 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
31556 getVerticalFourBoxColPositions : function(x, y, box)
31560 if(box[0].size == 'xs'){
31569 y : y + (this.unitHeight + this.gutter) * 1
31574 y : y + (this.unitHeight + this.gutter) * 2
31578 x : x + (this.unitWidth + this.gutter) * 1,
31592 x : x + (this.unitWidth + this.gutter) * 2,
31597 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
31598 y : y + (this.unitHeight + this.gutter) * 1
31602 x : x + (this.unitWidth + this.gutter) * 2,
31603 y : y + (this.unitWidth + this.gutter) * 2
31610 getHorizontalOneBoxColPositions : function(maxX, minY, box)
31614 if(box[0].size == 'md-left'){
31616 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31623 if(box[0].size == 'md-right'){
31625 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31626 y : minY + (this.unitWidth + this.gutter) * 1
31632 var rand = Math.floor(Math.random() * (4 - box[0].y));
31635 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31636 y : minY + (this.unitWidth + this.gutter) * rand
31643 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
31647 if(box[0].size == 'xs'){
31650 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31655 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31656 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
31664 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31669 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31670 y : minY + (this.unitWidth + this.gutter) * 2
31677 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
31681 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31684 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31689 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31690 y : minY + (this.unitWidth + this.gutter) * 1
31694 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31695 y : minY + (this.unitWidth + this.gutter) * 2
31702 if(box[0].size == 'xs' && box[1].size == 'xs'){
31705 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31710 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31715 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31716 y : minY + (this.unitWidth + this.gutter) * 1
31724 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31729 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31730 y : minY + (this.unitWidth + this.gutter) * 2
31734 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31735 y : minY + (this.unitWidth + this.gutter) * 2
31742 getHorizontalFourBoxColPositions : function(maxX, minY, box)
31746 if(box[0].size == 'xs'){
31749 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31754 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31759 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),
31764 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
31765 y : minY + (this.unitWidth + this.gutter) * 1
31773 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31778 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31779 y : minY + (this.unitWidth + this.gutter) * 2
31783 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31784 y : minY + (this.unitWidth + this.gutter) * 2
31788 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),
31789 y : minY + (this.unitWidth + this.gutter) * 2
31797 * remove a Masonry Brick
31798 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
31800 removeBrick : function(brick_id)
31806 for (var i = 0; i<this.bricks.length; i++) {
31807 if (this.bricks[i].id == brick_id) {
31808 this.bricks.splice(i,1);
31809 this.el.dom.removeChild(Roo.get(brick_id).dom);
31816 * adds a Masonry Brick
31817 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31819 addBrick : function(cfg)
31821 var cn = new Roo.bootstrap.MasonryBrick(cfg);
31822 //this.register(cn);
31823 cn.parentId = this.id;
31824 cn.onRender(this.el, null);
31829 * register a Masonry Brick
31830 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31833 register : function(brick)
31835 this.bricks.push(brick);
31836 brick.masonryId = this.id;
31840 * clear all the Masonry Brick
31842 clearAll : function()
31845 //this.getChildContainer().dom.innerHTML = "";
31846 this.el.dom.innerHTML = '';
31849 getSelected : function()
31851 if (!this.selectedBrick) {
31855 return this.selectedBrick;
31859 Roo.apply(Roo.bootstrap.LayoutMasonry, {
31863 * register a Masonry Layout
31864 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
31867 register : function(layout)
31869 this.groups[layout.id] = layout;
31872 * fetch a Masonry Layout based on the masonry layout ID
31873 * @param {string} the masonry layout to add
31874 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
31877 get: function(layout_id) {
31878 if (typeof(this.groups[layout_id]) == 'undefined') {
31881 return this.groups[layout_id] ;
31893 * http://masonry.desandro.com
31895 * The idea is to render all the bricks based on vertical width...
31897 * The original code extends 'outlayer' - we might need to use that....
31903 * @class Roo.bootstrap.LayoutMasonryAuto
31904 * @extends Roo.bootstrap.Component
31905 * Bootstrap Layout Masonry class
31908 * Create a new Element
31909 * @param {Object} config The config object
31912 Roo.bootstrap.LayoutMasonryAuto = function(config){
31913 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
31916 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
31919 * @cfg {Boolean} isFitWidth - resize the width..
31921 isFitWidth : false, // options..
31923 * @cfg {Boolean} isOriginLeft = left align?
31925 isOriginLeft : true,
31927 * @cfg {Boolean} isOriginTop = top align?
31929 isOriginTop : false,
31931 * @cfg {Boolean} isLayoutInstant = no animation?
31933 isLayoutInstant : false, // needed?
31935 * @cfg {Boolean} isResizingContainer = not sure if this is used..
31937 isResizingContainer : true,
31939 * @cfg {Number} columnWidth width of the columns
31945 * @cfg {Number} maxCols maximum number of columns
31950 * @cfg {Number} padHeight padding below box..
31956 * @cfg {Boolean} isAutoInitial defalut true
31959 isAutoInitial : true,
31965 initialColumnWidth : 0,
31966 currentSize : null,
31968 colYs : null, // array.
31975 bricks: null, //CompositeElement
31976 cols : 0, // array?
31977 // element : null, // wrapped now this.el
31978 _isLayoutInited : null,
31981 getAutoCreate : function(){
31985 cls: 'blog-masonary-wrapper ' + this.cls,
31987 cls : 'mas-boxes masonary'
31994 getChildContainer: function( )
31996 if (this.boxesEl) {
31997 return this.boxesEl;
32000 this.boxesEl = this.el.select('.mas-boxes').first();
32002 return this.boxesEl;
32006 initEvents : function()
32010 if(this.isAutoInitial){
32011 Roo.log('hook children rendered');
32012 this.on('childrenrendered', function() {
32013 Roo.log('children rendered');
32020 initial : function()
32022 this.reloadItems();
32024 this.currentSize = this.el.getBox(true);
32026 /// was window resize... - let's see if this works..
32027 Roo.EventManager.onWindowResize(this.resize, this);
32029 if(!this.isAutoInitial){
32034 this.layout.defer(500,this);
32037 reloadItems: function()
32039 this.bricks = this.el.select('.masonry-brick', true);
32041 this.bricks.each(function(b) {
32042 //Roo.log(b.getSize());
32043 if (!b.attr('originalwidth')) {
32044 b.attr('originalwidth', b.getSize().width);
32049 Roo.log(this.bricks.elements.length);
32052 resize : function()
32055 var cs = this.el.getBox(true);
32057 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
32058 Roo.log("no change in with or X");
32061 this.currentSize = cs;
32065 layout : function()
32068 this._resetLayout();
32069 //this._manageStamps();
32071 // don't animate first layout
32072 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
32073 this.layoutItems( isInstant );
32075 // flag for initalized
32076 this._isLayoutInited = true;
32079 layoutItems : function( isInstant )
32081 //var items = this._getItemsForLayout( this.items );
32082 // original code supports filtering layout items.. we just ignore it..
32084 this._layoutItems( this.bricks , isInstant );
32086 this._postLayout();
32088 _layoutItems : function ( items , isInstant)
32090 //this.fireEvent( 'layout', this, items );
32093 if ( !items || !items.elements.length ) {
32094 // no items, emit event with empty array
32099 items.each(function(item) {
32100 Roo.log("layout item");
32102 // get x/y object from method
32103 var position = this._getItemLayoutPosition( item );
32105 position.item = item;
32106 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
32107 queue.push( position );
32110 this._processLayoutQueue( queue );
32112 /** Sets position of item in DOM
32113 * @param {Element} item
32114 * @param {Number} x - horizontal position
32115 * @param {Number} y - vertical position
32116 * @param {Boolean} isInstant - disables transitions
32118 _processLayoutQueue : function( queue )
32120 for ( var i=0, len = queue.length; i < len; i++ ) {
32121 var obj = queue[i];
32122 obj.item.position('absolute');
32123 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
32129 * Any logic you want to do after each layout,
32130 * i.e. size the container
32132 _postLayout : function()
32134 this.resizeContainer();
32137 resizeContainer : function()
32139 if ( !this.isResizingContainer ) {
32142 var size = this._getContainerSize();
32144 this.el.setSize(size.width,size.height);
32145 this.boxesEl.setSize(size.width,size.height);
32151 _resetLayout : function()
32153 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
32154 this.colWidth = this.el.getWidth();
32155 //this.gutter = this.el.getWidth();
32157 this.measureColumns();
32163 this.colYs.push( 0 );
32169 measureColumns : function()
32171 this.getContainerWidth();
32172 // if columnWidth is 0, default to outerWidth of first item
32173 if ( !this.columnWidth ) {
32174 var firstItem = this.bricks.first();
32175 Roo.log(firstItem);
32176 this.columnWidth = this.containerWidth;
32177 if (firstItem && firstItem.attr('originalwidth') ) {
32178 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
32180 // columnWidth fall back to item of first element
32181 Roo.log("set column width?");
32182 this.initialColumnWidth = this.columnWidth ;
32184 // if first elem has no width, default to size of container
32189 if (this.initialColumnWidth) {
32190 this.columnWidth = this.initialColumnWidth;
32195 // column width is fixed at the top - however if container width get's smaller we should
32198 // this bit calcs how man columns..
32200 var columnWidth = this.columnWidth += this.gutter;
32202 // calculate columns
32203 var containerWidth = this.containerWidth + this.gutter;
32205 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
32206 // fix rounding errors, typically with gutters
32207 var excess = columnWidth - containerWidth % columnWidth;
32210 // if overshoot is less than a pixel, round up, otherwise floor it
32211 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
32212 cols = Math[ mathMethod ]( cols );
32213 this.cols = Math.max( cols, 1 );
32214 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
32216 // padding positioning..
32217 var totalColWidth = this.cols * this.columnWidth;
32218 var padavail = this.containerWidth - totalColWidth;
32219 // so for 2 columns - we need 3 'pads'
32221 var padNeeded = (1+this.cols) * this.padWidth;
32223 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
32225 this.columnWidth += padExtra
32226 //this.padWidth = Math.floor(padavail / ( this.cols));
32228 // adjust colum width so that padding is fixed??
32230 // we have 3 columns ... total = width * 3
32231 // we have X left over... that should be used by
32233 //if (this.expandC) {
32241 getContainerWidth : function()
32243 /* // container is parent if fit width
32244 var container = this.isFitWidth ? this.element.parentNode : this.element;
32245 // check that this.size and size are there
32246 // IE8 triggers resize on body size change, so they might not be
32248 var size = getSize( container ); //FIXME
32249 this.containerWidth = size && size.innerWidth; //FIXME
32252 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
32256 _getItemLayoutPosition : function( item ) // what is item?
32258 // we resize the item to our columnWidth..
32260 item.setWidth(this.columnWidth);
32261 item.autoBoxAdjust = false;
32263 var sz = item.getSize();
32265 // how many columns does this brick span
32266 var remainder = this.containerWidth % this.columnWidth;
32268 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
32269 // round if off by 1 pixel, otherwise use ceil
32270 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
32271 colSpan = Math.min( colSpan, this.cols );
32273 // normally this should be '1' as we dont' currently allow multi width columns..
32275 var colGroup = this._getColGroup( colSpan );
32276 // get the minimum Y value from the columns
32277 var minimumY = Math.min.apply( Math, colGroup );
32278 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32280 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
32282 // position the brick
32284 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
32285 y: this.currentSize.y + minimumY + this.padHeight
32289 // apply setHeight to necessary columns
32290 var setHeight = minimumY + sz.height + this.padHeight;
32291 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32293 var setSpan = this.cols + 1 - colGroup.length;
32294 for ( var i = 0; i < setSpan; i++ ) {
32295 this.colYs[ shortColIndex + i ] = setHeight ;
32302 * @param {Number} colSpan - number of columns the element spans
32303 * @returns {Array} colGroup
32305 _getColGroup : function( colSpan )
32307 if ( colSpan < 2 ) {
32308 // if brick spans only one column, use all the column Ys
32313 // how many different places could this brick fit horizontally
32314 var groupCount = this.cols + 1 - colSpan;
32315 // for each group potential horizontal position
32316 for ( var i = 0; i < groupCount; i++ ) {
32317 // make an array of colY values for that one group
32318 var groupColYs = this.colYs.slice( i, i + colSpan );
32319 // and get the max value of the array
32320 colGroup[i] = Math.max.apply( Math, groupColYs );
32325 _manageStamp : function( stamp )
32327 var stampSize = stamp.getSize();
32328 var offset = stamp.getBox();
32329 // get the columns that this stamp affects
32330 var firstX = this.isOriginLeft ? offset.x : offset.right;
32331 var lastX = firstX + stampSize.width;
32332 var firstCol = Math.floor( firstX / this.columnWidth );
32333 firstCol = Math.max( 0, firstCol );
32335 var lastCol = Math.floor( lastX / this.columnWidth );
32336 // lastCol should not go over if multiple of columnWidth #425
32337 lastCol -= lastX % this.columnWidth ? 0 : 1;
32338 lastCol = Math.min( this.cols - 1, lastCol );
32340 // set colYs to bottom of the stamp
32341 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
32344 for ( var i = firstCol; i <= lastCol; i++ ) {
32345 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
32350 _getContainerSize : function()
32352 this.maxY = Math.max.apply( Math, this.colYs );
32357 if ( this.isFitWidth ) {
32358 size.width = this._getContainerFitWidth();
32364 _getContainerFitWidth : function()
32366 var unusedCols = 0;
32367 // count unused columns
32370 if ( this.colYs[i] !== 0 ) {
32375 // fit container to columns that have been used
32376 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
32379 needsResizeLayout : function()
32381 var previousWidth = this.containerWidth;
32382 this.getContainerWidth();
32383 return previousWidth !== this.containerWidth;
32398 * @class Roo.bootstrap.MasonryBrick
32399 * @extends Roo.bootstrap.Component
32400 * Bootstrap MasonryBrick class
32403 * Create a new MasonryBrick
32404 * @param {Object} config The config object
32407 Roo.bootstrap.MasonryBrick = function(config){
32409 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
32411 Roo.bootstrap.MasonryBrick.register(this);
32417 * When a MasonryBrick is clcik
32418 * @param {Roo.bootstrap.MasonryBrick} this
32419 * @param {Roo.EventObject} e
32425 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
32428 * @cfg {String} title
32432 * @cfg {String} html
32436 * @cfg {String} bgimage
32440 * @cfg {String} videourl
32444 * @cfg {String} cls
32448 * @cfg {String} href
32452 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
32457 * @cfg {String} placetitle (center|bottom)
32462 * @cfg {Boolean} isFitContainer defalut true
32464 isFitContainer : true,
32467 * @cfg {Boolean} preventDefault defalut false
32469 preventDefault : false,
32472 * @cfg {Boolean} inverse defalut false
32474 maskInverse : false,
32476 getAutoCreate : function()
32478 if(!this.isFitContainer){
32479 return this.getSplitAutoCreate();
32482 var cls = 'masonry-brick masonry-brick-full';
32484 if(this.href.length){
32485 cls += ' masonry-brick-link';
32488 if(this.bgimage.length){
32489 cls += ' masonry-brick-image';
32492 if(this.maskInverse){
32493 cls += ' mask-inverse';
32496 if(!this.html.length && !this.maskInverse && !this.videourl.length){
32497 cls += ' enable-mask';
32501 cls += ' masonry-' + this.size + '-brick';
32504 if(this.placetitle.length){
32506 switch (this.placetitle) {
32508 cls += ' masonry-center-title';
32511 cls += ' masonry-bottom-title';
32518 if(!this.html.length && !this.bgimage.length){
32519 cls += ' masonry-center-title';
32522 if(!this.html.length && this.bgimage.length){
32523 cls += ' masonry-bottom-title';
32528 cls += ' ' + this.cls;
32532 tag: (this.href.length) ? 'a' : 'div',
32537 cls: 'masonry-brick-mask'
32541 cls: 'masonry-brick-paragraph',
32547 if(this.href.length){
32548 cfg.href = this.href;
32551 var cn = cfg.cn[1].cn;
32553 if(this.title.length){
32556 cls: 'masonry-brick-title',
32561 if(this.html.length){
32564 cls: 'masonry-brick-text',
32569 if (!this.title.length && !this.html.length) {
32570 cfg.cn[1].cls += ' hide';
32573 if(this.bgimage.length){
32576 cls: 'masonry-brick-image-view',
32581 if(this.videourl.length){
32582 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32583 // youtube support only?
32586 cls: 'masonry-brick-image-view',
32589 allowfullscreen : true
32597 getSplitAutoCreate : function()
32599 var cls = 'masonry-brick masonry-brick-split';
32601 if(this.href.length){
32602 cls += ' masonry-brick-link';
32605 if(this.bgimage.length){
32606 cls += ' masonry-brick-image';
32610 cls += ' masonry-' + this.size + '-brick';
32613 switch (this.placetitle) {
32615 cls += ' masonry-center-title';
32618 cls += ' masonry-bottom-title';
32621 if(!this.bgimage.length){
32622 cls += ' masonry-center-title';
32625 if(this.bgimage.length){
32626 cls += ' masonry-bottom-title';
32632 cls += ' ' + this.cls;
32636 tag: (this.href.length) ? 'a' : 'div',
32641 cls: 'masonry-brick-split-head',
32645 cls: 'masonry-brick-paragraph',
32652 cls: 'masonry-brick-split-body',
32658 if(this.href.length){
32659 cfg.href = this.href;
32662 if(this.title.length){
32663 cfg.cn[0].cn[0].cn.push({
32665 cls: 'masonry-brick-title',
32670 if(this.html.length){
32671 cfg.cn[1].cn.push({
32673 cls: 'masonry-brick-text',
32678 if(this.bgimage.length){
32679 cfg.cn[0].cn.push({
32681 cls: 'masonry-brick-image-view',
32686 if(this.videourl.length){
32687 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32688 // youtube support only?
32689 cfg.cn[0].cn.cn.push({
32691 cls: 'masonry-brick-image-view',
32694 allowfullscreen : true
32701 initEvents: function()
32703 switch (this.size) {
32736 this.el.on('touchstart', this.onTouchStart, this);
32737 this.el.on('touchmove', this.onTouchMove, this);
32738 this.el.on('touchend', this.onTouchEnd, this);
32739 this.el.on('contextmenu', this.onContextMenu, this);
32741 this.el.on('mouseenter' ,this.enter, this);
32742 this.el.on('mouseleave', this.leave, this);
32743 this.el.on('click', this.onClick, this);
32746 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
32747 this.parent().bricks.push(this);
32752 onClick: function(e, el)
32754 var time = this.endTimer - this.startTimer;
32755 // Roo.log(e.preventDefault());
32758 e.preventDefault();
32763 if(!this.preventDefault){
32767 e.preventDefault();
32769 if (this.activeClass != '') {
32770 this.selectBrick();
32773 this.fireEvent('click', this, e);
32776 enter: function(e, el)
32778 e.preventDefault();
32780 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32784 if(this.bgimage.length && this.html.length){
32785 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32789 leave: function(e, el)
32791 e.preventDefault();
32793 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32797 if(this.bgimage.length && this.html.length){
32798 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
32802 onTouchStart: function(e, el)
32804 // e.preventDefault();
32806 this.touchmoved = false;
32808 if(!this.isFitContainer){
32812 if(!this.bgimage.length || !this.html.length){
32816 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32818 this.timer = new Date().getTime();
32822 onTouchMove: function(e, el)
32824 this.touchmoved = true;
32827 onContextMenu : function(e,el)
32829 e.preventDefault();
32830 e.stopPropagation();
32834 onTouchEnd: function(e, el)
32836 // e.preventDefault();
32838 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
32845 if(!this.bgimage.length || !this.html.length){
32847 if(this.href.length){
32848 window.location.href = this.href;
32854 if(!this.isFitContainer){
32858 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
32860 window.location.href = this.href;
32863 //selection on single brick only
32864 selectBrick : function() {
32866 if (!this.parentId) {
32870 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
32871 var index = m.selectedBrick.indexOf(this.id);
32874 m.selectedBrick.splice(index,1);
32875 this.el.removeClass(this.activeClass);
32879 for(var i = 0; i < m.selectedBrick.length; i++) {
32880 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
32881 b.el.removeClass(b.activeClass);
32884 m.selectedBrick = [];
32886 m.selectedBrick.push(this.id);
32887 this.el.addClass(this.activeClass);
32891 isSelected : function(){
32892 return this.el.hasClass(this.activeClass);
32897 Roo.apply(Roo.bootstrap.MasonryBrick, {
32900 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
32902 * register a Masonry Brick
32903 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
32906 register : function(brick)
32908 //this.groups[brick.id] = brick;
32909 this.groups.add(brick.id, brick);
32912 * fetch a masonry brick based on the masonry brick ID
32913 * @param {string} the masonry brick to add
32914 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
32917 get: function(brick_id)
32919 // if (typeof(this.groups[brick_id]) == 'undefined') {
32922 // return this.groups[brick_id] ;
32924 if(this.groups.key(brick_id)) {
32925 return this.groups.key(brick_id);
32943 * @class Roo.bootstrap.Brick
32944 * @extends Roo.bootstrap.Component
32945 * Bootstrap Brick class
32948 * Create a new Brick
32949 * @param {Object} config The config object
32952 Roo.bootstrap.Brick = function(config){
32953 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
32959 * When a Brick is click
32960 * @param {Roo.bootstrap.Brick} this
32961 * @param {Roo.EventObject} e
32967 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
32970 * @cfg {String} title
32974 * @cfg {String} html
32978 * @cfg {String} bgimage
32982 * @cfg {String} cls
32986 * @cfg {String} href
32990 * @cfg {String} video
32994 * @cfg {Boolean} square
32998 getAutoCreate : function()
33000 var cls = 'roo-brick';
33002 if(this.href.length){
33003 cls += ' roo-brick-link';
33006 if(this.bgimage.length){
33007 cls += ' roo-brick-image';
33010 if(!this.html.length && !this.bgimage.length){
33011 cls += ' roo-brick-center-title';
33014 if(!this.html.length && this.bgimage.length){
33015 cls += ' roo-brick-bottom-title';
33019 cls += ' ' + this.cls;
33023 tag: (this.href.length) ? 'a' : 'div',
33028 cls: 'roo-brick-paragraph',
33034 if(this.href.length){
33035 cfg.href = this.href;
33038 var cn = cfg.cn[0].cn;
33040 if(this.title.length){
33043 cls: 'roo-brick-title',
33048 if(this.html.length){
33051 cls: 'roo-brick-text',
33058 if(this.bgimage.length){
33061 cls: 'roo-brick-image-view',
33069 initEvents: function()
33071 if(this.title.length || this.html.length){
33072 this.el.on('mouseenter' ,this.enter, this);
33073 this.el.on('mouseleave', this.leave, this);
33076 Roo.EventManager.onWindowResize(this.resize, this);
33078 if(this.bgimage.length){
33079 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
33080 this.imageEl.on('load', this.onImageLoad, this);
33087 onImageLoad : function()
33092 resize : function()
33094 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
33096 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
33098 if(this.bgimage.length){
33099 var image = this.el.select('.roo-brick-image-view', true).first();
33101 image.setWidth(paragraph.getWidth());
33104 image.setHeight(paragraph.getWidth());
33107 this.el.setHeight(image.getHeight());
33108 paragraph.setHeight(image.getHeight());
33114 enter: function(e, el)
33116 e.preventDefault();
33118 if(this.bgimage.length){
33119 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
33120 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
33124 leave: function(e, el)
33126 e.preventDefault();
33128 if(this.bgimage.length){
33129 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
33130 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
33145 * @class Roo.bootstrap.NumberField
33146 * @extends Roo.bootstrap.Input
33147 * Bootstrap NumberField class
33153 * Create a new NumberField
33154 * @param {Object} config The config object
33157 Roo.bootstrap.NumberField = function(config){
33158 Roo.bootstrap.NumberField.superclass.constructor.call(this, config);
33161 Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
33164 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
33166 allowDecimals : true,
33168 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
33170 decimalSeparator : ".",
33172 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
33174 decimalPrecision : 2,
33176 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
33178 allowNegative : true,
33181 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
33185 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
33187 minValue : Number.NEGATIVE_INFINITY,
33189 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
33191 maxValue : Number.MAX_VALUE,
33193 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
33195 minText : "The minimum value for this field is {0}",
33197 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
33199 maxText : "The maximum value for this field is {0}",
33201 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
33202 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
33204 nanText : "{0} is not a valid number",
33206 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
33210 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
33212 thousandsDelimiter : false,
33214 * @cfg {String} valueAlign alignment of value
33216 valueAlign : "left",
33218 getAutoCreate : function()
33220 var hiddenInput = {
33224 cls: 'hidden-number-input'
33228 hiddenInput.name = this.name;
33233 var cfg = Roo.bootstrap.NumberField.superclass.getAutoCreate.call(this);
33235 this.name = hiddenInput.name;
33237 if(cfg.cn.length > 0) {
33238 cfg.cn.push(hiddenInput);
33245 initEvents : function()
33247 Roo.bootstrap.NumberField.superclass.initEvents.call(this);
33249 var allowed = "0123456789";
33251 if(this.allowDecimals){
33252 allowed += this.decimalSeparator;
33255 if(this.allowNegative){
33259 if(this.thousandsDelimiter) {
33263 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
33265 var keyPress = function(e){
33267 var k = e.getKey();
33269 var c = e.getCharCode();
33272 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
33273 allowed.indexOf(String.fromCharCode(c)) === -1
33279 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
33283 if(allowed.indexOf(String.fromCharCode(c)) === -1){
33288 this.el.on("keypress", keyPress, this);
33291 validateValue : function(value)
33294 if(!Roo.bootstrap.NumberField.superclass.validateValue.call(this, value)){
33298 var num = this.parseValue(value);
33301 this.markInvalid(String.format(this.nanText, value));
33305 if(num < this.minValue){
33306 this.markInvalid(String.format(this.minText, this.minValue));
33310 if(num > this.maxValue){
33311 this.markInvalid(String.format(this.maxText, this.maxValue));
33318 getValue : function()
33320 var v = this.hiddenEl().getValue();
33322 return this.fixPrecision(this.parseValue(v));
33325 parseValue : function(value)
33327 if(this.thousandsDelimiter) {
33329 r = new RegExp(",", "g");
33330 value = value.replace(r, "");
33333 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
33334 return isNaN(value) ? '' : value;
33337 fixPrecision : function(value)
33339 if(this.thousandsDelimiter) {
33341 r = new RegExp(",", "g");
33342 value = value.replace(r, "");
33345 var nan = isNaN(value);
33347 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
33348 return nan ? '' : value;
33350 return parseFloat(value).toFixed(this.decimalPrecision);
33353 setValue : function(v)
33355 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
33361 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
33363 this.inputEl().dom.value = (v == '') ? '' :
33364 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
33366 if(!this.allowZero && v === '0') {
33367 this.hiddenEl().dom.value = '';
33368 this.inputEl().dom.value = '';
33375 decimalPrecisionFcn : function(v)
33377 return Math.floor(v);
33380 beforeBlur : function()
33386 var v = this.parseValue(this.getRawValue());
33393 hiddenEl : function()
33395 return this.el.select('input.hidden-number-input',true).first();
33407 * @class Roo.bootstrap.DocumentSlider
33408 * @extends Roo.bootstrap.Component
33409 * Bootstrap DocumentSlider class
33412 * Create a new DocumentViewer
33413 * @param {Object} config The config object
33416 Roo.bootstrap.DocumentSlider = function(config){
33417 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
33424 * Fire after initEvent
33425 * @param {Roo.bootstrap.DocumentSlider} this
33430 * Fire after update
33431 * @param {Roo.bootstrap.DocumentSlider} this
33437 * @param {Roo.bootstrap.DocumentSlider} this
33443 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
33449 getAutoCreate : function()
33453 cls : 'roo-document-slider',
33457 cls : 'roo-document-slider-header',
33461 cls : 'roo-document-slider-header-title'
33467 cls : 'roo-document-slider-body',
33471 cls : 'roo-document-slider-prev',
33475 cls : 'fa fa-chevron-left'
33481 cls : 'roo-document-slider-thumb',
33485 cls : 'roo-document-slider-image'
33491 cls : 'roo-document-slider-next',
33495 cls : 'fa fa-chevron-right'
33507 initEvents : function()
33509 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
33510 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
33512 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
33513 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
33515 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
33516 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
33518 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
33519 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
33521 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
33522 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
33524 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
33525 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33527 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
33528 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33530 this.thumbEl.on('click', this.onClick, this);
33532 this.prevIndicator.on('click', this.prev, this);
33534 this.nextIndicator.on('click', this.next, this);
33538 initial : function()
33540 if(this.files.length){
33541 this.indicator = 1;
33545 this.fireEvent('initial', this);
33548 update : function()
33550 this.imageEl.attr('src', this.files[this.indicator - 1]);
33552 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
33554 this.prevIndicator.show();
33556 if(this.indicator == 1){
33557 this.prevIndicator.hide();
33560 this.nextIndicator.show();
33562 if(this.indicator == this.files.length){
33563 this.nextIndicator.hide();
33566 this.thumbEl.scrollTo('top');
33568 this.fireEvent('update', this);
33571 onClick : function(e)
33573 e.preventDefault();
33575 this.fireEvent('click', this);
33580 e.preventDefault();
33582 this.indicator = Math.max(1, this.indicator - 1);
33589 e.preventDefault();
33591 this.indicator = Math.min(this.files.length, this.indicator + 1);
33605 * @class Roo.bootstrap.RadioSet
33606 * @extends Roo.bootstrap.Input
33607 * Bootstrap RadioSet class
33608 * @cfg {String} indicatorpos (left|right) default left
33609 * @cfg {Boolean} inline (true|false) inline the element (default true)
33610 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
33612 * Create a new RadioSet
33613 * @param {Object} config The config object
33616 Roo.bootstrap.RadioSet = function(config){
33618 Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
33622 Roo.bootstrap.RadioSet.register(this);
33627 * Fires when the element is checked or unchecked.
33628 * @param {Roo.bootstrap.RadioSet} this This radio
33629 * @param {Roo.bootstrap.Radio} item The checked item
33634 * Fires when the element is click.
33635 * @param {Roo.bootstrap.RadioSet} this This radio set
33636 * @param {Roo.bootstrap.Radio} item The checked item
33637 * @param {Roo.EventObject} e The event object
33644 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
33652 indicatorpos : 'left',
33654 getAutoCreate : function()
33658 cls : 'roo-radio-set-label',
33662 html : this.fieldLabel
33667 if(this.indicatorpos == 'left'){
33670 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
33671 tooltip : 'This field is required'
33676 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
33677 tooltip : 'This field is required'
33683 cls : 'roo-radio-set-items'
33686 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
33688 if (align === 'left' && this.fieldLabel.length) {
33691 cls : "roo-radio-set-right",
33697 if(this.labelWidth > 12){
33698 label.style = "width: " + this.labelWidth + 'px';
33701 if(this.labelWidth < 13 && this.labelmd == 0){
33702 this.labelmd = this.labelWidth;
33705 if(this.labellg > 0){
33706 label.cls += ' col-lg-' + this.labellg;
33707 items.cls += ' col-lg-' + (12 - this.labellg);
33710 if(this.labelmd > 0){
33711 label.cls += ' col-md-' + this.labelmd;
33712 items.cls += ' col-md-' + (12 - this.labelmd);
33715 if(this.labelsm > 0){
33716 label.cls += ' col-sm-' + this.labelsm;
33717 items.cls += ' col-sm-' + (12 - this.labelsm);
33720 if(this.labelxs > 0){
33721 label.cls += ' col-xs-' + this.labelxs;
33722 items.cls += ' col-xs-' + (12 - this.labelxs);
33728 cls : 'roo-radio-set',
33732 cls : 'roo-radio-set-input',
33735 value : this.value ? this.value : ''
33742 if(this.weight.length){
33743 cfg.cls += ' roo-radio-' + this.weight;
33747 cfg.cls += ' roo-radio-set-inline';
33751 ['xs','sm','md','lg'].map(function(size){
33752 if (settings[size]) {
33753 cfg.cls += ' col-' + size + '-' + settings[size];
33761 initEvents : function()
33763 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
33764 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
33766 if(!this.fieldLabel.length){
33767 this.labelEl.hide();
33770 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
33771 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
33773 this.indicator = this.indicatorEl();
33775 if(this.indicator){
33776 this.indicator.addClass('invisible');
33779 this.originalValue = this.getValue();
33783 inputEl: function ()
33785 return this.el.select('.roo-radio-set-input', true).first();
33788 getChildContainer : function()
33790 return this.itemsEl;
33793 register : function(item)
33795 this.radioes.push(item);
33799 validate : function()
33801 if(this.getVisibilityEl().hasClass('hidden')){
33807 Roo.each(this.radioes, function(i){
33816 if(this.allowBlank) {
33820 if(this.disabled || valid){
33825 this.markInvalid();
33830 markValid : function()
33832 if(this.labelEl.isVisible(true)){
33833 this.indicatorEl().removeClass('visible');
33834 this.indicatorEl().addClass('invisible');
33837 this.el.removeClass([this.invalidClass, this.validClass]);
33838 this.el.addClass(this.validClass);
33840 this.fireEvent('valid', this);
33843 markInvalid : function(msg)
33845 if(this.allowBlank || this.disabled){
33849 if(this.labelEl.isVisible(true)){
33850 this.indicatorEl().removeClass('invisible');
33851 this.indicatorEl().addClass('visible');
33854 this.el.removeClass([this.invalidClass, this.validClass]);
33855 this.el.addClass(this.invalidClass);
33857 this.fireEvent('invalid', this, msg);
33861 setValue : function(v, suppressEvent)
33863 if(this.value === v){
33870 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
33873 Roo.each(this.radioes, function(i){
33875 i.el.removeClass('checked');
33878 Roo.each(this.radioes, function(i){
33880 if(i.value === v || i.value.toString() === v.toString()){
33882 i.el.addClass('checked');
33884 if(suppressEvent !== true){
33885 this.fireEvent('check', this, i);
33896 clearInvalid : function(){
33898 if(!this.el || this.preventMark){
33902 this.el.removeClass([this.invalidClass]);
33904 this.fireEvent('valid', this);
33909 Roo.apply(Roo.bootstrap.RadioSet, {
33913 register : function(set)
33915 this.groups[set.name] = set;
33918 get: function(name)
33920 if (typeof(this.groups[name]) == 'undefined') {
33924 return this.groups[name] ;
33930 * Ext JS Library 1.1.1
33931 * Copyright(c) 2006-2007, Ext JS, LLC.
33933 * Originally Released Under LGPL - original licence link has changed is not relivant.
33936 * <script type="text/javascript">
33941 * @class Roo.bootstrap.SplitBar
33942 * @extends Roo.util.Observable
33943 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
33947 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
33948 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
33949 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
33950 split.minSize = 100;
33951 split.maxSize = 600;
33952 split.animate = true;
33953 split.on('moved', splitterMoved);
33956 * Create a new SplitBar
33957 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
33958 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
33959 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
33960 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
33961 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
33962 position of the SplitBar).
33964 Roo.bootstrap.SplitBar = function(cfg){
33969 // dragElement : elm
33970 // resizingElement: el,
33972 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
33973 // placement : Roo.bootstrap.SplitBar.LEFT ,
33974 // existingProxy ???
33977 this.el = Roo.get(cfg.dragElement, true);
33978 this.el.dom.unselectable = "on";
33980 this.resizingEl = Roo.get(cfg.resizingElement, true);
33984 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
33985 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
33988 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
33991 * The minimum size of the resizing element. (Defaults to 0)
33997 * The maximum size of the resizing element. (Defaults to 2000)
34000 this.maxSize = 2000;
34003 * Whether to animate the transition to the new size
34006 this.animate = false;
34009 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
34012 this.useShim = false;
34017 if(!cfg.existingProxy){
34019 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
34021 this.proxy = Roo.get(cfg.existingProxy).dom;
34024 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
34027 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
34030 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
34033 this.dragSpecs = {};
34036 * @private The adapter to use to positon and resize elements
34038 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34039 this.adapter.init(this);
34041 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34043 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
34044 this.el.addClass("roo-splitbar-h");
34047 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
34048 this.el.addClass("roo-splitbar-v");
34054 * Fires when the splitter is moved (alias for {@link #event-moved})
34055 * @param {Roo.bootstrap.SplitBar} this
34056 * @param {Number} newSize the new width or height
34061 * Fires when the splitter is moved
34062 * @param {Roo.bootstrap.SplitBar} this
34063 * @param {Number} newSize the new width or height
34067 * @event beforeresize
34068 * Fires before the splitter is dragged
34069 * @param {Roo.bootstrap.SplitBar} this
34071 "beforeresize" : true,
34073 "beforeapply" : true
34076 Roo.util.Observable.call(this);
34079 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
34080 onStartProxyDrag : function(x, y){
34081 this.fireEvent("beforeresize", this);
34083 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
34085 o.enableDisplayMode("block");
34086 // all splitbars share the same overlay
34087 Roo.bootstrap.SplitBar.prototype.overlay = o;
34089 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
34090 this.overlay.show();
34091 Roo.get(this.proxy).setDisplayed("block");
34092 var size = this.adapter.getElementSize(this);
34093 this.activeMinSize = this.getMinimumSize();;
34094 this.activeMaxSize = this.getMaximumSize();;
34095 var c1 = size - this.activeMinSize;
34096 var c2 = Math.max(this.activeMaxSize - size, 0);
34097 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34098 this.dd.resetConstraints();
34099 this.dd.setXConstraint(
34100 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
34101 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
34103 this.dd.setYConstraint(0, 0);
34105 this.dd.resetConstraints();
34106 this.dd.setXConstraint(0, 0);
34107 this.dd.setYConstraint(
34108 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
34109 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
34112 this.dragSpecs.startSize = size;
34113 this.dragSpecs.startPoint = [x, y];
34114 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
34118 * @private Called after the drag operation by the DDProxy
34120 onEndProxyDrag : function(e){
34121 Roo.get(this.proxy).setDisplayed(false);
34122 var endPoint = Roo.lib.Event.getXY(e);
34124 this.overlay.hide();
34127 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34128 newSize = this.dragSpecs.startSize +
34129 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
34130 endPoint[0] - this.dragSpecs.startPoint[0] :
34131 this.dragSpecs.startPoint[0] - endPoint[0]
34134 newSize = this.dragSpecs.startSize +
34135 (this.placement == Roo.bootstrap.SplitBar.TOP ?
34136 endPoint[1] - this.dragSpecs.startPoint[1] :
34137 this.dragSpecs.startPoint[1] - endPoint[1]
34140 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
34141 if(newSize != this.dragSpecs.startSize){
34142 if(this.fireEvent('beforeapply', this, newSize) !== false){
34143 this.adapter.setElementSize(this, newSize);
34144 this.fireEvent("moved", this, newSize);
34145 this.fireEvent("resize", this, newSize);
34151 * Get the adapter this SplitBar uses
34152 * @return The adapter object
34154 getAdapter : function(){
34155 return this.adapter;
34159 * Set the adapter this SplitBar uses
34160 * @param {Object} adapter A SplitBar adapter object
34162 setAdapter : function(adapter){
34163 this.adapter = adapter;
34164 this.adapter.init(this);
34168 * Gets the minimum size for the resizing element
34169 * @return {Number} The minimum size
34171 getMinimumSize : function(){
34172 return this.minSize;
34176 * Sets the minimum size for the resizing element
34177 * @param {Number} minSize The minimum size
34179 setMinimumSize : function(minSize){
34180 this.minSize = minSize;
34184 * Gets the maximum size for the resizing element
34185 * @return {Number} The maximum size
34187 getMaximumSize : function(){
34188 return this.maxSize;
34192 * Sets the maximum size for the resizing element
34193 * @param {Number} maxSize The maximum size
34195 setMaximumSize : function(maxSize){
34196 this.maxSize = maxSize;
34200 * Sets the initialize size for the resizing element
34201 * @param {Number} size The initial size
34203 setCurrentSize : function(size){
34204 var oldAnimate = this.animate;
34205 this.animate = false;
34206 this.adapter.setElementSize(this, size);
34207 this.animate = oldAnimate;
34211 * Destroy this splitbar.
34212 * @param {Boolean} removeEl True to remove the element
34214 destroy : function(removeEl){
34216 this.shim.remove();
34219 this.proxy.parentNode.removeChild(this.proxy);
34227 * @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.
34229 Roo.bootstrap.SplitBar.createProxy = function(dir){
34230 var proxy = new Roo.Element(document.createElement("div"));
34231 proxy.unselectable();
34232 var cls = 'roo-splitbar-proxy';
34233 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
34234 document.body.appendChild(proxy.dom);
34239 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
34240 * Default Adapter. It assumes the splitter and resizing element are not positioned
34241 * elements and only gets/sets the width of the element. Generally used for table based layouts.
34243 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
34246 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
34247 // do nothing for now
34248 init : function(s){
34252 * Called before drag operations to get the current size of the resizing element.
34253 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34255 getElementSize : function(s){
34256 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34257 return s.resizingEl.getWidth();
34259 return s.resizingEl.getHeight();
34264 * Called after drag operations to set the size of the resizing element.
34265 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34266 * @param {Number} newSize The new size to set
34267 * @param {Function} onComplete A function to be invoked when resizing is complete
34269 setElementSize : function(s, newSize, onComplete){
34270 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34272 s.resizingEl.setWidth(newSize);
34274 onComplete(s, newSize);
34277 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
34282 s.resizingEl.setHeight(newSize);
34284 onComplete(s, newSize);
34287 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
34294 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
34295 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
34296 * Adapter that moves the splitter element to align with the resized sizing element.
34297 * Used with an absolute positioned SplitBar.
34298 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
34299 * document.body, make sure you assign an id to the body element.
34301 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
34302 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34303 this.container = Roo.get(container);
34306 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
34307 init : function(s){
34308 this.basic.init(s);
34311 getElementSize : function(s){
34312 return this.basic.getElementSize(s);
34315 setElementSize : function(s, newSize, onComplete){
34316 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
34319 moveSplitter : function(s){
34320 var yes = Roo.bootstrap.SplitBar;
34321 switch(s.placement){
34323 s.el.setX(s.resizingEl.getRight());
34326 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
34329 s.el.setY(s.resizingEl.getBottom());
34332 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
34339 * Orientation constant - Create a vertical SplitBar
34343 Roo.bootstrap.SplitBar.VERTICAL = 1;
34346 * Orientation constant - Create a horizontal SplitBar
34350 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
34353 * Placement constant - The resizing element is to the left of the splitter element
34357 Roo.bootstrap.SplitBar.LEFT = 1;
34360 * Placement constant - The resizing element is to the right of the splitter element
34364 Roo.bootstrap.SplitBar.RIGHT = 2;
34367 * Placement constant - The resizing element is positioned above the splitter element
34371 Roo.bootstrap.SplitBar.TOP = 3;
34374 * Placement constant - The resizing element is positioned under splitter element
34378 Roo.bootstrap.SplitBar.BOTTOM = 4;
34379 Roo.namespace("Roo.bootstrap.layout");/*
34381 * Ext JS Library 1.1.1
34382 * Copyright(c) 2006-2007, Ext JS, LLC.
34384 * Originally Released Under LGPL - original licence link has changed is not relivant.
34387 * <script type="text/javascript">
34391 * @class Roo.bootstrap.layout.Manager
34392 * @extends Roo.bootstrap.Component
34393 * Base class for layout managers.
34395 Roo.bootstrap.layout.Manager = function(config)
34397 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
34403 /** false to disable window resize monitoring @type Boolean */
34404 this.monitorWindowResize = true;
34409 * Fires when a layout is performed.
34410 * @param {Roo.LayoutManager} this
34414 * @event regionresized
34415 * Fires when the user resizes a region.
34416 * @param {Roo.LayoutRegion} region The resized region
34417 * @param {Number} newSize The new size (width for east/west, height for north/south)
34419 "regionresized" : true,
34421 * @event regioncollapsed
34422 * Fires when a region is collapsed.
34423 * @param {Roo.LayoutRegion} region The collapsed region
34425 "regioncollapsed" : true,
34427 * @event regionexpanded
34428 * Fires when a region is expanded.
34429 * @param {Roo.LayoutRegion} region The expanded region
34431 "regionexpanded" : true
34433 this.updating = false;
34436 this.el = Roo.get(config.el);
34442 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
34447 monitorWindowResize : true,
34453 onRender : function(ct, position)
34456 this.el = Roo.get(ct);
34459 //this.fireEvent('render',this);
34463 initEvents: function()
34467 // ie scrollbar fix
34468 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
34469 document.body.scroll = "no";
34470 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
34471 this.el.position('relative');
34473 this.id = this.el.id;
34474 this.el.addClass("roo-layout-container");
34475 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34476 if(this.el.dom != document.body ) {
34477 this.el.on('resize', this.layout,this);
34478 this.el.on('show', this.layout,this);
34484 * Returns true if this layout is currently being updated
34485 * @return {Boolean}
34487 isUpdating : function(){
34488 return this.updating;
34492 * Suspend the LayoutManager from doing auto-layouts while
34493 * making multiple add or remove calls
34495 beginUpdate : function(){
34496 this.updating = true;
34500 * Restore auto-layouts and optionally disable the manager from performing a layout
34501 * @param {Boolean} noLayout true to disable a layout update
34503 endUpdate : function(noLayout){
34504 this.updating = false;
34510 layout: function(){
34514 onRegionResized : function(region, newSize){
34515 this.fireEvent("regionresized", region, newSize);
34519 onRegionCollapsed : function(region){
34520 this.fireEvent("regioncollapsed", region);
34523 onRegionExpanded : function(region){
34524 this.fireEvent("regionexpanded", region);
34528 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
34529 * performs box-model adjustments.
34530 * @return {Object} The size as an object {width: (the width), height: (the height)}
34532 getViewSize : function()
34535 if(this.el.dom != document.body){
34536 size = this.el.getSize();
34538 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
34540 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
34541 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34546 * Returns the Element this layout is bound to.
34547 * @return {Roo.Element}
34549 getEl : function(){
34554 * Returns the specified region.
34555 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
34556 * @return {Roo.LayoutRegion}
34558 getRegion : function(target){
34559 return this.regions[target.toLowerCase()];
34562 onWindowResize : function(){
34563 if(this.monitorWindowResize){
34570 * Ext JS Library 1.1.1
34571 * Copyright(c) 2006-2007, Ext JS, LLC.
34573 * Originally Released Under LGPL - original licence link has changed is not relivant.
34576 * <script type="text/javascript">
34579 * @class Roo.bootstrap.layout.Border
34580 * @extends Roo.bootstrap.layout.Manager
34581 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
34582 * please see: examples/bootstrap/nested.html<br><br>
34584 <b>The container the layout is rendered into can be either the body element or any other element.
34585 If it is not the body element, the container needs to either be an absolute positioned element,
34586 or you will need to add "position:relative" to the css of the container. You will also need to specify
34587 the container size if it is not the body element.</b>
34590 * Create a new Border
34591 * @param {Object} config Configuration options
34593 Roo.bootstrap.layout.Border = function(config){
34594 config = config || {};
34595 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
34599 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34600 if(config[region]){
34601 config[region].region = region;
34602 this.addRegion(config[region]);
34608 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
34610 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
34612 * Creates and adds a new region if it doesn't already exist.
34613 * @param {String} target The target region key (north, south, east, west or center).
34614 * @param {Object} config The regions config object
34615 * @return {BorderLayoutRegion} The new region
34617 addRegion : function(config)
34619 if(!this.regions[config.region]){
34620 var r = this.factory(config);
34621 this.bindRegion(r);
34623 return this.regions[config.region];
34627 bindRegion : function(r){
34628 this.regions[r.config.region] = r;
34630 r.on("visibilitychange", this.layout, this);
34631 r.on("paneladded", this.layout, this);
34632 r.on("panelremoved", this.layout, this);
34633 r.on("invalidated", this.layout, this);
34634 r.on("resized", this.onRegionResized, this);
34635 r.on("collapsed", this.onRegionCollapsed, this);
34636 r.on("expanded", this.onRegionExpanded, this);
34640 * Performs a layout update.
34642 layout : function()
34644 if(this.updating) {
34648 // render all the rebions if they have not been done alreayd?
34649 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34650 if(this.regions[region] && !this.regions[region].bodyEl){
34651 this.regions[region].onRender(this.el)
34655 var size = this.getViewSize();
34656 var w = size.width;
34657 var h = size.height;
34662 //var x = 0, y = 0;
34664 var rs = this.regions;
34665 var north = rs["north"];
34666 var south = rs["south"];
34667 var west = rs["west"];
34668 var east = rs["east"];
34669 var center = rs["center"];
34670 //if(this.hideOnLayout){ // not supported anymore
34671 //c.el.setStyle("display", "none");
34673 if(north && north.isVisible()){
34674 var b = north.getBox();
34675 var m = north.getMargins();
34676 b.width = w - (m.left+m.right);
34679 centerY = b.height + b.y + m.bottom;
34680 centerH -= centerY;
34681 north.updateBox(this.safeBox(b));
34683 if(south && south.isVisible()){
34684 var b = south.getBox();
34685 var m = south.getMargins();
34686 b.width = w - (m.left+m.right);
34688 var totalHeight = (b.height + m.top + m.bottom);
34689 b.y = h - totalHeight + m.top;
34690 centerH -= totalHeight;
34691 south.updateBox(this.safeBox(b));
34693 if(west && west.isVisible()){
34694 var b = west.getBox();
34695 var m = west.getMargins();
34696 b.height = centerH - (m.top+m.bottom);
34698 b.y = centerY + m.top;
34699 var totalWidth = (b.width + m.left + m.right);
34700 centerX += totalWidth;
34701 centerW -= totalWidth;
34702 west.updateBox(this.safeBox(b));
34704 if(east && east.isVisible()){
34705 var b = east.getBox();
34706 var m = east.getMargins();
34707 b.height = centerH - (m.top+m.bottom);
34708 var totalWidth = (b.width + m.left + m.right);
34709 b.x = w - totalWidth + m.left;
34710 b.y = centerY + m.top;
34711 centerW -= totalWidth;
34712 east.updateBox(this.safeBox(b));
34715 var m = center.getMargins();
34717 x: centerX + m.left,
34718 y: centerY + m.top,
34719 width: centerW - (m.left+m.right),
34720 height: centerH - (m.top+m.bottom)
34722 //if(this.hideOnLayout){
34723 //center.el.setStyle("display", "block");
34725 center.updateBox(this.safeBox(centerBox));
34728 this.fireEvent("layout", this);
34732 safeBox : function(box){
34733 box.width = Math.max(0, box.width);
34734 box.height = Math.max(0, box.height);
34739 * Adds a ContentPanel (or subclass) to this layout.
34740 * @param {String} target The target region key (north, south, east, west or center).
34741 * @param {Roo.ContentPanel} panel The panel to add
34742 * @return {Roo.ContentPanel} The added panel
34744 add : function(target, panel){
34746 target = target.toLowerCase();
34747 return this.regions[target].add(panel);
34751 * Remove a ContentPanel (or subclass) to this layout.
34752 * @param {String} target The target region key (north, south, east, west or center).
34753 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
34754 * @return {Roo.ContentPanel} The removed panel
34756 remove : function(target, panel){
34757 target = target.toLowerCase();
34758 return this.regions[target].remove(panel);
34762 * Searches all regions for a panel with the specified id
34763 * @param {String} panelId
34764 * @return {Roo.ContentPanel} The panel or null if it wasn't found
34766 findPanel : function(panelId){
34767 var rs = this.regions;
34768 for(var target in rs){
34769 if(typeof rs[target] != "function"){
34770 var p = rs[target].getPanel(panelId);
34780 * Searches all regions for a panel with the specified id and activates (shows) it.
34781 * @param {String/ContentPanel} panelId The panels id or the panel itself
34782 * @return {Roo.ContentPanel} The shown panel or null
34784 showPanel : function(panelId) {
34785 var rs = this.regions;
34786 for(var target in rs){
34787 var r = rs[target];
34788 if(typeof r != "function"){
34789 if(r.hasPanel(panelId)){
34790 return r.showPanel(panelId);
34798 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
34799 * @param {Roo.state.Provider} provider (optional) An alternate state provider
34802 restoreState : function(provider){
34804 provider = Roo.state.Manager;
34806 var sm = new Roo.LayoutStateManager();
34807 sm.init(this, provider);
34813 * Adds a xtype elements to the layout.
34817 xtype : 'ContentPanel',
34824 xtype : 'NestedLayoutPanel',
34830 items : [ ... list of content panels or nested layout panels.. ]
34834 * @param {Object} cfg Xtype definition of item to add.
34836 addxtype : function(cfg)
34838 // basically accepts a pannel...
34839 // can accept a layout region..!?!?
34840 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
34843 // theory? children can only be panels??
34845 //if (!cfg.xtype.match(/Panel$/)) {
34850 if (typeof(cfg.region) == 'undefined') {
34851 Roo.log("Failed to add Panel, region was not set");
34855 var region = cfg.region;
34861 xitems = cfg.items;
34868 case 'Content': // ContentPanel (el, cfg)
34869 case 'Scroll': // ContentPanel (el, cfg)
34871 cfg.autoCreate = true;
34872 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34874 // var el = this.el.createChild();
34875 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
34878 this.add(region, ret);
34882 case 'TreePanel': // our new panel!
34883 cfg.el = this.el.createChild();
34884 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
34885 this.add(region, ret);
34890 // create a new Layout (which is a Border Layout...
34892 var clayout = cfg.layout;
34893 clayout.el = this.el.createChild();
34894 clayout.items = clayout.items || [];
34898 // replace this exitems with the clayout ones..
34899 xitems = clayout.items;
34901 // force background off if it's in center...
34902 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
34903 cfg.background = false;
34905 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
34908 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34909 //console.log('adding nested layout panel ' + cfg.toSource());
34910 this.add(region, ret);
34911 nb = {}; /// find first...
34916 // needs grid and region
34918 //var el = this.getRegion(region).el.createChild();
34920 *var el = this.el.createChild();
34921 // create the grid first...
34922 cfg.grid.container = el;
34923 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
34926 if (region == 'center' && this.active ) {
34927 cfg.background = false;
34930 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
34932 this.add(region, ret);
34934 if (cfg.background) {
34935 // render grid on panel activation (if panel background)
34936 ret.on('activate', function(gp) {
34937 if (!gp.grid.rendered) {
34938 // gp.grid.render(el);
34942 // cfg.grid.render(el);
34948 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
34949 // it was the old xcomponent building that caused this before.
34950 // espeically if border is the top element in the tree.
34960 if (typeof(Roo[cfg.xtype]) != 'undefined') {
34962 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
34963 this.add(region, ret);
34967 throw "Can not add '" + cfg.xtype + "' to Border";
34973 this.beginUpdate();
34977 Roo.each(xitems, function(i) {
34978 region = nb && i.region ? i.region : false;
34980 var add = ret.addxtype(i);
34983 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
34984 if (!i.background) {
34985 abn[region] = nb[region] ;
34992 // make the last non-background panel active..
34993 //if (nb) { Roo.log(abn); }
34996 for(var r in abn) {
34997 region = this.getRegion(r);
34999 // tried using nb[r], but it does not work..
35001 region.showPanel(abn[r]);
35012 factory : function(cfg)
35015 var validRegions = Roo.bootstrap.layout.Border.regions;
35017 var target = cfg.region;
35020 var r = Roo.bootstrap.layout;
35024 return new r.North(cfg);
35026 return new r.South(cfg);
35028 return new r.East(cfg);
35030 return new r.West(cfg);
35032 return new r.Center(cfg);
35034 throw 'Layout region "'+target+'" not supported.';
35041 * Ext JS Library 1.1.1
35042 * Copyright(c) 2006-2007, Ext JS, LLC.
35044 * Originally Released Under LGPL - original licence link has changed is not relivant.
35047 * <script type="text/javascript">
35051 * @class Roo.bootstrap.layout.Basic
35052 * @extends Roo.util.Observable
35053 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
35054 * and does not have a titlebar, tabs or any other features. All it does is size and position
35055 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
35056 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35057 * @cfg {string} region the region that it inhabits..
35058 * @cfg {bool} skipConfig skip config?
35062 Roo.bootstrap.layout.Basic = function(config){
35064 this.mgr = config.mgr;
35066 this.position = config.region;
35068 var skipConfig = config.skipConfig;
35072 * @scope Roo.BasicLayoutRegion
35076 * @event beforeremove
35077 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
35078 * @param {Roo.LayoutRegion} this
35079 * @param {Roo.ContentPanel} panel The panel
35080 * @param {Object} e The cancel event object
35082 "beforeremove" : true,
35084 * @event invalidated
35085 * Fires when the layout for this region is changed.
35086 * @param {Roo.LayoutRegion} this
35088 "invalidated" : true,
35090 * @event visibilitychange
35091 * Fires when this region is shown or hidden
35092 * @param {Roo.LayoutRegion} this
35093 * @param {Boolean} visibility true or false
35095 "visibilitychange" : true,
35097 * @event paneladded
35098 * Fires when a panel is added.
35099 * @param {Roo.LayoutRegion} this
35100 * @param {Roo.ContentPanel} panel The panel
35102 "paneladded" : true,
35104 * @event panelremoved
35105 * Fires when a panel is removed.
35106 * @param {Roo.LayoutRegion} this
35107 * @param {Roo.ContentPanel} panel The panel
35109 "panelremoved" : true,
35111 * @event beforecollapse
35112 * Fires when this region before collapse.
35113 * @param {Roo.LayoutRegion} this
35115 "beforecollapse" : true,
35118 * Fires when this region is collapsed.
35119 * @param {Roo.LayoutRegion} this
35121 "collapsed" : true,
35124 * Fires when this region is expanded.
35125 * @param {Roo.LayoutRegion} this
35130 * Fires when this region is slid into view.
35131 * @param {Roo.LayoutRegion} this
35133 "slideshow" : true,
35136 * Fires when this region slides out of view.
35137 * @param {Roo.LayoutRegion} this
35139 "slidehide" : true,
35141 * @event panelactivated
35142 * Fires when a panel is activated.
35143 * @param {Roo.LayoutRegion} this
35144 * @param {Roo.ContentPanel} panel The activated panel
35146 "panelactivated" : true,
35149 * Fires when the user resizes this region.
35150 * @param {Roo.LayoutRegion} this
35151 * @param {Number} newSize The new size (width for east/west, height for north/south)
35155 /** A collection of panels in this region. @type Roo.util.MixedCollection */
35156 this.panels = new Roo.util.MixedCollection();
35157 this.panels.getKey = this.getPanelId.createDelegate(this);
35159 this.activePanel = null;
35160 // ensure listeners are added...
35162 if (config.listeners || config.events) {
35163 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
35164 listeners : config.listeners || {},
35165 events : config.events || {}
35169 if(skipConfig !== true){
35170 this.applyConfig(config);
35174 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
35176 getPanelId : function(p){
35180 applyConfig : function(config){
35181 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35182 this.config = config;
35187 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
35188 * the width, for horizontal (north, south) the height.
35189 * @param {Number} newSize The new width or height
35191 resizeTo : function(newSize){
35192 var el = this.el ? this.el :
35193 (this.activePanel ? this.activePanel.getEl() : null);
35195 switch(this.position){
35198 el.setWidth(newSize);
35199 this.fireEvent("resized", this, newSize);
35203 el.setHeight(newSize);
35204 this.fireEvent("resized", this, newSize);
35210 getBox : function(){
35211 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
35214 getMargins : function(){
35215 return this.margins;
35218 updateBox : function(box){
35220 var el = this.activePanel.getEl();
35221 el.dom.style.left = box.x + "px";
35222 el.dom.style.top = box.y + "px";
35223 this.activePanel.setSize(box.width, box.height);
35227 * Returns the container element for this region.
35228 * @return {Roo.Element}
35230 getEl : function(){
35231 return this.activePanel;
35235 * Returns true if this region is currently visible.
35236 * @return {Boolean}
35238 isVisible : function(){
35239 return this.activePanel ? true : false;
35242 setActivePanel : function(panel){
35243 panel = this.getPanel(panel);
35244 if(this.activePanel && this.activePanel != panel){
35245 this.activePanel.setActiveState(false);
35246 this.activePanel.getEl().setLeftTop(-10000,-10000);
35248 this.activePanel = panel;
35249 panel.setActiveState(true);
35251 panel.setSize(this.box.width, this.box.height);
35253 this.fireEvent("panelactivated", this, panel);
35254 this.fireEvent("invalidated");
35258 * Show the specified panel.
35259 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
35260 * @return {Roo.ContentPanel} The shown panel or null
35262 showPanel : function(panel){
35263 panel = this.getPanel(panel);
35265 this.setActivePanel(panel);
35271 * Get the active panel for this region.
35272 * @return {Roo.ContentPanel} The active panel or null
35274 getActivePanel : function(){
35275 return this.activePanel;
35279 * Add the passed ContentPanel(s)
35280 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35281 * @return {Roo.ContentPanel} The panel added (if only one was added)
35283 add : function(panel){
35284 if(arguments.length > 1){
35285 for(var i = 0, len = arguments.length; i < len; i++) {
35286 this.add(arguments[i]);
35290 if(this.hasPanel(panel)){
35291 this.showPanel(panel);
35294 var el = panel.getEl();
35295 if(el.dom.parentNode != this.mgr.el.dom){
35296 this.mgr.el.dom.appendChild(el.dom);
35298 if(panel.setRegion){
35299 panel.setRegion(this);
35301 this.panels.add(panel);
35302 el.setStyle("position", "absolute");
35303 if(!panel.background){
35304 this.setActivePanel(panel);
35305 if(this.config.initialSize && this.panels.getCount()==1){
35306 this.resizeTo(this.config.initialSize);
35309 this.fireEvent("paneladded", this, panel);
35314 * Returns true if the panel is in this region.
35315 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35316 * @return {Boolean}
35318 hasPanel : function(panel){
35319 if(typeof panel == "object"){ // must be panel obj
35320 panel = panel.getId();
35322 return this.getPanel(panel) ? true : false;
35326 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35327 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35328 * @param {Boolean} preservePanel Overrides the config preservePanel option
35329 * @return {Roo.ContentPanel} The panel that was removed
35331 remove : function(panel, preservePanel){
35332 panel = this.getPanel(panel);
35337 this.fireEvent("beforeremove", this, panel, e);
35338 if(e.cancel === true){
35341 var panelId = panel.getId();
35342 this.panels.removeKey(panelId);
35347 * Returns the panel specified or null if it's not in this region.
35348 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35349 * @return {Roo.ContentPanel}
35351 getPanel : function(id){
35352 if(typeof id == "object"){ // must be panel obj
35355 return this.panels.get(id);
35359 * Returns this regions position (north/south/east/west/center).
35362 getPosition: function(){
35363 return this.position;
35367 * Ext JS Library 1.1.1
35368 * Copyright(c) 2006-2007, Ext JS, LLC.
35370 * Originally Released Under LGPL - original licence link has changed is not relivant.
35373 * <script type="text/javascript">
35377 * @class Roo.bootstrap.layout.Region
35378 * @extends Roo.bootstrap.layout.Basic
35379 * This class represents a region in a layout manager.
35381 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
35382 * @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})
35383 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
35384 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
35385 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
35386 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
35387 * @cfg {String} title The title for the region (overrides panel titles)
35388 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
35389 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
35390 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
35391 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
35392 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
35393 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
35394 * the space available, similar to FireFox 1.5 tabs (defaults to false)
35395 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
35396 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
35397 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
35399 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
35400 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
35401 * @cfg {Boolean} disableTabTips True to disable tab tooltips
35402 * @cfg {Number} width For East/West panels
35403 * @cfg {Number} height For North/South panels
35404 * @cfg {Boolean} split To show the splitter
35405 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
35407 * @cfg {string} cls Extra CSS classes to add to region
35409 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35410 * @cfg {string} region the region that it inhabits..
35413 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
35414 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
35416 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
35417 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
35418 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
35420 Roo.bootstrap.layout.Region = function(config)
35422 this.applyConfig(config);
35424 var mgr = config.mgr;
35425 var pos = config.region;
35426 config.skipConfig = true;
35427 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
35430 this.onRender(mgr.el);
35433 this.visible = true;
35434 this.collapsed = false;
35435 this.unrendered_panels = [];
35438 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
35440 position: '', // set by wrapper (eg. north/south etc..)
35441 unrendered_panels : null, // unrendered panels.
35442 createBody : function(){
35443 /** This region's body element
35444 * @type Roo.Element */
35445 this.bodyEl = this.el.createChild({
35447 cls: "roo-layout-panel-body tab-content" // bootstrap added...
35451 onRender: function(ctr, pos)
35453 var dh = Roo.DomHelper;
35454 /** This region's container element
35455 * @type Roo.Element */
35456 this.el = dh.append(ctr.dom, {
35458 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
35460 /** This region's title element
35461 * @type Roo.Element */
35463 this.titleEl = dh.append(this.el.dom,
35466 unselectable: "on",
35467 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
35469 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
35470 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
35473 this.titleEl.enableDisplayMode();
35474 /** This region's title text element
35475 * @type HTMLElement */
35476 this.titleTextEl = this.titleEl.dom.firstChild;
35477 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
35479 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
35480 this.closeBtn.enableDisplayMode();
35481 this.closeBtn.on("click", this.closeClicked, this);
35482 this.closeBtn.hide();
35484 this.createBody(this.config);
35485 if(this.config.hideWhenEmpty){
35487 this.on("paneladded", this.validateVisibility, this);
35488 this.on("panelremoved", this.validateVisibility, this);
35490 if(this.autoScroll){
35491 this.bodyEl.setStyle("overflow", "auto");
35493 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
35495 //if(c.titlebar !== false){
35496 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
35497 this.titleEl.hide();
35499 this.titleEl.show();
35500 if(this.config.title){
35501 this.titleTextEl.innerHTML = this.config.title;
35505 if(this.config.collapsed){
35506 this.collapse(true);
35508 if(this.config.hidden){
35512 if (this.unrendered_panels && this.unrendered_panels.length) {
35513 for (var i =0;i< this.unrendered_panels.length; i++) {
35514 this.add(this.unrendered_panels[i]);
35516 this.unrendered_panels = null;
35522 applyConfig : function(c)
35525 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
35526 var dh = Roo.DomHelper;
35527 if(c.titlebar !== false){
35528 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
35529 this.collapseBtn.on("click", this.collapse, this);
35530 this.collapseBtn.enableDisplayMode();
35532 if(c.showPin === true || this.showPin){
35533 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
35534 this.stickBtn.enableDisplayMode();
35535 this.stickBtn.on("click", this.expand, this);
35536 this.stickBtn.hide();
35541 /** This region's collapsed element
35542 * @type Roo.Element */
35545 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
35546 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
35549 if(c.floatable !== false){
35550 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
35551 this.collapsedEl.on("click", this.collapseClick, this);
35554 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
35555 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
35556 id: "message", unselectable: "on", style:{"float":"left"}});
35557 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
35559 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
35560 this.expandBtn.on("click", this.expand, this);
35564 if(this.collapseBtn){
35565 this.collapseBtn.setVisible(c.collapsible == true);
35568 this.cmargins = c.cmargins || this.cmargins ||
35569 (this.position == "west" || this.position == "east" ?
35570 {top: 0, left: 2, right:2, bottom: 0} :
35571 {top: 2, left: 0, right:0, bottom: 2});
35573 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35576 this.bottomTabs = c.tabPosition != "top";
35578 this.autoScroll = c.autoScroll || false;
35583 this.duration = c.duration || .30;
35584 this.slideDuration = c.slideDuration || .45;
35589 * Returns true if this region is currently visible.
35590 * @return {Boolean}
35592 isVisible : function(){
35593 return this.visible;
35597 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
35598 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
35600 //setCollapsedTitle : function(title){
35601 // title = title || " ";
35602 // if(this.collapsedTitleTextEl){
35603 // this.collapsedTitleTextEl.innerHTML = title;
35607 getBox : function(){
35609 // if(!this.collapsed){
35610 b = this.el.getBox(false, true);
35612 // b = this.collapsedEl.getBox(false, true);
35617 getMargins : function(){
35618 return this.margins;
35619 //return this.collapsed ? this.cmargins : this.margins;
35622 highlight : function(){
35623 this.el.addClass("x-layout-panel-dragover");
35626 unhighlight : function(){
35627 this.el.removeClass("x-layout-panel-dragover");
35630 updateBox : function(box)
35632 if (!this.bodyEl) {
35633 return; // not rendered yet..
35637 if(!this.collapsed){
35638 this.el.dom.style.left = box.x + "px";
35639 this.el.dom.style.top = box.y + "px";
35640 this.updateBody(box.width, box.height);
35642 this.collapsedEl.dom.style.left = box.x + "px";
35643 this.collapsedEl.dom.style.top = box.y + "px";
35644 this.collapsedEl.setSize(box.width, box.height);
35647 this.tabs.autoSizeTabs();
35651 updateBody : function(w, h)
35654 this.el.setWidth(w);
35655 w -= this.el.getBorderWidth("rl");
35656 if(this.config.adjustments){
35657 w += this.config.adjustments[0];
35660 if(h !== null && h > 0){
35661 this.el.setHeight(h);
35662 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
35663 h -= this.el.getBorderWidth("tb");
35664 if(this.config.adjustments){
35665 h += this.config.adjustments[1];
35667 this.bodyEl.setHeight(h);
35669 h = this.tabs.syncHeight(h);
35672 if(this.panelSize){
35673 w = w !== null ? w : this.panelSize.width;
35674 h = h !== null ? h : this.panelSize.height;
35676 if(this.activePanel){
35677 var el = this.activePanel.getEl();
35678 w = w !== null ? w : el.getWidth();
35679 h = h !== null ? h : el.getHeight();
35680 this.panelSize = {width: w, height: h};
35681 this.activePanel.setSize(w, h);
35683 if(Roo.isIE && this.tabs){
35684 this.tabs.el.repaint();
35689 * Returns the container element for this region.
35690 * @return {Roo.Element}
35692 getEl : function(){
35697 * Hides this region.
35700 //if(!this.collapsed){
35701 this.el.dom.style.left = "-2000px";
35704 // this.collapsedEl.dom.style.left = "-2000px";
35705 // this.collapsedEl.hide();
35707 this.visible = false;
35708 this.fireEvent("visibilitychange", this, false);
35712 * Shows this region if it was previously hidden.
35715 //if(!this.collapsed){
35718 // this.collapsedEl.show();
35720 this.visible = true;
35721 this.fireEvent("visibilitychange", this, true);
35724 closeClicked : function(){
35725 if(this.activePanel){
35726 this.remove(this.activePanel);
35730 collapseClick : function(e){
35732 e.stopPropagation();
35735 e.stopPropagation();
35741 * Collapses this region.
35742 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
35745 collapse : function(skipAnim, skipCheck = false){
35746 if(this.collapsed) {
35750 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
35752 this.collapsed = true;
35754 this.split.el.hide();
35756 if(this.config.animate && skipAnim !== true){
35757 this.fireEvent("invalidated", this);
35758 this.animateCollapse();
35760 this.el.setLocation(-20000,-20000);
35762 this.collapsedEl.show();
35763 this.fireEvent("collapsed", this);
35764 this.fireEvent("invalidated", this);
35770 animateCollapse : function(){
35775 * Expands this region if it was previously collapsed.
35776 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
35777 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
35780 expand : function(e, skipAnim){
35782 e.stopPropagation();
35784 if(!this.collapsed || this.el.hasActiveFx()) {
35788 this.afterSlideIn();
35791 this.collapsed = false;
35792 if(this.config.animate && skipAnim !== true){
35793 this.animateExpand();
35797 this.split.el.show();
35799 this.collapsedEl.setLocation(-2000,-2000);
35800 this.collapsedEl.hide();
35801 this.fireEvent("invalidated", this);
35802 this.fireEvent("expanded", this);
35806 animateExpand : function(){
35810 initTabs : function()
35812 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
35814 var ts = new Roo.bootstrap.panel.Tabs({
35815 el: this.bodyEl.dom,
35816 tabPosition: this.bottomTabs ? 'bottom' : 'top',
35817 disableTooltips: this.config.disableTabTips,
35818 toolbar : this.config.toolbar
35821 if(this.config.hideTabs){
35822 ts.stripWrap.setDisplayed(false);
35825 ts.resizeTabs = this.config.resizeTabs === true;
35826 ts.minTabWidth = this.config.minTabWidth || 40;
35827 ts.maxTabWidth = this.config.maxTabWidth || 250;
35828 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
35829 ts.monitorResize = false;
35830 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
35831 ts.bodyEl.addClass('roo-layout-tabs-body');
35832 this.panels.each(this.initPanelAsTab, this);
35835 initPanelAsTab : function(panel){
35836 var ti = this.tabs.addTab(
35840 this.config.closeOnTab && panel.isClosable(),
35843 if(panel.tabTip !== undefined){
35844 ti.setTooltip(panel.tabTip);
35846 ti.on("activate", function(){
35847 this.setActivePanel(panel);
35850 if(this.config.closeOnTab){
35851 ti.on("beforeclose", function(t, e){
35853 this.remove(panel);
35857 panel.tabItem = ti;
35862 updatePanelTitle : function(panel, title)
35864 if(this.activePanel == panel){
35865 this.updateTitle(title);
35868 var ti = this.tabs.getTab(panel.getEl().id);
35870 if(panel.tabTip !== undefined){
35871 ti.setTooltip(panel.tabTip);
35876 updateTitle : function(title){
35877 if(this.titleTextEl && !this.config.title){
35878 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
35882 setActivePanel : function(panel)
35884 panel = this.getPanel(panel);
35885 if(this.activePanel && this.activePanel != panel){
35886 if(this.activePanel.setActiveState(false) === false){
35890 this.activePanel = panel;
35891 panel.setActiveState(true);
35892 if(this.panelSize){
35893 panel.setSize(this.panelSize.width, this.panelSize.height);
35896 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
35898 this.updateTitle(panel.getTitle());
35900 this.fireEvent("invalidated", this);
35902 this.fireEvent("panelactivated", this, panel);
35906 * Shows the specified panel.
35907 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
35908 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
35910 showPanel : function(panel)
35912 panel = this.getPanel(panel);
35915 var tab = this.tabs.getTab(panel.getEl().id);
35916 if(tab.isHidden()){
35917 this.tabs.unhideTab(tab.id);
35921 this.setActivePanel(panel);
35928 * Get the active panel for this region.
35929 * @return {Roo.ContentPanel} The active panel or null
35931 getActivePanel : function(){
35932 return this.activePanel;
35935 validateVisibility : function(){
35936 if(this.panels.getCount() < 1){
35937 this.updateTitle(" ");
35938 this.closeBtn.hide();
35941 if(!this.isVisible()){
35948 * Adds the passed ContentPanel(s) to this region.
35949 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35950 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
35952 add : function(panel)
35954 if(arguments.length > 1){
35955 for(var i = 0, len = arguments.length; i < len; i++) {
35956 this.add(arguments[i]);
35961 // if we have not been rendered yet, then we can not really do much of this..
35962 if (!this.bodyEl) {
35963 this.unrendered_panels.push(panel);
35970 if(this.hasPanel(panel)){
35971 this.showPanel(panel);
35974 panel.setRegion(this);
35975 this.panels.add(panel);
35976 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
35977 // sinle panel - no tab...?? would it not be better to render it with the tabs,
35978 // and hide them... ???
35979 this.bodyEl.dom.appendChild(panel.getEl().dom);
35980 if(panel.background !== true){
35981 this.setActivePanel(panel);
35983 this.fireEvent("paneladded", this, panel);
35990 this.initPanelAsTab(panel);
35994 if(panel.background !== true){
35995 this.tabs.activate(panel.getEl().id);
35997 this.fireEvent("paneladded", this, panel);
36002 * Hides the tab for the specified panel.
36003 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36005 hidePanel : function(panel){
36006 if(this.tabs && (panel = this.getPanel(panel))){
36007 this.tabs.hideTab(panel.getEl().id);
36012 * Unhides the tab for a previously hidden panel.
36013 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36015 unhidePanel : function(panel){
36016 if(this.tabs && (panel = this.getPanel(panel))){
36017 this.tabs.unhideTab(panel.getEl().id);
36021 clearPanels : function(){
36022 while(this.panels.getCount() > 0){
36023 this.remove(this.panels.first());
36028 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
36029 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36030 * @param {Boolean} preservePanel Overrides the config preservePanel option
36031 * @return {Roo.ContentPanel} The panel that was removed
36033 remove : function(panel, preservePanel)
36035 panel = this.getPanel(panel);
36040 this.fireEvent("beforeremove", this, panel, e);
36041 if(e.cancel === true){
36044 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
36045 var panelId = panel.getId();
36046 this.panels.removeKey(panelId);
36048 document.body.appendChild(panel.getEl().dom);
36051 this.tabs.removeTab(panel.getEl().id);
36052 }else if (!preservePanel){
36053 this.bodyEl.dom.removeChild(panel.getEl().dom);
36055 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
36056 var p = this.panels.first();
36057 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
36058 tempEl.appendChild(p.getEl().dom);
36059 this.bodyEl.update("");
36060 this.bodyEl.dom.appendChild(p.getEl().dom);
36062 this.updateTitle(p.getTitle());
36064 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
36065 this.setActivePanel(p);
36067 panel.setRegion(null);
36068 if(this.activePanel == panel){
36069 this.activePanel = null;
36071 if(this.config.autoDestroy !== false && preservePanel !== true){
36072 try{panel.destroy();}catch(e){}
36074 this.fireEvent("panelremoved", this, panel);
36079 * Returns the TabPanel component used by this region
36080 * @return {Roo.TabPanel}
36082 getTabs : function(){
36086 createTool : function(parentEl, className){
36087 var btn = Roo.DomHelper.append(parentEl, {
36089 cls: "x-layout-tools-button",
36092 cls: "roo-layout-tools-button-inner " + className,
36096 btn.addClassOnOver("roo-layout-tools-button-over");
36101 * Ext JS Library 1.1.1
36102 * Copyright(c) 2006-2007, Ext JS, LLC.
36104 * Originally Released Under LGPL - original licence link has changed is not relivant.
36107 * <script type="text/javascript">
36113 * @class Roo.SplitLayoutRegion
36114 * @extends Roo.LayoutRegion
36115 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
36117 Roo.bootstrap.layout.Split = function(config){
36118 this.cursor = config.cursor;
36119 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
36122 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
36124 splitTip : "Drag to resize.",
36125 collapsibleSplitTip : "Drag to resize. Double click to hide.",
36126 useSplitTips : false,
36128 applyConfig : function(config){
36129 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
36132 onRender : function(ctr,pos) {
36134 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
36135 if(!this.config.split){
36140 var splitEl = Roo.DomHelper.append(ctr.dom, {
36142 id: this.el.id + "-split",
36143 cls: "roo-layout-split roo-layout-split-"+this.position,
36146 /** The SplitBar for this region
36147 * @type Roo.SplitBar */
36148 // does not exist yet...
36149 Roo.log([this.position, this.orientation]);
36151 this.split = new Roo.bootstrap.SplitBar({
36152 dragElement : splitEl,
36153 resizingElement: this.el,
36154 orientation : this.orientation
36157 this.split.on("moved", this.onSplitMove, this);
36158 this.split.useShim = this.config.useShim === true;
36159 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
36160 if(this.useSplitTips){
36161 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
36163 //if(config.collapsible){
36164 // this.split.el.on("dblclick", this.collapse, this);
36167 if(typeof this.config.minSize != "undefined"){
36168 this.split.minSize = this.config.minSize;
36170 if(typeof this.config.maxSize != "undefined"){
36171 this.split.maxSize = this.config.maxSize;
36173 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
36174 this.hideSplitter();
36179 getHMaxSize : function(){
36180 var cmax = this.config.maxSize || 10000;
36181 var center = this.mgr.getRegion("center");
36182 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
36185 getVMaxSize : function(){
36186 var cmax = this.config.maxSize || 10000;
36187 var center = this.mgr.getRegion("center");
36188 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
36191 onSplitMove : function(split, newSize){
36192 this.fireEvent("resized", this, newSize);
36196 * Returns the {@link Roo.SplitBar} for this region.
36197 * @return {Roo.SplitBar}
36199 getSplitBar : function(){
36204 this.hideSplitter();
36205 Roo.bootstrap.layout.Split.superclass.hide.call(this);
36208 hideSplitter : function(){
36210 this.split.el.setLocation(-2000,-2000);
36211 this.split.el.hide();
36217 this.split.el.show();
36219 Roo.bootstrap.layout.Split.superclass.show.call(this);
36222 beforeSlide: function(){
36223 if(Roo.isGecko){// firefox overflow auto bug workaround
36224 this.bodyEl.clip();
36226 this.tabs.bodyEl.clip();
36228 if(this.activePanel){
36229 this.activePanel.getEl().clip();
36231 if(this.activePanel.beforeSlide){
36232 this.activePanel.beforeSlide();
36238 afterSlide : function(){
36239 if(Roo.isGecko){// firefox overflow auto bug workaround
36240 this.bodyEl.unclip();
36242 this.tabs.bodyEl.unclip();
36244 if(this.activePanel){
36245 this.activePanel.getEl().unclip();
36246 if(this.activePanel.afterSlide){
36247 this.activePanel.afterSlide();
36253 initAutoHide : function(){
36254 if(this.autoHide !== false){
36255 if(!this.autoHideHd){
36256 var st = new Roo.util.DelayedTask(this.slideIn, this);
36257 this.autoHideHd = {
36258 "mouseout": function(e){
36259 if(!e.within(this.el, true)){
36263 "mouseover" : function(e){
36269 this.el.on(this.autoHideHd);
36273 clearAutoHide : function(){
36274 if(this.autoHide !== false){
36275 this.el.un("mouseout", this.autoHideHd.mouseout);
36276 this.el.un("mouseover", this.autoHideHd.mouseover);
36280 clearMonitor : function(){
36281 Roo.get(document).un("click", this.slideInIf, this);
36284 // these names are backwards but not changed for compat
36285 slideOut : function(){
36286 if(this.isSlid || this.el.hasActiveFx()){
36289 this.isSlid = true;
36290 if(this.collapseBtn){
36291 this.collapseBtn.hide();
36293 this.closeBtnState = this.closeBtn.getStyle('display');
36294 this.closeBtn.hide();
36296 this.stickBtn.show();
36299 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
36300 this.beforeSlide();
36301 this.el.setStyle("z-index", 10001);
36302 this.el.slideIn(this.getSlideAnchor(), {
36303 callback: function(){
36305 this.initAutoHide();
36306 Roo.get(document).on("click", this.slideInIf, this);
36307 this.fireEvent("slideshow", this);
36314 afterSlideIn : function(){
36315 this.clearAutoHide();
36316 this.isSlid = false;
36317 this.clearMonitor();
36318 this.el.setStyle("z-index", "");
36319 if(this.collapseBtn){
36320 this.collapseBtn.show();
36322 this.closeBtn.setStyle('display', this.closeBtnState);
36324 this.stickBtn.hide();
36326 this.fireEvent("slidehide", this);
36329 slideIn : function(cb){
36330 if(!this.isSlid || this.el.hasActiveFx()){
36334 this.isSlid = false;
36335 this.beforeSlide();
36336 this.el.slideOut(this.getSlideAnchor(), {
36337 callback: function(){
36338 this.el.setLeftTop(-10000, -10000);
36340 this.afterSlideIn();
36348 slideInIf : function(e){
36349 if(!e.within(this.el)){
36354 animateCollapse : function(){
36355 this.beforeSlide();
36356 this.el.setStyle("z-index", 20000);
36357 var anchor = this.getSlideAnchor();
36358 this.el.slideOut(anchor, {
36359 callback : function(){
36360 this.el.setStyle("z-index", "");
36361 this.collapsedEl.slideIn(anchor, {duration:.3});
36363 this.el.setLocation(-10000,-10000);
36365 this.fireEvent("collapsed", this);
36372 animateExpand : function(){
36373 this.beforeSlide();
36374 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
36375 this.el.setStyle("z-index", 20000);
36376 this.collapsedEl.hide({
36379 this.el.slideIn(this.getSlideAnchor(), {
36380 callback : function(){
36381 this.el.setStyle("z-index", "");
36384 this.split.el.show();
36386 this.fireEvent("invalidated", this);
36387 this.fireEvent("expanded", this);
36415 getAnchor : function(){
36416 return this.anchors[this.position];
36419 getCollapseAnchor : function(){
36420 return this.canchors[this.position];
36423 getSlideAnchor : function(){
36424 return this.sanchors[this.position];
36427 getAlignAdj : function(){
36428 var cm = this.cmargins;
36429 switch(this.position){
36445 getExpandAdj : function(){
36446 var c = this.collapsedEl, cm = this.cmargins;
36447 switch(this.position){
36449 return [-(cm.right+c.getWidth()+cm.left), 0];
36452 return [cm.right+c.getWidth()+cm.left, 0];
36455 return [0, -(cm.top+cm.bottom+c.getHeight())];
36458 return [0, cm.top+cm.bottom+c.getHeight()];
36464 * Ext JS Library 1.1.1
36465 * Copyright(c) 2006-2007, Ext JS, LLC.
36467 * Originally Released Under LGPL - original licence link has changed is not relivant.
36470 * <script type="text/javascript">
36473 * These classes are private internal classes
36475 Roo.bootstrap.layout.Center = function(config){
36476 config.region = "center";
36477 Roo.bootstrap.layout.Region.call(this, config);
36478 this.visible = true;
36479 this.minWidth = config.minWidth || 20;
36480 this.minHeight = config.minHeight || 20;
36483 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
36485 // center panel can't be hidden
36489 // center panel can't be hidden
36492 getMinWidth: function(){
36493 return this.minWidth;
36496 getMinHeight: function(){
36497 return this.minHeight;
36510 Roo.bootstrap.layout.North = function(config)
36512 config.region = 'north';
36513 config.cursor = 'n-resize';
36515 Roo.bootstrap.layout.Split.call(this, config);
36519 this.split.placement = Roo.bootstrap.SplitBar.TOP;
36520 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36521 this.split.el.addClass("roo-layout-split-v");
36523 var size = config.initialSize || config.height;
36524 if(typeof size != "undefined"){
36525 this.el.setHeight(size);
36528 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
36530 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36534 getBox : function(){
36535 if(this.collapsed){
36536 return this.collapsedEl.getBox();
36538 var box = this.el.getBox();
36540 box.height += this.split.el.getHeight();
36545 updateBox : function(box){
36546 if(this.split && !this.collapsed){
36547 box.height -= this.split.el.getHeight();
36548 this.split.el.setLeft(box.x);
36549 this.split.el.setTop(box.y+box.height);
36550 this.split.el.setWidth(box.width);
36552 if(this.collapsed){
36553 this.updateBody(box.width, null);
36555 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36563 Roo.bootstrap.layout.South = function(config){
36564 config.region = 'south';
36565 config.cursor = 's-resize';
36566 Roo.bootstrap.layout.Split.call(this, config);
36568 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
36569 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36570 this.split.el.addClass("roo-layout-split-v");
36572 var size = config.initialSize || config.height;
36573 if(typeof size != "undefined"){
36574 this.el.setHeight(size);
36578 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
36579 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36580 getBox : function(){
36581 if(this.collapsed){
36582 return this.collapsedEl.getBox();
36584 var box = this.el.getBox();
36586 var sh = this.split.el.getHeight();
36593 updateBox : function(box){
36594 if(this.split && !this.collapsed){
36595 var sh = this.split.el.getHeight();
36598 this.split.el.setLeft(box.x);
36599 this.split.el.setTop(box.y-sh);
36600 this.split.el.setWidth(box.width);
36602 if(this.collapsed){
36603 this.updateBody(box.width, null);
36605 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36609 Roo.bootstrap.layout.East = function(config){
36610 config.region = "east";
36611 config.cursor = "e-resize";
36612 Roo.bootstrap.layout.Split.call(this, config);
36614 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
36615 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36616 this.split.el.addClass("roo-layout-split-h");
36618 var size = config.initialSize || config.width;
36619 if(typeof size != "undefined"){
36620 this.el.setWidth(size);
36623 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
36624 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36625 getBox : function(){
36626 if(this.collapsed){
36627 return this.collapsedEl.getBox();
36629 var box = this.el.getBox();
36631 var sw = this.split.el.getWidth();
36638 updateBox : function(box){
36639 if(this.split && !this.collapsed){
36640 var sw = this.split.el.getWidth();
36642 this.split.el.setLeft(box.x);
36643 this.split.el.setTop(box.y);
36644 this.split.el.setHeight(box.height);
36647 if(this.collapsed){
36648 this.updateBody(null, box.height);
36650 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36654 Roo.bootstrap.layout.West = function(config){
36655 config.region = "west";
36656 config.cursor = "w-resize";
36658 Roo.bootstrap.layout.Split.call(this, config);
36660 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
36661 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36662 this.split.el.addClass("roo-layout-split-h");
36666 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
36667 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36669 onRender: function(ctr, pos)
36671 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
36672 var size = this.config.initialSize || this.config.width;
36673 if(typeof size != "undefined"){
36674 this.el.setWidth(size);
36678 getBox : function(){
36679 if(this.collapsed){
36680 return this.collapsedEl.getBox();
36682 var box = this.el.getBox();
36684 box.width += this.split.el.getWidth();
36689 updateBox : function(box){
36690 if(this.split && !this.collapsed){
36691 var sw = this.split.el.getWidth();
36693 this.split.el.setLeft(box.x+box.width);
36694 this.split.el.setTop(box.y);
36695 this.split.el.setHeight(box.height);
36697 if(this.collapsed){
36698 this.updateBody(null, box.height);
36700 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36703 Roo.namespace("Roo.bootstrap.panel");/*
36705 * Ext JS Library 1.1.1
36706 * Copyright(c) 2006-2007, Ext JS, LLC.
36708 * Originally Released Under LGPL - original licence link has changed is not relivant.
36711 * <script type="text/javascript">
36714 * @class Roo.ContentPanel
36715 * @extends Roo.util.Observable
36716 * A basic ContentPanel element.
36717 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
36718 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
36719 * @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
36720 * @cfg {Boolean} closable True if the panel can be closed/removed
36721 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
36722 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
36723 * @cfg {Toolbar} toolbar A toolbar for this panel
36724 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
36725 * @cfg {String} title The title for this panel
36726 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
36727 * @cfg {String} url Calls {@link #setUrl} with this value
36728 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
36729 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
36730 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
36731 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
36732 * @cfg {Boolean} badges render the badges
36735 * Create a new ContentPanel.
36736 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
36737 * @param {String/Object} config A string to set only the title or a config object
36738 * @param {String} content (optional) Set the HTML content for this panel
36739 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
36741 Roo.bootstrap.panel.Content = function( config){
36743 this.tpl = config.tpl || false;
36745 var el = config.el;
36746 var content = config.content;
36748 if(config.autoCreate){ // xtype is available if this is called from factory
36751 this.el = Roo.get(el);
36752 if(!this.el && config && config.autoCreate){
36753 if(typeof config.autoCreate == "object"){
36754 if(!config.autoCreate.id){
36755 config.autoCreate.id = config.id||el;
36757 this.el = Roo.DomHelper.append(document.body,
36758 config.autoCreate, true);
36760 var elcfg = { tag: "div",
36761 cls: "roo-layout-inactive-content",
36765 elcfg.html = config.html;
36769 this.el = Roo.DomHelper.append(document.body, elcfg , true);
36772 this.closable = false;
36773 this.loaded = false;
36774 this.active = false;
36777 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
36779 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
36781 this.wrapEl = this.el; //this.el.wrap();
36783 if (config.toolbar.items) {
36784 ti = config.toolbar.items ;
36785 delete config.toolbar.items ;
36789 this.toolbar.render(this.wrapEl, 'before');
36790 for(var i =0;i < ti.length;i++) {
36791 // Roo.log(['add child', items[i]]);
36792 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
36794 this.toolbar.items = nitems;
36795 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
36796 delete config.toolbar;
36800 // xtype created footer. - not sure if will work as we normally have to render first..
36801 if (this.footer && !this.footer.el && this.footer.xtype) {
36802 if (!this.wrapEl) {
36803 this.wrapEl = this.el.wrap();
36806 this.footer.container = this.wrapEl.createChild();
36808 this.footer = Roo.factory(this.footer, Roo);
36813 if(typeof config == "string"){
36814 this.title = config;
36816 Roo.apply(this, config);
36820 this.resizeEl = Roo.get(this.resizeEl, true);
36822 this.resizeEl = this.el;
36824 // handle view.xtype
36832 * Fires when this panel is activated.
36833 * @param {Roo.ContentPanel} this
36837 * @event deactivate
36838 * Fires when this panel is activated.
36839 * @param {Roo.ContentPanel} this
36841 "deactivate" : true,
36845 * Fires when this panel is resized if fitToFrame is true.
36846 * @param {Roo.ContentPanel} this
36847 * @param {Number} width The width after any component adjustments
36848 * @param {Number} height The height after any component adjustments
36854 * Fires when this tab is created
36855 * @param {Roo.ContentPanel} this
36866 if(this.autoScroll){
36867 this.resizeEl.setStyle("overflow", "auto");
36869 // fix randome scrolling
36870 //this.el.on('scroll', function() {
36871 // Roo.log('fix random scolling');
36872 // this.scrollTo('top',0);
36875 content = content || this.content;
36877 this.setContent(content);
36879 if(config && config.url){
36880 this.setUrl(this.url, this.params, this.loadOnce);
36885 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
36887 if (this.view && typeof(this.view.xtype) != 'undefined') {
36888 this.view.el = this.el.appendChild(document.createElement("div"));
36889 this.view = Roo.factory(this.view);
36890 this.view.render && this.view.render(false, '');
36894 this.fireEvent('render', this);
36897 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
36901 setRegion : function(region){
36902 this.region = region;
36903 this.setActiveClass(region && !this.background);
36907 setActiveClass: function(state)
36910 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
36911 this.el.setStyle('position','relative');
36913 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
36914 this.el.setStyle('position', 'absolute');
36919 * Returns the toolbar for this Panel if one was configured.
36920 * @return {Roo.Toolbar}
36922 getToolbar : function(){
36923 return this.toolbar;
36926 setActiveState : function(active)
36928 this.active = active;
36929 this.setActiveClass(active);
36931 if(this.fireEvent("deactivate", this) === false){
36936 this.fireEvent("activate", this);
36940 * Updates this panel's element
36941 * @param {String} content The new content
36942 * @param {Boolean} loadScripts (optional) true to look for and process scripts
36944 setContent : function(content, loadScripts){
36945 this.el.update(content, loadScripts);
36948 ignoreResize : function(w, h){
36949 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
36952 this.lastSize = {width: w, height: h};
36957 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
36958 * @return {Roo.UpdateManager} The UpdateManager
36960 getUpdateManager : function(){
36961 return this.el.getUpdateManager();
36964 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
36965 * @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:
36968 url: "your-url.php",
36969 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
36970 callback: yourFunction,
36971 scope: yourObject, //(optional scope)
36974 text: "Loading...",
36979 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
36980 * 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.
36981 * @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}
36982 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
36983 * @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.
36984 * @return {Roo.ContentPanel} this
36987 var um = this.el.getUpdateManager();
36988 um.update.apply(um, arguments);
36994 * 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.
36995 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
36996 * @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)
36997 * @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)
36998 * @return {Roo.UpdateManager} The UpdateManager
37000 setUrl : function(url, params, loadOnce){
37001 if(this.refreshDelegate){
37002 this.removeListener("activate", this.refreshDelegate);
37004 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
37005 this.on("activate", this.refreshDelegate);
37006 return this.el.getUpdateManager();
37009 _handleRefresh : function(url, params, loadOnce){
37010 if(!loadOnce || !this.loaded){
37011 var updater = this.el.getUpdateManager();
37012 updater.update(url, params, this._setLoaded.createDelegate(this));
37016 _setLoaded : function(){
37017 this.loaded = true;
37021 * Returns this panel's id
37024 getId : function(){
37029 * Returns this panel's element - used by regiosn to add.
37030 * @return {Roo.Element}
37032 getEl : function(){
37033 return this.wrapEl || this.el;
37038 adjustForComponents : function(width, height)
37040 //Roo.log('adjustForComponents ');
37041 if(this.resizeEl != this.el){
37042 width -= this.el.getFrameWidth('lr');
37043 height -= this.el.getFrameWidth('tb');
37046 var te = this.toolbar.getEl();
37047 te.setWidth(width);
37048 height -= te.getHeight();
37051 var te = this.footer.getEl();
37052 te.setWidth(width);
37053 height -= te.getHeight();
37057 if(this.adjustments){
37058 width += this.adjustments[0];
37059 height += this.adjustments[1];
37061 return {"width": width, "height": height};
37064 setSize : function(width, height){
37065 if(this.fitToFrame && !this.ignoreResize(width, height)){
37066 if(this.fitContainer && this.resizeEl != this.el){
37067 this.el.setSize(width, height);
37069 var size = this.adjustForComponents(width, height);
37070 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
37071 this.fireEvent('resize', this, size.width, size.height);
37076 * Returns this panel's title
37079 getTitle : function(){
37081 if (typeof(this.title) != 'object') {
37086 for (var k in this.title) {
37087 if (!this.title.hasOwnProperty(k)) {
37091 if (k.indexOf('-') >= 0) {
37092 var s = k.split('-');
37093 for (var i = 0; i<s.length; i++) {
37094 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
37097 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
37104 * Set this panel's title
37105 * @param {String} title
37107 setTitle : function(title){
37108 this.title = title;
37110 this.region.updatePanelTitle(this, title);
37115 * Returns true is this panel was configured to be closable
37116 * @return {Boolean}
37118 isClosable : function(){
37119 return this.closable;
37122 beforeSlide : function(){
37124 this.resizeEl.clip();
37127 afterSlide : function(){
37129 this.resizeEl.unclip();
37133 * Force a content refresh from the URL specified in the {@link #setUrl} method.
37134 * Will fail silently if the {@link #setUrl} method has not been called.
37135 * This does not activate the panel, just updates its content.
37137 refresh : function(){
37138 if(this.refreshDelegate){
37139 this.loaded = false;
37140 this.refreshDelegate();
37145 * Destroys this panel
37147 destroy : function(){
37148 this.el.removeAllListeners();
37149 var tempEl = document.createElement("span");
37150 tempEl.appendChild(this.el.dom);
37151 tempEl.innerHTML = "";
37157 * form - if the content panel contains a form - this is a reference to it.
37158 * @type {Roo.form.Form}
37162 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
37163 * This contains a reference to it.
37169 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
37179 * @param {Object} cfg Xtype definition of item to add.
37183 getChildContainer: function () {
37184 return this.getEl();
37189 var ret = new Roo.factory(cfg);
37194 if (cfg.xtype.match(/^Form$/)) {
37197 //if (this.footer) {
37198 // el = this.footer.container.insertSibling(false, 'before');
37200 el = this.el.createChild();
37203 this.form = new Roo.form.Form(cfg);
37206 if ( this.form.allItems.length) {
37207 this.form.render(el.dom);
37211 // should only have one of theses..
37212 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
37213 // views.. should not be just added - used named prop 'view''
37215 cfg.el = this.el.appendChild(document.createElement("div"));
37218 var ret = new Roo.factory(cfg);
37220 ret.render && ret.render(false, ''); // render blank..
37230 * @class Roo.bootstrap.panel.Grid
37231 * @extends Roo.bootstrap.panel.Content
37233 * Create a new GridPanel.
37234 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
37235 * @param {Object} config A the config object
37241 Roo.bootstrap.panel.Grid = function(config)
37245 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
37246 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
37248 config.el = this.wrapper;
37249 //this.el = this.wrapper;
37251 if (config.container) {
37252 // ctor'ed from a Border/panel.grid
37255 this.wrapper.setStyle("overflow", "hidden");
37256 this.wrapper.addClass('roo-grid-container');
37261 if(config.toolbar){
37262 var tool_el = this.wrapper.createChild();
37263 this.toolbar = Roo.factory(config.toolbar);
37265 if (config.toolbar.items) {
37266 ti = config.toolbar.items ;
37267 delete config.toolbar.items ;
37271 this.toolbar.render(tool_el);
37272 for(var i =0;i < ti.length;i++) {
37273 // Roo.log(['add child', items[i]]);
37274 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37276 this.toolbar.items = nitems;
37278 delete config.toolbar;
37281 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
37282 config.grid.scrollBody = true;;
37283 config.grid.monitorWindowResize = false; // turn off autosizing
37284 config.grid.autoHeight = false;
37285 config.grid.autoWidth = false;
37287 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
37289 if (config.background) {
37290 // render grid on panel activation (if panel background)
37291 this.on('activate', function(gp) {
37292 if (!gp.grid.rendered) {
37293 gp.grid.render(this.wrapper);
37294 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37299 this.grid.render(this.wrapper);
37300 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37303 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
37304 // ??? needed ??? config.el = this.wrapper;
37309 // xtype created footer. - not sure if will work as we normally have to render first..
37310 if (this.footer && !this.footer.el && this.footer.xtype) {
37312 var ctr = this.grid.getView().getFooterPanel(true);
37313 this.footer.dataSource = this.grid.dataSource;
37314 this.footer = Roo.factory(this.footer, Roo);
37315 this.footer.render(ctr);
37325 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
37326 getId : function(){
37327 return this.grid.id;
37331 * Returns the grid for this panel
37332 * @return {Roo.bootstrap.Table}
37334 getGrid : function(){
37338 setSize : function(width, height){
37339 if(!this.ignoreResize(width, height)){
37340 var grid = this.grid;
37341 var size = this.adjustForComponents(width, height);
37342 var gridel = grid.getGridEl();
37343 gridel.setSize(size.width, size.height);
37345 var thd = grid.getGridEl().select('thead',true).first();
37346 var tbd = grid.getGridEl().select('tbody', true).first();
37348 tbd.setSize(width, height - thd.getHeight());
37357 beforeSlide : function(){
37358 this.grid.getView().scroller.clip();
37361 afterSlide : function(){
37362 this.grid.getView().scroller.unclip();
37365 destroy : function(){
37366 this.grid.destroy();
37368 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
37373 * @class Roo.bootstrap.panel.Nest
37374 * @extends Roo.bootstrap.panel.Content
37376 * Create a new Panel, that can contain a layout.Border.
37379 * @param {Roo.BorderLayout} layout The layout for this panel
37380 * @param {String/Object} config A string to set only the title or a config object
37382 Roo.bootstrap.panel.Nest = function(config)
37384 // construct with only one argument..
37385 /* FIXME - implement nicer consturctors
37386 if (layout.layout) {
37388 layout = config.layout;
37389 delete config.layout;
37391 if (layout.xtype && !layout.getEl) {
37392 // then layout needs constructing..
37393 layout = Roo.factory(layout, Roo);
37397 config.el = config.layout.getEl();
37399 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
37401 config.layout.monitorWindowResize = false; // turn off autosizing
37402 this.layout = config.layout;
37403 this.layout.getEl().addClass("roo-layout-nested-layout");
37410 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
37412 setSize : function(width, height){
37413 if(!this.ignoreResize(width, height)){
37414 var size = this.adjustForComponents(width, height);
37415 var el = this.layout.getEl();
37416 if (size.height < 1) {
37417 el.setWidth(size.width);
37419 el.setSize(size.width, size.height);
37421 var touch = el.dom.offsetWidth;
37422 this.layout.layout();
37423 // ie requires a double layout on the first pass
37424 if(Roo.isIE && !this.initialized){
37425 this.initialized = true;
37426 this.layout.layout();
37431 // activate all subpanels if not currently active..
37433 setActiveState : function(active){
37434 this.active = active;
37435 this.setActiveClass(active);
37438 this.fireEvent("deactivate", this);
37442 this.fireEvent("activate", this);
37443 // not sure if this should happen before or after..
37444 if (!this.layout) {
37445 return; // should not happen..
37448 for (var r in this.layout.regions) {
37449 reg = this.layout.getRegion(r);
37450 if (reg.getActivePanel()) {
37451 //reg.showPanel(reg.getActivePanel()); // force it to activate..
37452 reg.setActivePanel(reg.getActivePanel());
37455 if (!reg.panels.length) {
37458 reg.showPanel(reg.getPanel(0));
37467 * Returns the nested BorderLayout for this panel
37468 * @return {Roo.BorderLayout}
37470 getLayout : function(){
37471 return this.layout;
37475 * Adds a xtype elements to the layout of the nested panel
37479 xtype : 'ContentPanel',
37486 xtype : 'NestedLayoutPanel',
37492 items : [ ... list of content panels or nested layout panels.. ]
37496 * @param {Object} cfg Xtype definition of item to add.
37498 addxtype : function(cfg) {
37499 return this.layout.addxtype(cfg);
37504 * Ext JS Library 1.1.1
37505 * Copyright(c) 2006-2007, Ext JS, LLC.
37507 * Originally Released Under LGPL - original licence link has changed is not relivant.
37510 * <script type="text/javascript">
37513 * @class Roo.TabPanel
37514 * @extends Roo.util.Observable
37515 * A lightweight tab container.
37519 // basic tabs 1, built from existing content
37520 var tabs = new Roo.TabPanel("tabs1");
37521 tabs.addTab("script", "View Script");
37522 tabs.addTab("markup", "View Markup");
37523 tabs.activate("script");
37525 // more advanced tabs, built from javascript
37526 var jtabs = new Roo.TabPanel("jtabs");
37527 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
37529 // set up the UpdateManager
37530 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
37531 var updater = tab2.getUpdateManager();
37532 updater.setDefaultUrl("ajax1.htm");
37533 tab2.on('activate', updater.refresh, updater, true);
37535 // Use setUrl for Ajax loading
37536 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
37537 tab3.setUrl("ajax2.htm", null, true);
37540 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
37543 jtabs.activate("jtabs-1");
37546 * Create a new TabPanel.
37547 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
37548 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
37550 Roo.bootstrap.panel.Tabs = function(config){
37552 * The container element for this TabPanel.
37553 * @type Roo.Element
37555 this.el = Roo.get(config.el);
37558 if(typeof config == "boolean"){
37559 this.tabPosition = config ? "bottom" : "top";
37561 Roo.apply(this, config);
37565 if(this.tabPosition == "bottom"){
37566 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37567 this.el.addClass("roo-tabs-bottom");
37569 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
37570 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
37571 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
37573 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
37575 if(this.tabPosition != "bottom"){
37576 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
37577 * @type Roo.Element
37579 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37580 this.el.addClass("roo-tabs-top");
37584 this.bodyEl.setStyle("position", "relative");
37586 this.active = null;
37587 this.activateDelegate = this.activate.createDelegate(this);
37592 * Fires when the active tab changes
37593 * @param {Roo.TabPanel} this
37594 * @param {Roo.TabPanelItem} activePanel The new active tab
37598 * @event beforetabchange
37599 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
37600 * @param {Roo.TabPanel} this
37601 * @param {Object} e Set cancel to true on this object to cancel the tab change
37602 * @param {Roo.TabPanelItem} tab The tab being changed to
37604 "beforetabchange" : true
37607 Roo.EventManager.onWindowResize(this.onResize, this);
37608 this.cpad = this.el.getPadding("lr");
37609 this.hiddenCount = 0;
37612 // toolbar on the tabbar support...
37613 if (this.toolbar) {
37614 alert("no toolbar support yet");
37615 this.toolbar = false;
37617 var tcfg = this.toolbar;
37618 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
37619 this.toolbar = new Roo.Toolbar(tcfg);
37620 if (Roo.isSafari) {
37621 var tbl = tcfg.container.child('table', true);
37622 tbl.setAttribute('width', '100%');
37630 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
37633 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
37635 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
37637 tabPosition : "top",
37639 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
37641 currentTabWidth : 0,
37643 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
37647 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
37651 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
37653 preferredTabWidth : 175,
37655 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
37657 resizeTabs : false,
37659 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
37661 monitorResize : true,
37663 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
37668 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
37669 * @param {String} id The id of the div to use <b>or create</b>
37670 * @param {String} text The text for the tab
37671 * @param {String} content (optional) Content to put in the TabPanelItem body
37672 * @param {Boolean} closable (optional) True to create a close icon on the tab
37673 * @return {Roo.TabPanelItem} The created TabPanelItem
37675 addTab : function(id, text, content, closable, tpl)
37677 var item = new Roo.bootstrap.panel.TabItem({
37681 closable : closable,
37684 this.addTabItem(item);
37686 item.setContent(content);
37692 * Returns the {@link Roo.TabPanelItem} with the specified id/index
37693 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
37694 * @return {Roo.TabPanelItem}
37696 getTab : function(id){
37697 return this.items[id];
37701 * Hides the {@link Roo.TabPanelItem} with the specified id/index
37702 * @param {String/Number} id The id or index of the TabPanelItem to hide.
37704 hideTab : function(id){
37705 var t = this.items[id];
37708 this.hiddenCount++;
37709 this.autoSizeTabs();
37714 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
37715 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
37717 unhideTab : function(id){
37718 var t = this.items[id];
37720 t.setHidden(false);
37721 this.hiddenCount--;
37722 this.autoSizeTabs();
37727 * Adds an existing {@link Roo.TabPanelItem}.
37728 * @param {Roo.TabPanelItem} item The TabPanelItem to add
37730 addTabItem : function(item){
37731 this.items[item.id] = item;
37732 this.items.push(item);
37733 // if(this.resizeTabs){
37734 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
37735 // this.autoSizeTabs();
37737 // item.autoSize();
37742 * Removes a {@link Roo.TabPanelItem}.
37743 * @param {String/Number} id The id or index of the TabPanelItem to remove.
37745 removeTab : function(id){
37746 var items = this.items;
37747 var tab = items[id];
37748 if(!tab) { return; }
37749 var index = items.indexOf(tab);
37750 if(this.active == tab && items.length > 1){
37751 var newTab = this.getNextAvailable(index);
37756 this.stripEl.dom.removeChild(tab.pnode.dom);
37757 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
37758 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
37760 items.splice(index, 1);
37761 delete this.items[tab.id];
37762 tab.fireEvent("close", tab);
37763 tab.purgeListeners();
37764 this.autoSizeTabs();
37767 getNextAvailable : function(start){
37768 var items = this.items;
37770 // look for a next tab that will slide over to
37771 // replace the one being removed
37772 while(index < items.length){
37773 var item = items[++index];
37774 if(item && !item.isHidden()){
37778 // if one isn't found select the previous tab (on the left)
37781 var item = items[--index];
37782 if(item && !item.isHidden()){
37790 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
37791 * @param {String/Number} id The id or index of the TabPanelItem to disable.
37793 disableTab : function(id){
37794 var tab = this.items[id];
37795 if(tab && this.active != tab){
37801 * Enables a {@link Roo.TabPanelItem} that is disabled.
37802 * @param {String/Number} id The id or index of the TabPanelItem to enable.
37804 enableTab : function(id){
37805 var tab = this.items[id];
37810 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
37811 * @param {String/Number} id The id or index of the TabPanelItem to activate.
37812 * @return {Roo.TabPanelItem} The TabPanelItem.
37814 activate : function(id){
37815 var tab = this.items[id];
37819 if(tab == this.active || tab.disabled){
37823 this.fireEvent("beforetabchange", this, e, tab);
37824 if(e.cancel !== true && !tab.disabled){
37826 this.active.hide();
37828 this.active = this.items[id];
37829 this.active.show();
37830 this.fireEvent("tabchange", this, this.active);
37836 * Gets the active {@link Roo.TabPanelItem}.
37837 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
37839 getActiveTab : function(){
37840 return this.active;
37844 * Updates the tab body element to fit the height of the container element
37845 * for overflow scrolling
37846 * @param {Number} targetHeight (optional) Override the starting height from the elements height
37848 syncHeight : function(targetHeight){
37849 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
37850 var bm = this.bodyEl.getMargins();
37851 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
37852 this.bodyEl.setHeight(newHeight);
37856 onResize : function(){
37857 if(this.monitorResize){
37858 this.autoSizeTabs();
37863 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
37865 beginUpdate : function(){
37866 this.updating = true;
37870 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
37872 endUpdate : function(){
37873 this.updating = false;
37874 this.autoSizeTabs();
37878 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
37880 autoSizeTabs : function(){
37881 var count = this.items.length;
37882 var vcount = count - this.hiddenCount;
37883 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
37886 var w = Math.max(this.el.getWidth() - this.cpad, 10);
37887 var availWidth = Math.floor(w / vcount);
37888 var b = this.stripBody;
37889 if(b.getWidth() > w){
37890 var tabs = this.items;
37891 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
37892 if(availWidth < this.minTabWidth){
37893 /*if(!this.sleft){ // incomplete scrolling code
37894 this.createScrollButtons();
37897 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
37900 if(this.currentTabWidth < this.preferredTabWidth){
37901 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
37907 * Returns the number of tabs in this TabPanel.
37910 getCount : function(){
37911 return this.items.length;
37915 * Resizes all the tabs to the passed width
37916 * @param {Number} The new width
37918 setTabWidth : function(width){
37919 this.currentTabWidth = width;
37920 for(var i = 0, len = this.items.length; i < len; i++) {
37921 if(!this.items[i].isHidden()) {
37922 this.items[i].setWidth(width);
37928 * Destroys this TabPanel
37929 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
37931 destroy : function(removeEl){
37932 Roo.EventManager.removeResizeListener(this.onResize, this);
37933 for(var i = 0, len = this.items.length; i < len; i++){
37934 this.items[i].purgeListeners();
37936 if(removeEl === true){
37937 this.el.update("");
37942 createStrip : function(container)
37944 var strip = document.createElement("nav");
37945 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
37946 container.appendChild(strip);
37950 createStripList : function(strip)
37952 // div wrapper for retard IE
37953 // returns the "tr" element.
37954 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
37955 //'<div class="x-tabs-strip-wrap">'+
37956 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
37957 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
37958 return strip.firstChild; //.firstChild.firstChild.firstChild;
37960 createBody : function(container)
37962 var body = document.createElement("div");
37963 Roo.id(body, "tab-body");
37964 //Roo.fly(body).addClass("x-tabs-body");
37965 Roo.fly(body).addClass("tab-content");
37966 container.appendChild(body);
37969 createItemBody :function(bodyEl, id){
37970 var body = Roo.getDom(id);
37972 body = document.createElement("div");
37975 //Roo.fly(body).addClass("x-tabs-item-body");
37976 Roo.fly(body).addClass("tab-pane");
37977 bodyEl.insertBefore(body, bodyEl.firstChild);
37981 createStripElements : function(stripEl, text, closable, tpl)
37983 var td = document.createElement("li"); // was td..
37986 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
37989 stripEl.appendChild(td);
37991 td.className = "x-tabs-closable";
37992 if(!this.closeTpl){
37993 this.closeTpl = new Roo.Template(
37994 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
37995 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
37996 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
37999 var el = this.closeTpl.overwrite(td, {"text": text});
38000 var close = el.getElementsByTagName("div")[0];
38001 var inner = el.getElementsByTagName("em")[0];
38002 return {"el": el, "close": close, "inner": inner};
38005 // not sure what this is..
38006 // if(!this.tabTpl){
38007 //this.tabTpl = new Roo.Template(
38008 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38009 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
38011 // this.tabTpl = new Roo.Template(
38012 // '<a href="#">' +
38013 // '<span unselectable="on"' +
38014 // (this.disableTooltips ? '' : ' title="{text}"') +
38015 // ' >{text}</span></a>'
38021 var template = tpl || this.tabTpl || false;
38025 template = new Roo.Template(
38027 '<span unselectable="on"' +
38028 (this.disableTooltips ? '' : ' title="{text}"') +
38029 ' >{text}</span></a>'
38033 switch (typeof(template)) {
38037 template = new Roo.Template(template);
38043 var el = template.overwrite(td, {"text": text});
38045 var inner = el.getElementsByTagName("span")[0];
38047 return {"el": el, "inner": inner};
38055 * @class Roo.TabPanelItem
38056 * @extends Roo.util.Observable
38057 * Represents an individual item (tab plus body) in a TabPanel.
38058 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
38059 * @param {String} id The id of this TabPanelItem
38060 * @param {String} text The text for the tab of this TabPanelItem
38061 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
38063 Roo.bootstrap.panel.TabItem = function(config){
38065 * The {@link Roo.TabPanel} this TabPanelItem belongs to
38066 * @type Roo.TabPanel
38068 this.tabPanel = config.panel;
38070 * The id for this TabPanelItem
38073 this.id = config.id;
38075 this.disabled = false;
38077 this.text = config.text;
38079 this.loaded = false;
38080 this.closable = config.closable;
38083 * The body element for this TabPanelItem.
38084 * @type Roo.Element
38086 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
38087 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
38088 this.bodyEl.setStyle("display", "block");
38089 this.bodyEl.setStyle("zoom", "1");
38090 //this.hideAction();
38092 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
38094 this.el = Roo.get(els.el);
38095 this.inner = Roo.get(els.inner, true);
38096 this.textEl = Roo.get(this.el.dom.firstChild, true);
38097 this.pnode = Roo.get(els.el.parentNode, true);
38098 // this.el.on("mousedown", this.onTabMouseDown, this);
38099 this.el.on("click", this.onTabClick, this);
38101 if(config.closable){
38102 var c = Roo.get(els.close, true);
38103 c.dom.title = this.closeText;
38104 c.addClassOnOver("close-over");
38105 c.on("click", this.closeClick, this);
38111 * Fires when this tab becomes the active tab.
38112 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38113 * @param {Roo.TabPanelItem} this
38117 * @event beforeclose
38118 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
38119 * @param {Roo.TabPanelItem} this
38120 * @param {Object} e Set cancel to true on this object to cancel the close.
38122 "beforeclose": true,
38125 * Fires when this tab is closed.
38126 * @param {Roo.TabPanelItem} this
38130 * @event deactivate
38131 * Fires when this tab is no longer the active tab.
38132 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38133 * @param {Roo.TabPanelItem} this
38135 "deactivate" : true
38137 this.hidden = false;
38139 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
38142 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
38144 purgeListeners : function(){
38145 Roo.util.Observable.prototype.purgeListeners.call(this);
38146 this.el.removeAllListeners();
38149 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
38152 this.pnode.addClass("active");
38155 this.tabPanel.stripWrap.repaint();
38157 this.fireEvent("activate", this.tabPanel, this);
38161 * Returns true if this tab is the active tab.
38162 * @return {Boolean}
38164 isActive : function(){
38165 return this.tabPanel.getActiveTab() == this;
38169 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
38172 this.pnode.removeClass("active");
38174 this.fireEvent("deactivate", this.tabPanel, this);
38177 hideAction : function(){
38178 this.bodyEl.hide();
38179 this.bodyEl.setStyle("position", "absolute");
38180 this.bodyEl.setLeft("-20000px");
38181 this.bodyEl.setTop("-20000px");
38184 showAction : function(){
38185 this.bodyEl.setStyle("position", "relative");
38186 this.bodyEl.setTop("");
38187 this.bodyEl.setLeft("");
38188 this.bodyEl.show();
38192 * Set the tooltip for the tab.
38193 * @param {String} tooltip The tab's tooltip
38195 setTooltip : function(text){
38196 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
38197 this.textEl.dom.qtip = text;
38198 this.textEl.dom.removeAttribute('title');
38200 this.textEl.dom.title = text;
38204 onTabClick : function(e){
38205 e.preventDefault();
38206 this.tabPanel.activate(this.id);
38209 onTabMouseDown : function(e){
38210 e.preventDefault();
38211 this.tabPanel.activate(this.id);
38214 getWidth : function(){
38215 return this.inner.getWidth();
38218 setWidth : function(width){
38219 var iwidth = width - this.pnode.getPadding("lr");
38220 this.inner.setWidth(iwidth);
38221 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
38222 this.pnode.setWidth(width);
38226 * Show or hide the tab
38227 * @param {Boolean} hidden True to hide or false to show.
38229 setHidden : function(hidden){
38230 this.hidden = hidden;
38231 this.pnode.setStyle("display", hidden ? "none" : "");
38235 * Returns true if this tab is "hidden"
38236 * @return {Boolean}
38238 isHidden : function(){
38239 return this.hidden;
38243 * Returns the text for this tab
38246 getText : function(){
38250 autoSize : function(){
38251 //this.el.beginMeasure();
38252 this.textEl.setWidth(1);
38254 * #2804 [new] Tabs in Roojs
38255 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
38257 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
38258 //this.el.endMeasure();
38262 * Sets the text for the tab (Note: this also sets the tooltip text)
38263 * @param {String} text The tab's text and tooltip
38265 setText : function(text){
38267 this.textEl.update(text);
38268 this.setTooltip(text);
38269 //if(!this.tabPanel.resizeTabs){
38270 // this.autoSize();
38274 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
38276 activate : function(){
38277 this.tabPanel.activate(this.id);
38281 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
38283 disable : function(){
38284 if(this.tabPanel.active != this){
38285 this.disabled = true;
38286 this.pnode.addClass("disabled");
38291 * Enables this TabPanelItem if it was previously disabled.
38293 enable : function(){
38294 this.disabled = false;
38295 this.pnode.removeClass("disabled");
38299 * Sets the content for this TabPanelItem.
38300 * @param {String} content The content
38301 * @param {Boolean} loadScripts true to look for and load scripts
38303 setContent : function(content, loadScripts){
38304 this.bodyEl.update(content, loadScripts);
38308 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
38309 * @return {Roo.UpdateManager} The UpdateManager
38311 getUpdateManager : function(){
38312 return this.bodyEl.getUpdateManager();
38316 * Set a URL to be used to load the content for this TabPanelItem.
38317 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
38318 * @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)
38319 * @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)
38320 * @return {Roo.UpdateManager} The UpdateManager
38322 setUrl : function(url, params, loadOnce){
38323 if(this.refreshDelegate){
38324 this.un('activate', this.refreshDelegate);
38326 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
38327 this.on("activate", this.refreshDelegate);
38328 return this.bodyEl.getUpdateManager();
38332 _handleRefresh : function(url, params, loadOnce){
38333 if(!loadOnce || !this.loaded){
38334 var updater = this.bodyEl.getUpdateManager();
38335 updater.update(url, params, this._setLoaded.createDelegate(this));
38340 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
38341 * Will fail silently if the setUrl method has not been called.
38342 * This does not activate the panel, just updates its content.
38344 refresh : function(){
38345 if(this.refreshDelegate){
38346 this.loaded = false;
38347 this.refreshDelegate();
38352 _setLoaded : function(){
38353 this.loaded = true;
38357 closeClick : function(e){
38360 this.fireEvent("beforeclose", this, o);
38361 if(o.cancel !== true){
38362 this.tabPanel.removeTab(this.id);
38366 * The text displayed in the tooltip for the close icon.
38369 closeText : "Close this tab"
38372 * This script refer to:
38373 * Title: International Telephone Input
38374 * Author: Jack O'Connor
38375 * Code version: v12.1.12
38376 * Availability: https://github.com/jackocnr/intl-tel-input.git
38379 Roo.bootstrap.PhoneInputData = function() {
38382 "Afghanistan (افغانستان)",
38387 "Albania (Shqipëri)",
38392 "Algeria (الجزائر)",
38417 "Antigua and Barbuda",
38427 "Armenia (Հայաստան)",
38443 "Austria (Österreich)",
38448 "Azerbaijan (Azərbaycan)",
38458 "Bahrain (البحرين)",
38463 "Bangladesh (বাংলাদেশ)",
38473 "Belarus (Беларусь)",
38478 "Belgium (België)",
38508 "Bosnia and Herzegovina (Босна и Херцеговина)",
38523 "British Indian Ocean Territory",
38528 "British Virgin Islands",
38538 "Bulgaria (България)",
38548 "Burundi (Uburundi)",
38553 "Cambodia (កម្ពុជា)",
38558 "Cameroon (Cameroun)",
38567 ["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"]
38570 "Cape Verde (Kabu Verdi)",
38575 "Caribbean Netherlands",
38586 "Central African Republic (République centrafricaine)",
38606 "Christmas Island",
38612 "Cocos (Keeling) Islands",
38623 "Comoros (جزر القمر)",
38628 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
38633 "Congo (Republic) (Congo-Brazzaville)",
38653 "Croatia (Hrvatska)",
38674 "Czech Republic (Česká republika)",
38679 "Denmark (Danmark)",
38694 "Dominican Republic (República Dominicana)",
38698 ["809", "829", "849"]
38716 "Equatorial Guinea (Guinea Ecuatorial)",
38736 "Falkland Islands (Islas Malvinas)",
38741 "Faroe Islands (Føroyar)",
38762 "French Guiana (Guyane française)",
38767 "French Polynesia (Polynésie française)",
38782 "Georgia (საქართველო)",
38787 "Germany (Deutschland)",
38807 "Greenland (Kalaallit Nunaat)",
38844 "Guinea-Bissau (Guiné Bissau)",
38869 "Hungary (Magyarország)",
38874 "Iceland (Ísland)",
38894 "Iraq (العراق)",
38910 "Israel (ישראל)",
38937 "Jordan (الأردن)",
38942 "Kazakhstan (Казахстан)",
38963 "Kuwait (الكويت)",
38968 "Kyrgyzstan (Кыргызстан)",
38978 "Latvia (Latvija)",
38983 "Lebanon (لبنان)",
38998 "Libya (ليبيا)",
39008 "Lithuania (Lietuva)",
39023 "Macedonia (FYROM) (Македонија)",
39028 "Madagascar (Madagasikara)",
39058 "Marshall Islands",
39068 "Mauritania (موريتانيا)",
39073 "Mauritius (Moris)",
39094 "Moldova (Republica Moldova)",
39104 "Mongolia (Монгол)",
39109 "Montenegro (Crna Gora)",
39119 "Morocco (المغرب)",
39125 "Mozambique (Moçambique)",
39130 "Myanmar (Burma) (မြန်မာ)",
39135 "Namibia (Namibië)",
39150 "Netherlands (Nederland)",
39155 "New Caledonia (Nouvelle-Calédonie)",
39190 "North Korea (조선 민주주의 인민 공화국)",
39195 "Northern Mariana Islands",
39211 "Pakistan (پاکستان)",
39221 "Palestine (فلسطين)",
39231 "Papua New Guinea",
39273 "Réunion (La Réunion)",
39279 "Romania (România)",
39295 "Saint Barthélemy",
39306 "Saint Kitts and Nevis",
39316 "Saint Martin (Saint-Martin (partie française))",
39322 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
39327 "Saint Vincent and the Grenadines",
39342 "São Tomé and Príncipe (São Tomé e Príncipe)",
39347 "Saudi Arabia (المملكة العربية السعودية)",
39352 "Senegal (Sénégal)",
39382 "Slovakia (Slovensko)",
39387 "Slovenia (Slovenija)",
39397 "Somalia (Soomaaliya)",
39407 "South Korea (대한민국)",
39412 "South Sudan (جنوب السودان)",
39422 "Sri Lanka (ශ්රී ලංකාව)",
39427 "Sudan (السودان)",
39437 "Svalbard and Jan Mayen",
39448 "Sweden (Sverige)",
39453 "Switzerland (Schweiz)",
39458 "Syria (سوريا)",
39503 "Trinidad and Tobago",
39508 "Tunisia (تونس)",
39513 "Turkey (Türkiye)",
39523 "Turks and Caicos Islands",
39533 "U.S. Virgin Islands",
39543 "Ukraine (Україна)",
39548 "United Arab Emirates (الإمارات العربية المتحدة)",
39570 "Uzbekistan (Oʻzbekiston)",
39580 "Vatican City (Città del Vaticano)",
39591 "Vietnam (Việt Nam)",
39596 "Wallis and Futuna (Wallis-et-Futuna)",
39601 "Western Sahara (الصحراء الغربية)",
39607 "Yemen (اليمن)",
39631 * This script refer to:
39632 * Title: International Telephone Input
39633 * Author: Jack O'Connor
39634 * Code version: v12.1.12
39635 * Availability: https://github.com/jackocnr/intl-tel-input.git
39639 * @class Roo.bootstrap.PhoneInput
39640 * @extends Roo.bootstrap.TriggerField
39641 * An input with International dial-code selection
39643 * @cfg {String} defaultDialCode default '+852'
39644 * @cfg {Array} preferedCountries default []
39647 * Create a new PhoneInput.
39648 * @param {Object} config Configuration options
39651 Roo.bootstrap.PhoneInput = function(config) {
39652 Roo.bootstrap.PhoneInput.superclass.constructor.call(this, config);
39655 Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
39657 listWidth: undefined,
39659 selectedClass: 'active',
39661 invalidClass : "has-warning",
39663 validClass: 'has-success',
39665 allowed: '0123456789',
39668 * @cfg {String} defaultDialCode The default dial code when initializing the input
39670 defaultDialCode: '+852',
39673 * @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
39675 preferedCountries: false,
39677 getAutoCreate : function()
39679 var data = Roo.bootstrap.PhoneInputData();
39680 var align = this.labelAlign || this.parentLabelAlign();
39683 this.allCountries = [];
39684 this.dialCodeMapping = [];
39686 for (var i = 0; i < data.length; i++) {
39688 this.allCountries[i] = {
39692 priority: c[3] || 0,
39693 areaCodes: c[4] || null
39695 this.dialCodeMapping[c[2]] = {
39698 priority: c[3] || 0,
39699 areaCodes: c[4] || null
39711 cls : 'form-control tel-input',
39712 autocomplete: 'new-password'
39715 var hiddenInput = {
39718 cls: 'hidden-tel-input'
39722 hiddenInput.name = this.name;
39725 if (this.disabled) {
39726 input.disabled = true;
39729 var flag_container = {
39746 cls: this.hasFeedback ? 'has-feedback' : '',
39752 cls: 'dial-code-holder',
39759 cls: 'roo-select2-container input-group',
39766 if (this.fieldLabel.length) {
39769 tooltip: 'This field is required'
39775 cls: 'control-label',
39781 html: this.fieldLabel
39784 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
39790 if(this.indicatorpos == 'right') {
39791 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
39798 if(align == 'left') {
39806 if(this.labelWidth > 12){
39807 label.style = "width: " + this.labelWidth + 'px';
39809 if(this.labelWidth < 13 && this.labelmd == 0){
39810 this.labelmd = this.labelWidth;
39812 if(this.labellg > 0){
39813 label.cls += ' col-lg-' + this.labellg;
39814 input.cls += ' col-lg-' + (12 - this.labellg);
39816 if(this.labelmd > 0){
39817 label.cls += ' col-md-' + this.labelmd;
39818 container.cls += ' col-md-' + (12 - this.labelmd);
39820 if(this.labelsm > 0){
39821 label.cls += ' col-sm-' + this.labelsm;
39822 container.cls += ' col-sm-' + (12 - this.labelsm);
39824 if(this.labelxs > 0){
39825 label.cls += ' col-xs-' + this.labelxs;
39826 container.cls += ' col-xs-' + (12 - this.labelxs);
39836 var settings = this;
39838 ['xs','sm','md','lg'].map(function(size){
39839 if (settings[size]) {
39840 cfg.cls += ' col-' + size + '-' + settings[size];
39844 this.store = new Roo.data.Store({
39845 proxy : new Roo.data.MemoryProxy({}),
39846 reader : new Roo.data.JsonReader({
39857 'name' : 'dialCode',
39861 'name' : 'priority',
39865 'name' : 'areaCodes',
39872 if(!this.preferedCountries) {
39873 this.preferedCountries = [
39880 var p = this.preferedCountries.reverse();
39883 for (var i = 0; i < p.length; i++) {
39884 for (var j = 0; j < this.allCountries.length; j++) {
39885 if(this.allCountries[j].iso2 == p[i]) {
39886 var t = this.allCountries[j];
39887 this.allCountries.splice(j,1);
39888 this.allCountries.unshift(t);
39894 this.store.proxy.data = {
39896 data: this.allCountries
39902 initEvents : function()
39905 Roo.bootstrap.PhoneInput.superclass.initEvents.call(this);
39907 this.indicator = this.indicatorEl();
39908 this.flag = this.flagEl();
39909 this.dialCodeHolder = this.dialCodeHolderEl();
39911 this.trigger = this.el.select('div.flag-box',true).first();
39912 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
39917 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
39918 _this.list.setWidth(lw);
39921 this.list.on('mouseover', this.onViewOver, this);
39922 this.list.on('mousemove', this.onViewMove, this);
39923 this.inputEl().on("keyup", this.onKeyUp, this);
39925 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
39927 this.view = new Roo.View(this.list, this.tpl, {
39928 singleSelect:true, store: this.store, selectedClass: this.selectedClass
39931 this.view.on('click', this.onViewClick, this);
39932 this.setValue(this.defaultDialCode);
39935 onTriggerClick : function(e)
39937 Roo.log('trigger click');
39942 if(this.isExpanded()){
39944 this.hasFocus = false;
39946 this.store.load({});
39947 this.hasFocus = true;
39952 isExpanded : function()
39954 return this.list.isVisible();
39957 collapse : function()
39959 if(!this.isExpanded()){
39963 Roo.get(document).un('mousedown', this.collapseIf, this);
39964 Roo.get(document).un('mousewheel', this.collapseIf, this);
39965 this.fireEvent('collapse', this);
39969 expand : function()
39973 if(this.isExpanded() || !this.hasFocus){
39977 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
39978 this.list.setWidth(lw);
39981 this.restrictHeight();
39983 Roo.get(document).on('mousedown', this.collapseIf, this);
39984 Roo.get(document).on('mousewheel', this.collapseIf, this);
39986 this.fireEvent('expand', this);
39989 restrictHeight : function()
39991 this.list.alignTo(this.inputEl(), this.listAlign);
39992 this.list.alignTo(this.inputEl(), this.listAlign);
39995 onViewOver : function(e, t)
39997 if(this.inKeyMode){
40000 var item = this.view.findItemFromChild(t);
40003 var index = this.view.indexOf(item);
40004 this.select(index, false);
40009 onViewClick : function(view, doFocus, el, e)
40011 var index = this.view.getSelectedIndexes()[0];
40013 var r = this.store.getAt(index);
40016 this.onSelect(r, index);
40018 if(doFocus !== false && !this.blockFocus){
40019 this.inputEl().focus();
40023 onViewMove : function(e, t)
40025 this.inKeyMode = false;
40028 select : function(index, scrollIntoView)
40030 this.selectedIndex = index;
40031 this.view.select(index);
40032 if(scrollIntoView !== false){
40033 var el = this.view.getNode(index);
40035 this.list.scrollChildIntoView(el, false);
40040 createList : function()
40042 this.list = Roo.get(document.body).createChild({
40044 cls: 'typeahead typeahead-long dropdown-menu tel-list',
40045 style: 'display:none'
40048 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
40051 collapseIf : function(e)
40053 var in_combo = e.within(this.el);
40054 var in_list = e.within(this.list);
40055 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
40057 if (in_combo || in_list || is_list) {
40063 onSelect : function(record, index)
40065 if(this.fireEvent('beforeselect', this, record, index) !== false){
40067 this.setFlagClass(record.data.iso2);
40068 this.setDialCode(record.data.dialCode);
40069 this.hasFocus = false;
40071 this.fireEvent('select', this, record, index);
40075 flagEl : function()
40077 var flag = this.el.select('div.flag',true).first();
40084 dialCodeHolderEl : function()
40086 var d = this.el.select('input.dial-code-holder',true).first();
40093 setDialCode : function(v)
40095 this.dialCodeHolder.dom.value = '+'+v;
40098 setFlagClass : function(n)
40100 this.flag.dom.className = 'flag '+n;
40103 getValue : function()
40105 var v = this.inputEl().getValue();
40106 if(this.dialCodeHolder) {
40107 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
40112 setValue : function(v)
40114 var d = this.getDialCode(v);
40116 //invalid dial code
40117 if(v.length == 0 || !d || d.length == 0) {
40119 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
40120 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40126 this.setFlagClass(this.dialCodeMapping[d].iso2);
40127 this.setDialCode(d);
40128 this.inputEl().dom.value = v.replace('+'+d,'');
40129 this.hiddenEl().dom.value = this.getValue();
40134 getDialCode : function(v)
40138 if (v.length == 0) {
40139 return this.dialCodeHolder.dom.value;
40143 if (v.charAt(0) != "+") {
40146 var numericChars = "";
40147 for (var i = 1; i < v.length; i++) {
40148 var c = v.charAt(i);
40151 if (this.dialCodeMapping[numericChars]) {
40152 dialCode = v.substr(1, i);
40154 if (numericChars.length == 4) {
40164 this.setValue(this.defaultDialCode);
40168 hiddenEl : function()
40170 return this.el.select('input.hidden-tel-input',true).first();
40173 onKeyUp : function(e){
40175 var k = e.getKey();
40176 var c = e.getCharCode();
40179 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40180 this.allowed.indexOf(String.fromCharCode(c)) === -1
40185 // if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40188 if(this.allowed.indexOf(String.fromCharCode(c)) === -1){
40192 this.setValue(this.getValue());
40197 * @class Roo.bootstrap.MoneyField
40198 * @extends Roo.bootstrap.ComboBox
40199 * Bootstrap MoneyField class
40202 * Create a new MoneyField.
40203 * @param {Object} config Configuration options
40206 Roo.bootstrap.MoneyField = function(config) {
40208 Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
40212 Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
40215 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
40217 allowDecimals : true,
40219 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
40221 decimalSeparator : ".",
40223 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
40225 decimalPrecision : 0,
40227 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
40229 allowNegative : true,
40231 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
40233 minValue : Number.NEGATIVE_INFINITY,
40235 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
40237 maxValue : Number.MAX_VALUE,
40239 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
40241 minText : "The minimum value for this field is {0}",
40243 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
40245 maxText : "The maximum value for this field is {0}",
40247 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
40248 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
40250 nanText : "{0} is not a valid number",
40252 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
40256 * @cfg {String} defaults currency of the MoneyField
40257 * value should be in lkey
40259 defaultCurrency : false,
40261 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
40263 thousandsDelimiter : false,
40273 getAutoCreate : function()
40275 var align = this.labelAlign || this.parentLabelAlign();
40287 cls : 'form-control roo-money-amount-input',
40288 autocomplete: 'new-password'
40291 var hiddenInput = {
40295 cls: 'hidden-number-input'
40299 hiddenInput.name = this.name;
40302 if (this.disabled) {
40303 input.disabled = true;
40306 var clg = 12 - this.inputlg;
40307 var cmd = 12 - this.inputmd;
40308 var csm = 12 - this.inputsm;
40309 var cxs = 12 - this.inputxs;
40313 cls : 'row roo-money-field',
40317 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
40321 cls: 'roo-select2-container input-group',
40325 cls : 'form-control roo-money-currency-input',
40326 autocomplete: 'new-password',
40328 name : this.currencyName
40332 cls : 'input-group-addon',
40346 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
40350 cls: this.hasFeedback ? 'has-feedback' : '',
40361 if (this.fieldLabel.length) {
40364 tooltip: 'This field is required'
40370 cls: 'control-label',
40376 html: this.fieldLabel
40379 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40385 if(this.indicatorpos == 'right') {
40386 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40393 if(align == 'left') {
40401 if(this.labelWidth > 12){
40402 label.style = "width: " + this.labelWidth + 'px';
40404 if(this.labelWidth < 13 && this.labelmd == 0){
40405 this.labelmd = this.labelWidth;
40407 if(this.labellg > 0){
40408 label.cls += ' col-lg-' + this.labellg;
40409 input.cls += ' col-lg-' + (12 - this.labellg);
40411 if(this.labelmd > 0){
40412 label.cls += ' col-md-' + this.labelmd;
40413 container.cls += ' col-md-' + (12 - this.labelmd);
40415 if(this.labelsm > 0){
40416 label.cls += ' col-sm-' + this.labelsm;
40417 container.cls += ' col-sm-' + (12 - this.labelsm);
40419 if(this.labelxs > 0){
40420 label.cls += ' col-xs-' + this.labelxs;
40421 container.cls += ' col-xs-' + (12 - this.labelxs);
40432 var settings = this;
40434 ['xs','sm','md','lg'].map(function(size){
40435 if (settings[size]) {
40436 cfg.cls += ' col-' + size + '-' + settings[size];
40443 initEvents : function()
40445 this.indicator = this.indicatorEl();
40447 this.initCurrencyEvent();
40449 this.initNumberEvent();
40452 initCurrencyEvent : function()
40455 throw "can not find store for combo";
40458 this.store = Roo.factory(this.store, Roo.data);
40459 this.store.parent = this;
40463 this.triggerEl = this.el.select('.input-group-addon', true).first();
40465 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
40470 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40471 _this.list.setWidth(lw);
40474 this.list.on('mouseover', this.onViewOver, this);
40475 this.list.on('mousemove', this.onViewMove, this);
40476 this.list.on('scroll', this.onViewScroll, this);
40479 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
40482 this.view = new Roo.View(this.list, this.tpl, {
40483 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40486 this.view.on('click', this.onViewClick, this);
40488 this.store.on('beforeload', this.onBeforeLoad, this);
40489 this.store.on('load', this.onLoad, this);
40490 this.store.on('loadexception', this.onLoadException, this);
40492 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
40493 "up" : function(e){
40494 this.inKeyMode = true;
40498 "down" : function(e){
40499 if(!this.isExpanded()){
40500 this.onTriggerClick();
40502 this.inKeyMode = true;
40507 "enter" : function(e){
40510 if(this.fireEvent("specialkey", this, e)){
40511 this.onViewClick(false);
40517 "esc" : function(e){
40521 "tab" : function(e){
40524 if(this.fireEvent("specialkey", this, e)){
40525 this.onViewClick(false);
40533 doRelay : function(foo, bar, hname){
40534 if(hname == 'down' || this.scope.isExpanded()){
40535 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
40543 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
40547 initNumberEvent : function(e)
40549 this.inputEl().on("keydown" , this.fireKey, this);
40550 this.inputEl().on("focus", this.onFocus, this);
40551 this.inputEl().on("blur", this.onBlur, this);
40553 this.inputEl().relayEvent('keyup', this);
40555 if(this.indicator){
40556 this.indicator.addClass('invisible');
40559 this.originalValue = this.getValue();
40561 if(this.validationEvent == 'keyup'){
40562 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
40563 this.inputEl().on('keyup', this.filterValidation, this);
40565 else if(this.validationEvent !== false){
40566 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
40569 if(this.selectOnFocus){
40570 this.on("focus", this.preFocus, this);
40573 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
40574 this.inputEl().on("keypress", this.filterKeys, this);
40576 this.inputEl().relayEvent('keypress', this);
40579 var allowed = "0123456789";
40581 if(this.allowDecimals){
40582 allowed += this.decimalSeparator;
40585 if(this.allowNegative){
40589 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
40591 var keyPress = function(e){
40593 var k = e.getKey();
40595 var c = e.getCharCode();
40598 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40599 allowed.indexOf(String.fromCharCode(c)) === -1
40605 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40609 if(allowed.indexOf(String.fromCharCode(c)) === -1){
40614 this.inputEl().on("keypress", keyPress, this);
40618 onTriggerClick : function(e)
40625 this.loadNext = false;
40627 if(this.isExpanded()){
40632 this.hasFocus = true;
40634 if(this.triggerAction == 'all') {
40635 this.doQuery(this.allQuery, true);
40639 this.doQuery(this.getRawValue());
40642 getCurrency : function()
40644 var v = this.currencyEl().getValue();
40649 restrictHeight : function()
40651 this.list.alignTo(this.currencyEl(), this.listAlign);
40652 this.list.alignTo(this.currencyEl(), this.listAlign);
40655 onViewClick : function(view, doFocus, el, e)
40657 var index = this.view.getSelectedIndexes()[0];
40659 var r = this.store.getAt(index);
40662 this.onSelect(r, index);
40666 onSelect : function(record, index){
40668 if(this.fireEvent('beforeselect', this, record, index) !== false){
40670 this.setFromCurrencyData(index > -1 ? record.data : false);
40674 this.fireEvent('select', this, record, index);
40678 setFromCurrencyData : function(o)
40682 this.lastCurrency = o;
40684 if (this.currencyField) {
40685 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
40687 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
40690 this.lastSelectionText = currency;
40692 //setting default currency
40693 if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
40694 this.setCurrency(this.defaultCurrency);
40698 this.setCurrency(currency);
40701 setFromData : function(o)
40705 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
40707 this.setFromCurrencyData(c);
40712 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
40714 Roo.log('no value set for '+ (this.name ? this.name : this.id));
40717 this.setValue(value);
40721 setCurrency : function(v)
40723 this.currencyValue = v;
40726 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
40731 setValue : function(v)
40733 v = this.fixPrecision(v);
40735 v = String(v).replace(".", this.decimalSeparator);
40741 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40743 this.inputEl().dom.value = Roo.util.Format.number(v, this.decimalPrecision,
40744 this.thousandsDelimiter || ','
40747 if(this.allowBlank && !v) {
40748 this.inputEl().dom.value = '';
40755 getRawValue : function()
40757 var v = this.inputEl().getValue();
40762 getValue : function()
40764 return this.fixPrecision(this.parseValue(this.getRawValue()));
40767 parseValue : function(value)
40769 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
40770 return isNaN(value) ? '' : value;
40773 fixPrecision : function(value)
40775 var nan = isNaN(value);
40777 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
40778 return nan ? '' : value;
40781 return parseFloat(value).toFixed(this.decimalPrecision);
40784 decimalPrecisionFcn : function(v)
40786 return Math.floor(v);
40789 validateValue : function(value)
40791 if(!Roo.bootstrap.MoneyField.superclass.validateValue.call(this, value)){
40795 var num = this.parseValue(value);
40798 this.markInvalid(String.format(this.nanText, value));
40802 if(num < this.minValue){
40803 this.markInvalid(String.format(this.minText, this.minValue));
40807 if(num > this.maxValue){
40808 this.markInvalid(String.format(this.maxText, this.maxValue));
40815 validate : function()
40817 if(this.disabled || this.allowBlank){
40822 var currency = this.getCurrency();
40824 if(this.validateValue(this.getRawValue()) && currency.length){
40829 this.markInvalid();
40833 getName: function()
40838 beforeBlur : function()
40844 var v = this.parseValue(this.getRawValue());
40851 onBlur : function()
40855 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
40856 //this.el.removeClass(this.focusClass);
40859 this.hasFocus = false;
40861 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
40865 var v = this.getValue();
40867 if(String(v) !== String(this.startValue)){
40868 this.fireEvent('change', this, v, this.startValue);
40871 this.fireEvent("blur", this);
40874 inputEl : function()
40876 return this.el.select('.roo-money-amount-input', true).first();
40879 currencyEl : function()
40881 return this.el.select('.roo-money-currency-input', true).first();
40884 hiddenEl : function()
40886 return this.el.select('input.hidden-number-input',true).first();