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');
404 this.fireEvent('show', this);
409 * Hide a component - adds 'hidden' class
413 if(!this.getVisibilityEl()){
417 this.getVisibilityEl().addClass('hidden');
419 this.fireEvent('hide', this);
432 * @class Roo.bootstrap.Body
433 * @extends Roo.bootstrap.Component
434 * Bootstrap Body class
438 * @param {Object} config The config object
441 Roo.bootstrap.Body = function(config){
443 config = config || {};
445 Roo.bootstrap.Body.superclass.constructor.call(this, config);
446 this.el = Roo.get(config.el ? config.el : document.body );
447 if (this.cls && this.cls.length) {
448 Roo.get(document.body).addClass(this.cls);
452 Roo.extend(Roo.bootstrap.Body, Roo.bootstrap.Component, {
454 is_body : true,// just to make sure it's constructed?
459 onRender : function(ct, position)
461 /* Roo.log("Roo.bootstrap.Body - onRender");
462 if (this.cls && this.cls.length) {
463 Roo.get(document.body).addClass(this.cls);
482 * @class Roo.bootstrap.ButtonGroup
483 * @extends Roo.bootstrap.Component
484 * Bootstrap ButtonGroup class
485 * @cfg {String} size lg | sm | xs (default empty normal)
486 * @cfg {String} align vertical | justified (default none)
487 * @cfg {String} direction up | down (default down)
488 * @cfg {Boolean} toolbar false | true
489 * @cfg {Boolean} btn true | false
494 * @param {Object} config The config object
497 Roo.bootstrap.ButtonGroup = function(config){
498 Roo.bootstrap.ButtonGroup.superclass.constructor.call(this, config);
501 Roo.extend(Roo.bootstrap.ButtonGroup, Roo.bootstrap.Component, {
509 getAutoCreate : function(){
515 cfg.html = this.html || cfg.html;
526 if (['vertical','justified'].indexOf(this.align)!==-1) {
527 cfg.cls = 'btn-group-' + this.align;
529 if (this.align == 'justified') {
530 console.log(this.items);
534 if (['lg','sm','xs'].indexOf(this.size)!==-1) {
535 cfg.cls += ' btn-group-' + this.size;
538 if (this.direction == 'up') {
539 cfg.cls += ' dropup' ;
555 * @class Roo.bootstrap.Button
556 * @extends Roo.bootstrap.Component
557 * Bootstrap Button class
558 * @cfg {String} html The button content
559 * @cfg {String} weight (default | primary | success | info | warning | danger | link ) default
560 * @cfg {String} size ( lg | sm | xs)
561 * @cfg {String} tag ( a | input | submit)
562 * @cfg {String} href empty or href
563 * @cfg {Boolean} disabled default false;
564 * @cfg {Boolean} isClose default false;
565 * @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)
566 * @cfg {String} badge text for badge
567 * @cfg {String} theme (default|glow)
568 * @cfg {Boolean} inverse dark themed version
569 * @cfg {Boolean} toggle is it a slidy toggle button
570 * @cfg {Boolean} pressed (true|false) default null - if the button ahs active state
571 * @cfg {String} ontext text for on slidy toggle state
572 * @cfg {String} offtext text for off slidy toggle state
573 * @cfg {Boolean} preventDefault default true (stop click event triggering the URL if it's a link.)
574 * @cfg {Boolean} removeClass remove the standard class..
575 * @cfg {String} target target for a href. (_self|_blank|_parent|_top| other)
578 * Create a new button
579 * @param {Object} config The config object
583 Roo.bootstrap.Button = function(config){
584 Roo.bootstrap.Button.superclass.constructor.call(this, config);
585 this.weightClass = ["btn-default",
597 * When a butotn is pressed
598 * @param {Roo.bootstrap.Button} btn
599 * @param {Roo.EventObject} e
604 * After the button has been toggles
605 * @param {Roo.bootstrap.Button} btn
606 * @param {Roo.EventObject} e
607 * @param {boolean} pressed (also available as button.pressed)
613 Roo.extend(Roo.bootstrap.Button, Roo.bootstrap.Component, {
631 preventDefault: true,
639 getAutoCreate : function(){
647 if (['a', 'button', 'input', 'submit'].indexOf(this.tag) < 0) {
648 throw "Invalid value for tag: " + this.tag + ". must be a, button, input or submit.";
653 cfg.html = '<span class="roo-button-text">' + (this.html || cfg.html) + '</span>';
655 if (this.toggle == true) {
658 cls: 'slider-frame roo-button',
663 'data-off-text':'OFF',
664 cls: 'slider-button',
670 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
671 cfg.cls += ' '+this.weight;
680 cfg["aria-hidden"] = true;
682 cfg.html = "×";
688 if (this.theme==='default') {
689 cfg.cls = 'btn roo-button';
691 //if (this.parentType != 'Navbar') {
692 this.weight = this.weight.length ? this.weight : 'default';
694 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
696 cfg.cls += ' btn-' + this.weight;
698 } else if (this.theme==='glow') {
701 cfg.cls = 'btn-glow roo-button';
703 if (['default', 'primary', 'success', 'info', 'warning', 'danger', 'link'].indexOf(this.weight) > -1) {
705 cfg.cls += ' ' + this.weight;
711 this.cls += ' inverse';
715 if (this.active || this.pressed === true) {
716 cfg.cls += ' active';
720 cfg.disabled = 'disabled';
724 Roo.log('changing to ul' );
726 this.glyphicon = 'caret';
729 cfg.cls += this.size.length ? (' btn-' + this.size) : '';
731 //gsRoo.log(this.parentType);
732 if (this.parentType === 'Navbar' && !this.parent().bar) {
733 Roo.log('changing to li?');
742 href : this.href || '#'
745 cfg.cn[0].html = this.html + ' <span class="caret"></span>';
746 cfg.cls += ' dropdown';
753 cfg.cls += this.parentType === 'Navbar' ? ' navbar-btn' : '';
755 if (this.glyphicon) {
756 cfg.html = ' ' + cfg.html;
761 cls: 'glyphicon glyphicon-' + this.glyphicon
771 // cfg.cls='btn roo-button';
775 var value = cfg.html;
780 cls: 'glyphicon glyphicon-' + this.glyphicon,
799 cfg.cls += ' dropdown';
800 cfg.html = typeof(cfg.html) != 'undefined' ?
801 cfg.html + ' <span class="caret"></span>' : '<span class="caret"></span>';
804 if (cfg.tag !== 'a' && this.href !== '') {
805 throw "Tag must be a to set href.";
806 } else if (this.href.length > 0) {
807 cfg.href = this.href;
810 if(this.removeClass){
815 cfg.target = this.target;
820 initEvents: function() {
821 // Roo.log('init events?');
822 // Roo.log(this.el.dom);
825 if (typeof (this.menu) != 'undefined') {
826 this.menu.parentType = this.xtype;
827 this.menu.triggerEl = this.el;
828 this.addxtype(Roo.apply({}, this.menu));
832 if (this.el.hasClass('roo-button')) {
833 this.el.on('click', this.onClick, this);
835 this.el.select('.roo-button').on('click', this.onClick, this);
838 if(this.removeClass){
839 this.el.on('click', this.onClick, this);
842 this.el.enableDisplayMode();
845 onClick : function(e)
851 Roo.log('button on click ');
852 if(this.preventDefault){
856 if (this.pressed === true || this.pressed === false) {
857 this.toggleActive(e);
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(e)
895 this.setActive(!this.pressed);
896 this.fireEvent('toggle', this, e, !this.pressed);
899 * get the current active state
900 * @return {boolean} true if it's active
902 isActive : function()
904 return this.el.hasClass('active');
907 * set the text of the first selected button
909 setText : function(str)
911 this.el.select('.roo-button-text',true).first().dom.innerHTML = str;
914 * get the text of the first selected button
918 return this.el.select('.roo-button-text',true).first().dom.innerHTML;
921 setWeight : function(str)
923 this.el.removeClass(this.weightClass);
924 this.el.addClass('btn-' + str);
938 * @class Roo.bootstrap.Column
939 * @extends Roo.bootstrap.Component
940 * Bootstrap Column class
941 * @cfg {Number} xs colspan out of 12 for mobile-sized screens or 0 for hidden
942 * @cfg {Number} sm colspan out of 12 for tablet-sized screens or 0 for hidden
943 * @cfg {Number} md colspan out of 12 for computer-sized screens or 0 for hidden
944 * @cfg {Number} lg colspan out of 12 for large computer-sized screens or 0 for hidden
945 * @cfg {Number} xsoff colspan offset out of 12 for mobile-sized screens or 0 for hidden
946 * @cfg {Number} smoff colspan offset out of 12 for tablet-sized screens or 0 for hidden
947 * @cfg {Number} mdoff colspan offset out of 12 for computer-sized screens or 0 for hidden
948 * @cfg {Number} lgoff colspan offset out of 12 for large computer-sized screens or 0 for hidden
951 * @cfg {Boolean} hidden (true|false) hide the element
952 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
953 * @cfg {String} fa (ban|check|...) font awesome icon
954 * @cfg {Number} fasize (1|2|....) font awsome size
956 * @cfg {String} icon (info-sign|check|...) glyphicon name
958 * @cfg {String} html content of column.
961 * Create a new Column
962 * @param {Object} config The config object
965 Roo.bootstrap.Column = function(config){
966 Roo.bootstrap.Column.superclass.constructor.call(this, config);
969 Roo.extend(Roo.bootstrap.Column, Roo.bootstrap.Component, {
987 getAutoCreate : function(){
988 var cfg = Roo.apply({}, Roo.bootstrap.Column.superclass.getAutoCreate.call(this));
996 ['xs','sm','md','lg'].map(function(size){
997 //Roo.log( size + ':' + settings[size]);
999 if (settings[size+'off'] !== false) {
1000 cfg.cls += ' col-' + size + '-offset-' + settings[size+'off'] ;
1003 if (settings[size] === false) {
1007 if (!settings[size]) { // 0 = hidden
1008 cfg.cls += ' hidden-' + size;
1011 cfg.cls += ' col-' + size + '-' + settings[size];
1016 cfg.cls += ' hidden';
1019 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1020 cfg.cls +=' alert alert-' + this.alert;
1024 if (this.html.length) {
1025 cfg.html = this.html;
1029 if (this.fasize > 1) {
1030 fasize = ' fa-' + this.fasize + 'x';
1032 cfg.html = '<i class="fa fa-'+this.fa + fasize + '"></i>' + (cfg.html || '');
1037 cfg.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + (cfg.html || '');
1056 * @class Roo.bootstrap.Container
1057 * @extends Roo.bootstrap.Component
1058 * Bootstrap Container class
1059 * @cfg {Boolean} jumbotron is it a jumbotron element
1060 * @cfg {String} html content of element
1061 * @cfg {String} well (lg|sm|md) a well, large, small or medium.
1062 * @cfg {String} panel (default|primary|success|info|warning|danger) render as panel - type - primary/success.....
1063 * @cfg {String} header content of header (for panel)
1064 * @cfg {String} footer content of footer (for panel)
1065 * @cfg {String} sticky (footer|wrap|push) block to use as footer or body- needs css-bootstrap/sticky-footer.css
1066 * @cfg {String} tag (header|aside|section) type of HTML tag.
1067 * @cfg {String} alert (success|info|warning|danger) type alert (changes background / border...)
1068 * @cfg {String} fa font awesome icon
1069 * @cfg {String} icon (info-sign|check|...) glyphicon name
1070 * @cfg {Boolean} hidden (true|false) hide the element
1071 * @cfg {Boolean} expandable (true|false) default false
1072 * @cfg {Boolean} expanded (true|false) default true
1073 * @cfg {String} rheader contet on the right of header
1074 * @cfg {Boolean} clickable (true|false) default false
1078 * Create a new Container
1079 * @param {Object} config The config object
1082 Roo.bootstrap.Container = function(config){
1083 Roo.bootstrap.Container.superclass.constructor.call(this, config);
1089 * After the panel has been expand
1091 * @param {Roo.bootstrap.Container} this
1096 * After the panel has been collapsed
1098 * @param {Roo.bootstrap.Container} this
1103 * When a element is chick
1104 * @param {Roo.bootstrap.Container} this
1105 * @param {Roo.EventObject} e
1111 Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component, {
1129 getChildContainer : function() {
1135 if (this.panel.length) {
1136 return this.el.select('.panel-body',true).first();
1143 getAutoCreate : function(){
1146 tag : this.tag || 'div',
1150 if (this.jumbotron) {
1151 cfg.cls = 'jumbotron';
1156 // - this is applied by the parent..
1158 // cfg.cls = this.cls + '';
1161 if (this.sticky.length) {
1163 var bd = Roo.get(document.body);
1164 if (!bd.hasClass('bootstrap-sticky')) {
1165 bd.addClass('bootstrap-sticky');
1166 Roo.select('html',true).setStyle('height', '100%');
1169 cfg.cls += 'bootstrap-sticky-' + this.sticky;
1173 if (this.well.length) {
1174 switch (this.well) {
1177 cfg.cls +=' well well-' +this.well;
1186 cfg.cls += ' hidden';
1190 if (this.alert && ["success","info","warning", "danger"].indexOf(this.alert) > -1) {
1191 cfg.cls +=' alert alert-' + this.alert;
1196 if (this.panel.length) {
1197 cfg.cls += ' panel panel-' + this.panel;
1199 if (this.header.length) {
1203 if(this.expandable){
1205 cfg.cls = cfg.cls + ' expandable';
1209 cls: (this.expanded ? 'fa fa-minus' : 'fa fa-plus')
1217 cls : 'panel-title',
1218 html : (this.expandable ? ' ' : '') + this.header
1222 cls: 'panel-header-right',
1228 cls : 'panel-heading',
1229 style : this.expandable ? 'cursor: pointer' : '',
1237 cls : 'panel-body' + (this.expanded ? '' : ' hide'),
1242 if (this.footer.length) {
1244 cls : 'panel-footer',
1253 body.html = this.html || cfg.html;
1254 // prefix with the icons..
1256 body.html = '<i class="fa fa-'+this.fa + '"></i>' + body.html ;
1259 body.html = '<i class="glyphicon glyphicon-'+this.icon + '"></i>' + body.html ;
1264 if ((!this.cls || !this.cls.length) && (!cfg.cls || !cfg.cls.length)) {
1265 cfg.cls = 'container';
1271 initEvents: function()
1273 if(this.expandable){
1274 var headerEl = this.headerEl();
1277 headerEl.on('click', this.onToggleClick, this);
1282 this.el.on('click', this.onClick, this);
1287 onToggleClick : function()
1289 var headerEl = this.headerEl();
1305 if(this.fireEvent('expand', this)) {
1307 this.expanded = true;
1309 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).show();
1311 this.el.select('.panel-body',true).first().removeClass('hide');
1313 var toggleEl = this.toggleEl();
1319 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-minus']);
1324 collapse : function()
1326 if(this.fireEvent('collapse', this)) {
1328 this.expanded = false;
1330 //this.el.select('.panel-body',true).first().setVisibilityMode(Roo.Element.DISPLAY).hide();
1331 this.el.select('.panel-body',true).first().addClass('hide');
1333 var toggleEl = this.toggleEl();
1339 toggleEl.removeClass(['fa-minus', 'fa-plus']).addClass(['fa-plus']);
1343 toggleEl : function()
1345 if(!this.el || !this.panel.length || !this.header.length || !this.expandable){
1349 return this.el.select('.panel-heading .fa',true).first();
1352 headerEl : function()
1354 if(!this.el || !this.panel.length || !this.header.length){
1358 return this.el.select('.panel-heading',true).first()
1363 if(!this.el || !this.panel.length){
1367 return this.el.select('.panel-body',true).first()
1370 titleEl : function()
1372 if(!this.el || !this.panel.length || !this.header.length){
1376 return this.el.select('.panel-title',true).first();
1379 setTitle : function(v)
1381 var titleEl = this.titleEl();
1387 titleEl.dom.innerHTML = v;
1390 getTitle : function()
1393 var titleEl = this.titleEl();
1399 return titleEl.dom.innerHTML;
1402 setRightTitle : function(v)
1404 var t = this.el.select('.panel-header-right',true).first();
1410 t.dom.innerHTML = v;
1413 onClick : function(e)
1417 this.fireEvent('click', this, e);
1430 * @class Roo.bootstrap.Img
1431 * @extends Roo.bootstrap.Component
1432 * Bootstrap Img class
1433 * @cfg {Boolean} imgResponsive false | true
1434 * @cfg {String} border rounded | circle | thumbnail
1435 * @cfg {String} src image source
1436 * @cfg {String} alt image alternative text
1437 * @cfg {String} href a tag href
1438 * @cfg {String} target (_self|_blank|_parent|_top)target for a href.
1439 * @cfg {String} xsUrl xs image source
1440 * @cfg {String} smUrl sm image source
1441 * @cfg {String} mdUrl md image source
1442 * @cfg {String} lgUrl lg image source
1445 * Create a new Input
1446 * @param {Object} config The config object
1449 Roo.bootstrap.Img = function(config){
1450 Roo.bootstrap.Img.superclass.constructor.call(this, config);
1456 * The img click event for the img.
1457 * @param {Roo.EventObject} e
1463 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
1465 imgResponsive: true,
1475 getAutoCreate : function()
1477 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1478 return this.createSingleImg();
1483 cls: 'roo-image-responsive-group',
1488 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
1490 if(!_this[size + 'Url']){
1496 cls: (_this.imgResponsive) ? 'img-responsive' : '',
1497 html: _this.html || cfg.html,
1498 src: _this[size + 'Url']
1501 img.cls += ' roo-image-responsive-' + size;
1503 var s = ['xs', 'sm', 'md', 'lg'];
1505 s.splice(s.indexOf(size), 1);
1507 Roo.each(s, function(ss){
1508 img.cls += ' hidden-' + ss;
1511 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
1512 cfg.cls += ' img-' + _this.border;
1516 cfg.alt = _this.alt;
1529 a.target = _this.target;
1533 cfg.cn.push((_this.href) ? a : img);
1540 createSingleImg : function()
1544 cls: (this.imgResponsive) ? 'img-responsive' : '',
1546 src : 'about:blank' // just incase src get's set to undefined?!?
1549 cfg.html = this.html || cfg.html;
1551 cfg.src = this.src || cfg.src;
1553 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
1554 cfg.cls += ' img-' + this.border;
1571 a.target = this.target;
1576 return (this.href) ? a : cfg;
1579 initEvents: function()
1582 this.el.on('click', this.onClick, this);
1587 onClick : function(e)
1589 Roo.log('img onclick');
1590 this.fireEvent('click', this, e);
1593 * Sets the url of the image - used to update it
1594 * @param {String} url the url of the image
1597 setSrc : function(url)
1601 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
1602 this.el.dom.src = url;
1606 this.el.select('img', true).first().dom.src = url;
1622 * @class Roo.bootstrap.Link
1623 * @extends Roo.bootstrap.Component
1624 * Bootstrap Link Class
1625 * @cfg {String} alt image alternative text
1626 * @cfg {String} href a tag href
1627 * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
1628 * @cfg {String} html the content of the link.
1629 * @cfg {String} anchor name for the anchor link
1630 * @cfg {String} fa - favicon
1632 * @cfg {Boolean} preventDefault (true | false) default false
1636 * Create a new Input
1637 * @param {Object} config The config object
1640 Roo.bootstrap.Link = function(config){
1641 Roo.bootstrap.Link.superclass.constructor.call(this, config);
1647 * The img click event for the img.
1648 * @param {Roo.EventObject} e
1654 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component, {
1658 preventDefault: false,
1664 getAutoCreate : function()
1666 var html = this.html || '';
1668 if (this.fa !== false) {
1669 html = '<i class="fa fa-' + this.fa + '"></i>';
1674 // anchor's do not require html/href...
1675 if (this.anchor === false) {
1677 cfg.href = this.href || '#';
1679 cfg.name = this.anchor;
1680 if (this.html !== false || this.fa !== false) {
1683 if (this.href !== false) {
1684 cfg.href = this.href;
1688 if(this.alt !== false){
1693 if(this.target !== false) {
1694 cfg.target = this.target;
1700 initEvents: function() {
1702 if(!this.href || this.preventDefault){
1703 this.el.on('click', this.onClick, this);
1707 onClick : function(e)
1709 if(this.preventDefault){
1712 //Roo.log('img onclick');
1713 this.fireEvent('click', this, e);
1726 * @class Roo.bootstrap.Header
1727 * @extends Roo.bootstrap.Component
1728 * Bootstrap Header class
1729 * @cfg {String} html content of header
1730 * @cfg {Number} level (1|2|3|4|5|6) default 1
1733 * Create a new Header
1734 * @param {Object} config The config object
1738 Roo.bootstrap.Header = function(config){
1739 Roo.bootstrap.Header.superclass.constructor.call(this, config);
1742 Roo.extend(Roo.bootstrap.Header, Roo.bootstrap.Component, {
1750 getAutoCreate : function(){
1755 tag: 'h' + (1 *this.level),
1756 html: this.html || ''
1768 * Ext JS Library 1.1.1
1769 * Copyright(c) 2006-2007, Ext JS, LLC.
1771 * Originally Released Under LGPL - original licence link has changed is not relivant.
1774 * <script type="text/javascript">
1778 * @class Roo.bootstrap.MenuMgr
1779 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
1782 Roo.bootstrap.MenuMgr = function(){
1783 var menus, active, groups = {}, attached = false, lastShow = new Date();
1785 // private - called when first menu is created
1788 active = new Roo.util.MixedCollection();
1789 Roo.get(document).addKeyListener(27, function(){
1790 if(active.length > 0){
1798 if(active && active.length > 0){
1799 var c = active.clone();
1809 if(active.length < 1){
1810 Roo.get(document).un("mouseup", onMouseDown);
1818 var last = active.last();
1819 lastShow = new Date();
1822 Roo.get(document).on("mouseup", onMouseDown);
1827 //m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
1828 m.parentMenu.activeChild = m;
1829 }else if(last && last.isVisible()){
1830 //m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
1835 function onBeforeHide(m){
1837 m.activeChild.hide();
1839 if(m.autoHideTimer){
1840 clearTimeout(m.autoHideTimer);
1841 delete m.autoHideTimer;
1846 function onBeforeShow(m){
1847 var pm = m.parentMenu;
1848 if(!pm && !m.allowOtherMenus){
1850 }else if(pm && pm.activeChild && active != m){
1851 pm.activeChild.hide();
1855 // private this should really trigger on mouseup..
1856 function onMouseDown(e){
1857 Roo.log("on Mouse Up");
1859 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".dropdown-menu") && !e.getTarget('.user-menu')){
1860 Roo.log("MenuManager hideAll");
1869 function onBeforeCheck(mi, state){
1871 var g = groups[mi.group];
1872 for(var i = 0, l = g.length; i < l; i++){
1874 g[i].setChecked(false);
1883 * Hides all menus that are currently visible
1885 hideAll : function(){
1890 register : function(menu){
1894 menus[menu.id] = menu;
1895 menu.on("beforehide", onBeforeHide);
1896 menu.on("hide", onHide);
1897 menu.on("beforeshow", onBeforeShow);
1898 menu.on("show", onShow);
1900 if(g && menu.events["checkchange"]){
1904 groups[g].push(menu);
1905 menu.on("checkchange", onCheck);
1910 * Returns a {@link Roo.menu.Menu} object
1911 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
1912 * be used to generate and return a new Menu instance.
1914 get : function(menu){
1915 if(typeof menu == "string"){ // menu id
1917 }else if(menu.events){ // menu instance
1920 /*else if(typeof menu.length == 'number'){ // array of menu items?
1921 return new Roo.bootstrap.Menu({items:menu});
1922 }else{ // otherwise, must be a config
1923 return new Roo.bootstrap.Menu(menu);
1930 unregister : function(menu){
1931 delete menus[menu.id];
1932 menu.un("beforehide", onBeforeHide);
1933 menu.un("hide", onHide);
1934 menu.un("beforeshow", onBeforeShow);
1935 menu.un("show", onShow);
1937 if(g && menu.events["checkchange"]){
1938 groups[g].remove(menu);
1939 menu.un("checkchange", onCheck);
1944 registerCheckable : function(menuItem){
1945 var g = menuItem.group;
1950 groups[g].push(menuItem);
1951 menuItem.on("beforecheckchange", onBeforeCheck);
1956 unregisterCheckable : function(menuItem){
1957 var g = menuItem.group;
1959 groups[g].remove(menuItem);
1960 menuItem.un("beforecheckchange", onBeforeCheck);
1972 * @class Roo.bootstrap.Menu
1973 * @extends Roo.bootstrap.Component
1974 * Bootstrap Menu class - container for MenuItems
1975 * @cfg {String} type (dropdown|treeview|submenu) type of menu
1976 * @cfg {bool} hidden if the menu should be hidden when rendered.
1977 * @cfg {bool} stopEvent (true|false) Stop event after trigger press (default true)
1978 * @cfg {bool} isLink (true|false) the menu has link disable auto expand and collaspe (default false)
1982 * @param {Object} config The config object
1986 Roo.bootstrap.Menu = function(config){
1987 Roo.bootstrap.Menu.superclass.constructor.call(this, config);
1988 if (this.registerMenu && this.type != 'treeview') {
1989 Roo.bootstrap.MenuMgr.register(this);
1994 * Fires before this menu is displayed
1995 * @param {Roo.menu.Menu} this
2000 * Fires before this menu is hidden
2001 * @param {Roo.menu.Menu} this
2006 * Fires after this menu is displayed
2007 * @param {Roo.menu.Menu} this
2012 * Fires after this menu is hidden
2013 * @param {Roo.menu.Menu} this
2018 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
2019 * @param {Roo.menu.Menu} this
2020 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2021 * @param {Roo.EventObject} e
2026 * Fires when the mouse is hovering over this menu
2027 * @param {Roo.menu.Menu} this
2028 * @param {Roo.EventObject} e
2029 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2034 * Fires when the mouse exits this menu
2035 * @param {Roo.menu.Menu} this
2036 * @param {Roo.EventObject} e
2037 * @param {Roo.menu.Item} menuItem The menu item that was clicked
2042 * Fires when a menu item contained in this menu is clicked
2043 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
2044 * @param {Roo.EventObject} e
2048 this.menuitems = new Roo.util.MixedCollection(false, function(o) { return o.el.id; });
2051 Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component, {
2055 triggerEl : false, // is this set by component builder? -- it should really be fetched from parent()???
2058 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
2060 registerMenu : true,
2062 menuItems :false, // stores the menu items..
2072 getChildContainer : function() {
2076 getAutoCreate : function(){
2078 //if (['right'].indexOf(this.align)!==-1) {
2079 // cfg.cn[1].cls += ' pull-right'
2085 cls : 'dropdown-menu' ,
2086 style : 'z-index:1000'
2090 if (this.type === 'submenu') {
2091 cfg.cls = 'submenu active';
2093 if (this.type === 'treeview') {
2094 cfg.cls = 'treeview-menu';
2099 initEvents : function() {
2101 // Roo.log("ADD event");
2102 // Roo.log(this.triggerEl.dom);
2104 this.triggerEl.on('click', this.onTriggerClick, this);
2106 this.triggerEl.on(Roo.isTouch ? 'touchstart' : 'mouseup', this.onTriggerPress, this);
2108 this.triggerEl.addClass('dropdown-toggle');
2111 this.el.on('touchstart' , this.onTouch, this);
2113 this.el.on('click' , this.onClick, this);
2115 this.el.on("mouseover", this.onMouseOver, this);
2116 this.el.on("mouseout", this.onMouseOut, this);
2120 findTargetItem : function(e)
2122 var t = e.getTarget(".dropdown-menu-item", this.el, true);
2126 //Roo.log(t); Roo.log(t.id);
2128 //Roo.log(this.menuitems);
2129 return this.menuitems.get(t.id);
2131 //return this.items.get(t.menuItemId);
2137 onTouch : function(e)
2139 Roo.log("menu.onTouch");
2140 //e.stopEvent(); this make the user popdown broken
2144 onClick : function(e)
2146 Roo.log("menu.onClick");
2148 var t = this.findTargetItem(e);
2149 if(!t || t.isContainer){
2154 if (Roo.isTouch && e.type == 'touchstart' && t.menu && !t.disabled) {
2155 if(t == this.activeItem && t.shouldDeactivate(e)){
2156 this.activeItem.deactivate();
2157 delete this.activeItem;
2161 this.setActiveItem(t, true);
2169 Roo.log('pass click event');
2173 this.fireEvent("click", this, t, e);
2177 if(!t.href.length || t.href == '#'){
2178 (function() { _this.hide(); }).defer(100);
2183 onMouseOver : function(e){
2184 var t = this.findTargetItem(e);
2187 // if(t.canActivate && !t.disabled){
2188 // this.setActiveItem(t, true);
2192 this.fireEvent("mouseover", this, e, t);
2194 isVisible : function(){
2195 return !this.hidden;
2197 onMouseOut : function(e){
2198 var t = this.findTargetItem(e);
2201 // if(t == this.activeItem && t.shouldDeactivate(e)){
2202 // this.activeItem.deactivate();
2203 // delete this.activeItem;
2206 this.fireEvent("mouseout", this, e, t);
2211 * Displays this menu relative to another element
2212 * @param {String/HTMLElement/Roo.Element} element The element to align to
2213 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
2214 * the element (defaults to this.defaultAlign)
2215 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2217 show : function(el, pos, parentMenu){
2218 this.parentMenu = parentMenu;
2222 this.fireEvent("beforeshow", this);
2223 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
2226 * Displays this menu at a specific xy position
2227 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
2228 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
2230 showAt : function(xy, parentMenu, /* private: */_e){
2231 this.parentMenu = parentMenu;
2236 this.fireEvent("beforeshow", this);
2237 //xy = this.el.adjustForConstraints(xy);
2241 this.hideMenuItems();
2242 this.hidden = false;
2243 this.triggerEl.addClass('open');
2245 // reassign x when hitting right
2246 if(this.el.getWidth() + xy[0] >= Roo.lib.Dom.getViewWidth()){
2247 xy[0] = xy[0] - this.el.getWidth() + this.triggerEl.getWidth();
2250 // reassign y when hitting bottom
2251 if(this.el.getHeight() + xy[1] >= Roo.lib.Dom.getViewHeight()){
2252 xy[1] = xy[1] - this.el.getHeight() - this.triggerEl.getHeight();
2255 // but the list may align on trigger left or trigger top... should it be a properity?
2257 if(this.el.getStyle('top') != 'auto' && this.el.getStyle('top').slice(-1) != "%"){
2262 this.fireEvent("show", this);
2268 this.doFocus.defer(50, this);
2272 doFocus : function(){
2274 this.focusEl.focus();
2279 * Hides this menu and optionally all parent menus
2280 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
2282 hide : function(deep)
2285 this.hideMenuItems();
2286 if(this.el && this.isVisible()){
2287 this.fireEvent("beforehide", this);
2288 if(this.activeItem){
2289 this.activeItem.deactivate();
2290 this.activeItem = null;
2292 this.triggerEl.removeClass('open');;
2294 this.fireEvent("hide", this);
2296 if(deep === true && this.parentMenu){
2297 this.parentMenu.hide(true);
2301 onTriggerClick : function(e)
2303 Roo.log('trigger click');
2305 var target = e.getTarget();
2307 Roo.log(target.nodeName.toLowerCase());
2309 if(target.nodeName.toLowerCase() === 'i'){
2315 onTriggerPress : function(e)
2317 Roo.log('trigger press');
2318 //Roo.log(e.getTarget());
2319 // Roo.log(this.triggerEl.dom);
2321 // trigger only occurs on normal menu's -- if it's a treeview or dropdown... do not hide/show..
2322 var pel = Roo.get(e.getTarget());
2323 if (pel.findParent('.dropdown-menu') || pel.findParent('.treeview-menu') ) {
2324 Roo.log('is treeview or dropdown?');
2328 if(e.getTarget().nodeName.toLowerCase() !== 'i' && this.isLink){
2332 if (this.isVisible()) {
2337 this.show(this.triggerEl, false, false);
2340 if(this.stopEvent || e.getTarget().nodeName.toLowerCase() === 'i'){
2347 hideMenuItems : function()
2349 Roo.log("hide Menu Items");
2353 //$(backdrop).remove()
2354 this.el.select('.open',true).each(function(aa) {
2356 aa.removeClass('open');
2357 //var parent = getParent($(this))
2358 //var relatedTarget = { relatedTarget: this }
2360 //$parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
2361 //if (e.isDefaultPrevented()) return
2362 //$parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
2365 addxtypeChild : function (tree, cntr) {
2366 var comp= Roo.bootstrap.Menu.superclass.addxtypeChild.call(this, tree, cntr);
2368 this.menuitems.add(comp);
2380 this.getEl().dom.innerHTML = '';
2381 this.menuitems.clear();
2395 * @class Roo.bootstrap.MenuItem
2396 * @extends Roo.bootstrap.Component
2397 * Bootstrap MenuItem class
2398 * @cfg {String} html the menu label
2399 * @cfg {String} href the link
2400 * @cfg {Boolean} preventDefault do not trigger A href on clicks (default false).
2401 * @cfg {Boolean} isContainer is it a container - just returns a drop down item..
2402 * @cfg {Boolean} active used on sidebars to highlight active itesm
2403 * @cfg {String} fa favicon to show on left of menu item.
2404 * @cfg {Roo.bootsrap.Menu} menu the child menu.
2408 * Create a new MenuItem
2409 * @param {Object} config The config object
2413 Roo.bootstrap.MenuItem = function(config){
2414 Roo.bootstrap.MenuItem.superclass.constructor.call(this, config);
2419 * The raw click event for the entire grid.
2420 * @param {Roo.bootstrap.MenuItem} this
2421 * @param {Roo.EventObject} e
2427 Roo.extend(Roo.bootstrap.MenuItem, Roo.bootstrap.Component, {
2431 preventDefault: false,
2432 isContainer : false,
2436 getAutoCreate : function(){
2438 if(this.isContainer){
2441 cls: 'dropdown-menu-item'
2455 if (this.fa !== false) {
2458 cls : 'fa fa-' + this.fa
2467 cls: 'dropdown-menu-item',
2470 if (this.parent().type == 'treeview') {
2471 cfg.cls = 'treeview-menu';
2474 cfg.cls += ' active';
2479 anc.href = this.href || cfg.cn[0].href ;
2480 ctag.html = this.html || cfg.cn[0].html ;
2484 initEvents: function()
2486 if (this.parent().type == 'treeview') {
2487 this.el.select('a').on('click', this.onClick, this);
2491 this.menu.parentType = this.xtype;
2492 this.menu.triggerEl = this.el;
2493 this.menu = this.addxtype(Roo.apply({}, this.menu));
2497 onClick : function(e)
2499 Roo.log('item on click ');
2501 if(this.preventDefault){
2504 //this.parent().hideMenuItems();
2506 this.fireEvent('click', this, e);
2525 * @class Roo.bootstrap.MenuSeparator
2526 * @extends Roo.bootstrap.Component
2527 * Bootstrap MenuSeparator class
2530 * Create a new MenuItem
2531 * @param {Object} config The config object
2535 Roo.bootstrap.MenuSeparator = function(config){
2536 Roo.bootstrap.MenuSeparator.superclass.constructor.call(this, config);
2539 Roo.extend(Roo.bootstrap.MenuSeparator, Roo.bootstrap.Component, {
2541 getAutoCreate : function(){
2560 * @class Roo.bootstrap.Modal
2561 * @extends Roo.bootstrap.Component
2562 * Bootstrap Modal class
2563 * @cfg {String} title Title of dialog
2564 * @cfg {String} html - the body of the dialog (for simple ones) - you can also use template..
2565 * @cfg {Roo.Template} tmpl - a template with variables. to use it, add a handler in show:method adn
2566 * @cfg {Boolean} specificTitle default false
2567 * @cfg {Array} buttons Array of buttons or standard button set..
2568 * @cfg {String} buttonPosition (left|right|center) default right
2569 * @cfg {Boolean} animate default true
2570 * @cfg {Boolean} allow_close default true
2571 * @cfg {Boolean} fitwindow default false
2572 * @cfg {String} size (sm|lg) default empty
2573 * @cfg {Number} max_width set the max width of modal
2577 * Create a new Modal Dialog
2578 * @param {Object} config The config object
2581 Roo.bootstrap.Modal = function(config){
2582 Roo.bootstrap.Modal.superclass.constructor.call(this, config);
2587 * The raw btnclick event for the button
2588 * @param {Roo.EventObject} e
2593 * Fire when dialog resize
2594 * @param {Roo.bootstrap.Modal} this
2595 * @param {Roo.EventObject} e
2599 this.buttons = this.buttons || [];
2602 this.tmpl = Roo.factory(this.tmpl);
2607 Roo.extend(Roo.bootstrap.Modal, Roo.bootstrap.Component, {
2609 title : 'test dialog',
2619 specificTitle: false,
2621 buttonPosition: 'right',
2644 onRender : function(ct, position)
2646 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
2649 var cfg = Roo.apply({}, this.getAutoCreate());
2652 // cfg.name = typeof(this.name) == 'undefined' ? this.id : this.name;
2654 //if (!cfg.name.length) {
2658 cfg.cls += ' ' + this.cls;
2661 cfg.style = this.style;
2663 this.el = Roo.get(document.body).createChild(cfg, position);
2665 //var type = this.el.dom.type;
2668 if(this.tabIndex !== undefined){
2669 this.el.dom.setAttribute('tabIndex', this.tabIndex);
2672 this.dialogEl = this.el.select('.modal-dialog',true).first();
2673 this.bodyEl = this.el.select('.modal-body',true).first();
2674 this.closeEl = this.el.select('.modal-header .close', true).first();
2675 this.headerEl = this.el.select('.modal-header',true).first();
2676 this.titleEl = this.el.select('.modal-title',true).first();
2677 this.footerEl = this.el.select('.modal-footer',true).first();
2679 this.maskEl = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
2681 //this.el.addClass("x-dlg-modal");
2683 if (this.buttons.length) {
2684 Roo.each(this.buttons, function(bb) {
2685 var b = Roo.apply({}, bb);
2686 b.xns = b.xns || Roo.bootstrap;
2687 b.xtype = b.xtype || 'Button';
2688 if (typeof(b.listeners) == 'undefined') {
2689 b.listeners = { click : this.onButtonClick.createDelegate(this) };
2692 var btn = Roo.factory(b);
2694 btn.render(this.el.select('.modal-footer div').first());
2698 // render the children.
2701 if(typeof(this.items) != 'undefined'){
2702 var items = this.items;
2705 for(var i =0;i < items.length;i++) {
2706 nitems.push(this.addxtype(Roo.apply({}, items[i])));
2710 this.items = nitems;
2712 // where are these used - they used to be body/close/footer
2716 //this.el.addClass([this.fieldClass, this.cls]);
2720 getAutoCreate : function()
2724 html : this.html || ''
2729 cls : 'modal-title',
2733 if(this.specificTitle){
2739 if (this.allow_close) {
2751 if(this.size.length){
2752 size = 'modal-' + this.size;
2759 cls: "modal-dialog " + size,
2762 cls : "modal-content",
2765 cls : 'modal-header',
2770 cls : 'modal-footer',
2774 cls: 'btn-' + this.buttonPosition
2791 modal.cls += ' fade';
2797 getChildContainer : function() {
2802 getButtonContainer : function() {
2803 return this.el.select('.modal-footer div',true).first();
2806 initEvents : function()
2808 if (this.allow_close) {
2809 this.closeEl.on('click', this.hide, this);
2811 Roo.EventManager.onWindowResize(this.resize, this, true);
2818 this.maskEl.setSize(
2819 Roo.lib.Dom.getViewWidth(true),
2820 Roo.lib.Dom.getViewHeight(true)
2823 if (this.fitwindow) {
2825 this.width || Roo.lib.Dom.getViewportWidth(true) - 30,
2826 this.height || Roo.lib.Dom.getViewportHeight(true) - 60
2831 if(this.max_width !== 0) {
2833 var w = Math.min(this.max_width, Roo.lib.Dom.getViewportWidth(true) - 30);
2836 this.setSize(w, this.height);
2840 if(this.max_height) {
2841 this.setSize(w,Math.min(
2843 Roo.lib.Dom.getViewportHeight(true) - 60
2849 if(!this.fit_content) {
2850 this.setSize(w, Roo.lib.Dom.getViewportHeight(true) - 60);
2854 this.setSize(w, Math.min(
2856 this.headerEl.getHeight() +
2857 this.footerEl.getHeight() +
2858 this.getChildHeight(this.bodyEl.dom.childNodes),
2859 Roo.lib.Dom.getViewportHeight(true) - 60)
2865 setSize : function(w,h)
2876 if (!this.rendered) {
2880 //this.el.setStyle('display', 'block');
2881 this.el.removeClass('hideing');
2882 this.el.addClass('show');
2884 if(this.animate){ // element has 'fade' - so stuff happens after .3s ?- not sure why the delay?
2887 this.el.addClass('in');
2890 this.el.addClass('in');
2893 // not sure how we can show data in here..
2895 // this.getChildContainer().dom.innerHTML = this.tmpl.applyTemplate(this);
2898 Roo.get(document.body).addClass("x-body-masked");
2900 this.maskEl.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
2901 this.maskEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2902 this.maskEl.addClass('show');
2906 this.fireEvent('show', this);
2908 // set zindex here - otherwise it appears to be ignored...
2909 this.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
2912 this.items.forEach( function(e) {
2913 e.layout ? e.layout() : false;
2921 if(this.fireEvent("beforehide", this) !== false){
2922 this.maskEl.removeClass('show');
2923 Roo.get(document.body).removeClass("x-body-masked");
2924 this.el.removeClass('in');
2925 this.el.select('.modal-dialog', true).first().setStyle('transform','');
2927 if(this.animate){ // why
2928 this.el.addClass('hideing');
2930 if (!this.el.hasClass('hideing')) {
2931 return; // it's been shown again...
2933 this.el.removeClass('show');
2934 this.el.removeClass('hideing');
2938 this.el.removeClass('show');
2940 this.fireEvent('hide', this);
2943 isVisible : function()
2946 return this.el.hasClass('show') && !this.el.hasClass('hideing');
2950 addButton : function(str, cb)
2954 var b = Roo.apply({}, { html : str } );
2955 b.xns = b.xns || Roo.bootstrap;
2956 b.xtype = b.xtype || 'Button';
2957 if (typeof(b.listeners) == 'undefined') {
2958 b.listeners = { click : cb.createDelegate(this) };
2961 var btn = Roo.factory(b);
2963 btn.render(this.el.select('.modal-footer div').first());
2969 setDefaultButton : function(btn)
2971 //this.el.select('.modal-footer').()
2975 resizeTo: function(w,h)
2979 this.dialogEl.setWidth(w);
2980 if (this.diff === false) {
2981 this.diff = this.dialogEl.getHeight() - this.bodyEl.getHeight();
2984 this.bodyEl.setHeight(h - this.diff);
2986 this.fireEvent('resize', this);
2989 setContentSize : function(w, h)
2993 onButtonClick: function(btn,e)
2996 this.fireEvent('btnclick', btn.name, e);
2999 * Set the title of the Dialog
3000 * @param {String} str new Title
3002 setTitle: function(str) {
3003 this.titleEl.dom.innerHTML = str;
3006 * Set the body of the Dialog
3007 * @param {String} str new Title
3009 setBody: function(str) {
3010 this.bodyEl.dom.innerHTML = str;
3013 * Set the body of the Dialog using the template
3014 * @param {Obj} data - apply this data to the template and replace the body contents.
3016 applyBody: function(obj)
3019 Roo.log("Error - using apply Body without a template");
3022 this.tmpl.overwrite(this.bodyEl, obj);
3025 getChildHeight : function(child_nodes)
3029 child_nodes.length == 0
3034 var child_height = 0;
3036 for(var i = 0; i < child_nodes.length; i++) {
3039 * for modal with tabs...
3040 if(child_nodes[i].classList.contains('roo-layout-panel')) {
3042 var layout_childs = child_nodes[i].childNodes;
3044 for(var j = 0; j < layout_childs.length; j++) {
3046 if(layout_childs[j].classList.contains('roo-layout-panel-body')) {
3048 var layout_body_childs = layout_childs[j].childNodes;
3050 for(var k = 0; k < layout_body_childs.length; k++) {
3052 if(layout_body_childs[k].classList.contains('navbar')) {
3053 child_height += layout_body_childs[k].offsetHeight;
3057 if(layout_body_childs[k].classList.contains('roo-layout-tabs-body')) {
3059 var layout_body_tab_childs = layout_body_childs[k].childNodes;
3061 for(var m = 0; m < layout_body_tab_childs.length; m++) {
3063 if(layout_body_tab_childs[m].classList.contains('roo-layout-active-content')) {
3064 child_height += this.getChildHeight(layout_body_tab_childs[m].childNodes);
3079 child_height += child_nodes[i].offsetHeight;
3080 // Roo.log(child_nodes[i].offsetHeight);
3083 return child_height;
3089 Roo.apply(Roo.bootstrap.Modal, {
3091 * Button config that displays a single OK button
3100 * Button config that displays Yes and No buttons
3116 * Button config that displays OK and Cancel buttons
3131 * Button config that displays Yes, No and Cancel buttons
3155 * messagebox - can be used as a replace
3159 * @class Roo.MessageBox
3160 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
3164 Roo.Msg.alert('Status', 'Changes saved successfully.');
3166 // Prompt for user data:
3167 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
3169 // process text value...
3173 // Show a dialog using config options:
3175 title:'Save Changes?',
3176 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
3177 buttons: Roo.Msg.YESNOCANCEL,
3184 Roo.bootstrap.MessageBox = function(){
3185 var dlg, opt, mask, waitTimer;
3186 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
3187 var buttons, activeTextEl, bwidth;
3191 var handleButton = function(button){
3193 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
3197 var handleHide = function(){
3199 dlg.el.removeClass(opt.cls);
3202 // Roo.TaskMgr.stop(waitTimer);
3203 // waitTimer = null;
3208 var updateButtons = function(b){
3211 buttons["ok"].hide();
3212 buttons["cancel"].hide();
3213 buttons["yes"].hide();
3214 buttons["no"].hide();
3215 //dlg.footer.dom.style.display = 'none';
3218 dlg.footerEl.dom.style.display = '';
3219 for(var k in buttons){
3220 if(typeof buttons[k] != "function"){
3223 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.bootstrap.MessageBox.buttonText[k]);
3224 width += buttons[k].el.getWidth()+15;
3234 var handleEsc = function(d, k, e){
3235 if(opt && opt.closable !== false){
3245 * Returns a reference to the underlying {@link Roo.BasicDialog} element
3246 * @return {Roo.BasicDialog} The BasicDialog element
3248 getDialog : function(){
3250 dlg = new Roo.bootstrap.Modal( {
3253 //constraintoviewport:false,
3255 //collapsible : false,
3260 //buttonAlign:"center",
3261 closeClick : function(){
3262 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
3265 handleButton("cancel");
3270 dlg.on("hide", handleHide);
3272 //dlg.addKeyListener(27, handleEsc);
3274 this.buttons = buttons;
3275 var bt = this.buttonText;
3276 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
3277 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
3278 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
3279 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
3281 bodyEl = dlg.bodyEl.createChild({
3283 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" />' +
3284 '<textarea class="roo-mb-textarea"></textarea>' +
3285 '<div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
3287 msgEl = bodyEl.dom.firstChild;
3288 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
3289 textboxEl.enableDisplayMode();
3290 textboxEl.addKeyListener([10,13], function(){
3291 if(dlg.isVisible() && opt && opt.buttons){
3294 }else if(opt.buttons.yes){
3295 handleButton("yes");
3299 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
3300 textareaEl.enableDisplayMode();
3301 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
3302 progressEl.enableDisplayMode();
3304 // This is supposed to be the progessElement.. but I think it's controlling the height of everything..
3305 var pf = progressEl.dom.firstChild;
3307 pp = Roo.get(pf.firstChild);
3308 pp.setHeight(pf.offsetHeight);
3316 * Updates the message box body text
3317 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
3318 * the XHTML-compliant non-breaking space character '&#160;')
3319 * @return {Roo.MessageBox} This message box
3321 updateText : function(text)
3323 if(!dlg.isVisible() && !opt.width){
3324 dlg.dialogEl.setStyle({ 'max-width' : this.maxWidth});
3325 // dlg.resizeTo(this.maxWidth, 100); // forcing the height breaks long alerts()
3327 msgEl.innerHTML = text || ' ';
3329 var cw = Math.max(msgEl.offsetWidth, msgEl.parentNode.scrollWidth);
3330 //Roo.log("guesed size: " + JSON.stringify([cw,msgEl.offsetWidth, msgEl.parentNode.scrollWidth]));
3332 Math.min(opt.width || cw , this.maxWidth),
3333 Math.max(opt.minWidth || this.minWidth, bwidth)
3336 activeTextEl.setWidth(w);
3338 if(dlg.isVisible()){
3339 dlg.fixedcenter = false;
3341 // to big, make it scroll. = But as usual stupid IE does not support
3344 if ( bodyEl.getHeight() > (Roo.lib.Dom.getViewHeight() - 100)) {
3345 bodyEl.setHeight ( Roo.lib.Dom.getViewHeight() - 100 );
3346 bodyEl.dom.style.overflowY = 'auto' + ( Roo.isIE ? '' : ' !important');
3348 bodyEl.dom.style.height = '';
3349 bodyEl.dom.style.overflowY = '';
3352 bodyEl.dom.style.get = 'auto' + ( Roo.isIE ? '' : ' !important');
3354 bodyEl.dom.style.overflowX = '';
3357 dlg.setContentSize(w, bodyEl.getHeight());
3358 if(dlg.isVisible()){
3359 dlg.fixedcenter = true;
3365 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
3366 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
3367 * @param {Number} value Any number between 0 and 1 (e.g., .5)
3368 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
3369 * @return {Roo.MessageBox} This message box
3371 updateProgress : function(value, text){
3373 this.updateText(text);
3376 if (pp) { // weird bug on my firefox - for some reason this is not defined
3377 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
3378 pp.setHeight(Math.floor(progressEl.dom.firstChild.offsetHeight));
3384 * Returns true if the message box is currently displayed
3385 * @return {Boolean} True if the message box is visible, else false
3387 isVisible : function(){
3388 return dlg && dlg.isVisible();
3392 * Hides the message box if it is displayed
3395 if(this.isVisible()){
3401 * Displays a new message box, or reinitializes an existing message box, based on the config options
3402 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
3403 * The following config object properties are supported:
3405 Property Type Description
3406 ---------- --------------- ------------------------------------------------------------------------------------
3407 animEl String/Element An id or Element from which the message box should animate as it opens and
3408 closes (defaults to undefined)
3409 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
3410 cancel:'Bar'}), or false to not show any buttons (defaults to false)
3411 closable Boolean False to hide the top-right close button (defaults to true). Note that
3412 progress and wait dialogs will ignore this property and always hide the
3413 close button as they can only be closed programmatically.
3414 cls String A custom CSS class to apply to the message box element
3415 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
3416 displayed (defaults to 75)
3417 fn Function A callback function to execute after closing the dialog. The arguments to the
3418 function will be btn (the name of the button that was clicked, if applicable,
3419 e.g. "ok"), and text (the value of the active text field, if applicable).
3420 Progress and wait dialogs will ignore this option since they do not respond to
3421 user actions and can only be closed programmatically, so any required function
3422 should be called by the same code after it closes the dialog.
3423 icon String A CSS class that provides a background image to be used as an icon for
3424 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
3425 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
3426 minWidth Number The minimum width in pixels of the message box (defaults to 100)
3427 modal Boolean False to allow user interaction with the page while the message box is
3428 displayed (defaults to true)
3429 msg String A string that will replace the existing message box body text (defaults
3430 to the XHTML-compliant non-breaking space character ' ')
3431 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
3432 progress Boolean True to display a progress bar (defaults to false)
3433 progressText String The text to display inside the progress bar if progress = true (defaults to '')
3434 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
3435 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
3436 title String The title text
3437 value String The string value to set into the active textbox element if displayed
3438 wait Boolean True to display a progress bar (defaults to false)
3439 width Number The width of the dialog in pixels
3446 msg: 'Please enter your address:',
3448 buttons: Roo.MessageBox.OKCANCEL,
3451 animEl: 'addAddressBtn'
3454 * @param {Object} config Configuration options
3455 * @return {Roo.MessageBox} This message box
3457 show : function(options)
3460 // this causes nightmares if you show one dialog after another
3461 // especially on callbacks..
3463 if(this.isVisible()){
3466 Roo.log("[Roo.Messagebox] Show called while message displayed:" );
3467 Roo.log("Old Dialog Message:" + msgEl.innerHTML );
3468 Roo.log("New Dialog Message:" + options.msg )
3469 //this.alert("ERROR", "Multiple dialogs where displayed at the same time");
3470 //throw "Roo.MessageBox ERROR : Multiple dialogs where displayed at the same time";
3473 var d = this.getDialog();
3475 d.setTitle(opt.title || " ");
3476 d.closeEl.setDisplayed(opt.closable !== false);
3477 activeTextEl = textboxEl;
3478 opt.prompt = opt.prompt || (opt.multiline ? true : false);
3483 textareaEl.setHeight(typeof opt.multiline == "number" ?
3484 opt.multiline : this.defaultTextHeight);
3485 activeTextEl = textareaEl;
3494 progressEl.setDisplayed(opt.progress === true);
3495 this.updateProgress(0);
3496 activeTextEl.dom.value = opt.value || "";
3498 dlg.setDefaultButton(activeTextEl);
3500 var bs = opt.buttons;
3504 }else if(bs && bs.yes){
3505 db = buttons["yes"];
3507 dlg.setDefaultButton(db);
3509 bwidth = updateButtons(opt.buttons);
3510 this.updateText(opt.msg);
3512 d.el.addClass(opt.cls);
3514 d.proxyDrag = opt.proxyDrag === true;
3515 d.modal = opt.modal !== false;
3516 d.mask = opt.modal !== false ? mask : false;
3518 // force it to the end of the z-index stack so it gets a cursor in FF
3519 document.body.appendChild(dlg.el.dom);
3520 d.animateTarget = null;
3521 d.show(options.animEl);
3527 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
3528 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
3529 * and closing the message box when the process is complete.
3530 * @param {String} title The title bar text
3531 * @param {String} msg The message box body text
3532 * @return {Roo.MessageBox} This message box
3534 progress : function(title, msg){
3541 minWidth: this.minProgressWidth,
3548 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
3549 * If a callback function is passed it will be called after the user clicks the button, and the
3550 * id of the button that was clicked will be passed as the only parameter to the callback
3551 * (could also be the top-right close button).
3552 * @param {String} title The title bar text
3553 * @param {String} msg The message box body text
3554 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3555 * @param {Object} scope (optional) The scope of the callback function
3556 * @return {Roo.MessageBox} This message box
3558 alert : function(title, msg, fn, scope)
3573 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
3574 * interaction while waiting for a long-running process to complete that does not have defined intervals.
3575 * You are responsible for closing the message box when the process is complete.
3576 * @param {String} msg The message box body text
3577 * @param {String} title (optional) The title bar text
3578 * @return {Roo.MessageBox} This message box
3580 wait : function(msg, title){
3591 waitTimer = Roo.TaskMgr.start({
3593 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
3601 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
3602 * If a callback function is passed it will be called after the user clicks either button, and the id of the
3603 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
3604 * @param {String} title The title bar text
3605 * @param {String} msg The message box body text
3606 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3607 * @param {Object} scope (optional) The scope of the callback function
3608 * @return {Roo.MessageBox} This message box
3610 confirm : function(title, msg, fn, scope){
3614 buttons: this.YESNO,
3623 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
3624 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
3625 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
3626 * (could also be the top-right close button) and the text that was entered will be passed as the two
3627 * parameters to the callback.
3628 * @param {String} title The title bar text
3629 * @param {String} msg The message box body text
3630 * @param {Function} fn (optional) The callback function invoked after the message box is closed
3631 * @param {Object} scope (optional) The scope of the callback function
3632 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
3633 * property, or the height in pixels to create the textbox (defaults to false / single-line)
3634 * @return {Roo.MessageBox} This message box
3636 prompt : function(title, msg, fn, scope, multiline){
3640 buttons: this.OKCANCEL,
3645 multiline: multiline,
3652 * Button config that displays a single OK button
3657 * Button config that displays Yes and No buttons
3660 YESNO : {yes:true, no:true},
3662 * Button config that displays OK and Cancel buttons
3665 OKCANCEL : {ok:true, cancel:true},
3667 * Button config that displays Yes, No and Cancel buttons
3670 YESNOCANCEL : {yes:true, no:true, cancel:true},
3673 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
3676 defaultTextHeight : 75,
3678 * The maximum width in pixels of the message box (defaults to 600)
3683 * The minimum width in pixels of the message box (defaults to 100)
3688 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
3689 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
3692 minProgressWidth : 250,
3694 * An object containing the default button text strings that can be overriden for localized language support.
3695 * Supported properties are: ok, cancel, yes and no.
3696 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
3709 * Shorthand for {@link Roo.MessageBox}
3711 Roo.MessageBox = Roo.MessageBox || Roo.bootstrap.MessageBox;
3712 Roo.Msg = Roo.Msg || Roo.MessageBox;
3721 * @class Roo.bootstrap.Navbar
3722 * @extends Roo.bootstrap.Component
3723 * Bootstrap Navbar class
3726 * Create a new Navbar
3727 * @param {Object} config The config object
3731 Roo.bootstrap.Navbar = function(config){
3732 Roo.bootstrap.Navbar.superclass.constructor.call(this, config);
3736 * @event beforetoggle
3737 * Fire before toggle the menu
3738 * @param {Roo.EventObject} e
3740 "beforetoggle" : true
3744 Roo.extend(Roo.bootstrap.Navbar, Roo.bootstrap.Component, {
3753 getAutoCreate : function(){
3756 throw { message : "nav bar is now a abstract base class - use NavSimplebar / NavHeaderbar / NavSidebar etc..."};
3760 initEvents :function ()
3762 //Roo.log(this.el.select('.navbar-toggle',true));
3763 this.el.select('.navbar-toggle',true).on('click', function() {
3764 if(this.fireEvent('beforetoggle', this) !== false){
3765 this.el.select('.navbar-collapse',true).toggleClass('in');
3775 this.maskEl = Roo.DomHelper.append(this.el, mark, true);
3777 var size = this.el.getSize();
3778 this.maskEl.setSize(size.width, size.height);
3779 this.maskEl.enableDisplayMode("block");
3788 getChildContainer : function()
3790 if (this.el.select('.collapse').getCount()) {
3791 return this.el.select('.collapse',true).first();
3824 * @class Roo.bootstrap.NavSimplebar
3825 * @extends Roo.bootstrap.Navbar
3826 * Bootstrap Sidebar class
3828 * @cfg {Boolean} inverse is inverted color
3830 * @cfg {String} type (nav | pills | tabs)
3831 * @cfg {Boolean} arrangement stacked | justified
3832 * @cfg {String} align (left | right) alignment
3834 * @cfg {Boolean} main (true|false) main nav bar? default false
3835 * @cfg {Boolean} loadMask (true|false) loadMask on the bar
3837 * @cfg {String} tag (header|footer|nav|div) default is nav
3843 * Create a new Sidebar
3844 * @param {Object} config The config object
3848 Roo.bootstrap.NavSimplebar = function(config){
3849 Roo.bootstrap.NavSimplebar.superclass.constructor.call(this, config);
3852 Roo.extend(Roo.bootstrap.NavSimplebar, Roo.bootstrap.Navbar, {
3868 getAutoCreate : function(){
3872 tag : this.tag || 'div',
3885 this.type = this.type || 'nav';
3886 if (['tabs','pills'].indexOf(this.type)!==-1) {
3887 cfg.cn[0].cls += ' nav-' + this.type
3891 if (this.type!=='nav') {
3892 Roo.log('nav type must be nav/tabs/pills')
3894 cfg.cn[0].cls += ' navbar-nav'
3900 if (['stacked','justified'].indexOf(this.arrangement)!==-1) {
3901 cfg.cn[0].cls += ' nav-' + this.arrangement;
3905 if (this.align === 'right') {
3906 cfg.cn[0].cls += ' navbar-right';
3910 cfg.cls += ' navbar-inverse';
3937 * @class Roo.bootstrap.NavHeaderbar
3938 * @extends Roo.bootstrap.NavSimplebar
3939 * Bootstrap Sidebar class
3941 * @cfg {String} brand what is brand
3942 * @cfg {String} position (fixed-top|fixed-bottom|static-top) position
3943 * @cfg {String} brand_href href of the brand
3944 * @cfg {Boolean} srButton generate the (screen reader / mobile) sr-only button default true
3945 * @cfg {Boolean} autohide a top nav bar header that hides on scroll.
3946 * @cfg {Boolean} desktopCenter should the header be centered on desktop using a container class
3947 * @cfg {Roo.bootstrap.Row} mobilerow - a row to display on mobile only..
3950 * Create a new Sidebar
3951 * @param {Object} config The config object
3955 Roo.bootstrap.NavHeaderbar = function(config){
3956 Roo.bootstrap.NavHeaderbar.superclass.constructor.call(this, config);
3960 Roo.extend(Roo.bootstrap.NavHeaderbar, Roo.bootstrap.NavSimplebar, {
3967 desktopCenter : false,
3970 getAutoCreate : function(){
3973 tag: this.nav || 'nav',
3980 if (this.desktopCenter) {
3981 cn.push({cls : 'container', cn : []});
3988 cls: 'navbar-header',
3993 cls: 'navbar-toggle',
3994 'data-toggle': 'collapse',
3999 html: 'Toggle navigation'
4021 cls: 'collapse navbar-collapse',
4025 cfg.cls += this.inverse ? ' navbar-inverse' : ' navbar-default';
4027 if (['fixed-top','fixed-bottom','static-top'].indexOf(this.position)>-1) {
4028 cfg.cls += ' navbar-' + this.position;
4030 // tag can override this..
4032 cfg.tag = this.tag || (this.position == 'fixed-bottom' ? 'footer' : 'header');
4035 if (this.brand !== '') {
4038 href: this.brand_href ? this.brand_href : '#',
4039 cls: 'navbar-brand',
4047 cfg.cls += ' main-nav';
4055 getHeaderChildContainer : function()
4057 if (this.srButton && this.el.select('.navbar-header').getCount()) {
4058 return this.el.select('.navbar-header',true).first();
4061 return this.getChildContainer();
4065 initEvents : function()
4067 Roo.bootstrap.NavHeaderbar.superclass.initEvents.call(this);
4069 if (this.autohide) {
4074 Roo.get(document).on('scroll',function(e) {
4075 var ns = Roo.get(document).getScroll().top;
4076 var os = prevScroll;
4080 ft.removeClass('slideDown');
4081 ft.addClass('slideUp');
4084 ft.removeClass('slideUp');
4085 ft.addClass('slideDown');
4106 * @class Roo.bootstrap.NavSidebar
4107 * @extends Roo.bootstrap.Navbar
4108 * Bootstrap Sidebar class
4111 * Create a new Sidebar
4112 * @param {Object} config The config object
4116 Roo.bootstrap.NavSidebar = function(config){
4117 Roo.bootstrap.NavSidebar.superclass.constructor.call(this, config);
4120 Roo.extend(Roo.bootstrap.NavSidebar, Roo.bootstrap.Navbar, {
4122 sidebar : true, // used by Navbar Item and NavbarGroup at present...
4124 getAutoCreate : function(){
4129 cls: 'sidebar sidebar-nav'
4151 * @class Roo.bootstrap.NavGroup
4152 * @extends Roo.bootstrap.Component
4153 * Bootstrap NavGroup class
4154 * @cfg {String} align (left|right)
4155 * @cfg {Boolean} inverse
4156 * @cfg {String} type (nav|pills|tab) default nav
4157 * @cfg {String} navId - reference Id for navbar.
4161 * Create a new nav group
4162 * @param {Object} config The config object
4165 Roo.bootstrap.NavGroup = function(config){
4166 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
4169 Roo.bootstrap.NavGroup.register(this);
4173 * Fires when the active item changes
4174 * @param {Roo.bootstrap.NavGroup} this
4175 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
4176 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
4183 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
4194 getAutoCreate : function()
4196 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
4203 if (['tabs','pills'].indexOf(this.type)!==-1) {
4204 cfg.cls += ' nav-' + this.type
4206 if (this.type!=='nav') {
4207 Roo.log('nav type must be nav/tabs/pills')
4209 cfg.cls += ' navbar-nav'
4212 if (this.parent() && this.parent().sidebar) {
4215 cls: 'dashboard-menu sidebar-menu'
4221 if (this.form === true) {
4227 if (this.align === 'right') {
4228 cfg.cls += ' navbar-right';
4230 cfg.cls += ' navbar-left';
4234 if (this.align === 'right') {
4235 cfg.cls += ' navbar-right';
4239 cfg.cls += ' navbar-inverse';
4247 * sets the active Navigation item
4248 * @param {Roo.bootstrap.NavItem} the new current navitem
4250 setActiveItem : function(item)
4253 Roo.each(this.navItems, function(v){
4258 v.setActive(false, true);
4265 item.setActive(true, true);
4266 this.fireEvent('changed', this, item, prev);
4271 * gets the active Navigation item
4272 * @return {Roo.bootstrap.NavItem} the current navitem
4274 getActive : function()
4278 Roo.each(this.navItems, function(v){
4289 indexOfNav : function()
4293 Roo.each(this.navItems, function(v,i){
4304 * adds a Navigation item
4305 * @param {Roo.bootstrap.NavItem} the navitem to add
4307 addItem : function(cfg)
4309 var cn = new Roo.bootstrap.NavItem(cfg);
4311 cn.parentId = this.id;
4312 cn.onRender(this.el, null);
4316 * register a Navigation item
4317 * @param {Roo.bootstrap.NavItem} the navitem to add
4319 register : function(item)
4321 this.navItems.push( item);
4322 item.navId = this.navId;
4327 * clear all the Navigation item
4330 clearAll : function()
4333 this.el.dom.innerHTML = '';
4336 getNavItem: function(tabId)
4339 Roo.each(this.navItems, function(e) {
4340 if (e.tabId == tabId) {
4350 setActiveNext : function()
4352 var i = this.indexOfNav(this.getActive());
4353 if (i > this.navItems.length) {
4356 this.setActiveItem(this.navItems[i+1]);
4358 setActivePrev : function()
4360 var i = this.indexOfNav(this.getActive());
4364 this.setActiveItem(this.navItems[i-1]);
4366 clearWasActive : function(except) {
4367 Roo.each(this.navItems, function(e) {
4368 if (e.tabId != except.tabId && e.was_active) {
4369 e.was_active = false;
4376 getWasActive : function ()
4379 Roo.each(this.navItems, function(e) {
4394 Roo.apply(Roo.bootstrap.NavGroup, {
4398 * register a Navigation Group
4399 * @param {Roo.bootstrap.NavGroup} the navgroup to add
4401 register : function(navgrp)
4403 this.groups[navgrp.navId] = navgrp;
4407 * fetch a Navigation Group based on the navigation ID
4408 * @param {string} the navgroup to add
4409 * @returns {Roo.bootstrap.NavGroup} the navgroup
4411 get: function(navId) {
4412 if (typeof(this.groups[navId]) == 'undefined') {
4414 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
4416 return this.groups[navId] ;
4431 * @class Roo.bootstrap.NavItem
4432 * @extends Roo.bootstrap.Component
4433 * Bootstrap Navbar.NavItem class
4434 * @cfg {String} href link to
4435 * @cfg {String} html content of button
4436 * @cfg {String} badge text inside badge
4437 * @cfg {String} badgecls (bg-green|bg-red|bg-yellow)the extra classes for the badge
4438 * @cfg {String} glyphicon name of glyphicon
4439 * @cfg {String} icon name of font awesome icon
4440 * @cfg {Boolean} active Is item active
4441 * @cfg {Boolean} disabled Is item disabled
4443 * @cfg {Boolean} preventDefault (true | false) default false
4444 * @cfg {String} tabId the tab that this item activates.
4445 * @cfg {String} tagtype (a|span) render as a href or span?
4446 * @cfg {Boolean} animateRef (true|false) link to element default false
4449 * Create a new Navbar Item
4450 * @param {Object} config The config object
4452 Roo.bootstrap.NavItem = function(config){
4453 Roo.bootstrap.NavItem.superclass.constructor.call(this, config);
4458 * The raw click event for the entire grid.
4459 * @param {Roo.EventObject} e
4464 * Fires when the active item active state changes
4465 * @param {Roo.bootstrap.NavItem} this
4466 * @param {boolean} state the new state
4472 * Fires when scroll to element
4473 * @param {Roo.bootstrap.NavItem} this
4474 * @param {Object} options
4475 * @param {Roo.EventObject} e
4483 Roo.extend(Roo.bootstrap.NavItem, Roo.bootstrap.Component, {
4491 preventDefault : false,
4498 getAutoCreate : function(){
4507 cfg.cls = typeof(cfg.cls) == 'undefined' ? 'active' : cfg.cls + ' active';
4509 if (this.disabled) {
4510 cfg.cls += ' disabled';
4513 if (this.href || this.html || this.glyphicon || this.icon) {
4517 href : this.href || "#",
4518 html: this.html || ''
4523 cfg.cn[0].html = '<i class="'+this.icon+'"></i> <span>' + cfg.cn[0].html + '</span>'
4526 if(this.glyphicon) {
4527 cfg.cn[0].html = '<span class="glyphicon glyphicon-' + this.glyphicon + '"></span> ' + cfg.cn[0].html;
4532 cfg.cn[0].html += " <span class='caret'></span>";
4536 if (this.badge !== '') {
4538 cfg.cn[0].html += ' <span class="badge">' + this.badge + '</span>';
4546 initEvents: function()
4548 if (typeof (this.menu) != 'undefined') {
4549 this.menu.parentType = this.xtype;
4550 this.menu.triggerEl = this.el;
4551 this.menu = this.addxtype(Roo.apply({}, this.menu));
4554 this.el.select('a',true).on('click', this.onClick, this);
4556 if(this.tagtype == 'span'){
4557 this.el.select('span',true).on('click', this.onClick, this);
4560 // at this point parent should be available..
4561 this.parent().register(this);
4564 onClick : function(e)
4566 if (e.getTarget('.dropdown-menu-item')) {
4567 // did you click on a menu itemm.... - then don't trigger onclick..
4572 this.preventDefault ||
4575 Roo.log("NavItem - prevent Default?");
4579 if (this.disabled) {
4583 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4584 if (tg && tg.transition) {
4585 Roo.log("waiting for the transitionend");
4591 //Roo.log("fire event clicked");
4592 if(this.fireEvent('click', this, e) === false){
4596 if(this.tagtype == 'span'){
4600 //Roo.log(this.href);
4601 var ael = this.el.select('a',true).first();
4604 if(ael && this.animateRef && this.href.indexOf('#') > -1){
4605 //Roo.log(["test:",ael.dom.href.split("#")[0], document.location.toString().split("#")[0]]);
4606 if (ael.dom.href.split("#")[0] != document.location.toString().split("#")[0]) {
4607 return; // ignore... - it's a 'hash' to another page.
4609 Roo.log("NavItem - prevent Default?");
4611 this.scrollToElement(e);
4615 var p = this.parent();
4617 if (['tabs','pills'].indexOf(p.type)!==-1) {
4618 if (typeof(p.setActiveItem) !== 'undefined') {
4619 p.setActiveItem(this);
4623 // if parent is a navbarheader....- and link is probably a '#' page ref.. then remove the expanded menu.
4624 if (p.parentType == 'NavHeaderbar' && !this.menu) {
4625 // remove the collapsed menu expand...
4626 p.parent().el.select('.navbar-collapse',true).removeClass('in');
4630 isActive: function () {
4633 setActive : function(state, fire, is_was_active)
4635 if (this.active && !state && this.navId) {
4636 this.was_active = true;
4637 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4639 nv.clearWasActive(this);
4643 this.active = state;
4646 this.el.removeClass('active');
4647 } else if (!this.el.hasClass('active')) {
4648 this.el.addClass('active');
4651 this.fireEvent('changed', this, state);
4654 // show a panel if it's registered and related..
4656 if (!this.navId || !this.tabId || !state || is_was_active) {
4660 var tg = Roo.bootstrap.TabGroup.get(this.navId);
4664 var pan = tg.getPanelByName(this.tabId);
4668 // if we can not flip to new panel - go back to old nav highlight..
4669 if (false == tg.showPanel(pan)) {
4670 var nv = Roo.bootstrap.NavGroup.get(this.navId);
4672 var onav = nv.getWasActive();
4674 onav.setActive(true, false, true);
4683 // this should not be here...
4684 setDisabled : function(state)
4686 this.disabled = state;
4688 this.el.removeClass('disabled');
4689 } else if (!this.el.hasClass('disabled')) {
4690 this.el.addClass('disabled');
4696 * Fetch the element to display the tooltip on.
4697 * @return {Roo.Element} defaults to this.el
4699 tooltipEl : function()
4701 return this.el.select('' + this.tagtype + '', true).first();
4704 scrollToElement : function(e)
4706 var c = document.body;
4709 * Firefox / IE places the overflow at the html level, unless specifically styled to behave differently.
4711 if(Roo.isFirefox || Roo.isIE || Roo.isIE11){
4712 c = document.documentElement;
4715 var target = Roo.get(c).select('a[name=' + this.href.split('#')[1] +']', true).first();
4721 var o = target.calcOffsetsTo(c);
4728 this.fireEvent('scrollto', this, options, e);
4730 Roo.get(c).scrollTo('top', options.value, true);
4743 * <span> icon </span>
4744 * <span> text </span>
4745 * <span>badge </span>
4749 * @class Roo.bootstrap.NavSidebarItem
4750 * @extends Roo.bootstrap.NavItem
4751 * Bootstrap Navbar.NavSidebarItem class
4752 * {String} badgeWeight (default|primary|success|info|warning|danger)the extra classes for the badge
4753 * {Boolean} open is the menu open
4754 * {Boolean} buttonView use button as the tigger el rather that a (default false)
4755 * {String} buttonWeight (default|primary|success|info|warning|danger)the extra classes for the button
4756 * {String} buttonSize (sm|md|lg)the extra classes for the button
4757 * {Boolean} showArrow show arrow next to the text (default true)
4759 * Create a new Navbar Button
4760 * @param {Object} config The config object
4762 Roo.bootstrap.NavSidebarItem = function(config){
4763 Roo.bootstrap.NavSidebarItem.superclass.constructor.call(this, config);
4768 * The raw click event for the entire grid.
4769 * @param {Roo.EventObject} e
4774 * Fires when the active item active state changes
4775 * @param {Roo.bootstrap.NavSidebarItem} this
4776 * @param {boolean} state the new state
4784 Roo.extend(Roo.bootstrap.NavSidebarItem, Roo.bootstrap.NavItem, {
4786 badgeWeight : 'default',
4792 buttonWeight : 'default',
4798 getAutoCreate : function(){
4803 href : this.href || '#',
4809 if(this.buttonView){
4812 href : this.href || '#',
4813 cls: 'btn btn-' + this.buttonWeight + ' btn-' + this.buttonSize + 'roo-button-dropdown-toggle',
4826 cfg.cls += ' active';
4829 if (this.disabled) {
4830 cfg.cls += ' disabled';
4833 cfg.cls += ' open x-open';
4836 if (this.glyphicon || this.icon) {
4837 var c = this.glyphicon ? ('glyphicon glyphicon-'+this.glyphicon) : this.icon;
4838 a.cn.push({ tag : 'i', cls : c }) ;
4841 if(!this.buttonView){
4844 html : this.html || ''
4851 if (this.badge !== '') {
4852 a.cn.push({ tag: 'span', cls : 'badge pull-right badge-' + this.badgeWeight, html: this.badge });
4858 a.cn.push({ tag : 'i', cls : 'glyphicon glyphicon-chevron-down pull-right'});
4861 a.cls += ' dropdown-toggle treeview' ;
4867 initEvents : function()
4869 if (typeof (this.menu) != 'undefined') {
4870 this.menu.parentType = this.xtype;
4871 this.menu.triggerEl = this.el;
4872 this.menu = this.addxtype(Roo.apply({}, this.menu));
4875 this.el.on('click', this.onClick, this);
4877 if(this.badge !== ''){
4878 this.badgeEl = this.el.select('.badge', true).first().setVisibilityMode(Roo.Element.DISPLAY);
4883 onClick : function(e)
4890 if(this.preventDefault){
4894 this.fireEvent('click', this);
4897 disable : function()
4899 this.setDisabled(true);
4904 this.setDisabled(false);
4907 setDisabled : function(state)
4909 if(this.disabled == state){
4913 this.disabled = state;
4916 this.el.addClass('disabled');
4920 this.el.removeClass('disabled');
4925 setActive : function(state)
4927 if(this.active == state){
4931 this.active = state;
4934 this.el.addClass('active');
4938 this.el.removeClass('active');
4943 isActive: function ()
4948 setBadge : function(str)
4954 this.badgeEl.dom.innerHTML = str;
4971 * @class Roo.bootstrap.Row
4972 * @extends Roo.bootstrap.Component
4973 * Bootstrap Row class (contains columns...)
4977 * @param {Object} config The config object
4980 Roo.bootstrap.Row = function(config){
4981 Roo.bootstrap.Row.superclass.constructor.call(this, config);
4984 Roo.extend(Roo.bootstrap.Row, Roo.bootstrap.Component, {
4986 getAutoCreate : function(){
5005 * @class Roo.bootstrap.Element
5006 * @extends Roo.bootstrap.Component
5007 * Bootstrap Element class
5008 * @cfg {String} html contents of the element
5009 * @cfg {String} tag tag of the element
5010 * @cfg {String} cls class of the element
5011 * @cfg {Boolean} preventDefault (true|false) default false
5012 * @cfg {Boolean} clickable (true|false) default false
5015 * Create a new Element
5016 * @param {Object} config The config object
5019 Roo.bootstrap.Element = function(config){
5020 Roo.bootstrap.Element.superclass.constructor.call(this, config);
5026 * When a element is chick
5027 * @param {Roo.bootstrap.Element} this
5028 * @param {Roo.EventObject} e
5034 Roo.extend(Roo.bootstrap.Element, Roo.bootstrap.Component, {
5039 preventDefault: false,
5042 getAutoCreate : function(){
5046 // cls: this.cls, double assign in parent class Component.js :: onRender
5053 initEvents: function()
5055 Roo.bootstrap.Element.superclass.initEvents.call(this);
5058 this.el.on('click', this.onClick, this);
5063 onClick : function(e)
5065 if(this.preventDefault){
5069 this.fireEvent('click', this, e);
5072 getValue : function()
5074 return this.el.dom.innerHTML;
5077 setValue : function(value)
5079 this.el.dom.innerHTML = value;
5094 * @class Roo.bootstrap.Pagination
5095 * @extends Roo.bootstrap.Component
5096 * Bootstrap Pagination class
5097 * @cfg {String} size xs | sm | md | lg
5098 * @cfg {Boolean} inverse false | true
5101 * Create a new Pagination
5102 * @param {Object} config The config object
5105 Roo.bootstrap.Pagination = function(config){
5106 Roo.bootstrap.Pagination.superclass.constructor.call(this, config);
5109 Roo.extend(Roo.bootstrap.Pagination, Roo.bootstrap.Component, {
5115 getAutoCreate : function(){
5121 cfg.cls += ' inverse';
5127 cfg.cls += " " + this.cls;
5145 * @class Roo.bootstrap.PaginationItem
5146 * @extends Roo.bootstrap.Component
5147 * Bootstrap PaginationItem class
5148 * @cfg {String} html text
5149 * @cfg {String} href the link
5150 * @cfg {Boolean} preventDefault (true | false) default true
5151 * @cfg {Boolean} active (true | false) default false
5152 * @cfg {Boolean} disabled default false
5156 * Create a new PaginationItem
5157 * @param {Object} config The config object
5161 Roo.bootstrap.PaginationItem = function(config){
5162 Roo.bootstrap.PaginationItem.superclass.constructor.call(this, config);
5167 * The raw click event for the entire grid.
5168 * @param {Roo.EventObject} e
5174 Roo.extend(Roo.bootstrap.PaginationItem, Roo.bootstrap.Component, {
5178 preventDefault: true,
5183 getAutoCreate : function(){
5189 href : this.href ? this.href : '#',
5190 html : this.html ? this.html : ''
5200 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' disabled' : 'disabled';
5204 cfg.cls = typeof(cfg.cls) !== 'undefined' ? cfg.cls + ' active' : 'active';
5210 initEvents: function() {
5212 this.el.on('click', this.onClick, this);
5215 onClick : function(e)
5217 Roo.log('PaginationItem on click ');
5218 if(this.preventDefault){
5226 this.fireEvent('click', this, e);
5242 * @class Roo.bootstrap.Slider
5243 * @extends Roo.bootstrap.Component
5244 * Bootstrap Slider class
5247 * Create a new Slider
5248 * @param {Object} config The config object
5251 Roo.bootstrap.Slider = function(config){
5252 Roo.bootstrap.Slider.superclass.constructor.call(this, config);
5255 Roo.extend(Roo.bootstrap.Slider, Roo.bootstrap.Component, {
5257 getAutoCreate : function(){
5261 cls: 'slider slider-sample1 vertical-handler ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all',
5265 cls: 'ui-slider-handle ui-state-default ui-corner-all'
5277 * Ext JS Library 1.1.1
5278 * Copyright(c) 2006-2007, Ext JS, LLC.
5280 * Originally Released Under LGPL - original licence link has changed is not relivant.
5283 * <script type="text/javascript">
5288 * @class Roo.grid.ColumnModel
5289 * @extends Roo.util.Observable
5290 * This is the default implementation of a ColumnModel used by the Grid. It defines
5291 * the columns in the grid.
5294 var colModel = new Roo.grid.ColumnModel([
5295 {header: "Ticker", width: 60, sortable: true, locked: true},
5296 {header: "Company Name", width: 150, sortable: true},
5297 {header: "Market Cap.", width: 100, sortable: true},
5298 {header: "$ Sales", width: 100, sortable: true, renderer: money},
5299 {header: "Employees", width: 100, sortable: true, resizable: false}
5304 * The config options listed for this class are options which may appear in each
5305 * individual column definition.
5306 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
5308 * @param {Object} config An Array of column config objects. See this class's
5309 * config objects for details.
5311 Roo.grid.ColumnModel = function(config){
5313 * The config passed into the constructor
5315 this.config = config;
5318 // if no id, create one
5319 // if the column does not have a dataIndex mapping,
5320 // map it to the order it is in the config
5321 for(var i = 0, len = config.length; i < len; i++){
5323 if(typeof c.dataIndex == "undefined"){
5326 if(typeof c.renderer == "string"){
5327 c.renderer = Roo.util.Format[c.renderer];
5329 if(typeof c.id == "undefined"){
5332 if(c.editor && c.editor.xtype){
5333 c.editor = Roo.factory(c.editor, Roo.grid);
5335 if(c.editor && c.editor.isFormField){
5336 c.editor = new Roo.grid.GridEditor(c.editor);
5338 this.lookup[c.id] = c;
5342 * The width of columns which have no width specified (defaults to 100)
5345 this.defaultWidth = 100;
5348 * Default sortable of columns which have no sortable specified (defaults to false)
5351 this.defaultSortable = false;
5355 * @event widthchange
5356 * Fires when the width of a column changes.
5357 * @param {ColumnModel} this
5358 * @param {Number} columnIndex The column index
5359 * @param {Number} newWidth The new width
5361 "widthchange": true,
5363 * @event headerchange
5364 * Fires when the text of a header changes.
5365 * @param {ColumnModel} this
5366 * @param {Number} columnIndex The column index
5367 * @param {Number} newText The new header text
5369 "headerchange": true,
5371 * @event hiddenchange
5372 * Fires when a column is hidden or "unhidden".
5373 * @param {ColumnModel} this
5374 * @param {Number} columnIndex The column index
5375 * @param {Boolean} hidden true if hidden, false otherwise
5377 "hiddenchange": true,
5379 * @event columnmoved
5380 * Fires when a column is moved.
5381 * @param {ColumnModel} this
5382 * @param {Number} oldIndex
5383 * @param {Number} newIndex
5385 "columnmoved" : true,
5387 * @event columlockchange
5388 * Fires when a column's locked state is changed
5389 * @param {ColumnModel} this
5390 * @param {Number} colIndex
5391 * @param {Boolean} locked true if locked
5393 "columnlockchange" : true
5395 Roo.grid.ColumnModel.superclass.constructor.call(this);
5397 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
5399 * @cfg {String} header The header text to display in the Grid view.
5402 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
5403 * {@link Roo.data.Record} definition from which to draw the column's value. If not
5404 * specified, the column's index is used as an index into the Record's data Array.
5407 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
5408 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
5411 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
5412 * Defaults to the value of the {@link #defaultSortable} property.
5413 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
5416 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
5419 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
5422 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
5425 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
5428 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
5429 * given the cell's data value. See {@link #setRenderer}. If not specified, the
5430 * default renderer returns the escaped data value. If an object is returned (bootstrap only)
5431 * then it is treated as a Roo Component object instance, and it is rendered after the initial row is rendered
5434 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
5437 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
5440 * @cfg {String} valign (Optional) Set the CSS vertical-align property of the column (eg. middle, top, bottom etc). Defaults to undefined.
5443 * @cfg {String} cursor (Optional)
5446 * @cfg {String} tooltip (Optional)
5449 * @cfg {Number} xs (Optional)
5452 * @cfg {Number} sm (Optional)
5455 * @cfg {Number} md (Optional)
5458 * @cfg {Number} lg (Optional)
5461 * Returns the id of the column at the specified index.
5462 * @param {Number} index The column index
5463 * @return {String} the id
5465 getColumnId : function(index){
5466 return this.config[index].id;
5470 * Returns the column for a specified id.
5471 * @param {String} id The column id
5472 * @return {Object} the column
5474 getColumnById : function(id){
5475 return this.lookup[id];
5480 * Returns the column for a specified dataIndex.
5481 * @param {String} dataIndex The column dataIndex
5482 * @return {Object|Boolean} the column or false if not found
5484 getColumnByDataIndex: function(dataIndex){
5485 var index = this.findColumnIndex(dataIndex);
5486 return index > -1 ? this.config[index] : false;
5490 * Returns the index for a specified column id.
5491 * @param {String} id The column id
5492 * @return {Number} the index, or -1 if not found
5494 getIndexById : function(id){
5495 for(var i = 0, len = this.config.length; i < len; i++){
5496 if(this.config[i].id == id){
5504 * Returns the index for a specified column dataIndex.
5505 * @param {String} dataIndex The column dataIndex
5506 * @return {Number} the index, or -1 if not found
5509 findColumnIndex : function(dataIndex){
5510 for(var i = 0, len = this.config.length; i < len; i++){
5511 if(this.config[i].dataIndex == dataIndex){
5519 moveColumn : function(oldIndex, newIndex){
5520 var c = this.config[oldIndex];
5521 this.config.splice(oldIndex, 1);
5522 this.config.splice(newIndex, 0, c);
5523 this.dataMap = null;
5524 this.fireEvent("columnmoved", this, oldIndex, newIndex);
5527 isLocked : function(colIndex){
5528 return this.config[colIndex].locked === true;
5531 setLocked : function(colIndex, value, suppressEvent){
5532 if(this.isLocked(colIndex) == value){
5535 this.config[colIndex].locked = value;
5537 this.fireEvent("columnlockchange", this, colIndex, value);
5541 getTotalLockedWidth : function(){
5543 for(var i = 0; i < this.config.length; i++){
5544 if(this.isLocked(i) && !this.isHidden(i)){
5545 this.totalWidth += this.getColumnWidth(i);
5551 getLockedCount : function(){
5552 for(var i = 0, len = this.config.length; i < len; i++){
5553 if(!this.isLocked(i)){
5558 return this.config.length;
5562 * Returns the number of columns.
5565 getColumnCount : function(visibleOnly){
5566 if(visibleOnly === true){
5568 for(var i = 0, len = this.config.length; i < len; i++){
5569 if(!this.isHidden(i)){
5575 return this.config.length;
5579 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
5580 * @param {Function} fn
5581 * @param {Object} scope (optional)
5582 * @return {Array} result
5584 getColumnsBy : function(fn, scope){
5586 for(var i = 0, len = this.config.length; i < len; i++){
5587 var c = this.config[i];
5588 if(fn.call(scope||this, c, i) === true){
5596 * Returns true if the specified column is sortable.
5597 * @param {Number} col The column index
5600 isSortable : function(col){
5601 if(typeof this.config[col].sortable == "undefined"){
5602 return this.defaultSortable;
5604 return this.config[col].sortable;
5608 * Returns the rendering (formatting) function defined for the column.
5609 * @param {Number} col The column index.
5610 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
5612 getRenderer : function(col){
5613 if(!this.config[col].renderer){
5614 return Roo.grid.ColumnModel.defaultRenderer;
5616 return this.config[col].renderer;
5620 * Sets the rendering (formatting) function for a column.
5621 * @param {Number} col The column index
5622 * @param {Function} fn The function to use to process the cell's raw data
5623 * to return HTML markup for the grid view. The render function is called with
5624 * the following parameters:<ul>
5625 * <li>Data value.</li>
5626 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
5627 * <li>css A CSS style string to apply to the table cell.</li>
5628 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
5629 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
5630 * <li>Row index</li>
5631 * <li>Column index</li>
5632 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
5634 setRenderer : function(col, fn){
5635 this.config[col].renderer = fn;
5639 * Returns the width for the specified column.
5640 * @param {Number} col The column index
5643 getColumnWidth : function(col){
5644 return this.config[col].width * 1 || this.defaultWidth;
5648 * Sets the width for a column.
5649 * @param {Number} col The column index
5650 * @param {Number} width The new width
5652 setColumnWidth : function(col, width, suppressEvent){
5653 this.config[col].width = width;
5654 this.totalWidth = null;
5656 this.fireEvent("widthchange", this, col, width);
5661 * Returns the total width of all columns.
5662 * @param {Boolean} includeHidden True to include hidden column widths
5665 getTotalWidth : function(includeHidden){
5666 if(!this.totalWidth){
5667 this.totalWidth = 0;
5668 for(var i = 0, len = this.config.length; i < len; i++){
5669 if(includeHidden || !this.isHidden(i)){
5670 this.totalWidth += this.getColumnWidth(i);
5674 return this.totalWidth;
5678 * Returns the header for the specified column.
5679 * @param {Number} col The column index
5682 getColumnHeader : function(col){
5683 return this.config[col].header;
5687 * Sets the header for a column.
5688 * @param {Number} col The column index
5689 * @param {String} header The new header
5691 setColumnHeader : function(col, header){
5692 this.config[col].header = header;
5693 this.fireEvent("headerchange", this, col, header);
5697 * Returns the tooltip for the specified column.
5698 * @param {Number} col The column index
5701 getColumnTooltip : function(col){
5702 return this.config[col].tooltip;
5705 * Sets the tooltip for a column.
5706 * @param {Number} col The column index
5707 * @param {String} tooltip The new tooltip
5709 setColumnTooltip : function(col, tooltip){
5710 this.config[col].tooltip = tooltip;
5714 * Returns the dataIndex for the specified column.
5715 * @param {Number} col The column index
5718 getDataIndex : function(col){
5719 return this.config[col].dataIndex;
5723 * Sets the dataIndex for a column.
5724 * @param {Number} col The column index
5725 * @param {Number} dataIndex The new dataIndex
5727 setDataIndex : function(col, dataIndex){
5728 this.config[col].dataIndex = dataIndex;
5734 * Returns true if the cell is editable.
5735 * @param {Number} colIndex The column index
5736 * @param {Number} rowIndex The row index - this is nto actually used..?
5739 isCellEditable : function(colIndex, rowIndex){
5740 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
5744 * Returns the editor defined for the cell/column.
5745 * return false or null to disable editing.
5746 * @param {Number} colIndex The column index
5747 * @param {Number} rowIndex The row index
5750 getCellEditor : function(colIndex, rowIndex){
5751 return this.config[colIndex].editor;
5755 * Sets if a column is editable.
5756 * @param {Number} col The column index
5757 * @param {Boolean} editable True if the column is editable
5759 setEditable : function(col, editable){
5760 this.config[col].editable = editable;
5765 * Returns true if the column is hidden.
5766 * @param {Number} colIndex The column index
5769 isHidden : function(colIndex){
5770 return this.config[colIndex].hidden;
5775 * Returns true if the column width cannot be changed
5777 isFixed : function(colIndex){
5778 return this.config[colIndex].fixed;
5782 * Returns true if the column can be resized
5785 isResizable : function(colIndex){
5786 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
5789 * Sets if a column is hidden.
5790 * @param {Number} colIndex The column index
5791 * @param {Boolean} hidden True if the column is hidden
5793 setHidden : function(colIndex, hidden){
5794 this.config[colIndex].hidden = hidden;
5795 this.totalWidth = null;
5796 this.fireEvent("hiddenchange", this, colIndex, hidden);
5800 * Sets the editor for a column.
5801 * @param {Number} col The column index
5802 * @param {Object} editor The editor object
5804 setEditor : function(col, editor){
5805 this.config[col].editor = editor;
5809 Roo.grid.ColumnModel.defaultRenderer = function(value)
5811 if(typeof value == "object") {
5814 if(typeof value == "string" && value.length < 1){
5818 return String.format("{0}", value);
5821 // Alias for backwards compatibility
5822 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
5825 * Ext JS Library 1.1.1
5826 * Copyright(c) 2006-2007, Ext JS, LLC.
5828 * Originally Released Under LGPL - original licence link has changed is not relivant.
5831 * <script type="text/javascript">
5835 * @class Roo.LoadMask
5836 * A simple utility class for generically masking elements while loading data. If the element being masked has
5837 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
5838 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
5839 * element's UpdateManager load indicator and will be destroyed after the initial load.
5841 * Create a new LoadMask
5842 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
5843 * @param {Object} config The config object
5845 Roo.LoadMask = function(el, config){
5846 this.el = Roo.get(el);
5847 Roo.apply(this, config);
5849 this.store.on('beforeload', this.onBeforeLoad, this);
5850 this.store.on('load', this.onLoad, this);
5851 this.store.on('loadexception', this.onLoadException, this);
5852 this.removeMask = false;
5854 var um = this.el.getUpdateManager();
5855 um.showLoadIndicator = false; // disable the default indicator
5856 um.on('beforeupdate', this.onBeforeLoad, this);
5857 um.on('update', this.onLoad, this);
5858 um.on('failure', this.onLoad, this);
5859 this.removeMask = true;
5863 Roo.LoadMask.prototype = {
5865 * @cfg {Boolean} removeMask
5866 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
5867 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
5871 * The text to display in a centered loading message box (defaults to 'Loading...')
5875 * @cfg {String} msgCls
5876 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
5878 msgCls : 'x-mask-loading',
5881 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
5887 * Disables the mask to prevent it from being displayed
5889 disable : function(){
5890 this.disabled = true;
5894 * Enables the mask so that it can be displayed
5896 enable : function(){
5897 this.disabled = false;
5900 onLoadException : function()
5904 if (typeof(arguments[3]) != 'undefined') {
5905 Roo.MessageBox.alert("Error loading",arguments[3]);
5909 if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
5910 Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
5917 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5922 (function() { this.el.unmask(this.removeMask); }).defer(50, this);
5926 onBeforeLoad : function(){
5928 (function() { this.el.mask(this.msg, this.msgCls); }).defer(50, this);
5933 destroy : function(){
5935 this.store.un('beforeload', this.onBeforeLoad, this);
5936 this.store.un('load', this.onLoad, this);
5937 this.store.un('loadexception', this.onLoadException, this);
5939 var um = this.el.getUpdateManager();
5940 um.un('beforeupdate', this.onBeforeLoad, this);
5941 um.un('update', this.onLoad, this);
5942 um.un('failure', this.onLoad, this);
5953 * @class Roo.bootstrap.Table
5954 * @extends Roo.bootstrap.Component
5955 * Bootstrap Table class
5956 * @cfg {String} cls table class
5957 * @cfg {String} align (left|center|right) Specifies the alignment of a table according to surrounding text
5958 * @cfg {String} bgcolor Specifies the background color for a table
5959 * @cfg {Number} border Specifies whether the table cells should have borders or not
5960 * @cfg {Number} cellpadding Specifies the space between the cell wall and the cell content
5961 * @cfg {Number} cellspacing Specifies the space between cells
5962 * @cfg {String} frame Specifies which parts of the outside borders that should be visible
5963 * @cfg {String} rules Specifies which parts of the inside borders that should be visible
5964 * @cfg {String} sortable Specifies that the table should be sortable
5965 * @cfg {String} summary Specifies a summary of the content of a table
5966 * @cfg {Number} width Specifies the width of a table
5967 * @cfg {String} layout table layout (auto | fixed | initial | inherit)
5969 * @cfg {boolean} striped Should the rows be alternative striped
5970 * @cfg {boolean} bordered Add borders to the table
5971 * @cfg {boolean} hover Add hover highlighting
5972 * @cfg {boolean} condensed Format condensed
5973 * @cfg {boolean} responsive Format condensed
5974 * @cfg {Boolean} loadMask (true|false) default false
5975 * @cfg {Boolean} footerShow (true|false) generate tfoot, default true
5976 * @cfg {Boolean} headerShow (true|false) generate thead, default true
5977 * @cfg {Boolean} rowSelection (true|false) default false
5978 * @cfg {Boolean} cellSelection (true|false) default false
5979 * @cfg {Boolean} scrollBody (true|false) default false - body scrolled / fixed header
5980 * @cfg {Roo.bootstrap.PagingToolbar} footer a paging toolbar
5981 * @cfg {Boolean} lazyLoad auto load data while scrolling to the end (default false)
5982 * @cfg {Boolean} auto_hide_footer auto hide footer if only one page (default false)
5986 * Create a new Table
5987 * @param {Object} config The config object
5990 Roo.bootstrap.Table = function(config){
5991 Roo.bootstrap.Table.superclass.constructor.call(this, config);
5996 this.rowSelection = (typeof(config.rowSelection) != 'undefined') ? config.rowSelection : this.rowSelection;
5997 this.cellSelection = (typeof(config.cellSelection) != 'undefined') ? config.cellSelection : this.cellSelection;
5998 this.headerShow = (typeof(config.thead) != 'undefined') ? config.thead : this.headerShow;
5999 this.footerShow = (typeof(config.tfoot) != 'undefined') ? config.tfoot : this.footerShow;
6001 this.sm = this.sm || {xtype: 'RowSelectionModel'};
6003 this.sm.grid = this;
6004 this.selModel = Roo.factory(this.sm, Roo.bootstrap.Table);
6005 this.sm = this.selModel;
6006 this.sm.xmodule = this.xmodule || false;
6009 if (this.cm && typeof(this.cm.config) == 'undefined') {
6010 this.colModel = new Roo.grid.ColumnModel(this.cm);
6011 this.cm = this.colModel;
6012 this.cm.xmodule = this.xmodule || false;
6015 this.store= Roo.factory(this.store, Roo.data);
6016 this.ds = this.store;
6017 this.ds.xmodule = this.xmodule || false;
6020 if (this.footer && this.store) {
6021 this.footer.dataSource = this.ds;
6022 this.footer = Roo.factory(this.footer);
6029 * Fires when a cell is clicked
6030 * @param {Roo.bootstrap.Table} this
6031 * @param {Roo.Element} el
6032 * @param {Number} rowIndex
6033 * @param {Number} columnIndex
6034 * @param {Roo.EventObject} e
6038 * @event celldblclick
6039 * Fires when a cell is double clicked
6040 * @param {Roo.bootstrap.Table} this
6041 * @param {Roo.Element} el
6042 * @param {Number} rowIndex
6043 * @param {Number} columnIndex
6044 * @param {Roo.EventObject} e
6046 "celldblclick" : true,
6049 * Fires when a row is clicked
6050 * @param {Roo.bootstrap.Table} this
6051 * @param {Roo.Element} el
6052 * @param {Number} rowIndex
6053 * @param {Roo.EventObject} e
6057 * @event rowdblclick
6058 * Fires when a row is double clicked
6059 * @param {Roo.bootstrap.Table} this
6060 * @param {Roo.Element} el
6061 * @param {Number} rowIndex
6062 * @param {Roo.EventObject} e
6064 "rowdblclick" : true,
6067 * Fires when a mouseover occur
6068 * @param {Roo.bootstrap.Table} this
6069 * @param {Roo.Element} el
6070 * @param {Number} rowIndex
6071 * @param {Number} columnIndex
6072 * @param {Roo.EventObject} e
6077 * Fires when a mouseout occur
6078 * @param {Roo.bootstrap.Table} this
6079 * @param {Roo.Element} el
6080 * @param {Number} rowIndex
6081 * @param {Number} columnIndex
6082 * @param {Roo.EventObject} e
6087 * Fires when a row is rendered, so you can change add a style to it.
6088 * @param {Roo.bootstrap.Table} this
6089 * @param {Object} rowcfg contains record rowIndex colIndex and rowClass - set rowClass to add a style.
6093 * @event rowsrendered
6094 * Fires when all the rows have been rendered
6095 * @param {Roo.bootstrap.Table} this
6097 'rowsrendered' : true,
6099 * @event contextmenu
6100 * The raw contextmenu event for the entire grid.
6101 * @param {Roo.EventObject} e
6103 "contextmenu" : true,
6105 * @event rowcontextmenu
6106 * Fires when a row is right clicked
6107 * @param {Roo.bootstrap.Table} this
6108 * @param {Number} rowIndex
6109 * @param {Roo.EventObject} e
6111 "rowcontextmenu" : true,
6113 * @event cellcontextmenu
6114 * Fires when a cell is right clicked
6115 * @param {Roo.bootstrap.Table} this
6116 * @param {Number} rowIndex
6117 * @param {Number} cellIndex
6118 * @param {Roo.EventObject} e
6120 "cellcontextmenu" : true,
6122 * @event headercontextmenu
6123 * Fires when a header is right clicked
6124 * @param {Roo.bootstrap.Table} this
6125 * @param {Number} columnIndex
6126 * @param {Roo.EventObject} e
6128 "headercontextmenu" : true
6132 Roo.extend(Roo.bootstrap.Table, Roo.bootstrap.Component, {
6158 rowSelection : false,
6159 cellSelection : false,
6162 // Roo.Element - the tbody
6164 // Roo.Element - thead element
6167 container: false, // used by gridpanel...
6173 auto_hide_footer : false,
6175 getAutoCreate : function()
6177 var cfg = Roo.apply({}, Roo.bootstrap.Table.superclass.getAutoCreate.call(this));
6184 if (this.scrollBody) {
6185 cfg.cls += ' table-body-fixed';
6188 cfg.cls += ' table-striped';
6192 cfg.cls += ' table-hover';
6194 if (this.bordered) {
6195 cfg.cls += ' table-bordered';
6197 if (this.condensed) {
6198 cfg.cls += ' table-condensed';
6200 if (this.responsive) {
6201 cfg.cls += ' table-responsive';
6205 cfg.cls+= ' ' +this.cls;
6208 // this lot should be simplifed...
6221 ].forEach(function(k) {
6229 cfg.style = (typeof(cfg.style) == 'undefined') ? ('table-layout:' + this.layout + ';') : (cfg.style + ('table-layout:' + this.layout + ';'));
6232 if(this.store || this.cm){
6233 if(this.headerShow){
6234 cfg.cn.push(this.renderHeader());
6237 cfg.cn.push(this.renderBody());
6239 if(this.footerShow){
6240 cfg.cn.push(this.renderFooter());
6242 // where does this come from?
6243 //cfg.cls+= ' TableGrid';
6246 return { cn : [ cfg ] };
6249 initEvents : function()
6251 if(!this.store || !this.cm){
6254 if (this.selModel) {
6255 this.selModel.initEvents();
6259 //Roo.log('initEvents with ds!!!!');
6261 this.mainBody = this.el.select('tbody', true).first();
6262 this.mainHead = this.el.select('thead', true).first();
6263 this.mainFoot = this.el.select('tfoot', true).first();
6269 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6270 e.on('click', _this.sort, _this);
6273 this.mainBody.on("click", this.onClick, this);
6274 this.mainBody.on("dblclick", this.onDblClick, this);
6276 // why is this done????? = it breaks dialogs??
6277 //this.parent().el.setStyle('position', 'relative');
6281 this.footer.parentId = this.id;
6282 this.footer.onRender(this.el.select('tfoot tr td').first(), null);
6285 this.el.select('tfoot tr td').first().addClass('hide');
6290 this.maskEl = new Roo.LoadMask(this.el, { store : this.ds, msgCls: 'roo-el-mask-msg' });
6293 this.store.on('load', this.onLoad, this);
6294 this.store.on('beforeload', this.onBeforeLoad, this);
6295 this.store.on('update', this.onUpdate, this);
6296 this.store.on('add', this.onAdd, this);
6297 this.store.on("clear", this.clear, this);
6299 this.el.on("contextmenu", this.onContextMenu, this);
6301 this.mainBody.on('scroll', this.onBodyScroll, this);
6303 this.cm.on("headerchange", this.onHeaderChange, this);
6305 this.cm.on("hiddenchange", this.onHiddenChange, this, arguments);
6309 onContextMenu : function(e, t)
6311 this.processEvent("contextmenu", e);
6314 processEvent : function(name, e)
6316 if (name != 'touchstart' ) {
6317 this.fireEvent(name, e);
6320 var t = e.getTarget();
6322 var cell = Roo.get(t);
6328 if(cell.findParent('tfoot', false, true)){
6332 if(cell.findParent('thead', false, true)){
6334 if(e.getTarget().nodeName.toLowerCase() != 'th'){
6335 cell = Roo.get(t).findParent('th', false, true);
6337 Roo.log("failed to find th in thead?");
6338 Roo.log(e.getTarget());
6343 var cellIndex = cell.dom.cellIndex;
6345 var ename = name == 'touchstart' ? 'click' : name;
6346 this.fireEvent("header" + ename, this, cellIndex, e);
6351 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6352 cell = Roo.get(t).findParent('td', false, true);
6354 Roo.log("failed to find th in tbody?");
6355 Roo.log(e.getTarget());
6360 var row = cell.findParent('tr', false, true);
6361 var cellIndex = cell.dom.cellIndex;
6362 var rowIndex = row.dom.rowIndex - 1;
6366 this.fireEvent("row" + name, this, rowIndex, e);
6370 this.fireEvent("cell" + name, this, rowIndex, cellIndex, e);
6376 onMouseover : function(e, el)
6378 var cell = Roo.get(el);
6384 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6385 cell = cell.findParent('td', false, true);
6388 var row = cell.findParent('tr', false, true);
6389 var cellIndex = cell.dom.cellIndex;
6390 var rowIndex = row.dom.rowIndex - 1; // start from 0
6392 this.fireEvent('mouseover', this, cell, rowIndex, cellIndex, e);
6396 onMouseout : function(e, el)
6398 var cell = Roo.get(el);
6404 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6405 cell = cell.findParent('td', false, true);
6408 var row = cell.findParent('tr', false, true);
6409 var cellIndex = cell.dom.cellIndex;
6410 var rowIndex = row.dom.rowIndex - 1; // start from 0
6412 this.fireEvent('mouseout', this, cell, rowIndex, cellIndex, e);
6416 onClick : function(e, el)
6418 var cell = Roo.get(el);
6420 if(!cell || (!this.cellSelection && !this.rowSelection)){
6424 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6425 cell = cell.findParent('td', false, true);
6428 if(!cell || typeof(cell) == 'undefined'){
6432 var row = cell.findParent('tr', false, true);
6434 if(!row || typeof(row) == 'undefined'){
6438 var cellIndex = cell.dom.cellIndex;
6439 var rowIndex = this.getRowIndex(row);
6441 // why??? - should these not be based on SelectionModel?
6442 if(this.cellSelection){
6443 this.fireEvent('cellclick', this, cell, rowIndex, cellIndex, e);
6446 if(this.rowSelection){
6447 this.fireEvent('rowclick', this, row, rowIndex, e);
6453 onDblClick : function(e,el)
6455 var cell = Roo.get(el);
6457 if(!cell || (!this.cellSelection && !this.rowSelection)){
6461 if(e.getTarget().nodeName.toLowerCase() != 'td'){
6462 cell = cell.findParent('td', false, true);
6465 if(!cell || typeof(cell) == 'undefined'){
6469 var row = cell.findParent('tr', false, true);
6471 if(!row || typeof(row) == 'undefined'){
6475 var cellIndex = cell.dom.cellIndex;
6476 var rowIndex = this.getRowIndex(row);
6478 if(this.cellSelection){
6479 this.fireEvent('celldblclick', this, cell, rowIndex, cellIndex, e);
6482 if(this.rowSelection){
6483 this.fireEvent('rowdblclick', this, row, rowIndex, e);
6487 sort : function(e,el)
6489 var col = Roo.get(el);
6491 if(!col.hasClass('sortable')){
6495 var sort = col.attr('sort');
6498 if(col.select('i', true).first().hasClass('glyphicon-arrow-up')){
6502 this.store.sortInfo = {field : sort, direction : dir};
6505 Roo.log("calling footer first");
6506 this.footer.onClick('first');
6509 this.store.load({ params : { start : 0 } });
6513 renderHeader : function()
6521 this.totalWidth = 0;
6523 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6525 var config = cm.config[i];
6529 cls : 'x-hcol-' + i,
6531 html: cm.getColumnHeader(i)
6536 if(typeof(config.sortable) != 'undefined' && config.sortable){
6538 c.html = '<i class="glyphicon"></i>' + c.html;
6541 if(typeof(config.lgHeader) != 'undefined'){
6542 hh += '<span class="hidden-xs hidden-sm hidden-md">' + config.lgHeader + '</span>';
6545 if(typeof(config.mdHeader) != 'undefined'){
6546 hh += '<span class="hidden-xs hidden-sm hidden-lg">' + config.mdHeader + '</span>';
6549 if(typeof(config.smHeader) != 'undefined'){
6550 hh += '<span class="hidden-xs hidden-md hidden-lg">' + config.smHeader + '</span>';
6553 if(typeof(config.xsHeader) != 'undefined'){
6554 hh += '<span class="hidden-sm hidden-md hidden-lg">' + config.xsHeader + '</span>';
6561 if(typeof(config.tooltip) != 'undefined'){
6562 c.tooltip = config.tooltip;
6565 if(typeof(config.colspan) != 'undefined'){
6566 c.colspan = config.colspan;
6569 if(typeof(config.hidden) != 'undefined' && config.hidden){
6570 c.style += ' display:none;';
6573 if(typeof(config.dataIndex) != 'undefined'){
6574 c.sort = config.dataIndex;
6579 if(typeof(config.align) != 'undefined' && config.align.length){
6580 c.style += ' text-align:' + config.align + ';';
6583 if(typeof(config.width) != 'undefined'){
6584 c.style += ' width:' + config.width + 'px;';
6585 this.totalWidth += config.width;
6587 this.totalWidth += 100; // assume minimum of 100 per column?
6590 if(typeof(config.cls) != 'undefined'){
6591 c.cls = (typeof(c.cls) == 'undefined') ? config.cls : (c.cls + ' ' + config.cls);
6594 ['xs','sm','md','lg'].map(function(size){
6596 if(typeof(config[size]) == 'undefined'){
6600 if (!config[size]) { // 0 = hidden
6601 c.cls += ' hidden-' + size;
6605 c.cls += ' col-' + size + '-' + config[size];
6615 renderBody : function()
6625 colspan : this.cm.getColumnCount()
6635 renderFooter : function()
6645 colspan : this.cm.getColumnCount()
6659 // Roo.log('ds onload');
6664 var ds = this.store;
6666 Roo.each(this.el.select('thead th.sortable', true).elements, function(e){
6667 e.select('i', true).removeClass(['glyphicon-arrow-up', 'glyphicon-arrow-down']);
6668 if (_this.store.sortInfo) {
6670 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'ASC'){
6671 e.select('i', true).addClass(['glyphicon-arrow-up']);
6674 if(e.hasClass('sortable') && e.attr('sort') == _this.store.sortInfo.field && _this.store.sortInfo.direction.toUpperCase() == 'DESC'){
6675 e.select('i', true).addClass(['glyphicon-arrow-down']);
6680 var tbody = this.mainBody;
6682 if(ds.getCount() > 0){
6683 ds.data.each(function(d,rowIndex){
6684 var row = this.renderRow(cm, ds, rowIndex);
6686 tbody.createChild(row);
6690 if(row.cellObjects.length){
6691 Roo.each(row.cellObjects, function(r){
6692 _this.renderCellObject(r);
6699 var tfoot = this.el.select('tfoot', true).first();
6701 if(this.footerShow && this.auto_hide_footer && this.mainFoot){
6703 this.mainFoot.setVisibilityMode(Roo.Element.DISPLAY).hide();
6705 var total = this.ds.getTotalCount();
6707 if(this.footer.pageSize < total){
6708 this.mainFoot.show();
6712 Roo.each(this.el.select('tbody td', true).elements, function(e){
6713 e.on('mouseover', _this.onMouseover, _this);
6716 Roo.each(this.el.select('tbody td', true).elements, function(e){
6717 e.on('mouseout', _this.onMouseout, _this);
6719 this.fireEvent('rowsrendered', this);
6725 onUpdate : function(ds,record)
6727 this.refreshRow(record);
6731 onRemove : function(ds, record, index, isUpdate){
6732 if(isUpdate !== true){
6733 this.fireEvent("beforerowremoved", this, index, record);
6735 var bt = this.mainBody.dom;
6737 var rows = this.el.select('tbody > tr', true).elements;
6739 if(typeof(rows[index]) != 'undefined'){
6740 bt.removeChild(rows[index].dom);
6743 // if(bt.rows[index]){
6744 // bt.removeChild(bt.rows[index]);
6747 if(isUpdate !== true){
6748 //this.stripeRows(index);
6749 //this.syncRowHeights(index, index);
6751 this.fireEvent("rowremoved", this, index, record);
6755 onAdd : function(ds, records, rowIndex)
6757 //Roo.log('on Add called');
6758 // - note this does not handle multiple adding very well..
6759 var bt = this.mainBody.dom;
6760 for (var i =0 ; i < records.length;i++) {
6761 //Roo.log('call insert row Add called on ' + rowIndex + ':' + i);
6762 //Roo.log(records[i]);
6763 //Roo.log(this.store.getAt(rowIndex+i));
6764 this.insertRow(this.store, rowIndex + i, false);
6771 refreshRow : function(record){
6772 var ds = this.store, index;
6773 if(typeof record == 'number'){
6775 record = ds.getAt(index);
6777 index = ds.indexOf(record);
6779 this.insertRow(ds, index, true);
6781 this.onRemove(ds, record, index+1, true);
6783 //this.syncRowHeights(index, index);
6785 this.fireEvent("rowupdated", this, index, record);
6788 insertRow : function(dm, rowIndex, isUpdate){
6791 this.fireEvent("beforerowsinserted", this, rowIndex);
6793 //var s = this.getScrollState();
6794 var row = this.renderRow(this.cm, this.store, rowIndex);
6795 // insert before rowIndex..
6796 var e = this.mainBody.createChild(row,this.getRowDom(rowIndex));
6800 if(row.cellObjects.length){
6801 Roo.each(row.cellObjects, function(r){
6802 _this.renderCellObject(r);
6807 this.fireEvent("rowsinserted", this, rowIndex);
6808 //this.syncRowHeights(firstRow, lastRow);
6809 //this.stripeRows(firstRow);
6816 getRowDom : function(rowIndex)
6818 var rows = this.el.select('tbody > tr', true).elements;
6820 return (typeof(rows[rowIndex]) == 'undefined') ? false : rows[rowIndex];
6823 // returns the object tree for a tr..
6826 renderRow : function(cm, ds, rowIndex)
6828 var d = ds.getAt(rowIndex);
6832 cls : 'x-row-' + rowIndex,
6836 var cellObjects = [];
6838 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
6839 var config = cm.config[i];
6841 var renderer = cm.getRenderer(i);
6845 if(typeof(renderer) !== 'undefined'){
6846 value = renderer(d.data[cm.getDataIndex(i)], false, d);
6848 // if object are returned, then they are expected to be Roo.bootstrap.Component instances
6849 // and are rendered into the cells after the row is rendered - using the id for the element.
6851 if(typeof(value) === 'object'){
6861 rowIndex : rowIndex,
6866 this.fireEvent('rowclass', this, rowcfg);
6870 cls : rowcfg.rowClass + ' x-col-' + i,
6872 html: (typeof(value) === 'object') ? '' : value
6879 if(typeof(config.colspan) != 'undefined'){
6880 td.colspan = config.colspan;
6883 if(typeof(config.hidden) != 'undefined' && config.hidden){
6884 td.style += ' display:none;';
6887 if(typeof(config.align) != 'undefined' && config.align.length){
6888 td.style += ' text-align:' + config.align + ';';
6890 if(typeof(config.valign) != 'undefined' && config.valign.length){
6891 td.style += ' vertical-align:' + config.valign + ';';
6894 if(typeof(config.width) != 'undefined'){
6895 td.style += ' width:' + config.width + 'px;';
6898 if(typeof(config.cursor) != 'undefined'){
6899 td.style += ' cursor:' + config.cursor + ';';
6902 if(typeof(config.cls) != 'undefined'){
6903 td.cls = (typeof(td.cls) == 'undefined') ? config.cls : (td.cls + ' ' + config.cls);
6906 ['xs','sm','md','lg'].map(function(size){
6908 if(typeof(config[size]) == 'undefined'){
6912 if (!config[size]) { // 0 = hidden
6913 td.cls += ' hidden-' + size;
6917 td.cls += ' col-' + size + '-' + config[size];
6925 row.cellObjects = cellObjects;
6933 onBeforeLoad : function()
6942 this.el.select('tbody', true).first().dom.innerHTML = '';
6945 * Show or hide a row.
6946 * @param {Number} rowIndex to show or hide
6947 * @param {Boolean} state hide
6949 setRowVisibility : function(rowIndex, state)
6951 var bt = this.mainBody.dom;
6953 var rows = this.el.select('tbody > tr', true).elements;
6955 if(typeof(rows[rowIndex]) == 'undefined'){
6958 rows[rowIndex].dom.style.display = state ? '' : 'none';
6962 getSelectionModel : function(){
6964 this.selModel = new Roo.bootstrap.Table.RowSelectionModel({grid: this});
6966 return this.selModel;
6969 * Render the Roo.bootstrap object from renderder
6971 renderCellObject : function(r)
6975 r.cfg.parentId = (typeof(r.container) == 'string') ? r.container : r.container.id;
6977 var t = r.cfg.render(r.container);
6980 Roo.each(r.cfg.cn, function(c){
6982 container: t.getChildContainer(),
6985 _this.renderCellObject(child);
6990 getRowIndex : function(row)
6994 Roo.each(this.el.select('tbody > tr', true).elements, function(el, index){
7005 * Returns the grid's underlying element = used by panel.Grid
7006 * @return {Element} The element
7008 getGridEl : function(){
7012 * Forces a resize - used by panel.Grid
7013 * @return {Element} The element
7015 autoSize : function()
7017 //var ctr = Roo.get(this.container.dom.parentElement);
7018 var ctr = Roo.get(this.el.dom);
7020 var thd = this.getGridEl().select('thead',true).first();
7021 var tbd = this.getGridEl().select('tbody', true).first();
7022 var tfd = this.getGridEl().select('tfoot', true).first();
7024 var cw = ctr.getWidth();
7028 tbd.setSize(ctr.getWidth(),
7029 ctr.getHeight() - ((thd ? thd.getHeight() : 0) + (tfd ? tfd.getHeight() : 0))
7031 var barsize = (tbd.dom.offsetWidth - tbd.dom.clientWidth);
7034 cw = Math.max(cw, this.totalWidth);
7035 this.getGridEl().select('tr',true).setWidth(cw);
7036 // resize 'expandable coloumn?
7038 return; // we doe not have a view in this design..
7041 onBodyScroll: function()
7043 //Roo.log("body scrolled');" + this.mainBody.dom.scrollLeft);
7045 this.mainHead.setStyle({
7046 'position' : 'relative',
7047 'left': (-1* this.mainBody.dom.scrollLeft) + 'px'
7053 var scrollHeight = this.mainBody.dom.scrollHeight;
7055 var scrollTop = Math.ceil(this.mainBody.getScroll().top);
7057 var height = this.mainBody.getHeight();
7059 if(scrollHeight - height == scrollTop) {
7061 var total = this.ds.getTotalCount();
7063 if(this.footer.cursor + this.footer.pageSize < total){
7065 this.footer.ds.load({
7067 start : this.footer.cursor + this.footer.pageSize,
7068 limit : this.footer.pageSize
7078 onHeaderChange : function()
7080 var header = this.renderHeader();
7081 var table = this.el.select('table', true).first();
7083 this.mainHead.remove();
7084 this.mainHead = table.createChild(header, this.mainBody, false);
7087 onHiddenChange : function(colModel, colIndex, hidden)
7089 var thSelector = '#' + this.id + ' .x-hcol-' + colIndex;
7090 var tdSelector = '#' + this.id + ' .x-col-' + colIndex;
7092 this.CSS.updateRule(thSelector, "display", "");
7093 this.CSS.updateRule(tdSelector, "display", "");
7096 this.CSS.updateRule(thSelector, "display", "none");
7097 this.CSS.updateRule(tdSelector, "display", "none");
7100 this.onHeaderChange();
7117 * @class Roo.bootstrap.TableCell
7118 * @extends Roo.bootstrap.Component
7119 * Bootstrap TableCell class
7120 * @cfg {String} html cell contain text
7121 * @cfg {String} cls cell class
7122 * @cfg {String} tag cell tag (td|th) default td
7123 * @cfg {String} abbr Specifies an abbreviated version of the content in a cell
7124 * @cfg {String} align Aligns the content in a cell
7125 * @cfg {String} axis Categorizes cells
7126 * @cfg {String} bgcolor Specifies the background color of a cell
7127 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7128 * @cfg {Number} colspan Specifies the number of columns a cell should span
7129 * @cfg {String} headers Specifies one or more header cells a cell is related to
7130 * @cfg {Number} height Sets the height of a cell
7131 * @cfg {String} nowrap Specifies that the content inside a cell should not wrap
7132 * @cfg {Number} rowspan Sets the number of rows a cell should span
7133 * @cfg {String} scope Defines a way to associate header cells and data cells in a table
7134 * @cfg {String} valign Vertical aligns the content in a cell
7135 * @cfg {Number} width Specifies the width of a cell
7138 * Create a new TableCell
7139 * @param {Object} config The config object
7142 Roo.bootstrap.TableCell = function(config){
7143 Roo.bootstrap.TableCell.superclass.constructor.call(this, config);
7146 Roo.extend(Roo.bootstrap.TableCell, Roo.bootstrap.Component, {
7166 getAutoCreate : function(){
7167 var cfg = Roo.apply({}, Roo.bootstrap.TableCell.superclass.getAutoCreate.call(this));
7187 cfg.align=this.align
7193 cfg.bgcolor=this.bgcolor
7196 cfg.charoff=this.charoff
7199 cfg.colspan=this.colspan
7202 cfg.headers=this.headers
7205 cfg.height=this.height
7208 cfg.nowrap=this.nowrap
7211 cfg.rowspan=this.rowspan
7214 cfg.scope=this.scope
7217 cfg.valign=this.valign
7220 cfg.width=this.width
7239 * @class Roo.bootstrap.TableRow
7240 * @extends Roo.bootstrap.Component
7241 * Bootstrap TableRow class
7242 * @cfg {String} cls row class
7243 * @cfg {String} align Aligns the content in a table row
7244 * @cfg {String} bgcolor Specifies a background color for a table row
7245 * @cfg {Number} charoff Sets the number of characters the content will be aligned from the character specified by the char attribute
7246 * @cfg {String} valign Vertical aligns the content in a table row
7249 * Create a new TableRow
7250 * @param {Object} config The config object
7253 Roo.bootstrap.TableRow = function(config){
7254 Roo.bootstrap.TableRow.superclass.constructor.call(this, config);
7257 Roo.extend(Roo.bootstrap.TableRow, Roo.bootstrap.Component, {
7265 getAutoCreate : function(){
7266 var cfg = Roo.apply({}, Roo.bootstrap.TableRow.superclass.getAutoCreate.call(this));
7276 cfg.align = this.align;
7279 cfg.bgcolor = this.bgcolor;
7282 cfg.charoff = this.charoff;
7285 cfg.valign = this.valign;
7303 * @class Roo.bootstrap.TableBody
7304 * @extends Roo.bootstrap.Component
7305 * Bootstrap TableBody class
7306 * @cfg {String} cls element class
7307 * @cfg {String} tag element tag (thead|tbody|tfoot) default tbody
7308 * @cfg {String} align Aligns the content inside the element
7309 * @cfg {Number} charoff Sets the number of characters the content inside the element will be aligned from the character specified by the char attribute
7310 * @cfg {String} valign Vertical aligns the content inside the <tbody> element
7313 * Create a new TableBody
7314 * @param {Object} config The config object
7317 Roo.bootstrap.TableBody = function(config){
7318 Roo.bootstrap.TableBody.superclass.constructor.call(this, config);
7321 Roo.extend(Roo.bootstrap.TableBody, Roo.bootstrap.Component, {
7329 getAutoCreate : function(){
7330 var cfg = Roo.apply({}, Roo.bootstrap.TableBody.superclass.getAutoCreate.call(this));
7344 cfg.align = this.align;
7347 cfg.charoff = this.charoff;
7350 cfg.valign = this.valign;
7357 // initEvents : function()
7364 // this.store = Roo.factory(this.store, Roo.data);
7365 // this.store.on('load', this.onLoad, this);
7367 // this.store.load();
7371 // onLoad: function ()
7373 // this.fireEvent('load', this);
7383 * Ext JS Library 1.1.1
7384 * Copyright(c) 2006-2007, Ext JS, LLC.
7386 * Originally Released Under LGPL - original licence link has changed is not relivant.
7389 * <script type="text/javascript">
7392 // as we use this in bootstrap.
7393 Roo.namespace('Roo.form');
7395 * @class Roo.form.Action
7396 * Internal Class used to handle form actions
7398 * @param {Roo.form.BasicForm} el The form element or its id
7399 * @param {Object} config Configuration options
7404 // define the action interface
7405 Roo.form.Action = function(form, options){
7407 this.options = options || {};
7410 * Client Validation Failed
7413 Roo.form.Action.CLIENT_INVALID = 'client';
7415 * Server Validation Failed
7418 Roo.form.Action.SERVER_INVALID = 'server';
7420 * Connect to Server Failed
7423 Roo.form.Action.CONNECT_FAILURE = 'connect';
7425 * Reading Data from Server Failed
7428 Roo.form.Action.LOAD_FAILURE = 'load';
7430 Roo.form.Action.prototype = {
7432 failureType : undefined,
7433 response : undefined,
7437 run : function(options){
7442 success : function(response){
7447 handleResponse : function(response){
7451 // default connection failure
7452 failure : function(response){
7454 this.response = response;
7455 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7456 this.form.afterAction(this, false);
7459 processResponse : function(response){
7460 this.response = response;
7461 if(!response.responseText){
7464 this.result = this.handleResponse(response);
7468 // utility functions used internally
7469 getUrl : function(appendParams){
7470 var url = this.options.url || this.form.url || this.form.el.dom.action;
7472 var p = this.getParams();
7474 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
7480 getMethod : function(){
7481 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
7484 getParams : function(){
7485 var bp = this.form.baseParams;
7486 var p = this.options.params;
7488 if(typeof p == "object"){
7489 p = Roo.urlEncode(Roo.applyIf(p, bp));
7490 }else if(typeof p == 'string' && bp){
7491 p += '&' + Roo.urlEncode(bp);
7494 p = Roo.urlEncode(bp);
7499 createCallback : function(){
7501 success: this.success,
7502 failure: this.failure,
7504 timeout: (this.form.timeout*1000),
7505 upload: this.form.fileUpload ? this.success : undefined
7510 Roo.form.Action.Submit = function(form, options){
7511 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
7514 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
7517 haveProgress : false,
7518 uploadComplete : false,
7520 // uploadProgress indicator.
7521 uploadProgress : function()
7523 if (!this.form.progressUrl) {
7527 if (!this.haveProgress) {
7528 Roo.MessageBox.progress("Uploading", "Uploading");
7530 if (this.uploadComplete) {
7531 Roo.MessageBox.hide();
7535 this.haveProgress = true;
7537 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
7539 var c = new Roo.data.Connection();
7541 url : this.form.progressUrl,
7546 success : function(req){
7547 //console.log(data);
7551 rdata = Roo.decode(req.responseText)
7553 Roo.log("Invalid data from server..");
7557 if (!rdata || !rdata.success) {
7559 Roo.MessageBox.alert(Roo.encode(rdata));
7562 var data = rdata.data;
7564 if (this.uploadComplete) {
7565 Roo.MessageBox.hide();
7570 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
7571 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
7574 this.uploadProgress.defer(2000,this);
7577 failure: function(data) {
7578 Roo.log('progress url failed ');
7589 // run get Values on the form, so it syncs any secondary forms.
7590 this.form.getValues();
7592 var o = this.options;
7593 var method = this.getMethod();
7594 var isPost = method == 'POST';
7595 if(o.clientValidation === false || this.form.isValid()){
7597 if (this.form.progressUrl) {
7598 this.form.findField('UPLOAD_IDENTIFIER').setValue(
7599 (new Date() * 1) + '' + Math.random());
7604 Roo.Ajax.request(Roo.apply(this.createCallback(), {
7605 form:this.form.el.dom,
7606 url:this.getUrl(!isPost),
7608 params:isPost ? this.getParams() : null,
7609 isUpload: this.form.fileUpload
7612 this.uploadProgress();
7614 }else if (o.clientValidation !== false){ // client validation failed
7615 this.failureType = Roo.form.Action.CLIENT_INVALID;
7616 this.form.afterAction(this, false);
7620 success : function(response)
7622 this.uploadComplete= true;
7623 if (this.haveProgress) {
7624 Roo.MessageBox.hide();
7628 var result = this.processResponse(response);
7629 if(result === true || result.success){
7630 this.form.afterAction(this, true);
7634 this.form.markInvalid(result.errors);
7635 this.failureType = Roo.form.Action.SERVER_INVALID;
7637 this.form.afterAction(this, false);
7639 failure : function(response)
7641 this.uploadComplete= true;
7642 if (this.haveProgress) {
7643 Roo.MessageBox.hide();
7646 this.response = response;
7647 this.failureType = Roo.form.Action.CONNECT_FAILURE;
7648 this.form.afterAction(this, false);
7651 handleResponse : function(response){
7652 if(this.form.errorReader){
7653 var rs = this.form.errorReader.read(response);
7656 for(var i = 0, len = rs.records.length; i < len; i++) {
7657 var r = rs.records[i];
7661 if(errors.length < 1){
7665 success : rs.success,
7671 ret = Roo.decode(response.responseText);
7675 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
7685 Roo.form.Action.Load = function(form, options){
7686 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
7687 this.reader = this.form.reader;
7690 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
7695 Roo.Ajax.request(Roo.apply(
7696 this.createCallback(), {
7697 method:this.getMethod(),
7698 url:this.getUrl(false),
7699 params:this.getParams()
7703 success : function(response){
7705 var result = this.processResponse(response);
7706 if(result === true || !result.success || !result.data){
7707 this.failureType = Roo.form.Action.LOAD_FAILURE;
7708 this.form.afterAction(this, false);
7711 this.form.clearInvalid();
7712 this.form.setValues(result.data);
7713 this.form.afterAction(this, true);
7716 handleResponse : function(response){
7717 if(this.form.reader){
7718 var rs = this.form.reader.read(response);
7719 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
7721 success : rs.success,
7725 return Roo.decode(response.responseText);
7729 Roo.form.Action.ACTION_TYPES = {
7730 'load' : Roo.form.Action.Load,
7731 'submit' : Roo.form.Action.Submit
7740 * @class Roo.bootstrap.Form
7741 * @extends Roo.bootstrap.Component
7742 * Bootstrap Form class
7743 * @cfg {String} method GET | POST (default POST)
7744 * @cfg {String} labelAlign top | left (default top)
7745 * @cfg {String} align left | right - for navbars
7746 * @cfg {Boolean} loadMask load mask when submit (default true)
7751 * @param {Object} config The config object
7755 Roo.bootstrap.Form = function(config){
7757 Roo.bootstrap.Form.superclass.constructor.call(this, config);
7759 Roo.bootstrap.Form.popover.apply();
7763 * @event clientvalidation
7764 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
7765 * @param {Form} this
7766 * @param {Boolean} valid true if the form has passed client-side validation
7768 clientvalidation: true,
7770 * @event beforeaction
7771 * Fires before any action is performed. Return false to cancel the action.
7772 * @param {Form} this
7773 * @param {Action} action The action to be performed
7777 * @event actionfailed
7778 * Fires when an action fails.
7779 * @param {Form} this
7780 * @param {Action} action The action that failed
7782 actionfailed : true,
7784 * @event actioncomplete
7785 * Fires when an action is completed.
7786 * @param {Form} this
7787 * @param {Action} action The action that completed
7789 actioncomplete : true
7793 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component, {
7796 * @cfg {String} method
7797 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
7802 * The URL to use for form actions if one isn't supplied in the action options.
7805 * @cfg {Boolean} fileUpload
7806 * Set to true if this form is a file upload.
7810 * @cfg {Object} baseParams
7811 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
7815 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
7819 * @cfg {Sting} align (left|right) for navbar forms
7824 activeAction : null,
7827 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
7828 * element by passing it or its id or mask the form itself by passing in true.
7831 waitMsgTarget : false,
7836 * @cfg {Boolean} errorMask (true|false) default false
7841 * @cfg {Number} maskOffset Default 100
7846 * @cfg {Boolean} maskBody
7850 getAutoCreate : function(){
7854 method : this.method || 'POST',
7855 id : this.id || Roo.id(),
7858 if (this.parent().xtype.match(/^Nav/)) {
7859 cfg.cls = 'navbar-form navbar-' + this.align;
7863 if (this.labelAlign == 'left' ) {
7864 cfg.cls += ' form-horizontal';
7870 initEvents : function()
7872 this.el.on('submit', this.onSubmit, this);
7873 // this was added as random key presses on the form where triggering form submit.
7874 this.el.on('keypress', function(e) {
7875 if (e.getCharCode() != 13) {
7878 // we might need to allow it for textareas.. and some other items.
7879 // check e.getTarget().
7881 if(e.getTarget().nodeName.toLowerCase() === 'textarea'){
7885 Roo.log("keypress blocked");
7893 onSubmit : function(e){
7898 * Returns true if client-side validation on the form is successful.
7901 isValid : function(){
7902 var items = this.getItems();
7906 items.each(function(f){
7912 Roo.log('invalid field: ' + f.name);
7916 if(!target && f.el.isVisible(true)){
7922 if(this.errorMask && !valid){
7923 Roo.bootstrap.Form.popover.mask(this, target);
7930 * Returns true if any fields in this form have changed since their original load.
7933 isDirty : function(){
7935 var items = this.getItems();
7936 items.each(function(f){
7946 * Performs a predefined action (submit or load) or custom actions you define on this form.
7947 * @param {String} actionName The name of the action type
7948 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
7949 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
7950 * accept other config options):
7952 Property Type Description
7953 ---------------- --------------- ----------------------------------------------------------------------------------
7954 url String The url for the action (defaults to the form's url)
7955 method String The form method to use (defaults to the form's method, or POST if not defined)
7956 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
7957 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
7958 validate the form on the client (defaults to false)
7960 * @return {BasicForm} this
7962 doAction : function(action, options){
7963 if(typeof action == 'string'){
7964 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
7966 if(this.fireEvent('beforeaction', this, action) !== false){
7967 this.beforeAction(action);
7968 action.run.defer(100, action);
7974 beforeAction : function(action){
7975 var o = action.options;
7980 Roo.get(document.body).mask(o.waitMsg || "Sending", 'x-mask-loading')
7982 this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7985 // not really supported yet.. ??
7987 //if(this.waitMsgTarget === true){
7988 // this.el.mask(o.waitMsg || "Sending", 'x-mask-loading');
7989 //}else if(this.waitMsgTarget){
7990 // this.waitMsgTarget = Roo.get(this.waitMsgTarget);
7991 // this.waitMsgTarget.mask(o.waitMsg || "Sending", 'x-mask-loading');
7993 // Roo.MessageBox.wait(o.waitMsg || "Sending", o.waitTitle || this.waitTitle || 'Please Wait...');
7999 afterAction : function(action, success){
8000 this.activeAction = null;
8001 var o = action.options;
8006 Roo.get(document.body).unmask();
8012 //if(this.waitMsgTarget === true){
8013 // this.el.unmask();
8014 //}else if(this.waitMsgTarget){
8015 // this.waitMsgTarget.unmask();
8017 // Roo.MessageBox.updateProgress(1);
8018 // Roo.MessageBox.hide();
8025 Roo.callback(o.success, o.scope, [this, action]);
8026 this.fireEvent('actioncomplete', this, action);
8030 // failure condition..
8031 // we have a scenario where updates need confirming.
8032 // eg. if a locking scenario exists..
8033 // we look for { errors : { needs_confirm : true }} in the response.
8035 (typeof(action.result) != 'undefined') &&
8036 (typeof(action.result.errors) != 'undefined') &&
8037 (typeof(action.result.errors.needs_confirm) != 'undefined')
8040 Roo.log("not supported yet");
8043 Roo.MessageBox.confirm(
8044 "Change requires confirmation",
8045 action.result.errorMsg,
8050 _t.doAction('submit', { params : { _submit_confirmed : 1 } } );
8060 Roo.callback(o.failure, o.scope, [this, action]);
8061 // show an error message if no failed handler is set..
8062 if (!this.hasListener('actionfailed')) {
8063 Roo.log("need to add dialog support");
8065 Roo.MessageBox.alert("Error",
8066 (typeof(action.result) != 'undefined' && typeof(action.result.errorMsg) != 'undefined') ?
8067 action.result.errorMsg :
8068 "Saving Failed, please check your entries or try again"
8073 this.fireEvent('actionfailed', this, action);
8078 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
8079 * @param {String} id The value to search for
8082 findField : function(id){
8083 var items = this.getItems();
8084 var field = items.get(id);
8086 items.each(function(f){
8087 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
8094 return field || null;
8097 * Mark fields in this form invalid in bulk.
8098 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
8099 * @return {BasicForm} this
8101 markInvalid : function(errors){
8102 if(errors instanceof Array){
8103 for(var i = 0, len = errors.length; i < len; i++){
8104 var fieldError = errors[i];
8105 var f = this.findField(fieldError.id);
8107 f.markInvalid(fieldError.msg);
8113 if(typeof errors[id] != 'function' && (field = this.findField(id))){
8114 field.markInvalid(errors[id]);
8118 //Roo.each(this.childForms || [], function (f) {
8119 // f.markInvalid(errors);
8126 * Set values for fields in this form in bulk.
8127 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
8128 * @return {BasicForm} this
8130 setValues : function(values){
8131 if(values instanceof Array){ // array of objects
8132 for(var i = 0, len = values.length; i < len; i++){
8134 var f = this.findField(v.id);
8136 f.setValue(v.value);
8137 if(this.trackResetOnLoad){
8138 f.originalValue = f.getValue();
8142 }else{ // object hash
8145 if(typeof values[id] != 'function' && (field = this.findField(id))){
8147 if (field.setFromData &&
8149 field.displayField &&
8150 // combos' with local stores can
8151 // be queried via setValue()
8152 // to set their value..
8153 (field.store && !field.store.isLocal)
8157 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
8158 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
8159 field.setFromData(sd);
8161 } else if(field.setFromData && (field.store && !field.store.isLocal)) {
8163 field.setFromData(values);
8166 field.setValue(values[id]);
8170 if(this.trackResetOnLoad){
8171 field.originalValue = field.getValue();
8177 //Roo.each(this.childForms || [], function (f) {
8178 // f.setValues(values);
8185 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
8186 * they are returned as an array.
8187 * @param {Boolean} asString
8190 getValues : function(asString){
8191 //if (this.childForms) {
8192 // copy values from the child forms
8193 // Roo.each(this.childForms, function (f) {
8194 // this.setValues(f.getValues());
8200 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
8201 if(asString === true){
8204 return Roo.urlDecode(fs);
8208 * Returns the fields in this form as an object with key/value pairs.
8209 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
8212 getFieldValues : function(with_hidden)
8214 var items = this.getItems();
8216 items.each(function(f){
8222 var v = f.getValue();
8224 if (f.inputType =='radio') {
8225 if (typeof(ret[f.getName()]) == 'undefined') {
8226 ret[f.getName()] = ''; // empty..
8229 if (!f.el.dom.checked) {
8237 if(f.xtype == 'MoneyField'){
8238 ret[f.currencyName] = f.getCurrency();
8241 // not sure if this supported any more..
8242 if ((typeof(v) == 'object') && f.getRawValue) {
8243 v = f.getRawValue() ; // dates..
8245 // combo boxes where name != hiddenName...
8246 if (f.name !== false && f.name != '' && f.name != f.getName()) {
8247 ret[f.name] = f.getRawValue();
8249 ret[f.getName()] = v;
8256 * Clears all invalid messages in this form.
8257 * @return {BasicForm} this
8259 clearInvalid : function(){
8260 var items = this.getItems();
8262 items.each(function(f){
8271 * @return {BasicForm} this
8274 var items = this.getItems();
8275 items.each(function(f){
8279 Roo.each(this.childForms || [], function (f) {
8287 getItems : function()
8289 var r=new Roo.util.MixedCollection(false, function(o){
8290 return o.id || (o.id = Roo.id());
8292 var iter = function(el) {
8299 Roo.each(el.items,function(e) {
8308 hideFields : function(items)
8310 Roo.each(items, function(i){
8312 var f = this.findField(i);
8323 showFields : function(items)
8325 Roo.each(items, function(i){
8327 var f = this.findField(i);
8340 Roo.apply(Roo.bootstrap.Form, {
8367 top : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-top-mask" }, true),
8368 left : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-left-mask" }, true),
8369 bottom : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-bottom-mask" }, true),
8370 right : Roo.DomHelper.append(Roo.get(document.body), { tag: "div", cls:"x-dlg-mask roo-form-right-mask" }, true)
8373 this.maskEl.top.enableDisplayMode("block");
8374 this.maskEl.left.enableDisplayMode("block");
8375 this.maskEl.bottom.enableDisplayMode("block");
8376 this.maskEl.right.enableDisplayMode("block");
8378 this.toolTip = new Roo.bootstrap.Tooltip({
8379 cls : 'roo-form-error-popover',
8381 'left' : ['r-l', [-2,0], 'right'],
8382 'right' : ['l-r', [2,0], 'left'],
8383 'bottom' : ['tl-bl', [0,2], 'top'],
8384 'top' : [ 'bl-tl', [0,-2], 'bottom']
8388 this.toolTip.render(Roo.get(document.body));
8390 this.toolTip.el.enableDisplayMode("block");
8392 Roo.get(document.body).on('click', function(){
8396 Roo.get(document.body).on('touchstart', function(){
8400 this.isApplied = true
8403 mask : function(form, target)
8407 this.target = target;
8409 if(!this.form.errorMask || !target.el){
8413 var scrollable = this.target.el.findScrollableParent() || this.target.el.findParent('div.modal', 100, true) || Roo.get(document.body);
8415 Roo.log(scrollable);
8417 var ot = this.target.el.calcOffsetsTo(scrollable);
8419 var scrollTo = ot[1] - this.form.maskOffset;
8421 scrollTo = Math.min(scrollTo, scrollable.dom.scrollHeight);
8423 scrollable.scrollTo('top', scrollTo);
8425 var box = this.target.el.getBox();
8427 var zIndex = Roo.bootstrap.Modal.zIndex++;
8430 this.maskEl.top.setStyle('position', 'absolute');
8431 this.maskEl.top.setStyle('z-index', zIndex);
8432 this.maskEl.top.setSize(Roo.lib.Dom.getDocumentWidth(), box.y - this.padding);
8433 this.maskEl.top.setLeft(0);
8434 this.maskEl.top.setTop(0);
8435 this.maskEl.top.show();
8437 this.maskEl.left.setStyle('position', 'absolute');
8438 this.maskEl.left.setStyle('z-index', zIndex);
8439 this.maskEl.left.setSize(box.x - this.padding, box.height + this.padding * 2);
8440 this.maskEl.left.setLeft(0);
8441 this.maskEl.left.setTop(box.y - this.padding);
8442 this.maskEl.left.show();
8444 this.maskEl.bottom.setStyle('position', 'absolute');
8445 this.maskEl.bottom.setStyle('z-index', zIndex);
8446 this.maskEl.bottom.setSize(Roo.lib.Dom.getDocumentWidth(), Roo.lib.Dom.getDocumentHeight() - box.bottom - this.padding);
8447 this.maskEl.bottom.setLeft(0);
8448 this.maskEl.bottom.setTop(box.bottom + this.padding);
8449 this.maskEl.bottom.show();
8451 this.maskEl.right.setStyle('position', 'absolute');
8452 this.maskEl.right.setStyle('z-index', zIndex);
8453 this.maskEl.right.setSize(Roo.lib.Dom.getDocumentWidth() - box.right - this.padding, box.height + this.padding * 2);
8454 this.maskEl.right.setLeft(box.right + this.padding);
8455 this.maskEl.right.setTop(box.y - this.padding);
8456 this.maskEl.right.show();
8458 this.toolTip.bindEl = this.target.el;
8460 this.toolTip.el.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
8462 var tip = this.target.blankText;
8464 if(this.target.getValue() !== '' ) {
8466 if (this.target.invalidText.length) {
8467 tip = this.target.invalidText;
8468 } else if (this.target.regexText.length){
8469 tip = this.target.regexText;
8473 this.toolTip.show(tip);
8475 this.intervalID = window.setInterval(function() {
8476 Roo.bootstrap.Form.popover.unmask();
8479 window.onwheel = function(){ return false;};
8481 (function(){ this.isMasked = true; }).defer(500, this);
8487 if(!this.isApplied || !this.isMasked || !this.form || !this.target || !this.form.errorMask){
8491 this.maskEl.top.setStyle('position', 'absolute');
8492 this.maskEl.top.setSize(0, 0).setXY([0, 0]);
8493 this.maskEl.top.hide();
8495 this.maskEl.left.setStyle('position', 'absolute');
8496 this.maskEl.left.setSize(0, 0).setXY([0, 0]);
8497 this.maskEl.left.hide();
8499 this.maskEl.bottom.setStyle('position', 'absolute');
8500 this.maskEl.bottom.setSize(0, 0).setXY([0, 0]);
8501 this.maskEl.bottom.hide();
8503 this.maskEl.right.setStyle('position', 'absolute');
8504 this.maskEl.right.setSize(0, 0).setXY([0, 0]);
8505 this.maskEl.right.hide();
8507 this.toolTip.hide();
8509 this.toolTip.el.hide();
8511 window.onwheel = function(){ return true;};
8513 if(this.intervalID){
8514 window.clearInterval(this.intervalID);
8515 this.intervalID = false;
8518 this.isMasked = false;
8528 * Ext JS Library 1.1.1
8529 * Copyright(c) 2006-2007, Ext JS, LLC.
8531 * Originally Released Under LGPL - original licence link has changed is not relivant.
8534 * <script type="text/javascript">
8537 * @class Roo.form.VTypes
8538 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
8541 Roo.form.VTypes = function(){
8542 // closure these in so they are only created once.
8543 var alpha = /^[a-zA-Z_]+$/;
8544 var alphanum = /^[a-zA-Z0-9_]+$/;
8545 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,24}$/;
8546 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
8548 // All these messages and functions are configurable
8551 * The function used to validate email addresses
8552 * @param {String} value The email address
8554 'email' : function(v){
8555 return email.test(v);
8558 * The error text to display when the email validation function returns false
8561 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
8563 * The keystroke filter mask to be applied on email input
8566 'emailMask' : /[a-z0-9_\.\-@]/i,
8569 * The function used to validate URLs
8570 * @param {String} value The URL
8572 'url' : function(v){
8576 * The error text to display when the url validation function returns false
8579 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
8582 * The function used to validate alpha values
8583 * @param {String} value The value
8585 'alpha' : function(v){
8586 return alpha.test(v);
8589 * The error text to display when the alpha validation function returns false
8592 'alphaText' : 'This field should only contain letters and _',
8594 * The keystroke filter mask to be applied on alpha input
8597 'alphaMask' : /[a-z_]/i,
8600 * The function used to validate alphanumeric values
8601 * @param {String} value The value
8603 'alphanum' : function(v){
8604 return alphanum.test(v);
8607 * The error text to display when the alphanumeric validation function returns false
8610 'alphanumText' : 'This field should only contain letters, numbers and _',
8612 * The keystroke filter mask to be applied on alphanumeric input
8615 'alphanumMask' : /[a-z0-9_]/i
8625 * @class Roo.bootstrap.Input
8626 * @extends Roo.bootstrap.Component
8627 * Bootstrap Input class
8628 * @cfg {Boolean} disabled is it disabled
8629 * @cfg {String} inputType button | checkbox | email | file | hidden | image | number | password | radio | range | reset | search | submit | text
8630 * @cfg {String} name name of the input
8631 * @cfg {string} fieldLabel - the label associated
8632 * @cfg {string} placeholder - placeholder to put in text.
8633 * @cfg {string} before - input group add on before
8634 * @cfg {string} after - input group add on after
8635 * @cfg {string} size - (lg|sm) or leave empty..
8636 * @cfg {Number} xs colspan out of 12 for mobile-sized screens
8637 * @cfg {Number} sm colspan out of 12 for tablet-sized screens
8638 * @cfg {Number} md colspan out of 12 for computer-sized screens
8639 * @cfg {Number} lg colspan out of 12 for large computer-sized screens
8640 * @cfg {string} value default value of the input
8641 * @cfg {Number} labelWidth set the width of label
8642 * @cfg {Number} labellg set the width of label (1-12)
8643 * @cfg {Number} labelmd set the width of label (1-12)
8644 * @cfg {Number} labelsm set the width of label (1-12)
8645 * @cfg {Number} labelxs set the width of label (1-12)
8646 * @cfg {String} labelAlign (top|left)
8647 * @cfg {Boolean} readOnly Specifies that the field should be read-only
8648 * @cfg {String} autocomplete - default is new-password see: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en
8649 * @cfg {String} indicatorpos (left|right) default left
8650 * @cfg {String} capture (user|camera) use for file input only. (default empty)
8651 * @cfg {String} accept (image|video|audio) use for file input only. (default empty)
8653 * @cfg {String} align (left|center|right) Default left
8654 * @cfg {Boolean} forceFeedback (true|false) Default false
8657 * Create a new Input
8658 * @param {Object} config The config object
8661 Roo.bootstrap.Input = function(config){
8663 Roo.bootstrap.Input.superclass.constructor.call(this, config);
8668 * Fires when this field receives input focus.
8669 * @param {Roo.form.Field} this
8674 * Fires when this field loses input focus.
8675 * @param {Roo.form.Field} this
8680 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
8681 * {@link Roo.EventObject#getKey} to determine which key was pressed.
8682 * @param {Roo.form.Field} this
8683 * @param {Roo.EventObject} e The event object
8688 * Fires just before the field blurs if the field value has changed.
8689 * @param {Roo.form.Field} this
8690 * @param {Mixed} newValue The new value
8691 * @param {Mixed} oldValue The original value
8696 * Fires after the field has been marked as invalid.
8697 * @param {Roo.form.Field} this
8698 * @param {String} msg The validation message
8703 * Fires after the field has been validated with no errors.
8704 * @param {Roo.form.Field} this
8709 * Fires after the key up
8710 * @param {Roo.form.Field} this
8711 * @param {Roo.EventObject} e The event Object
8717 Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component, {
8719 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
8720 automatic validation (defaults to "keyup").
8722 validationEvent : "keyup",
8724 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
8726 validateOnBlur : true,
8728 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
8730 validationDelay : 250,
8732 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
8734 focusClass : "x-form-focus", // not needed???
8738 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
8740 invalidClass : "has-warning",
8743 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
8745 validClass : "has-success",
8748 * @cfg {Boolean} hasFeedback (true|false) default true
8753 * @cfg {String} invalidFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8755 invalidFeedbackClass : "glyphicon-warning-sign",
8758 * @cfg {String} validFeedbackIcon The CSS class to use when create feedback icon (defaults to "x-form-invalid")
8760 validFeedbackClass : "glyphicon-ok",
8763 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
8765 selectOnFocus : false,
8768 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
8772 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
8777 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
8779 disableKeyFilter : false,
8782 * @cfg {Boolean} disabled True to disable the field (defaults to false).
8786 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
8790 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
8792 blankText : "Please complete this mandatory field",
8795 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
8799 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
8801 maxLength : Number.MAX_VALUE,
8803 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
8805 minLengthText : "The minimum length for this field is {0}",
8807 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
8809 maxLengthText : "The maximum length for this field is {0}",
8813 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
8814 * If available, this function will be called only after the basic validators all return true, and will be passed the
8815 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
8819 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
8820 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
8821 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
8825 * @cfg {String} regexText -- Depricated - use Invalid Text
8830 * @cfg {String} invalidText The error text to display if {@link #validator} test fails during validation (defaults to "")
8836 autocomplete: false,
8855 formatedValue : false,
8856 forceFeedback : false,
8858 indicatorpos : 'left',
8868 parentLabelAlign : function()
8871 while (parent.parent()) {
8872 parent = parent.parent();
8873 if (typeof(parent.labelAlign) !='undefined') {
8874 return parent.labelAlign;
8881 getAutoCreate : function()
8883 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
8889 if(this.inputType != 'hidden'){
8890 cfg.cls = 'form-group' //input-group
8896 type : this.inputType,
8898 cls : 'form-control',
8899 placeholder : this.placeholder || '',
8900 autocomplete : this.autocomplete || 'new-password'
8903 if(this.capture.length){
8904 input.capture = this.capture;
8907 if(this.accept.length){
8908 input.accept = this.accept + "/*";
8912 input.style = (typeof(input.style) == 'undefined') ? ('text-align:' + this.align) : (input.style + 'text-align:' + this.align);
8915 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
8916 input.maxLength = this.maxLength;
8919 if (this.disabled) {
8920 input.disabled=true;
8923 if (this.readOnly) {
8924 input.readonly=true;
8928 input.name = this.name;
8932 input.cls += ' input-' + this.size;
8936 ['xs','sm','md','lg'].map(function(size){
8937 if (settings[size]) {
8938 cfg.cls += ' col-' + size + '-' + settings[size];
8942 var inputblock = input;
8946 cls: 'glyphicon form-control-feedback'
8949 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
8952 cls : 'has-feedback',
8960 if (this.before || this.after) {
8963 cls : 'input-group',
8967 if (this.before && typeof(this.before) == 'string') {
8969 inputblock.cn.push({
8971 cls : 'roo-input-before input-group-addon',
8975 if (this.before && typeof(this.before) == 'object') {
8976 this.before = Roo.factory(this.before);
8978 inputblock.cn.push({
8980 cls : 'roo-input-before input-group-' +
8981 (this.before.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
8985 inputblock.cn.push(input);
8987 if (this.after && typeof(this.after) == 'string') {
8988 inputblock.cn.push({
8990 cls : 'roo-input-after input-group-addon',
8994 if (this.after && typeof(this.after) == 'object') {
8995 this.after = Roo.factory(this.after);
8997 inputblock.cn.push({
8999 cls : 'roo-input-after input-group-' +
9000 (this.after.xtype == 'Button' ? 'btn' : 'addon') //?? what about checkboxes - that looks like a bit of a hack thought?
9004 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9005 inputblock.cls += ' has-feedback';
9006 inputblock.cn.push(feedback);
9010 if (align ==='left' && this.fieldLabel.length) {
9012 cfg.cls += ' roo-form-group-label-left';
9017 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9018 tooltip : 'This field is required'
9023 cls : 'control-label',
9024 html : this.fieldLabel
9035 var labelCfg = cfg.cn[1];
9036 var contentCfg = cfg.cn[2];
9038 if(this.indicatorpos == 'right'){
9043 cls : 'control-label',
9047 html : this.fieldLabel
9051 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9052 tooltip : 'This field is required'
9065 labelCfg = cfg.cn[0];
9066 contentCfg = cfg.cn[1];
9070 if(this.labelWidth > 12){
9071 labelCfg.style = "width: " + this.labelWidth + 'px';
9074 if(this.labelWidth < 13 && this.labelmd == 0){
9075 this.labelmd = this.labelWidth;
9078 if(this.labellg > 0){
9079 labelCfg.cls += ' col-lg-' + this.labellg;
9080 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
9083 if(this.labelmd > 0){
9084 labelCfg.cls += ' col-md-' + this.labelmd;
9085 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
9088 if(this.labelsm > 0){
9089 labelCfg.cls += ' col-sm-' + this.labelsm;
9090 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
9093 if(this.labelxs > 0){
9094 labelCfg.cls += ' col-xs-' + this.labelxs;
9095 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
9099 } else if ( this.fieldLabel.length) {
9104 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
9105 tooltip : 'This field is required'
9109 //cls : 'input-group-addon',
9110 html : this.fieldLabel
9118 if(this.indicatorpos == 'right'){
9123 //cls : 'input-group-addon',
9124 html : this.fieldLabel
9129 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
9130 tooltip : 'This field is required'
9150 if (this.parentType === 'Navbar' && this.parent().bar) {
9151 cfg.cls += ' navbar-form';
9154 if (this.parentType === 'NavGroup') {
9155 cfg.cls += ' navbar-form';
9163 * return the real input element.
9165 inputEl: function ()
9167 return this.el.select('input.form-control',true).first();
9170 tooltipEl : function()
9172 return this.inputEl();
9175 indicatorEl : function()
9177 var indicator = this.el.select('i.roo-required-indicator',true).first();
9187 setDisabled : function(v)
9189 var i = this.inputEl().dom;
9191 i.removeAttribute('disabled');
9195 i.setAttribute('disabled','true');
9197 initEvents : function()
9200 this.inputEl().on("keydown" , this.fireKey, this);
9201 this.inputEl().on("focus", this.onFocus, this);
9202 this.inputEl().on("blur", this.onBlur, this);
9204 this.inputEl().relayEvent('keyup', this);
9206 this.indicator = this.indicatorEl();
9209 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible'); // changed from invisible??? -
9212 // reference to original value for reset
9213 this.originalValue = this.getValue();
9214 //Roo.form.TextField.superclass.initEvents.call(this);
9215 if(this.validationEvent == 'keyup'){
9216 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
9217 this.inputEl().on('keyup', this.filterValidation, this);
9219 else if(this.validationEvent !== false){
9220 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
9223 if(this.selectOnFocus){
9224 this.on("focus", this.preFocus, this);
9227 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
9228 this.inputEl().on("keypress", this.filterKeys, this);
9230 this.inputEl().relayEvent('keypress', this);
9233 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
9234 this.el.on("click", this.autoSize, this);
9237 if(this.inputEl().is('input[type=password]') && Roo.isSafari){
9238 this.inputEl().on('keydown', this.SafariOnKeyDown, this);
9241 if (typeof(this.before) == 'object') {
9242 this.before.render(this.el.select('.roo-input-before',true).first());
9244 if (typeof(this.after) == 'object') {
9245 this.after.render(this.el.select('.roo-input-after',true).first());
9248 this.inputEl().on('change', this.onChange, this);
9251 filterValidation : function(e){
9252 if(!e.isNavKeyPress()){
9253 this.validationTask.delay(this.validationDelay);
9257 * Validates the field value
9258 * @return {Boolean} True if the value is valid, else false
9260 validate : function(){
9261 //if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
9262 if(this.disabled || this.validateValue(this.getRawValue())){
9273 * Validates a value according to the field's validation rules and marks the field as invalid
9274 * if the validation fails
9275 * @param {Mixed} value The value to validate
9276 * @return {Boolean} True if the value is valid, else false
9278 validateValue : function(value)
9280 if(this.getVisibilityEl().hasClass('hidden')){
9284 if(value.length < 1) { // if it's blank
9285 if(this.allowBlank){
9291 if(value.length < this.minLength){
9294 if(value.length > this.maxLength){
9298 var vt = Roo.form.VTypes;
9299 if(!vt[this.vtype](value, this)){
9303 if(typeof this.validator == "function"){
9304 var msg = this.validator(value);
9308 if (typeof(msg) == 'string') {
9309 this.invalidText = msg;
9313 if(this.regex && !this.regex.test(value)){
9321 fireKey : function(e){
9322 //Roo.log('field ' + e.getKey());
9323 if(e.isNavKeyPress()){
9324 this.fireEvent("specialkey", this, e);
9327 focus : function (selectText){
9329 this.inputEl().focus();
9330 if(selectText === true){
9331 this.inputEl().dom.select();
9337 onFocus : function(){
9338 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9339 // this.el.addClass(this.focusClass);
9342 this.hasFocus = true;
9343 this.startValue = this.getValue();
9344 this.fireEvent("focus", this);
9348 beforeBlur : Roo.emptyFn,
9352 onBlur : function(){
9354 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
9355 //this.el.removeClass(this.focusClass);
9357 this.hasFocus = false;
9358 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
9361 var v = this.getValue();
9362 if(String(v) !== String(this.startValue)){
9363 this.fireEvent('change', this, v, this.startValue);
9365 this.fireEvent("blur", this);
9368 onChange : function(e)
9370 var v = this.getValue();
9371 if(String(v) !== String(this.startValue)){
9372 this.fireEvent('change', this, v, this.startValue);
9378 * Resets the current field value to the originally loaded value and clears any validation messages
9381 this.setValue(this.originalValue);
9385 * Returns the name of the field
9386 * @return {Mixed} name The name field
9388 getName: function(){
9392 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
9393 * @return {Mixed} value The field value
9395 getValue : function(){
9397 var v = this.inputEl().getValue();
9402 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
9403 * @return {Mixed} value The field value
9405 getRawValue : function(){
9406 var v = this.inputEl().getValue();
9412 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
9413 * @param {Mixed} value The value to set
9415 setRawValue : function(v){
9416 return this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9419 selectText : function(start, end){
9420 var v = this.getRawValue();
9422 start = start === undefined ? 0 : start;
9423 end = end === undefined ? v.length : end;
9424 var d = this.inputEl().dom;
9425 if(d.setSelectionRange){
9426 d.setSelectionRange(start, end);
9427 }else if(d.createTextRange){
9428 var range = d.createTextRange();
9429 range.moveStart("character", start);
9430 range.moveEnd("character", v.length-end);
9437 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
9438 * @param {Mixed} value The value to set
9440 setValue : function(v){
9443 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
9449 processValue : function(value){
9450 if(this.stripCharsRe){
9451 var newValue = value.replace(this.stripCharsRe, '');
9452 if(newValue !== value){
9453 this.setRawValue(newValue);
9460 preFocus : function(){
9462 if(this.selectOnFocus){
9463 this.inputEl().dom.select();
9466 filterKeys : function(e){
9468 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
9471 var c = e.getCharCode(), cc = String.fromCharCode(c);
9472 if(Roo.isIE && (e.isSpecialKey() || !cc)){
9475 if(!this.maskRe.test(cc)){
9480 * Clear any invalid styles/messages for this field
9482 clearInvalid : function(){
9484 if(!this.el || this.preventMark){ // not rendered
9489 this.el.removeClass(this.invalidClass);
9491 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9493 var feedback = this.el.select('.form-control-feedback', true).first();
9496 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9502 this.indicator.removeClass('visible');
9503 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9506 this.fireEvent('valid', this);
9510 * Mark this field as valid
9512 markValid : function()
9514 if(!this.el || this.preventMark){ // not rendered...
9518 this.el.removeClass([this.invalidClass, this.validClass]);
9520 var feedback = this.el.select('.form-control-feedback', true).first();
9523 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9527 this.indicator.removeClass('visible');
9528 this.indicator.addClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9535 if(this.allowBlank && !this.getRawValue().length){
9539 this.el.addClass(this.validClass);
9541 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9543 var feedback = this.el.select('.form-control-feedback', true).first();
9546 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9547 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9552 this.fireEvent('valid', this);
9556 * Mark this field as invalid
9557 * @param {String} msg The validation message
9559 markInvalid : function(msg)
9561 if(!this.el || this.preventMark){ // not rendered
9565 this.el.removeClass([this.invalidClass, this.validClass]);
9567 var feedback = this.el.select('.form-control-feedback', true).first();
9570 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9577 if(this.allowBlank && !this.getRawValue().length){
9582 this.indicator.removeClass(this.indicatorpos == 'right' ? 'hidden' : 'invisible');
9583 this.indicator.addClass('visible');
9586 this.el.addClass(this.invalidClass);
9588 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9590 var feedback = this.el.select('.form-control-feedback', true).first();
9593 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9595 if(this.getValue().length || this.forceFeedback){
9596 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
9603 this.fireEvent('invalid', this, msg);
9606 SafariOnKeyDown : function(event)
9608 // this is a workaround for a password hang bug on chrome/ webkit.
9609 if (this.inputEl().dom.type != 'password') {
9613 var isSelectAll = false;
9615 if(this.inputEl().dom.selectionEnd > 0){
9616 isSelectAll = (this.inputEl().dom.selectionEnd - this.inputEl().dom.selectionStart - this.getValue().length == 0) ? true : false;
9618 if(((event.getKey() == 8 || event.getKey() == 46) && this.getValue().length ==1)){ // backspace and delete key
9619 event.preventDefault();
9624 if(isSelectAll && event.getCharCode() > 31 && !event.ctrlKey) { // not backspace and delete key (or ctrl-v)
9626 event.preventDefault();
9627 // this is very hacky as keydown always get's upper case.
9629 var cc = String.fromCharCode(event.getCharCode());
9630 this.setValue( event.shiftKey ? cc : cc.toLowerCase());
9634 adjustWidth : function(tag, w){
9635 tag = tag.toLowerCase();
9636 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
9637 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
9641 if(tag == 'textarea'){
9644 }else if(Roo.isOpera){
9648 if(tag == 'textarea'){
9656 setFieldLabel : function(v)
9663 var ar = this.el.select('label > span',true);
9665 if (ar.elements.length) {
9666 this.el.select('label > span',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9667 this.fieldLabel = v;
9671 var br = this.el.select('label',true);
9673 if(br.elements.length) {
9674 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9675 this.fieldLabel = v;
9679 Roo.log('Cannot Found any of label > span || label in input');
9683 this.el.select('label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
9684 this.fieldLabel = v;
9699 * @class Roo.bootstrap.TextArea
9700 * @extends Roo.bootstrap.Input
9701 * Bootstrap TextArea class
9702 * @cfg {Number} cols Specifies the visible width of a text area
9703 * @cfg {Number} rows Specifies the visible number of lines in a text area
9704 * @cfg {string} wrap (soft|hard)Specifies how the text in a text area is to be wrapped when submitted in a form
9705 * @cfg {string} resize (none|both|horizontal|vertical|inherit|initial)
9706 * @cfg {string} html text
9709 * Create a new TextArea
9710 * @param {Object} config The config object
9713 Roo.bootstrap.TextArea = function(config){
9714 Roo.bootstrap.TextArea.superclass.constructor.call(this, config);
9718 Roo.extend(Roo.bootstrap.TextArea, Roo.bootstrap.Input, {
9728 getAutoCreate : function(){
9730 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
9736 if(this.inputType != 'hidden'){
9737 cfg.cls = 'form-group' //input-group
9745 value : this.value || '',
9746 html: this.html || '',
9747 cls : 'form-control',
9748 placeholder : this.placeholder || ''
9752 if(this.maxLength && this.maxLength != Number.MAX_VALUE){
9753 input.maxLength = this.maxLength;
9757 input.style = (typeof(input.style) == 'undefined') ? 'resize:' + this.resize : input.style + 'resize:' + this.resize;
9761 input.cols = this.cols;
9764 if (this.readOnly) {
9765 input.readonly = true;
9769 input.name = this.name;
9773 input.cls = (typeof(input.cls) == 'undefined') ? 'input-' + this.size : input.cls + ' input-' + this.size;
9777 ['xs','sm','md','lg'].map(function(size){
9778 if (settings[size]) {
9779 cfg.cls += ' col-' + size + '-' + settings[size];
9783 var inputblock = input;
9785 if(this.hasFeedback && !this.allowBlank){
9789 cls: 'glyphicon form-control-feedback'
9793 cls : 'has-feedback',
9802 if (this.before || this.after) {
9805 cls : 'input-group',
9809 inputblock.cn.push({
9811 cls : 'input-group-addon',
9816 inputblock.cn.push(input);
9818 if(this.hasFeedback && !this.allowBlank){
9819 inputblock.cls += ' has-feedback';
9820 inputblock.cn.push(feedback);
9824 inputblock.cn.push({
9826 cls : 'input-group-addon',
9833 if (align ==='left' && this.fieldLabel.length) {
9838 cls : 'control-label',
9839 html : this.fieldLabel
9850 if(this.labelWidth > 12){
9851 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
9854 if(this.labelWidth < 13 && this.labelmd == 0){
9855 this.labelmd = this.labelWidth;
9858 if(this.labellg > 0){
9859 cfg.cn[0].cls += ' col-lg-' + this.labellg;
9860 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
9863 if(this.labelmd > 0){
9864 cfg.cn[0].cls += ' col-md-' + this.labelmd;
9865 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
9868 if(this.labelsm > 0){
9869 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
9870 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
9873 if(this.labelxs > 0){
9874 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
9875 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
9878 } else if ( this.fieldLabel.length) {
9883 //cls : 'input-group-addon',
9884 html : this.fieldLabel
9902 if (this.disabled) {
9903 input.disabled=true;
9910 * return the real textarea element.
9912 inputEl: function ()
9914 return this.el.select('textarea.form-control',true).first();
9918 * Clear any invalid styles/messages for this field
9920 clearInvalid : function()
9923 if(!this.el || this.preventMark){ // not rendered
9927 var label = this.el.select('label', true).first();
9928 var icon = this.el.select('i.fa-star', true).first();
9934 this.el.removeClass(this.invalidClass);
9936 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
9938 var feedback = this.el.select('.form-control-feedback', true).first();
9941 this.el.select('.form-control-feedback', true).first().removeClass(this.invalidFeedbackClass);
9946 this.fireEvent('valid', this);
9950 * Mark this field as valid
9952 markValid : function()
9954 if(!this.el || this.preventMark){ // not rendered
9958 this.el.removeClass([this.invalidClass, this.validClass]);
9960 var feedback = this.el.select('.form-control-feedback', true).first();
9963 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9966 if(this.disabled || this.allowBlank){
9970 var label = this.el.select('label', true).first();
9971 var icon = this.el.select('i.fa-star', true).first();
9977 this.el.addClass(this.validClass);
9979 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
9981 var feedback = this.el.select('.form-control-feedback', true).first();
9984 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
9985 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
9990 this.fireEvent('valid', this);
9994 * Mark this field as invalid
9995 * @param {String} msg The validation message
9997 markInvalid : function(msg)
9999 if(!this.el || this.preventMark){ // not rendered
10003 this.el.removeClass([this.invalidClass, this.validClass]);
10005 var feedback = this.el.select('.form-control-feedback', true).first();
10008 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10011 if(this.disabled || this.allowBlank){
10015 var label = this.el.select('label', true).first();
10016 var icon = this.el.select('i.fa-star', true).first();
10018 if(!this.getValue().length && label && !icon){
10019 this.el.createChild({
10021 cls : 'text-danger fa fa-lg fa-star',
10022 tooltip : 'This field is required',
10023 style : 'margin-right:5px;'
10027 this.el.addClass(this.invalidClass);
10029 if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
10031 var feedback = this.el.select('.form-control-feedback', true).first();
10034 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
10036 if(this.getValue().length || this.forceFeedback){
10037 this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
10044 this.fireEvent('invalid', this, msg);
10052 * trigger field - base class for combo..
10057 * @class Roo.bootstrap.TriggerField
10058 * @extends Roo.bootstrap.Input
10059 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
10060 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
10061 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
10062 * for which you can provide a custom implementation. For example:
10064 var trigger = new Roo.bootstrap.TriggerField();
10065 trigger.onTriggerClick = myTriggerFn;
10066 trigger.applyTo('my-field');
10069 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
10070 * {@link Roo.bootstrap.DateField} and {@link Roo.bootstrap.ComboBox} are perfect examples of this.
10071 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
10072 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
10073 * @cfg {String} caret (search|calendar) a fontawesome for the trigger icon see http://fortawesome.github.io/Font-Awesome/icons/
10076 * Create a new TriggerField.
10077 * @param {Object} config Configuration options (valid {@Roo.bootstrap.Input} config options will also be applied
10078 * to the base TextField)
10080 Roo.bootstrap.TriggerField = function(config){
10081 this.mimicing = false;
10082 Roo.bootstrap.TriggerField.superclass.constructor.call(this, config);
10085 Roo.extend(Roo.bootstrap.TriggerField, Roo.bootstrap.Input, {
10087 * @cfg {String} triggerClass A CSS class to apply to the trigger
10090 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
10095 * @cfg {Boolean} removable (true|false) special filter default false
10099 /** @cfg {Boolean} grow @hide */
10100 /** @cfg {Number} growMin @hide */
10101 /** @cfg {Number} growMax @hide */
10107 autoSize: Roo.emptyFn,
10111 deferHeight : true,
10114 actionMode : 'wrap',
10119 getAutoCreate : function(){
10121 var align = this.labelAlign || this.parentLabelAlign();
10126 cls: 'form-group' //input-group
10133 type : this.inputType,
10134 cls : 'form-control',
10135 autocomplete: 'new-password',
10136 placeholder : this.placeholder || ''
10140 input.name = this.name;
10143 input.cls += ' input-' + this.size;
10146 if (this.disabled) {
10147 input.disabled=true;
10150 var inputblock = input;
10152 if(this.hasFeedback && !this.allowBlank){
10156 cls: 'glyphicon form-control-feedback'
10159 if(this.removable && !this.editable && !this.tickable){
10161 cls : 'has-feedback',
10167 cls : 'roo-combo-removable-btn close'
10174 cls : 'has-feedback',
10183 if(this.removable && !this.editable && !this.tickable){
10185 cls : 'roo-removable',
10191 cls : 'roo-combo-removable-btn close'
10198 if (this.before || this.after) {
10201 cls : 'input-group',
10205 inputblock.cn.push({
10207 cls : 'input-group-addon',
10212 inputblock.cn.push(input);
10214 if(this.hasFeedback && !this.allowBlank){
10215 inputblock.cls += ' has-feedback';
10216 inputblock.cn.push(feedback);
10220 inputblock.cn.push({
10222 cls : 'input-group-addon',
10235 cls: 'form-hidden-field'
10249 cls: 'form-hidden-field'
10253 cls: 'roo-select2-choices',
10257 cls: 'roo-select2-search-field',
10270 cls: 'roo-select2-container input-group',
10275 // cls: 'typeahead typeahead-long dropdown-menu',
10276 // style: 'display:none'
10281 if(!this.multiple && this.showToggleBtn){
10287 if (this.caret != false) {
10290 cls: 'fa fa-' + this.caret
10297 cls : 'input-group-addon btn dropdown-toggle',
10302 cls: 'combobox-clear',
10316 combobox.cls += ' roo-select2-container-multi';
10319 if (align ==='left' && this.fieldLabel.length) {
10321 cfg.cls += ' roo-form-group-label-left';
10326 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10327 tooltip : 'This field is required'
10332 cls : 'control-label',
10333 html : this.fieldLabel
10345 var labelCfg = cfg.cn[1];
10346 var contentCfg = cfg.cn[2];
10348 if(this.indicatorpos == 'right'){
10353 cls : 'control-label',
10357 html : this.fieldLabel
10361 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10362 tooltip : 'This field is required'
10375 labelCfg = cfg.cn[0];
10376 contentCfg = cfg.cn[1];
10379 if(this.labelWidth > 12){
10380 labelCfg.style = "width: " + this.labelWidth + 'px';
10383 if(this.labelWidth < 13 && this.labelmd == 0){
10384 this.labelmd = this.labelWidth;
10387 if(this.labellg > 0){
10388 labelCfg.cls += ' col-lg-' + this.labellg;
10389 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
10392 if(this.labelmd > 0){
10393 labelCfg.cls += ' col-md-' + this.labelmd;
10394 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
10397 if(this.labelsm > 0){
10398 labelCfg.cls += ' col-sm-' + this.labelsm;
10399 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
10402 if(this.labelxs > 0){
10403 labelCfg.cls += ' col-xs-' + this.labelxs;
10404 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
10407 } else if ( this.fieldLabel.length) {
10408 // Roo.log(" label");
10412 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
10413 tooltip : 'This field is required'
10417 //cls : 'input-group-addon',
10418 html : this.fieldLabel
10426 if(this.indicatorpos == 'right'){
10434 html : this.fieldLabel
10438 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
10439 tooltip : 'This field is required'
10452 // Roo.log(" no label && no align");
10459 ['xs','sm','md','lg'].map(function(size){
10460 if (settings[size]) {
10461 cfg.cls += ' col-' + size + '-' + settings[size];
10472 onResize : function(w, h){
10473 // Roo.bootstrap.TriggerField.superclass.onResize.apply(this, arguments);
10474 // if(typeof w == 'number'){
10475 // var x = w - this.trigger.getWidth();
10476 // this.inputEl().setWidth(this.adjustWidth('input', x));
10477 // this.trigger.setStyle('left', x+'px');
10482 adjustSize : Roo.BoxComponent.prototype.adjustSize,
10485 getResizeEl : function(){
10486 return this.inputEl();
10490 getPositionEl : function(){
10491 return this.inputEl();
10495 alignErrorIcon : function(){
10496 this.errorIcon.alignTo(this.inputEl(), 'tl-tr', [2, 0]);
10500 initEvents : function(){
10504 Roo.bootstrap.TriggerField.superclass.initEvents.call(this);
10505 //this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
10506 if(!this.multiple && this.showToggleBtn){
10507 this.trigger = this.el.select('span.dropdown-toggle',true).first();
10508 if(this.hideTrigger){
10509 this.trigger.setDisplayed(false);
10511 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
10515 this.inputEl().on("click", this.onTriggerClick, this, {preventDefault:true});
10518 if(this.removable && !this.editable && !this.tickable){
10519 var close = this.closeTriggerEl();
10522 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
10523 close.on('click', this.removeBtnClick, this, close);
10527 //this.trigger.addClassOnOver('x-form-trigger-over');
10528 //this.trigger.addClassOnClick('x-form-trigger-click');
10531 // this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
10535 closeTriggerEl : function()
10537 var close = this.el.select('.roo-combo-removable-btn', true).first();
10538 return close ? close : false;
10541 removeBtnClick : function(e, h, el)
10543 e.preventDefault();
10545 if(this.fireEvent("remove", this) !== false){
10547 this.fireEvent("afterremove", this)
10551 createList : function()
10553 this.list = Roo.get(document.body).createChild({
10555 cls: 'typeahead typeahead-long dropdown-menu',
10556 style: 'display:none'
10559 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';;
10564 initTrigger : function(){
10569 onDestroy : function(){
10571 this.trigger.removeAllListeners();
10572 // this.trigger.remove();
10575 // this.wrap.remove();
10577 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
10581 onFocus : function(){
10582 Roo.bootstrap.TriggerField.superclass.onFocus.call(this);
10584 if(!this.mimicing){
10585 this.wrap.addClass('x-trigger-wrap-focus');
10586 this.mimicing = true;
10587 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
10588 if(this.monitorTab){
10589 this.el.on("keydown", this.checkTab, this);
10596 checkTab : function(e){
10597 if(e.getKey() == e.TAB){
10598 this.triggerBlur();
10603 onBlur : function(){
10608 mimicBlur : function(e, t){
10610 if(!this.wrap.contains(t) && this.validateBlur()){
10611 this.triggerBlur();
10617 triggerBlur : function(){
10618 this.mimicing = false;
10619 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
10620 if(this.monitorTab){
10621 this.el.un("keydown", this.checkTab, this);
10623 //this.wrap.removeClass('x-trigger-wrap-focus');
10624 Roo.bootstrap.TriggerField.superclass.onBlur.call(this);
10628 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
10629 validateBlur : function(e, t){
10634 onDisable : function(){
10635 this.inputEl().dom.disabled = true;
10636 //Roo.bootstrap.TriggerField.superclass.onDisable.call(this);
10638 // this.wrap.addClass('x-item-disabled');
10643 onEnable : function(){
10644 this.inputEl().dom.disabled = false;
10645 //Roo.bootstrap.TriggerField.superclass.onEnable.call(this);
10647 // this.el.removeClass('x-item-disabled');
10652 onShow : function(){
10653 var ae = this.getActionEl();
10656 ae.dom.style.display = '';
10657 ae.dom.style.visibility = 'visible';
10663 onHide : function(){
10664 var ae = this.getActionEl();
10665 ae.dom.style.display = 'none';
10669 * The function that should handle the trigger's click event. This method does nothing by default until overridden
10670 * by an implementing function.
10672 * @param {EventObject} e
10674 onTriggerClick : Roo.emptyFn
10678 * Ext JS Library 1.1.1
10679 * Copyright(c) 2006-2007, Ext JS, LLC.
10681 * Originally Released Under LGPL - original licence link has changed is not relivant.
10684 * <script type="text/javascript">
10689 * @class Roo.data.SortTypes
10691 * Defines the default sorting (casting?) comparison functions used when sorting data.
10693 Roo.data.SortTypes = {
10695 * Default sort that does nothing
10696 * @param {Mixed} s The value being converted
10697 * @return {Mixed} The comparison value
10699 none : function(s){
10704 * The regular expression used to strip tags
10708 stripTagsRE : /<\/?[^>]+>/gi,
10711 * Strips all HTML tags to sort on text only
10712 * @param {Mixed} s The value being converted
10713 * @return {String} The comparison value
10715 asText : function(s){
10716 return String(s).replace(this.stripTagsRE, "");
10720 * Strips all HTML tags to sort on text only - Case insensitive
10721 * @param {Mixed} s The value being converted
10722 * @return {String} The comparison value
10724 asUCText : function(s){
10725 return String(s).toUpperCase().replace(this.stripTagsRE, "");
10729 * Case insensitive string
10730 * @param {Mixed} s The value being converted
10731 * @return {String} The comparison value
10733 asUCString : function(s) {
10734 return String(s).toUpperCase();
10739 * @param {Mixed} s The value being converted
10740 * @return {Number} The comparison value
10742 asDate : function(s) {
10746 if(s instanceof Date){
10747 return s.getTime();
10749 return Date.parse(String(s));
10754 * @param {Mixed} s The value being converted
10755 * @return {Float} The comparison value
10757 asFloat : function(s) {
10758 var val = parseFloat(String(s).replace(/,/g, ""));
10767 * @param {Mixed} s The value being converted
10768 * @return {Number} The comparison value
10770 asInt : function(s) {
10771 var val = parseInt(String(s).replace(/,/g, ""));
10779 * Ext JS Library 1.1.1
10780 * Copyright(c) 2006-2007, Ext JS, LLC.
10782 * Originally Released Under LGPL - original licence link has changed is not relivant.
10785 * <script type="text/javascript">
10789 * @class Roo.data.Record
10790 * Instances of this class encapsulate both record <em>definition</em> information, and record
10791 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
10792 * to access Records cached in an {@link Roo.data.Store} object.<br>
10794 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
10795 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
10798 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
10800 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
10801 * {@link #create}. The parameters are the same.
10802 * @param {Array} data An associative Array of data values keyed by the field name.
10803 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
10804 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
10805 * not specified an integer id is generated.
10807 Roo.data.Record = function(data, id){
10808 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
10813 * Generate a constructor for a specific record layout.
10814 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
10815 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
10816 * Each field definition object may contain the following properties: <ul>
10817 * <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,
10818 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
10819 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
10820 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
10821 * is being used, then this is a string containing the javascript expression to reference the data relative to
10822 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
10823 * to the data item relative to the record element. If the mapping expression is the same as the field name,
10824 * this may be omitted.</p></li>
10825 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
10826 * <ul><li>auto (Default, implies no conversion)</li>
10831 * <li>date</li></ul></p></li>
10832 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
10833 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
10834 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
10835 * by the Reader into an object that will be stored in the Record. It is passed the
10836 * following parameters:<ul>
10837 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
10839 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
10841 * <br>usage:<br><pre><code>
10842 var TopicRecord = Roo.data.Record.create(
10843 {name: 'title', mapping: 'topic_title'},
10844 {name: 'author', mapping: 'username'},
10845 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
10846 {name: 'lastPost', mapping: 'post_time', type: 'date'},
10847 {name: 'lastPoster', mapping: 'user2'},
10848 {name: 'excerpt', mapping: 'post_text'}
10851 var myNewRecord = new TopicRecord({
10852 title: 'Do my job please',
10855 lastPost: new Date(),
10856 lastPoster: 'Animal',
10857 excerpt: 'No way dude!'
10859 myStore.add(myNewRecord);
10864 Roo.data.Record.create = function(o){
10865 var f = function(){
10866 f.superclass.constructor.apply(this, arguments);
10868 Roo.extend(f, Roo.data.Record);
10869 var p = f.prototype;
10870 p.fields = new Roo.util.MixedCollection(false, function(field){
10873 for(var i = 0, len = o.length; i < len; i++){
10874 p.fields.add(new Roo.data.Field(o[i]));
10876 f.getField = function(name){
10877 return p.fields.get(name);
10882 Roo.data.Record.AUTO_ID = 1000;
10883 Roo.data.Record.EDIT = 'edit';
10884 Roo.data.Record.REJECT = 'reject';
10885 Roo.data.Record.COMMIT = 'commit';
10887 Roo.data.Record.prototype = {
10889 * Readonly flag - true if this record has been modified.
10898 join : function(store){
10899 this.store = store;
10903 * Set the named field to the specified value.
10904 * @param {String} name The name of the field to set.
10905 * @param {Object} value The value to set the field to.
10907 set : function(name, value){
10908 if(this.data[name] == value){
10912 if(!this.modified){
10913 this.modified = {};
10915 if(typeof this.modified[name] == 'undefined'){
10916 this.modified[name] = this.data[name];
10918 this.data[name] = value;
10919 if(!this.editing && this.store){
10920 this.store.afterEdit(this);
10925 * Get the value of the named field.
10926 * @param {String} name The name of the field to get the value of.
10927 * @return {Object} The value of the field.
10929 get : function(name){
10930 return this.data[name];
10934 beginEdit : function(){
10935 this.editing = true;
10936 this.modified = {};
10940 cancelEdit : function(){
10941 this.editing = false;
10942 delete this.modified;
10946 endEdit : function(){
10947 this.editing = false;
10948 if(this.dirty && this.store){
10949 this.store.afterEdit(this);
10954 * Usually called by the {@link Roo.data.Store} which owns the Record.
10955 * Rejects all changes made to the Record since either creation, or the last commit operation.
10956 * Modified fields are reverted to their original values.
10958 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10959 * of reject operations.
10961 reject : function(){
10962 var m = this.modified;
10964 if(typeof m[n] != "function"){
10965 this.data[n] = m[n];
10968 this.dirty = false;
10969 delete this.modified;
10970 this.editing = false;
10972 this.store.afterReject(this);
10977 * Usually called by the {@link Roo.data.Store} which owns the Record.
10978 * Commits all changes made to the Record since either creation, or the last commit operation.
10980 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
10981 * of commit operations.
10983 commit : function(){
10984 this.dirty = false;
10985 delete this.modified;
10986 this.editing = false;
10988 this.store.afterCommit(this);
10993 hasError : function(){
10994 return this.error != null;
10998 clearError : function(){
11003 * Creates a copy of this record.
11004 * @param {String} id (optional) A new record id if you don't want to use this record's id
11007 copy : function(newId) {
11008 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
11012 * Ext JS Library 1.1.1
11013 * Copyright(c) 2006-2007, Ext JS, LLC.
11015 * Originally Released Under LGPL - original licence link has changed is not relivant.
11018 * <script type="text/javascript">
11024 * @class Roo.data.Store
11025 * @extends Roo.util.Observable
11026 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
11027 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
11029 * 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
11030 * has no knowledge of the format of the data returned by the Proxy.<br>
11032 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
11033 * instances from the data object. These records are cached and made available through accessor functions.
11035 * Creates a new Store.
11036 * @param {Object} config A config object containing the objects needed for the Store to access data,
11037 * and read the data into Records.
11039 Roo.data.Store = function(config){
11040 this.data = new Roo.util.MixedCollection(false);
11041 this.data.getKey = function(o){
11044 this.baseParams = {};
11046 this.paramNames = {
11051 "multisort" : "_multisort"
11054 if(config && config.data){
11055 this.inlineData = config.data;
11056 delete config.data;
11059 Roo.apply(this, config);
11061 if(this.reader){ // reader passed
11062 this.reader = Roo.factory(this.reader, Roo.data);
11063 this.reader.xmodule = this.xmodule || false;
11064 if(!this.recordType){
11065 this.recordType = this.reader.recordType;
11067 if(this.reader.onMetaChange){
11068 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
11072 if(this.recordType){
11073 this.fields = this.recordType.prototype.fields;
11075 this.modified = [];
11079 * @event datachanged
11080 * Fires when the data cache has changed, and a widget which is using this Store
11081 * as a Record cache should refresh its view.
11082 * @param {Store} this
11084 datachanged : true,
11086 * @event metachange
11087 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
11088 * @param {Store} this
11089 * @param {Object} meta The JSON metadata
11094 * Fires when Records have been added to the Store
11095 * @param {Store} this
11096 * @param {Roo.data.Record[]} records The array of Records added
11097 * @param {Number} index The index at which the record(s) were added
11102 * Fires when a Record has been removed from the Store
11103 * @param {Store} this
11104 * @param {Roo.data.Record} record The Record that was removed
11105 * @param {Number} index The index at which the record was removed
11110 * Fires when a Record has been updated
11111 * @param {Store} this
11112 * @param {Roo.data.Record} record The Record that was updated
11113 * @param {String} operation The update operation being performed. Value may be one of:
11115 Roo.data.Record.EDIT
11116 Roo.data.Record.REJECT
11117 Roo.data.Record.COMMIT
11123 * Fires when the data cache has been cleared.
11124 * @param {Store} this
11128 * @event beforeload
11129 * Fires before a request is made for a new data object. If the beforeload handler returns false
11130 * the load action will be canceled.
11131 * @param {Store} this
11132 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11136 * @event beforeloadadd
11137 * Fires after a new set of Records has been loaded.
11138 * @param {Store} this
11139 * @param {Roo.data.Record[]} records The Records that were loaded
11140 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11142 beforeloadadd : true,
11145 * Fires after a new set of Records has been loaded, before they are added to the store.
11146 * @param {Store} this
11147 * @param {Roo.data.Record[]} records The Records that were loaded
11148 * @param {Object} options The loading options that were specified (see {@link #load} for details)
11149 * @params {Object} return from reader
11153 * @event loadexception
11154 * Fires if an exception occurs in the Proxy during loading.
11155 * Called with the signature of the Proxy's "loadexception" event.
11156 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
11159 * @param {Object} return from JsonData.reader() - success, totalRecords, records
11160 * @param {Object} load options
11161 * @param {Object} jsonData from your request (normally this contains the Exception)
11163 loadexception : true
11167 this.proxy = Roo.factory(this.proxy, Roo.data);
11168 this.proxy.xmodule = this.xmodule || false;
11169 this.relayEvents(this.proxy, ["loadexception"]);
11171 this.sortToggle = {};
11172 this.sortOrder = []; // array of order of sorting - updated by grid if multisort is enabled.
11174 Roo.data.Store.superclass.constructor.call(this);
11176 if(this.inlineData){
11177 this.loadData(this.inlineData);
11178 delete this.inlineData;
11182 Roo.extend(Roo.data.Store, Roo.util.Observable, {
11184 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
11185 * without a remote query - used by combo/forms at present.
11189 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
11192 * @cfg {Array} data Inline data to be loaded when the store is initialized.
11195 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
11196 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
11199 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
11200 * on any HTTP request
11203 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
11206 * @cfg {Boolean} multiSort enable multi column sorting (sort is based on the order of columns, remote only at present)
11210 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
11211 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
11213 remoteSort : false,
11216 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
11217 * loaded or when a record is removed. (defaults to false).
11219 pruneModifiedRecords : false,
11222 lastOptions : null,
11225 * Add Records to the Store and fires the add event.
11226 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11228 add : function(records){
11229 records = [].concat(records);
11230 for(var i = 0, len = records.length; i < len; i++){
11231 records[i].join(this);
11233 var index = this.data.length;
11234 this.data.addAll(records);
11235 this.fireEvent("add", this, records, index);
11239 * Remove a Record from the Store and fires the remove event.
11240 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
11242 remove : function(record){
11243 var index = this.data.indexOf(record);
11244 this.data.removeAt(index);
11246 if(this.pruneModifiedRecords){
11247 this.modified.remove(record);
11249 this.fireEvent("remove", this, record, index);
11253 * Remove all Records from the Store and fires the clear event.
11255 removeAll : function(){
11257 if(this.pruneModifiedRecords){
11258 this.modified = [];
11260 this.fireEvent("clear", this);
11264 * Inserts Records to the Store at the given index and fires the add event.
11265 * @param {Number} index The start index at which to insert the passed Records.
11266 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
11268 insert : function(index, records){
11269 records = [].concat(records);
11270 for(var i = 0, len = records.length; i < len; i++){
11271 this.data.insert(index, records[i]);
11272 records[i].join(this);
11274 this.fireEvent("add", this, records, index);
11278 * Get the index within the cache of the passed Record.
11279 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
11280 * @return {Number} The index of the passed Record. Returns -1 if not found.
11282 indexOf : function(record){
11283 return this.data.indexOf(record);
11287 * Get the index within the cache of the Record with the passed id.
11288 * @param {String} id The id of the Record to find.
11289 * @return {Number} The index of the Record. Returns -1 if not found.
11291 indexOfId : function(id){
11292 return this.data.indexOfKey(id);
11296 * Get the Record with the specified id.
11297 * @param {String} id The id of the Record to find.
11298 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
11300 getById : function(id){
11301 return this.data.key(id);
11305 * Get the Record at the specified index.
11306 * @param {Number} index The index of the Record to find.
11307 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
11309 getAt : function(index){
11310 return this.data.itemAt(index);
11314 * Returns a range of Records between specified indices.
11315 * @param {Number} startIndex (optional) The starting index (defaults to 0)
11316 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
11317 * @return {Roo.data.Record[]} An array of Records
11319 getRange : function(start, end){
11320 return this.data.getRange(start, end);
11324 storeOptions : function(o){
11325 o = Roo.apply({}, o);
11328 this.lastOptions = o;
11332 * Loads the Record cache from the configured Proxy using the configured Reader.
11334 * If using remote paging, then the first load call must specify the <em>start</em>
11335 * and <em>limit</em> properties in the options.params property to establish the initial
11336 * position within the dataset, and the number of Records to cache on each read from the Proxy.
11338 * <strong>It is important to note that for remote data sources, loading is asynchronous,
11339 * and this call will return before the new data has been loaded. Perform any post-processing
11340 * in a callback function, or in a "load" event handler.</strong>
11342 * @param {Object} options An object containing properties which control loading options:<ul>
11343 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
11344 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
11345 * passed the following arguments:<ul>
11346 * <li>r : Roo.data.Record[]</li>
11347 * <li>options: Options object from the load call</li>
11348 * <li>success: Boolean success indicator</li></ul></li>
11349 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
11350 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
11353 load : function(options){
11354 options = options || {};
11355 if(this.fireEvent("beforeload", this, options) !== false){
11356 this.storeOptions(options);
11357 var p = Roo.apply(options.params || {}, this.baseParams);
11358 // if meta was not loaded from remote source.. try requesting it.
11359 if (!this.reader.metaFromRemote) {
11360 p._requestMeta = 1;
11362 if(this.sortInfo && this.remoteSort){
11363 var pn = this.paramNames;
11364 p[pn["sort"]] = this.sortInfo.field;
11365 p[pn["dir"]] = this.sortInfo.direction;
11367 if (this.multiSort) {
11368 var pn = this.paramNames;
11369 p[pn["multisort"]] = Roo.encode( { sort : this.sortToggle, order: this.sortOrder });
11372 this.proxy.load(p, this.reader, this.loadRecords, this, options);
11377 * Reloads the Record cache from the configured Proxy using the configured Reader and
11378 * the options from the last load operation performed.
11379 * @param {Object} options (optional) An object containing properties which may override the options
11380 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
11381 * the most recently used options are reused).
11383 reload : function(options){
11384 this.load(Roo.applyIf(options||{}, this.lastOptions));
11388 // Called as a callback by the Reader during a load operation.
11389 loadRecords : function(o, options, success){
11390 if(!o || success === false){
11391 if(success !== false){
11392 this.fireEvent("load", this, [], options, o);
11394 if(options.callback){
11395 options.callback.call(options.scope || this, [], options, false);
11399 // if data returned failure - throw an exception.
11400 if (o.success === false) {
11401 // show a message if no listener is registered.
11402 if (!this.hasListener('loadexception') && typeof(o.raw.errorMsg) != 'undefined') {
11403 Roo.MessageBox.alert("Error loading",o.raw.errorMsg);
11405 // loadmask wil be hooked into this..
11406 this.fireEvent("loadexception", this, o, options, o.raw.errorMsg);
11409 var r = o.records, t = o.totalRecords || r.length;
11411 this.fireEvent("beforeloadadd", this, r, options, o);
11413 if(!options || options.add !== true){
11414 if(this.pruneModifiedRecords){
11415 this.modified = [];
11417 for(var i = 0, len = r.length; i < len; i++){
11421 this.data = this.snapshot;
11422 delete this.snapshot;
11425 this.data.addAll(r);
11426 this.totalLength = t;
11428 this.fireEvent("datachanged", this);
11430 this.totalLength = Math.max(t, this.data.length+r.length);
11434 if(this.parent && !Roo.isIOS && !this.useNativeIOS && this.parent.emptyTitle.length) {
11436 var e = new Roo.data.Record({});
11438 e.set(this.parent.displayField, this.parent.emptyTitle);
11439 e.set(this.parent.valueField, '');
11444 this.fireEvent("load", this, r, options, o);
11445 if(options.callback){
11446 options.callback.call(options.scope || this, r, options, true);
11452 * Loads data from a passed data block. A Reader which understands the format of the data
11453 * must have been configured in the constructor.
11454 * @param {Object} data The data block from which to read the Records. The format of the data expected
11455 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
11456 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
11458 loadData : function(o, append){
11459 var r = this.reader.readRecords(o);
11460 this.loadRecords(r, {add: append}, true);
11464 * Gets the number of cached records.
11466 * <em>If using paging, this may not be the total size of the dataset. If the data object
11467 * used by the Reader contains the dataset size, then the getTotalCount() function returns
11468 * the data set size</em>
11470 getCount : function(){
11471 return this.data.length || 0;
11475 * Gets the total number of records in the dataset as returned by the server.
11477 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
11478 * the dataset size</em>
11480 getTotalCount : function(){
11481 return this.totalLength || 0;
11485 * Returns the sort state of the Store as an object with two properties:
11487 field {String} The name of the field by which the Records are sorted
11488 direction {String} The sort order, "ASC" or "DESC"
11491 getSortState : function(){
11492 return this.sortInfo;
11496 applySort : function(){
11497 if(this.sortInfo && !this.remoteSort){
11498 var s = this.sortInfo, f = s.field;
11499 var st = this.fields.get(f).sortType;
11500 var fn = function(r1, r2){
11501 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
11502 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
11504 this.data.sort(s.direction, fn);
11505 if(this.snapshot && this.snapshot != this.data){
11506 this.snapshot.sort(s.direction, fn);
11512 * Sets the default sort column and order to be used by the next load operation.
11513 * @param {String} fieldName The name of the field to sort by.
11514 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11516 setDefaultSort : function(field, dir){
11517 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
11521 * Sort the Records.
11522 * If remote sorting is used, the sort is performed on the server, and the cache is
11523 * reloaded. If local sorting is used, the cache is sorted internally.
11524 * @param {String} fieldName The name of the field to sort by.
11525 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
11527 sort : function(fieldName, dir){
11528 var f = this.fields.get(fieldName);
11530 this.sortToggle[f.name] = this.sortToggle[f.name] || f.sortDir;
11532 if(this.multiSort || (this.sortInfo && this.sortInfo.field == f.name) ){ // toggle sort dir
11533 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
11538 this.sortToggle[f.name] = dir;
11539 this.sortInfo = {field: f.name, direction: dir};
11540 if(!this.remoteSort){
11542 this.fireEvent("datachanged", this);
11544 this.load(this.lastOptions);
11549 * Calls the specified function for each of the Records in the cache.
11550 * @param {Function} fn The function to call. The Record is passed as the first parameter.
11551 * Returning <em>false</em> aborts and exits the iteration.
11552 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
11554 each : function(fn, scope){
11555 this.data.each(fn, scope);
11559 * Gets all records modified since the last commit. Modified records are persisted across load operations
11560 * (e.g., during paging).
11561 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
11563 getModifiedRecords : function(){
11564 return this.modified;
11568 createFilterFn : function(property, value, anyMatch){
11569 if(!value.exec){ // not a regex
11570 value = String(value);
11571 if(value.length == 0){
11574 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
11576 return function(r){
11577 return value.test(r.data[property]);
11582 * Sums the value of <i>property</i> for each record between start and end and returns the result.
11583 * @param {String} property A field on your records
11584 * @param {Number} start The record index to start at (defaults to 0)
11585 * @param {Number} end The last record index to include (defaults to length - 1)
11586 * @return {Number} The sum
11588 sum : function(property, start, end){
11589 var rs = this.data.items, v = 0;
11590 start = start || 0;
11591 end = (end || end === 0) ? end : rs.length-1;
11593 for(var i = start; i <= end; i++){
11594 v += (rs[i].data[property] || 0);
11600 * Filter the records by a specified property.
11601 * @param {String} field A field on your records
11602 * @param {String/RegExp} value Either a string that the field
11603 * should start with or a RegExp to test against the field
11604 * @param {Boolean} anyMatch True to match any part not just the beginning
11606 filter : function(property, value, anyMatch){
11607 var fn = this.createFilterFn(property, value, anyMatch);
11608 return fn ? this.filterBy(fn) : this.clearFilter();
11612 * Filter by a function. The specified function will be called with each
11613 * record in this data source. If the function returns true the record is included,
11614 * otherwise it is filtered.
11615 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11616 * @param {Object} scope (optional) The scope of the function (defaults to this)
11618 filterBy : function(fn, scope){
11619 this.snapshot = this.snapshot || this.data;
11620 this.data = this.queryBy(fn, scope||this);
11621 this.fireEvent("datachanged", this);
11625 * Query the records by a specified property.
11626 * @param {String} field A field on your records
11627 * @param {String/RegExp} value Either a string that the field
11628 * should start with or a RegExp to test against the field
11629 * @param {Boolean} anyMatch True to match any part not just the beginning
11630 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11632 query : function(property, value, anyMatch){
11633 var fn = this.createFilterFn(property, value, anyMatch);
11634 return fn ? this.queryBy(fn) : this.data.clone();
11638 * Query by a function. The specified function will be called with each
11639 * record in this data source. If the function returns true the record is included
11641 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
11642 * @param {Object} scope (optional) The scope of the function (defaults to this)
11643 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
11645 queryBy : function(fn, scope){
11646 var data = this.snapshot || this.data;
11647 return data.filterBy(fn, scope||this);
11651 * Collects unique values for a particular dataIndex from this store.
11652 * @param {String} dataIndex The property to collect
11653 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
11654 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
11655 * @return {Array} An array of the unique values
11657 collect : function(dataIndex, allowNull, bypassFilter){
11658 var d = (bypassFilter === true && this.snapshot) ?
11659 this.snapshot.items : this.data.items;
11660 var v, sv, r = [], l = {};
11661 for(var i = 0, len = d.length; i < len; i++){
11662 v = d[i].data[dataIndex];
11664 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
11673 * Revert to a view of the Record cache with no filtering applied.
11674 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
11676 clearFilter : function(suppressEvent){
11677 if(this.snapshot && this.snapshot != this.data){
11678 this.data = this.snapshot;
11679 delete this.snapshot;
11680 if(suppressEvent !== true){
11681 this.fireEvent("datachanged", this);
11687 afterEdit : function(record){
11688 if(this.modified.indexOf(record) == -1){
11689 this.modified.push(record);
11691 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
11695 afterReject : function(record){
11696 this.modified.remove(record);
11697 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
11701 afterCommit : function(record){
11702 this.modified.remove(record);
11703 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
11707 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
11708 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
11710 commitChanges : function(){
11711 var m = this.modified.slice(0);
11712 this.modified = [];
11713 for(var i = 0, len = m.length; i < len; i++){
11719 * Cancel outstanding changes on all changed records.
11721 rejectChanges : function(){
11722 var m = this.modified.slice(0);
11723 this.modified = [];
11724 for(var i = 0, len = m.length; i < len; i++){
11729 onMetaChange : function(meta, rtype, o){
11730 this.recordType = rtype;
11731 this.fields = rtype.prototype.fields;
11732 delete this.snapshot;
11733 this.sortInfo = meta.sortInfo || this.sortInfo;
11734 this.modified = [];
11735 this.fireEvent('metachange', this, this.reader.meta);
11738 moveIndex : function(data, type)
11740 var index = this.indexOf(data);
11742 var newIndex = index + type;
11746 this.insert(newIndex, data);
11751 * Ext JS Library 1.1.1
11752 * Copyright(c) 2006-2007, Ext JS, LLC.
11754 * Originally Released Under LGPL - original licence link has changed is not relivant.
11757 * <script type="text/javascript">
11761 * @class Roo.data.SimpleStore
11762 * @extends Roo.data.Store
11763 * Small helper class to make creating Stores from Array data easier.
11764 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
11765 * @cfg {Array} fields An array of field definition objects, or field name strings.
11766 * @cfg {Array} data The multi-dimensional array of data
11768 * @param {Object} config
11770 Roo.data.SimpleStore = function(config){
11771 Roo.data.SimpleStore.superclass.constructor.call(this, {
11773 reader: new Roo.data.ArrayReader({
11776 Roo.data.Record.create(config.fields)
11778 proxy : new Roo.data.MemoryProxy(config.data)
11782 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
11784 * Ext JS Library 1.1.1
11785 * Copyright(c) 2006-2007, Ext JS, LLC.
11787 * Originally Released Under LGPL - original licence link has changed is not relivant.
11790 * <script type="text/javascript">
11795 * @extends Roo.data.Store
11796 * @class Roo.data.JsonStore
11797 * Small helper class to make creating Stores for JSON data easier. <br/>
11799 var store = new Roo.data.JsonStore({
11800 url: 'get-images.php',
11802 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
11805 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
11806 * JsonReader and HttpProxy (unless inline data is provided).</b>
11807 * @cfg {Array} fields An array of field definition objects, or field name strings.
11809 * @param {Object} config
11811 Roo.data.JsonStore = function(c){
11812 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
11813 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
11814 reader: new Roo.data.JsonReader(c, c.fields)
11817 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
11819 * Ext JS Library 1.1.1
11820 * Copyright(c) 2006-2007, Ext JS, LLC.
11822 * Originally Released Under LGPL - original licence link has changed is not relivant.
11825 * <script type="text/javascript">
11829 Roo.data.Field = function(config){
11830 if(typeof config == "string"){
11831 config = {name: config};
11833 Roo.apply(this, config);
11836 this.type = "auto";
11839 var st = Roo.data.SortTypes;
11840 // named sortTypes are supported, here we look them up
11841 if(typeof this.sortType == "string"){
11842 this.sortType = st[this.sortType];
11845 // set default sortType for strings and dates
11846 if(!this.sortType){
11849 this.sortType = st.asUCString;
11852 this.sortType = st.asDate;
11855 this.sortType = st.none;
11860 var stripRe = /[\$,%]/g;
11862 // prebuilt conversion function for this field, instead of
11863 // switching every time we're reading a value
11865 var cv, dateFormat = this.dateFormat;
11870 cv = function(v){ return v; };
11873 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
11877 return v !== undefined && v !== null && v !== '' ?
11878 parseInt(String(v).replace(stripRe, ""), 10) : '';
11883 return v !== undefined && v !== null && v !== '' ?
11884 parseFloat(String(v).replace(stripRe, ""), 10) : '';
11889 cv = function(v){ return v === true || v === "true" || v == 1; };
11896 if(v instanceof Date){
11900 if(dateFormat == "timestamp"){
11901 return new Date(v*1000);
11903 return Date.parseDate(v, dateFormat);
11905 var parsed = Date.parse(v);
11906 return parsed ? new Date(parsed) : null;
11915 Roo.data.Field.prototype = {
11923 * Ext JS Library 1.1.1
11924 * Copyright(c) 2006-2007, Ext JS, LLC.
11926 * Originally Released Under LGPL - original licence link has changed is not relivant.
11929 * <script type="text/javascript">
11932 // Base class for reading structured data from a data source. This class is intended to be
11933 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
11936 * @class Roo.data.DataReader
11937 * Base class for reading structured data from a data source. This class is intended to be
11938 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
11941 Roo.data.DataReader = function(meta, recordType){
11945 this.recordType = recordType instanceof Array ?
11946 Roo.data.Record.create(recordType) : recordType;
11949 Roo.data.DataReader.prototype = {
11951 * Create an empty record
11952 * @param {Object} data (optional) - overlay some values
11953 * @return {Roo.data.Record} record created.
11955 newRow : function(d) {
11957 this.recordType.prototype.fields.each(function(c) {
11959 case 'int' : da[c.name] = 0; break;
11960 case 'date' : da[c.name] = new Date(); break;
11961 case 'float' : da[c.name] = 0.0; break;
11962 case 'boolean' : da[c.name] = false; break;
11963 default : da[c.name] = ""; break;
11967 return new this.recordType(Roo.apply(da, d));
11972 * Ext JS Library 1.1.1
11973 * Copyright(c) 2006-2007, Ext JS, LLC.
11975 * Originally Released Under LGPL - original licence link has changed is not relivant.
11978 * <script type="text/javascript">
11982 * @class Roo.data.DataProxy
11983 * @extends Roo.data.Observable
11984 * This class is an abstract base class for implementations which provide retrieval of
11985 * unformatted data objects.<br>
11987 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
11988 * (of the appropriate type which knows how to parse the data object) to provide a block of
11989 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
11991 * Custom implementations must implement the load method as described in
11992 * {@link Roo.data.HttpProxy#load}.
11994 Roo.data.DataProxy = function(){
11997 * @event beforeload
11998 * Fires before a network request is made to retrieve a data object.
11999 * @param {Object} This DataProxy object.
12000 * @param {Object} params The params parameter to the load function.
12005 * Fires before the load method's callback is called.
12006 * @param {Object} This DataProxy object.
12007 * @param {Object} o The data object.
12008 * @param {Object} arg The callback argument object passed to the load function.
12012 * @event loadexception
12013 * Fires if an Exception occurs during data retrieval.
12014 * @param {Object} This DataProxy object.
12015 * @param {Object} o The data object.
12016 * @param {Object} arg The callback argument object passed to the load function.
12017 * @param {Object} e The Exception.
12019 loadexception : true
12021 Roo.data.DataProxy.superclass.constructor.call(this);
12024 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
12027 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
12031 * Ext JS Library 1.1.1
12032 * Copyright(c) 2006-2007, Ext JS, LLC.
12034 * Originally Released Under LGPL - original licence link has changed is not relivant.
12037 * <script type="text/javascript">
12040 * @class Roo.data.MemoryProxy
12041 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
12042 * to the Reader when its load method is called.
12044 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
12046 Roo.data.MemoryProxy = function(data){
12050 Roo.data.MemoryProxy.superclass.constructor.call(this);
12054 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
12057 * Load data from the requested source (in this case an in-memory
12058 * data object passed to the constructor), read the data object into
12059 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12060 * process that block using the passed callback.
12061 * @param {Object} params This parameter is not used by the MemoryProxy class.
12062 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12063 * object into a block of Roo.data.Records.
12064 * @param {Function} callback The function into which to pass the block of Roo.data.records.
12065 * The function must be passed <ul>
12066 * <li>The Record block object</li>
12067 * <li>The "arg" argument from the load function</li>
12068 * <li>A boolean success indicator</li>
12070 * @param {Object} scope The scope in which to call the callback
12071 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12073 load : function(params, reader, callback, scope, arg){
12074 params = params || {};
12077 result = reader.readRecords(this.data);
12079 this.fireEvent("loadexception", this, arg, null, e);
12080 callback.call(scope, null, arg, false);
12083 callback.call(scope, result, arg, true);
12087 update : function(params, records){
12092 * Ext JS Library 1.1.1
12093 * Copyright(c) 2006-2007, Ext JS, LLC.
12095 * Originally Released Under LGPL - original licence link has changed is not relivant.
12098 * <script type="text/javascript">
12101 * @class Roo.data.HttpProxy
12102 * @extends Roo.data.DataProxy
12103 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
12104 * configured to reference a certain URL.<br><br>
12106 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
12107 * from which the running page was served.<br><br>
12109 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
12111 * Be aware that to enable the browser to parse an XML document, the server must set
12112 * the Content-Type header in the HTTP response to "text/xml".
12114 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
12115 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
12116 * will be used to make the request.
12118 Roo.data.HttpProxy = function(conn){
12119 Roo.data.HttpProxy.superclass.constructor.call(this);
12120 // is conn a conn config or a real conn?
12122 this.useAjax = !conn || !conn.events;
12126 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
12127 // thse are take from connection...
12130 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
12133 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
12134 * extra parameters to each request made by this object. (defaults to undefined)
12137 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
12138 * to each request made by this object. (defaults to undefined)
12141 * @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)
12144 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
12147 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
12153 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
12157 * Return the {@link Roo.data.Connection} object being used by this Proxy.
12158 * @return {Connection} The Connection object. This object may be used to subscribe to events on
12159 * a finer-grained basis than the DataProxy events.
12161 getConnection : function(){
12162 return this.useAjax ? Roo.Ajax : this.conn;
12166 * Load data from the configured {@link Roo.data.Connection}, read the data object into
12167 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
12168 * process that block using the passed callback.
12169 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12170 * for the request to the remote server.
12171 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12172 * object into a block of Roo.data.Records.
12173 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12174 * The function must be passed <ul>
12175 * <li>The Record block object</li>
12176 * <li>The "arg" argument from the load function</li>
12177 * <li>A boolean success indicator</li>
12179 * @param {Object} scope The scope in which to call the callback
12180 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12182 load : function(params, reader, callback, scope, arg){
12183 if(this.fireEvent("beforeload", this, params) !== false){
12185 params : params || {},
12187 callback : callback,
12192 callback : this.loadResponse,
12196 Roo.applyIf(o, this.conn);
12197 if(this.activeRequest){
12198 Roo.Ajax.abort(this.activeRequest);
12200 this.activeRequest = Roo.Ajax.request(o);
12202 this.conn.request(o);
12205 callback.call(scope||this, null, arg, false);
12210 loadResponse : function(o, success, response){
12211 delete this.activeRequest;
12213 this.fireEvent("loadexception", this, o, response);
12214 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12219 result = o.reader.read(response);
12221 this.fireEvent("loadexception", this, o, response, e);
12222 o.request.callback.call(o.request.scope, null, o.request.arg, false);
12226 this.fireEvent("load", this, o, o.request.arg);
12227 o.request.callback.call(o.request.scope, result, o.request.arg, true);
12231 update : function(dataSet){
12236 updateResponse : function(dataSet){
12241 * Ext JS Library 1.1.1
12242 * Copyright(c) 2006-2007, Ext JS, LLC.
12244 * Originally Released Under LGPL - original licence link has changed is not relivant.
12247 * <script type="text/javascript">
12251 * @class Roo.data.ScriptTagProxy
12252 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
12253 * other than the originating domain of the running page.<br><br>
12255 * <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
12256 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
12258 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
12259 * source code that is used as the source inside a <script> tag.<br><br>
12261 * In order for the browser to process the returned data, the server must wrap the data object
12262 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
12263 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
12264 * depending on whether the callback name was passed:
12267 boolean scriptTag = false;
12268 String cb = request.getParameter("callback");
12271 response.setContentType("text/javascript");
12273 response.setContentType("application/x-json");
12275 Writer out = response.getWriter();
12277 out.write(cb + "(");
12279 out.print(dataBlock.toJsonString());
12286 * @param {Object} config A configuration object.
12288 Roo.data.ScriptTagProxy = function(config){
12289 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
12290 Roo.apply(this, config);
12291 this.head = document.getElementsByTagName("head")[0];
12294 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
12296 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
12298 * @cfg {String} url The URL from which to request the data object.
12301 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
12305 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
12306 * the server the name of the callback function set up by the load call to process the returned data object.
12307 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
12308 * javascript output which calls this named function passing the data object as its only parameter.
12310 callbackParam : "callback",
12312 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
12313 * name to the request.
12318 * Load data from the configured URL, read the data object into
12319 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
12320 * process that block using the passed callback.
12321 * @param {Object} params An object containing properties which are to be used as HTTP parameters
12322 * for the request to the remote server.
12323 * @param {Roo.data.DataReader} reader The Reader object which converts the data
12324 * object into a block of Roo.data.Records.
12325 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
12326 * The function must be passed <ul>
12327 * <li>The Record block object</li>
12328 * <li>The "arg" argument from the load function</li>
12329 * <li>A boolean success indicator</li>
12331 * @param {Object} scope The scope in which to call the callback
12332 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
12334 load : function(params, reader, callback, scope, arg){
12335 if(this.fireEvent("beforeload", this, params) !== false){
12337 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
12339 var url = this.url;
12340 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
12342 url += "&_dc=" + (new Date().getTime());
12344 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
12347 cb : "stcCallback"+transId,
12348 scriptId : "stcScript"+transId,
12352 callback : callback,
12358 window[trans.cb] = function(o){
12359 conn.handleResponse(o, trans);
12362 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
12364 if(this.autoAbort !== false){
12368 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
12370 var script = document.createElement("script");
12371 script.setAttribute("src", url);
12372 script.setAttribute("type", "text/javascript");
12373 script.setAttribute("id", trans.scriptId);
12374 this.head.appendChild(script);
12376 this.trans = trans;
12378 callback.call(scope||this, null, arg, false);
12383 isLoading : function(){
12384 return this.trans ? true : false;
12388 * Abort the current server request.
12390 abort : function(){
12391 if(this.isLoading()){
12392 this.destroyTrans(this.trans);
12397 destroyTrans : function(trans, isLoaded){
12398 this.head.removeChild(document.getElementById(trans.scriptId));
12399 clearTimeout(trans.timeoutId);
12401 window[trans.cb] = undefined;
12403 delete window[trans.cb];
12406 // if hasn't been loaded, wait for load to remove it to prevent script error
12407 window[trans.cb] = function(){
12408 window[trans.cb] = undefined;
12410 delete window[trans.cb];
12417 handleResponse : function(o, trans){
12418 this.trans = false;
12419 this.destroyTrans(trans, true);
12422 result = trans.reader.readRecords(o);
12424 this.fireEvent("loadexception", this, o, trans.arg, e);
12425 trans.callback.call(trans.scope||window, null, trans.arg, false);
12428 this.fireEvent("load", this, o, trans.arg);
12429 trans.callback.call(trans.scope||window, result, trans.arg, true);
12433 handleFailure : function(trans){
12434 this.trans = false;
12435 this.destroyTrans(trans, false);
12436 this.fireEvent("loadexception", this, null, trans.arg);
12437 trans.callback.call(trans.scope||window, null, trans.arg, false);
12441 * Ext JS Library 1.1.1
12442 * Copyright(c) 2006-2007, Ext JS, LLC.
12444 * Originally Released Under LGPL - original licence link has changed is not relivant.
12447 * <script type="text/javascript">
12451 * @class Roo.data.JsonReader
12452 * @extends Roo.data.DataReader
12453 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
12454 * based on mappings in a provided Roo.data.Record constructor.
12456 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
12457 * in the reply previously.
12462 var RecordDef = Roo.data.Record.create([
12463 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
12464 {name: 'occupation'} // This field will use "occupation" as the mapping.
12466 var myReader = new Roo.data.JsonReader({
12467 totalProperty: "results", // The property which contains the total dataset size (optional)
12468 root: "rows", // The property which contains an Array of row objects
12469 id: "id" // The property within each row object that provides an ID for the record (optional)
12473 * This would consume a JSON file like this:
12475 { 'results': 2, 'rows': [
12476 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
12477 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
12480 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
12481 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
12482 * paged from the remote server.
12483 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
12484 * @cfg {String} root name of the property which contains the Array of row objects.
12485 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
12486 * @cfg {Array} fields Array of field definition objects
12488 * Create a new JsonReader
12489 * @param {Object} meta Metadata configuration options
12490 * @param {Object} recordType Either an Array of field definition objects,
12491 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
12493 Roo.data.JsonReader = function(meta, recordType){
12496 // set some defaults:
12497 Roo.applyIf(meta, {
12498 totalProperty: 'total',
12499 successProperty : 'success',
12504 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
12506 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
12509 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
12510 * Used by Store query builder to append _requestMeta to params.
12513 metaFromRemote : false,
12515 * This method is only used by a DataProxy which has retrieved data from a remote server.
12516 * @param {Object} response The XHR object which contains the JSON data in its responseText.
12517 * @return {Object} data A data block which is used by an Roo.data.Store object as
12518 * a cache of Roo.data.Records.
12520 read : function(response){
12521 var json = response.responseText;
12523 var o = /* eval:var:o */ eval("("+json+")");
12525 throw {message: "JsonReader.read: Json object not found"};
12531 this.metaFromRemote = true;
12532 this.meta = o.metaData;
12533 this.recordType = Roo.data.Record.create(o.metaData.fields);
12534 this.onMetaChange(this.meta, this.recordType, o);
12536 return this.readRecords(o);
12539 // private function a store will implement
12540 onMetaChange : function(meta, recordType, o){
12547 simpleAccess: function(obj, subsc) {
12554 getJsonAccessor: function(){
12556 return function(expr) {
12558 return(re.test(expr))
12559 ? new Function("obj", "return obj." + expr)
12564 return Roo.emptyFn;
12569 * Create a data block containing Roo.data.Records from an XML document.
12570 * @param {Object} o An object which contains an Array of row objects in the property specified
12571 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
12572 * which contains the total size of the dataset.
12573 * @return {Object} data A data block which is used by an Roo.data.Store object as
12574 * a cache of Roo.data.Records.
12576 readRecords : function(o){
12578 * After any data loads, the raw JSON data is available for further custom processing.
12582 var s = this.meta, Record = this.recordType,
12583 f = Record ? Record.prototype.fields : null, fi = f ? f.items : [], fl = f ? f.length : 0;
12585 // Generate extraction functions for the totalProperty, the root, the id, and for each field
12587 if(s.totalProperty) {
12588 this.getTotal = this.getJsonAccessor(s.totalProperty);
12590 if(s.successProperty) {
12591 this.getSuccess = this.getJsonAccessor(s.successProperty);
12593 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
12595 var g = this.getJsonAccessor(s.id);
12596 this.getId = function(rec) {
12598 return (r === undefined || r === "") ? null : r;
12601 this.getId = function(){return null;};
12604 for(var jj = 0; jj < fl; jj++){
12606 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
12607 this.ef[jj] = this.getJsonAccessor(map);
12611 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
12612 if(s.totalProperty){
12613 var vt = parseInt(this.getTotal(o), 10);
12618 if(s.successProperty){
12619 var vs = this.getSuccess(o);
12620 if(vs === false || vs === 'false'){
12625 for(var i = 0; i < c; i++){
12628 var id = this.getId(n);
12629 for(var j = 0; j < fl; j++){
12631 var v = this.ef[j](n);
12633 Roo.log('missing convert for ' + f.name);
12637 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
12639 var record = new Record(values, id);
12641 records[i] = record;
12647 totalRecords : totalRecords
12652 * Ext JS Library 1.1.1
12653 * Copyright(c) 2006-2007, Ext JS, LLC.
12655 * Originally Released Under LGPL - original licence link has changed is not relivant.
12658 * <script type="text/javascript">
12662 * @class Roo.data.ArrayReader
12663 * @extends Roo.data.DataReader
12664 * Data reader class to create an Array of Roo.data.Record objects from an Array.
12665 * Each element of that Array represents a row of data fields. The
12666 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
12667 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
12671 var RecordDef = Roo.data.Record.create([
12672 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
12673 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
12675 var myReader = new Roo.data.ArrayReader({
12676 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
12680 * This would consume an Array like this:
12682 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
12684 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
12686 * Create a new JsonReader
12687 * @param {Object} meta Metadata configuration options.
12688 * @param {Object} recordType Either an Array of field definition objects
12689 * as specified to {@link Roo.data.Record#create},
12690 * or an {@link Roo.data.Record} object
12691 * created using {@link Roo.data.Record#create}.
12693 Roo.data.ArrayReader = function(meta, recordType){
12694 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
12697 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
12699 * Create a data block containing Roo.data.Records from an XML document.
12700 * @param {Object} o An Array of row objects which represents the dataset.
12701 * @return {Object} data A data block which is used by an Roo.data.Store object as
12702 * a cache of Roo.data.Records.
12704 readRecords : function(o){
12705 var sid = this.meta ? this.meta.id : null;
12706 var recordType = this.recordType, fields = recordType.prototype.fields;
12709 for(var i = 0; i < root.length; i++){
12712 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
12713 for(var j = 0, jlen = fields.length; j < jlen; j++){
12714 var f = fields.items[j];
12715 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
12716 var v = n[k] !== undefined ? n[k] : f.defaultValue;
12718 values[f.name] = v;
12720 var record = new recordType(values, id);
12722 records[records.length] = record;
12726 totalRecords : records.length
12735 * @class Roo.bootstrap.ComboBox
12736 * @extends Roo.bootstrap.TriggerField
12737 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
12738 * @cfg {Boolean} append (true|false) default false
12739 * @cfg {Boolean} autoFocus (true|false) auto focus the first item, default true
12740 * @cfg {Boolean} tickable ComboBox with tickable selections (true|false), default false
12741 * @cfg {Boolean} triggerList trigger show the list or not (true|false) default true
12742 * @cfg {Boolean} showToggleBtn show toggle button or not (true|false) default true
12743 * @cfg {String} btnPosition set the position of the trigger button (left | right) default right
12744 * @cfg {Boolean} animate default true
12745 * @cfg {Boolean} emptyResultText only for touch device
12746 * @cfg {String} triggerText multiple combobox trigger button text default 'Select'
12747 * @cfg {String} emptyTitle default ''
12749 * Create a new ComboBox.
12750 * @param {Object} config Configuration options
12752 Roo.bootstrap.ComboBox = function(config){
12753 Roo.bootstrap.ComboBox.superclass.constructor.call(this, config);
12757 * Fires when the dropdown list is expanded
12758 * @param {Roo.bootstrap.ComboBox} combo This combo box
12763 * Fires when the dropdown list is collapsed
12764 * @param {Roo.bootstrap.ComboBox} combo This combo box
12768 * @event beforeselect
12769 * Fires before a list item is selected. Return false to cancel the selection.
12770 * @param {Roo.bootstrap.ComboBox} combo This combo box
12771 * @param {Roo.data.Record} record The data record returned from the underlying store
12772 * @param {Number} index The index of the selected item in the dropdown list
12774 'beforeselect' : true,
12777 * Fires when a list item is selected
12778 * @param {Roo.bootstrap.ComboBox} combo This combo box
12779 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
12780 * @param {Number} index The index of the selected item in the dropdown list
12784 * @event beforequery
12785 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
12786 * The event object passed has these properties:
12787 * @param {Roo.bootstrap.ComboBox} combo This combo box
12788 * @param {String} query The query
12789 * @param {Boolean} forceAll true to force "all" query
12790 * @param {Boolean} cancel true to cancel the query
12791 * @param {Object} e The query event object
12793 'beforequery': true,
12796 * Fires when the 'add' icon is pressed (add a listener to enable add button)
12797 * @param {Roo.bootstrap.ComboBox} combo This combo box
12802 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
12803 * @param {Roo.bootstrap.ComboBox} combo This combo box
12804 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
12809 * Fires when the remove value from the combobox array
12810 * @param {Roo.bootstrap.ComboBox} combo This combo box
12814 * @event afterremove
12815 * Fires when the remove value from the combobox array
12816 * @param {Roo.bootstrap.ComboBox} combo This combo box
12818 'afterremove' : true,
12820 * @event specialfilter
12821 * Fires when specialfilter
12822 * @param {Roo.bootstrap.ComboBox} combo This combo box
12824 'specialfilter' : true,
12827 * Fires when tick the element
12828 * @param {Roo.bootstrap.ComboBox} combo This combo box
12832 * @event touchviewdisplay
12833 * Fires when touch view require special display (default is using displayField)
12834 * @param {Roo.bootstrap.ComboBox} combo This combo box
12835 * @param {Object} cfg set html .
12837 'touchviewdisplay' : true
12842 this.tickItems = [];
12844 this.selectedIndex = -1;
12845 if(this.mode == 'local'){
12846 if(config.queryDelay === undefined){
12847 this.queryDelay = 10;
12849 if(config.minChars === undefined){
12855 Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
12858 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
12859 * rendering into an Roo.Editor, defaults to false)
12862 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
12863 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
12866 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
12869 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
12870 * the dropdown list (defaults to undefined, with no header element)
12874 * @cfg {String/Roo.Template} tpl The template to use to render the output
12878 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
12880 listWidth: undefined,
12882 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
12883 * mode = 'remote' or 'text' if mode = 'local')
12885 displayField: undefined,
12888 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
12889 * mode = 'remote' or 'value' if mode = 'local').
12890 * Note: use of a valueField requires the user make a selection
12891 * in order for a value to be mapped.
12893 valueField: undefined,
12895 * @cfg {String} modalTitle The title of the dialog that pops up on mobile views.
12900 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
12901 * field's data value (defaults to the underlying DOM element's name)
12903 hiddenName: undefined,
12905 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
12909 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
12911 selectedClass: 'active',
12914 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
12918 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
12919 * anchor positions (defaults to 'tl-bl')
12921 listAlign: 'tl-bl?',
12923 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
12927 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
12928 * query specified by the allQuery config option (defaults to 'query')
12930 triggerAction: 'query',
12932 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
12933 * (defaults to 4, does not apply if editable = false)
12937 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
12938 * delay (typeAheadDelay) if it matches a known value (defaults to false)
12942 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
12943 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
12947 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
12948 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
12952 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
12953 * when editable = true (defaults to false)
12955 selectOnFocus:false,
12957 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
12959 queryParam: 'query',
12961 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
12962 * when mode = 'remote' (defaults to 'Loading...')
12964 loadingText: 'Loading...',
12966 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
12970 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
12974 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
12975 * traditional select (defaults to true)
12979 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
12983 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
12987 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
12988 * listWidth has a higher value)
12992 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
12993 * allow the user to set arbitrary text into the field (defaults to false)
12995 forceSelection:false,
12997 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
12998 * if typeAhead = true (defaults to 250)
13000 typeAheadDelay : 250,
13002 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
13003 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
13005 valueNotFoundText : undefined,
13007 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
13009 blockFocus : false,
13012 * @cfg {Boolean} disableClear Disable showing of clear button.
13014 disableClear : false,
13016 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
13018 alwaysQuery : false,
13021 * @cfg {Boolean} multiple (true|false) ComboBobArray, default false
13026 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
13028 invalidClass : "has-warning",
13031 * @cfg {String} validClass The CSS class to use when marking a field valid (defaults to "x-form-invalid")
13033 validClass : "has-success",
13036 * @cfg {Boolean} specialFilter (true|false) special filter default false
13038 specialFilter : false,
13041 * @cfg {Boolean} mobileTouchView (true|false) show mobile touch view when using a mobile default true
13043 mobileTouchView : true,
13046 * @cfg {Boolean} useNativeIOS (true|false) render it as classic select for ios, not support dynamic load data (default false)
13048 useNativeIOS : false,
13051 * @cfg {Boolean} mobile_restrict_height (true|false) restrict height for touch view
13053 mobile_restrict_height : false,
13055 ios_options : false,
13067 btnPosition : 'right',
13068 triggerList : true,
13069 showToggleBtn : true,
13071 emptyResultText: 'Empty',
13072 triggerText : 'Select',
13075 // element that contains real text value.. (when hidden is used..)
13077 getAutoCreate : function()
13082 * Render classic select for iso
13085 if(Roo.isIOS && this.useNativeIOS){
13086 cfg = this.getAutoCreateNativeIOS();
13094 if(Roo.isTouch && this.mobileTouchView){
13095 cfg = this.getAutoCreateTouchView();
13102 if(!this.tickable){
13103 cfg = Roo.bootstrap.ComboBox.superclass.getAutoCreate.call(this);
13108 * ComboBox with tickable selections
13111 var align = this.labelAlign || this.parentLabelAlign();
13114 cls : 'form-group roo-combobox-tickable' //input-group
13117 var btn_text_select = '';
13118 var btn_text_done = '';
13119 var btn_text_cancel = '';
13121 if (this.btn_text_show) {
13122 btn_text_select = 'Select';
13123 btn_text_done = 'Done';
13124 btn_text_cancel = 'Cancel';
13129 cls : 'tickable-buttons',
13134 cls : 'btn btn-link btn-edit pull-' + this.btnPosition,
13135 //html : this.triggerText
13136 html: btn_text_select
13142 cls : 'btn btn-link btn-ok pull-' + this.btnPosition,
13144 html: btn_text_done
13150 cls : 'btn btn-link btn-cancel pull-' + this.btnPosition,
13152 html: btn_text_cancel
13158 buttons.cn.unshift({
13160 cls: 'roo-select2-search-field-input'
13166 Roo.each(buttons.cn, function(c){
13168 c.cls += ' btn-' + _this.size;
13171 if (_this.disabled) {
13182 cls: 'form-hidden-field'
13186 cls: 'roo-select2-choices',
13190 cls: 'roo-select2-search-field',
13201 cls: 'roo-select2-container input-group roo-select2-container-multi',
13206 // cls: 'typeahead typeahead-long dropdown-menu',
13207 // style: 'display:none; max-height:' + this.maxHeight + 'px;'
13212 if(this.hasFeedback && !this.allowBlank){
13216 cls: 'glyphicon form-control-feedback'
13219 combobox.cn.push(feedback);
13223 if (align ==='left' && this.fieldLabel.length) {
13225 cfg.cls += ' roo-form-group-label-left';
13230 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13231 tooltip : 'This field is required'
13236 cls : 'control-label',
13237 html : this.fieldLabel
13249 var labelCfg = cfg.cn[1];
13250 var contentCfg = cfg.cn[2];
13253 if(this.indicatorpos == 'right'){
13259 cls : 'control-label',
13263 html : this.fieldLabel
13267 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13268 tooltip : 'This field is required'
13283 labelCfg = cfg.cn[0];
13284 contentCfg = cfg.cn[1];
13288 if(this.labelWidth > 12){
13289 labelCfg.style = "width: " + this.labelWidth + 'px';
13292 if(this.labelWidth < 13 && this.labelmd == 0){
13293 this.labelmd = this.labelWidth;
13296 if(this.labellg > 0){
13297 labelCfg.cls += ' col-lg-' + this.labellg;
13298 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
13301 if(this.labelmd > 0){
13302 labelCfg.cls += ' col-md-' + this.labelmd;
13303 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
13306 if(this.labelsm > 0){
13307 labelCfg.cls += ' col-sm-' + this.labelsm;
13308 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
13311 if(this.labelxs > 0){
13312 labelCfg.cls += ' col-xs-' + this.labelxs;
13313 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
13317 } else if ( this.fieldLabel.length) {
13318 // Roo.log(" label");
13322 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
13323 tooltip : 'This field is required'
13327 //cls : 'input-group-addon',
13328 html : this.fieldLabel
13333 if(this.indicatorpos == 'right'){
13337 //cls : 'input-group-addon',
13338 html : this.fieldLabel
13342 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
13343 tooltip : 'This field is required'
13352 // Roo.log(" no label && no align");
13359 ['xs','sm','md','lg'].map(function(size){
13360 if (settings[size]) {
13361 cfg.cls += ' col-' + size + '-' + settings[size];
13369 _initEventsCalled : false,
13372 initEvents: function()
13374 if (this._initEventsCalled) { // as we call render... prevent looping...
13377 this._initEventsCalled = true;
13380 throw "can not find store for combo";
13383 this.indicator = this.indicatorEl();
13385 this.store = Roo.factory(this.store, Roo.data);
13386 this.store.parent = this;
13388 // if we are building from html. then this element is so complex, that we can not really
13389 // use the rendered HTML.
13390 // so we have to trash and replace the previous code.
13391 if (Roo.XComponent.build_from_html) {
13392 // remove this element....
13393 var e = this.el.dom, k=0;
13394 while (e ) { e = e.previousSibling; ++k;}
13399 this.rendered = false;
13401 this.render(this.parent().getChildContainer(true), k);
13404 if(Roo.isIOS && this.useNativeIOS){
13405 this.initIOSView();
13413 if(Roo.isTouch && this.mobileTouchView){
13414 this.initTouchView();
13419 this.initTickableEvents();
13423 Roo.bootstrap.ComboBox.superclass.initEvents.call(this);
13425 if(this.hiddenName){
13427 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13429 this.hiddenField.dom.value =
13430 this.hiddenValue !== undefined ? this.hiddenValue :
13431 this.value !== undefined ? this.value : '';
13433 // prevent input submission
13434 this.el.dom.removeAttribute('name');
13435 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13440 // this.el.dom.setAttribute('autocomplete', 'off');
13443 var cls = 'x-combo-list';
13445 //this.list = new Roo.Layer({
13446 // shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
13452 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13453 _this.list.setWidth(lw);
13456 this.list.on('mouseover', this.onViewOver, this);
13457 this.list.on('mousemove', this.onViewMove, this);
13458 this.list.on('scroll', this.onViewScroll, this);
13461 this.list.swallowEvent('mousewheel');
13462 this.assetHeight = 0;
13465 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
13466 this.assetHeight += this.header.getHeight();
13469 this.innerList = this.list.createChild({cls:cls+'-inner'});
13470 this.innerList.on('mouseover', this.onViewOver, this);
13471 this.innerList.on('mousemove', this.onViewMove, this);
13472 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13474 if(this.allowBlank && !this.pageSize && !this.disableClear){
13475 this.footer = this.list.createChild({cls:cls+'-ft'});
13476 this.pageTb = new Roo.Toolbar(this.footer);
13480 this.footer = this.list.createChild({cls:cls+'-ft'});
13481 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
13482 {pageSize: this.pageSize});
13486 if (this.pageTb && this.allowBlank && !this.disableClear) {
13488 this.pageTb.add(new Roo.Toolbar.Fill(), {
13489 cls: 'x-btn-icon x-btn-clear',
13491 handler: function()
13494 _this.clearValue();
13495 _this.onSelect(false, -1);
13500 this.assetHeight += this.footer.getHeight();
13505 this.tpl = '<li><a href="#">{' + this.displayField + '}</a></li>';
13508 this.view = new Roo.View(this.list, this.tpl, {
13509 singleSelect:true, store: this.store, selectedClass: this.selectedClass
13511 //this.view.wrapEl.setDisplayed(false);
13512 this.view.on('click', this.onViewClick, this);
13515 this.store.on('beforeload', this.onBeforeLoad, this);
13516 this.store.on('load', this.onLoad, this);
13517 this.store.on('loadexception', this.onLoadException, this);
13519 if(this.resizable){
13520 this.resizer = new Roo.Resizable(this.list, {
13521 pinned:true, handles:'se'
13523 this.resizer.on('resize', function(r, w, h){
13524 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
13525 this.listWidth = w;
13526 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
13527 this.restrictHeight();
13529 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
13532 if(!this.editable){
13533 this.editable = true;
13534 this.setEditable(false);
13539 if (typeof(this.events.add.listeners) != 'undefined') {
13541 this.addicon = this.wrap.createChild(
13542 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
13544 this.addicon.on('click', function(e) {
13545 this.fireEvent('add', this);
13548 if (typeof(this.events.edit.listeners) != 'undefined') {
13550 this.editicon = this.wrap.createChild(
13551 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
13552 if (this.addicon) {
13553 this.editicon.setStyle('margin-left', '40px');
13555 this.editicon.on('click', function(e) {
13557 // we fire even if inothing is selected..
13558 this.fireEvent('edit', this, this.lastData );
13564 this.keyNav = new Roo.KeyNav(this.inputEl(), {
13565 "up" : function(e){
13566 this.inKeyMode = true;
13570 "down" : function(e){
13571 if(!this.isExpanded()){
13572 this.onTriggerClick();
13574 this.inKeyMode = true;
13579 "enter" : function(e){
13580 // this.onViewClick();
13584 if(this.fireEvent("specialkey", this, e)){
13585 this.onViewClick(false);
13591 "esc" : function(e){
13595 "tab" : function(e){
13598 if(this.fireEvent("specialkey", this, e)){
13599 this.onViewClick(false);
13607 doRelay : function(foo, bar, hname){
13608 if(hname == 'down' || this.scope.isExpanded()){
13609 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13618 this.queryDelay = Math.max(this.queryDelay || 10,
13619 this.mode == 'local' ? 10 : 250);
13622 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13624 if(this.typeAhead){
13625 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13627 if(this.editable !== false){
13628 this.inputEl().on("keyup", this.onKeyUp, this);
13630 if(this.forceSelection){
13631 this.inputEl().on('blur', this.doForce, this);
13635 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13636 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13640 initTickableEvents: function()
13644 if(this.hiddenName){
13646 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
13648 this.hiddenField.dom.value =
13649 this.hiddenValue !== undefined ? this.hiddenValue :
13650 this.value !== undefined ? this.value : '';
13652 // prevent input submission
13653 this.el.dom.removeAttribute('name');
13654 this.hiddenField.dom.setAttribute('name', this.hiddenName);
13659 // this.list = this.el.select('ul.dropdown-menu',true).first();
13661 this.choices = this.el.select('ul.roo-select2-choices', true).first();
13662 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
13663 if(this.triggerList){
13664 this.searchField.on("click", this.onSearchFieldClick, this, {preventDefault:true});
13667 this.trigger = this.el.select('.tickable-buttons > .btn-edit', true).first();
13668 this.trigger.on("click", this.onTickableTriggerClick, this, {preventDefault:true});
13670 this.okBtn = this.el.select('.tickable-buttons > .btn-ok', true).first();
13671 this.cancelBtn = this.el.select('.tickable-buttons > .btn-cancel', true).first();
13673 this.okBtn.on('click', this.onTickableFooterButtonClick, this, this.okBtn);
13674 this.cancelBtn.on('click', this.onTickableFooterButtonClick, this, this.cancelBtn);
13676 this.trigger.setVisibilityMode(Roo.Element.DISPLAY);
13677 this.okBtn.setVisibilityMode(Roo.Element.DISPLAY);
13678 this.cancelBtn.setVisibilityMode(Roo.Element.DISPLAY);
13681 this.cancelBtn.hide();
13686 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
13687 _this.list.setWidth(lw);
13690 this.list.on('mouseover', this.onViewOver, this);
13691 this.list.on('mousemove', this.onViewMove, this);
13693 this.list.on('scroll', this.onViewScroll, this);
13696 this.tpl = '<li class="roo-select2-result"><div class="checkbox"><input id="{roo-id}"' +
13697 'type="checkbox" {roo-data-checked}><label for="{roo-id}"><b>{' + this.displayField + '}</b></label></div></li>';
13700 this.view = new Roo.View(this.list, this.tpl, {
13705 selectedClass: this.selectedClass
13708 //this.view.wrapEl.setDisplayed(false);
13709 this.view.on('click', this.onViewClick, this);
13713 this.store.on('beforeload', this.onBeforeLoad, this);
13714 this.store.on('load', this.onLoad, this);
13715 this.store.on('loadexception', this.onLoadException, this);
13718 this.keyNav = new Roo.KeyNav(this.tickableInputEl(), {
13719 "up" : function(e){
13720 this.inKeyMode = true;
13724 "down" : function(e){
13725 this.inKeyMode = true;
13729 "enter" : function(e){
13730 if(this.fireEvent("specialkey", this, e)){
13731 this.onViewClick(false);
13737 "esc" : function(e){
13738 this.onTickableFooterButtonClick(e, false, false);
13741 "tab" : function(e){
13742 this.fireEvent("specialkey", this, e);
13744 this.onTickableFooterButtonClick(e, false, false);
13751 doRelay : function(e, fn, key){
13752 if(this.scope.isExpanded()){
13753 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
13762 this.queryDelay = Math.max(this.queryDelay || 10,
13763 this.mode == 'local' ? 10 : 250);
13766 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
13768 if(this.typeAhead){
13769 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
13772 if(this.editable !== false){
13773 this.tickableInputEl().on("keyup", this.onKeyUp, this);
13776 this.indicator = this.indicatorEl();
13778 if(this.indicator){
13779 this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
13780 this.indicator.hide();
13785 onDestroy : function(){
13787 this.view.setStore(null);
13788 this.view.el.removeAllListeners();
13789 this.view.el.remove();
13790 this.view.purgeListeners();
13793 this.list.dom.innerHTML = '';
13797 this.store.un('beforeload', this.onBeforeLoad, this);
13798 this.store.un('load', this.onLoad, this);
13799 this.store.un('loadexception', this.onLoadException, this);
13801 Roo.bootstrap.ComboBox.superclass.onDestroy.call(this);
13805 fireKey : function(e){
13806 if(e.isNavKeyPress() && !this.list.isVisible()){
13807 this.fireEvent("specialkey", this, e);
13812 onResize: function(w, h){
13813 // Roo.bootstrap.ComboBox.superclass.onResize.apply(this, arguments);
13815 // if(typeof w != 'number'){
13816 // // we do not handle it!?!?
13819 // var tw = this.trigger.getWidth();
13820 // // tw += this.addicon ? this.addicon.getWidth() : 0;
13821 // // tw += this.editicon ? this.editicon.getWidth() : 0;
13823 // this.inputEl().setWidth( this.adjustWidth('input', x));
13825 // //this.trigger.setStyle('left', x+'px');
13827 // if(this.list && this.listWidth === undefined){
13828 // var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
13829 // this.list.setWidth(lw);
13830 // this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
13838 * Allow or prevent the user from directly editing the field text. If false is passed,
13839 * the user will only be able to select from the items defined in the dropdown list. This method
13840 * is the runtime equivalent of setting the 'editable' config option at config time.
13841 * @param {Boolean} value True to allow the user to directly edit the field text
13843 setEditable : function(value){
13844 if(value == this.editable){
13847 this.editable = value;
13849 this.inputEl().dom.setAttribute('readOnly', true);
13850 this.inputEl().on('mousedown', this.onTriggerClick, this);
13851 this.inputEl().addClass('x-combo-noedit');
13853 this.inputEl().dom.setAttribute('readOnly', false);
13854 this.inputEl().un('mousedown', this.onTriggerClick, this);
13855 this.inputEl().removeClass('x-combo-noedit');
13861 onBeforeLoad : function(combo,opts){
13862 if(!this.hasFocus){
13866 this.list.dom.innerHTML = '<li class="loading-indicator">'+(this.loadingText||'loading')+'</li>' ;
13868 this.restrictHeight();
13869 this.selectedIndex = -1;
13873 onLoad : function(){
13875 this.hasQuery = false;
13877 if(!this.hasFocus){
13881 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13882 this.loading.hide();
13885 if(this.store.getCount() > 0){
13888 this.restrictHeight();
13889 if(this.lastQuery == this.allQuery){
13890 if(this.editable && !this.tickable){
13891 this.inputEl().dom.select();
13895 !this.selectByValue(this.value, true) &&
13898 !this.store.lastOptions ||
13899 typeof(this.store.lastOptions.add) == 'undefined' ||
13900 this.store.lastOptions.add != true
13903 this.select(0, true);
13906 if(this.autoFocus){
13909 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
13910 this.taTask.delay(this.typeAheadDelay);
13914 this.onEmptyResults();
13920 onLoadException : function()
13922 this.hasQuery = false;
13924 if(typeof(this.loading) !== 'undefined' && this.loading !== null){
13925 this.loading.hide();
13928 if(this.tickable && this.editable){
13933 // only causes errors at present
13934 //Roo.log(this.store.reader.jsonData);
13935 //if (this.store && typeof(this.store.reader.jsonData.errorMsg) != 'undefined') {
13937 //Roo.MessageBox.alert("Error loading",this.store.reader.jsonData.errorMsg);
13943 onTypeAhead : function(){
13944 if(this.store.getCount() > 0){
13945 var r = this.store.getAt(0);
13946 var newValue = r.data[this.displayField];
13947 var len = newValue.length;
13948 var selStart = this.getRawValue().length;
13950 if(selStart != len){
13951 this.setRawValue(newValue);
13952 this.selectText(selStart, newValue.length);
13958 onSelect : function(record, index){
13960 if(this.fireEvent('beforeselect', this, record, index) !== false){
13962 this.setFromData(index > -1 ? record.data : false);
13965 this.fireEvent('select', this, record, index);
13970 * Returns the currently selected field value or empty string if no value is set.
13971 * @return {String} value The selected value
13973 getValue : function()
13975 if(Roo.isIOS && this.useNativeIOS){
13976 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.valueField];
13980 return (this.hiddenField) ? this.hiddenField.dom.value : this.value;
13983 if(this.valueField){
13984 return typeof this.value != 'undefined' ? this.value : '';
13986 return Roo.bootstrap.ComboBox.superclass.getValue.call(this);
13990 getRawValue : function()
13992 if(Roo.isIOS && this.useNativeIOS){
13993 return this.ios_options[this.inputEl().dom.selectedIndex].data[this.displayField];
13996 var v = this.inputEl().getValue();
14002 * Clears any text/value currently set in the field
14004 clearValue : function(){
14006 if(this.hiddenField){
14007 this.hiddenField.dom.value = '';
14010 this.setRawValue('');
14011 this.lastSelectionText = '';
14012 this.lastData = false;
14014 var close = this.closeTriggerEl();
14025 * Sets the specified value into the field. If the value finds a match, the corresponding record text
14026 * will be displayed in the field. If the value does not match the data value of an existing item,
14027 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
14028 * Otherwise the field will be blank (although the value will still be set).
14029 * @param {String} value The value to match
14031 setValue : function(v)
14033 if(Roo.isIOS && this.useNativeIOS){
14034 this.setIOSValue(v);
14044 if(this.valueField){
14045 var r = this.findRecord(this.valueField, v);
14047 text = r.data[this.displayField];
14048 }else if(this.valueNotFoundText !== undefined){
14049 text = this.valueNotFoundText;
14052 this.lastSelectionText = text;
14053 if(this.hiddenField){
14054 this.hiddenField.dom.value = v;
14056 Roo.bootstrap.ComboBox.superclass.setValue.call(this, text);
14059 var close = this.closeTriggerEl();
14062 (v && (v.length || v * 1 > 0)) ? close.show() : close.hide();
14068 * @property {Object} the last set data for the element
14073 * Sets the value of the field based on a object which is related to the record format for the store.
14074 * @param {Object} value the value to set as. or false on reset?
14076 setFromData : function(o){
14083 var dv = ''; // display value
14084 var vv = ''; // value value..
14086 if (this.displayField) {
14087 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14089 // this is an error condition!!!
14090 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14093 if(this.valueField){
14094 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
14097 var close = this.closeTriggerEl();
14100 if(dv.length || vv * 1 > 0){
14102 this.blockFocus=true;
14108 if(this.hiddenField){
14109 this.hiddenField.dom.value = vv;
14111 this.lastSelectionText = dv;
14112 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14116 // no hidden field.. - we store the value in 'value', but still display
14117 // display field!!!!
14118 this.lastSelectionText = dv;
14119 Roo.bootstrap.ComboBox.superclass.setValue.call(this, dv);
14126 reset : function(){
14127 // overridden so that last data is reset..
14134 this.setValue(this.originalValue);
14135 //this.clearInvalid();
14136 this.lastData = false;
14138 this.view.clearSelections();
14144 findRecord : function(prop, value){
14146 if(this.store.getCount() > 0){
14147 this.store.each(function(r){
14148 if(r.data[prop] == value){
14158 getName: function()
14160 // returns hidden if it's set..
14161 if (!this.rendered) {return ''};
14162 return !this.hiddenName && this.inputEl().dom.name ? this.inputEl().dom.name : (this.hiddenName || '');
14166 onViewMove : function(e, t){
14167 this.inKeyMode = false;
14171 onViewOver : function(e, t){
14172 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
14175 var item = this.view.findItemFromChild(t);
14178 var index = this.view.indexOf(item);
14179 this.select(index, false);
14184 onViewClick : function(view, doFocus, el, e)
14186 var index = this.view.getSelectedIndexes()[0];
14188 var r = this.store.getAt(index);
14192 if(typeof(e) != 'undefined' && e.getTarget().nodeName.toLowerCase() != 'input'){
14199 Roo.each(this.tickItems, function(v,k){
14201 if(typeof(v) != 'undefined' && v[_this.valueField] == r.data[_this.valueField]){
14203 _this.tickItems.splice(k, 1);
14205 if(typeof(e) == 'undefined' && view == false){
14206 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = false;
14218 if(this.fireEvent('tick', this, r, index, Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked) !== false){
14219 this.tickItems.push(r.data);
14222 if(typeof(e) == 'undefined' && view == false){
14223 Roo.get(_this.view.getNodes(index, index)[0]).select('input', true).first().dom.checked = true;
14230 this.onSelect(r, index);
14232 if(doFocus !== false && !this.blockFocus){
14233 this.inputEl().focus();
14238 restrictHeight : function(){
14239 //this.innerList.dom.style.height = '';
14240 //var inner = this.innerList.dom;
14241 //var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
14242 //this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
14243 //this.list.beginUpdate();
14244 //this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
14245 this.list.alignTo(this.inputEl(), this.listAlign);
14246 this.list.alignTo(this.inputEl(), this.listAlign);
14247 //this.list.endUpdate();
14251 onEmptyResults : function(){
14253 if(this.tickable && this.editable){
14254 this.hasFocus = false;
14255 this.restrictHeight();
14263 * Returns true if the dropdown list is expanded, else false.
14265 isExpanded : function(){
14266 return this.list.isVisible();
14270 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
14271 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14272 * @param {String} value The data value of the item to select
14273 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14274 * selected item if it is not currently in view (defaults to true)
14275 * @return {Boolean} True if the value matched an item in the list, else false
14277 selectByValue : function(v, scrollIntoView){
14278 if(v !== undefined && v !== null){
14279 var r = this.findRecord(this.valueField || this.displayField, v);
14281 this.select(this.store.indexOf(r), scrollIntoView);
14289 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
14290 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
14291 * @param {Number} index The zero-based index of the list item to select
14292 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
14293 * selected item if it is not currently in view (defaults to true)
14295 select : function(index, scrollIntoView){
14296 this.selectedIndex = index;
14297 this.view.select(index);
14298 if(scrollIntoView !== false){
14299 var el = this.view.getNode(index);
14301 * el && !this.multiple && !this.tickable // not sure why we disable multiple before..
14304 this.list.scrollChildIntoView(el, false);
14310 selectNext : function(){
14311 var ct = this.store.getCount();
14313 if(this.selectedIndex == -1){
14315 }else if(this.selectedIndex < ct-1){
14316 this.select(this.selectedIndex+1);
14322 selectPrev : function(){
14323 var ct = this.store.getCount();
14325 if(this.selectedIndex == -1){
14327 }else if(this.selectedIndex != 0){
14328 this.select(this.selectedIndex-1);
14334 onKeyUp : function(e){
14335 if(this.editable !== false && !e.isSpecialKey()){
14336 this.lastKey = e.getKey();
14337 this.dqTask.delay(this.queryDelay);
14342 validateBlur : function(){
14343 return !this.list || !this.list.isVisible();
14347 initQuery : function(){
14349 var v = this.getRawValue();
14351 if(this.tickable && this.editable){
14352 v = this.tickableInputEl().getValue();
14359 doForce : function(){
14360 if(this.inputEl().dom.value.length > 0){
14361 this.inputEl().dom.value =
14362 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
14368 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
14369 * query allowing the query action to be canceled if needed.
14370 * @param {String} query The SQL query to execute
14371 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
14372 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
14373 * saved in the current store (defaults to false)
14375 doQuery : function(q, forceAll){
14377 if(q === undefined || q === null){
14382 forceAll: forceAll,
14386 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
14391 forceAll = qe.forceAll;
14392 if(forceAll === true || (q.length >= this.minChars)){
14394 this.hasQuery = true;
14396 if(this.lastQuery != q || this.alwaysQuery){
14397 this.lastQuery = q;
14398 if(this.mode == 'local'){
14399 this.selectedIndex = -1;
14401 this.store.clearFilter();
14404 if(this.specialFilter){
14405 this.fireEvent('specialfilter', this);
14410 this.store.filter(this.displayField, q);
14413 this.store.fireEvent("datachanged", this.store);
14420 this.store.baseParams[this.queryParam] = q;
14422 var options = {params : this.getParams(q)};
14425 options.add = true;
14426 options.params.start = this.page * this.pageSize;
14429 this.store.load(options);
14432 * this code will make the page width larger, at the beginning, the list not align correctly,
14433 * we should expand the list on onLoad
14434 * so command out it
14439 this.selectedIndex = -1;
14444 this.loadNext = false;
14448 getParams : function(q){
14450 //p[this.queryParam] = q;
14454 p.limit = this.pageSize;
14460 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
14462 collapse : function(){
14463 if(!this.isExpanded()){
14469 this.hasFocus = false;
14473 this.cancelBtn.hide();
14474 this.trigger.show();
14477 this.tickableInputEl().dom.value = '';
14478 this.tickableInputEl().blur();
14483 Roo.get(document).un('mousedown', this.collapseIf, this);
14484 Roo.get(document).un('mousewheel', this.collapseIf, this);
14485 if (!this.editable) {
14486 Roo.get(document).un('keydown', this.listKeyPress, this);
14488 this.fireEvent('collapse', this);
14494 collapseIf : function(e){
14495 var in_combo = e.within(this.el);
14496 var in_list = e.within(this.list);
14497 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
14499 if (in_combo || in_list || is_list) {
14500 //e.stopPropagation();
14505 this.onTickableFooterButtonClick(e, false, false);
14513 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
14515 expand : function(){
14517 if(this.isExpanded() || !this.hasFocus){
14521 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
14522 this.list.setWidth(lw);
14528 this.restrictHeight();
14532 this.tickItems = Roo.apply([], this.item);
14535 this.cancelBtn.show();
14536 this.trigger.hide();
14539 this.tickableInputEl().focus();
14544 Roo.get(document).on('mousedown', this.collapseIf, this);
14545 Roo.get(document).on('mousewheel', this.collapseIf, this);
14546 if (!this.editable) {
14547 Roo.get(document).on('keydown', this.listKeyPress, this);
14550 this.fireEvent('expand', this);
14554 // Implements the default empty TriggerField.onTriggerClick function
14555 onTriggerClick : function(e)
14557 Roo.log('trigger click');
14559 if(this.disabled || !this.triggerList){
14564 this.loadNext = false;
14566 if(this.isExpanded()){
14568 if (!this.blockFocus) {
14569 this.inputEl().focus();
14573 this.hasFocus = true;
14574 if(this.triggerAction == 'all') {
14575 this.doQuery(this.allQuery, true);
14577 this.doQuery(this.getRawValue());
14579 if (!this.blockFocus) {
14580 this.inputEl().focus();
14585 onTickableTriggerClick : function(e)
14592 this.loadNext = false;
14593 this.hasFocus = true;
14595 if(this.triggerAction == 'all') {
14596 this.doQuery(this.allQuery, true);
14598 this.doQuery(this.getRawValue());
14602 onSearchFieldClick : function(e)
14604 if(this.hasFocus && !this.disabled && e.getTarget().nodeName.toLowerCase() != 'button'){
14605 this.onTickableFooterButtonClick(e, false, false);
14609 if(this.hasFocus || this.disabled || e.getTarget().nodeName.toLowerCase() == 'button'){
14614 this.loadNext = false;
14615 this.hasFocus = true;
14617 if(this.triggerAction == 'all') {
14618 this.doQuery(this.allQuery, true);
14620 this.doQuery(this.getRawValue());
14624 listKeyPress : function(e)
14626 //Roo.log('listkeypress');
14627 // scroll to first matching element based on key pres..
14628 if (e.isSpecialKey()) {
14631 var k = String.fromCharCode(e.getKey()).toUpperCase();
14634 var csel = this.view.getSelectedNodes();
14635 var cselitem = false;
14637 var ix = this.view.indexOf(csel[0]);
14638 cselitem = this.store.getAt(ix);
14639 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
14645 this.store.each(function(v) {
14647 // start at existing selection.
14648 if (cselitem.id == v.id) {
14654 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
14655 match = this.store.indexOf(v);
14661 if (match === false) {
14662 return true; // no more action?
14665 this.view.select(match);
14666 var sn = Roo.get(this.view.getSelectedNodes()[0]);
14667 sn.scrollIntoView(sn.dom.parentNode, false);
14670 onViewScroll : function(e, t){
14672 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){
14676 this.hasQuery = true;
14678 this.loading = this.list.select('.loading', true).first();
14680 if(this.loading === null){
14681 this.list.createChild({
14683 cls: 'loading roo-select2-more-results roo-select2-active',
14684 html: 'Loading more results...'
14687 this.loading = this.list.select('.loading', true).first();
14689 this.loading.setVisibilityMode(Roo.Element.DISPLAY);
14691 this.loading.hide();
14694 this.loading.show();
14699 this.loadNext = true;
14701 (function() { _combo.doQuery(_combo.allQuery, true); }).defer(500);
14706 addItem : function(o)
14708 var dv = ''; // display value
14710 if (this.displayField) {
14711 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
14713 // this is an error condition!!!
14714 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
14721 var choice = this.choices.createChild({
14723 cls: 'roo-select2-search-choice',
14732 cls: 'roo-select2-search-choice-close fa fa-times',
14737 }, this.searchField);
14739 var close = choice.select('a.roo-select2-search-choice-close', true).first();
14741 close.on('click', this.onRemoveItem, this, { item : choice, data : o} );
14749 this.inputEl().dom.value = '';
14754 onRemoveItem : function(e, _self, o)
14756 e.preventDefault();
14758 this.lastItem = Roo.apply([], this.item);
14760 var index = this.item.indexOf(o.data) * 1;
14763 Roo.log('not this item?!');
14767 this.item.splice(index, 1);
14772 this.fireEvent('remove', this, e);
14778 syncValue : function()
14780 if(!this.item.length){
14787 Roo.each(this.item, function(i){
14788 if(_this.valueField){
14789 value.push(i[_this.valueField]);
14796 this.value = value.join(',');
14798 if(this.hiddenField){
14799 this.hiddenField.dom.value = this.value;
14802 this.store.fireEvent("datachanged", this.store);
14807 clearItem : function()
14809 if(!this.multiple){
14815 Roo.each(this.choices.select('>li.roo-select2-search-choice', true).elements, function(c){
14823 if(this.tickable && !Roo.isTouch){
14824 this.view.refresh();
14828 inputEl: function ()
14830 if(Roo.isIOS && this.useNativeIOS){
14831 return this.el.select('select.roo-ios-select', true).first();
14834 if(Roo.isTouch && this.mobileTouchView){
14835 return this.el.select('input.form-control',true).first();
14839 return this.searchField;
14842 return this.el.select('input.form-control',true).first();
14845 onTickableFooterButtonClick : function(e, btn, el)
14847 e.preventDefault();
14849 this.lastItem = Roo.apply([], this.item);
14851 if(btn && btn.name == 'cancel'){
14852 this.tickItems = Roo.apply([], this.item);
14861 Roo.each(this.tickItems, function(o){
14869 validate : function()
14871 if(this.getVisibilityEl().hasClass('hidden')){
14875 var v = this.getRawValue();
14878 v = this.getValue();
14881 if(this.disabled || this.allowBlank || v.length){
14886 this.markInvalid();
14890 tickableInputEl : function()
14892 if(!this.tickable || !this.editable){
14893 return this.inputEl();
14896 return this.inputEl().select('.roo-select2-search-field-input', true).first();
14900 getAutoCreateTouchView : function()
14905 cls: 'form-group' //input-group
14911 type : this.inputType,
14912 cls : 'form-control x-combo-noedit',
14913 autocomplete: 'new-password',
14914 placeholder : this.placeholder || '',
14919 input.name = this.name;
14923 input.cls += ' input-' + this.size;
14926 if (this.disabled) {
14927 input.disabled = true;
14938 inputblock.cls += ' input-group';
14940 inputblock.cn.unshift({
14942 cls : 'input-group-addon',
14947 if(this.removable && !this.multiple){
14948 inputblock.cls += ' roo-removable';
14950 inputblock.cn.push({
14953 cls : 'roo-combo-removable-btn close'
14957 if(this.hasFeedback && !this.allowBlank){
14959 inputblock.cls += ' has-feedback';
14961 inputblock.cn.push({
14963 cls: 'glyphicon form-control-feedback'
14970 inputblock.cls += (this.before) ? '' : ' input-group';
14972 inputblock.cn.push({
14974 cls : 'input-group-addon',
14985 cls: 'form-hidden-field'
14999 cls: 'form-hidden-field'
15003 cls: 'roo-select2-choices',
15007 cls: 'roo-select2-search-field',
15020 cls: 'roo-select2-container input-group roo-touchview-combobox ',
15026 if(!this.multiple && this.showToggleBtn){
15033 if (this.caret != false) {
15036 cls: 'fa fa-' + this.caret
15043 cls : 'input-group-addon btn dropdown-toggle',
15048 cls: 'combobox-clear',
15062 combobox.cls += ' roo-select2-container-multi';
15065 var align = this.labelAlign || this.parentLabelAlign();
15067 if (align ==='left' && this.fieldLabel.length) {
15072 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15073 tooltip : 'This field is required'
15077 cls : 'control-label',
15078 html : this.fieldLabel
15089 var labelCfg = cfg.cn[1];
15090 var contentCfg = cfg.cn[2];
15093 if(this.indicatorpos == 'right'){
15098 cls : 'control-label',
15102 html : this.fieldLabel
15106 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15107 tooltip : 'This field is required'
15120 labelCfg = cfg.cn[0];
15121 contentCfg = cfg.cn[1];
15126 if(this.labelWidth > 12){
15127 labelCfg.style = "width: " + this.labelWidth + 'px';
15130 if(this.labelWidth < 13 && this.labelmd == 0){
15131 this.labelmd = this.labelWidth;
15134 if(this.labellg > 0){
15135 labelCfg.cls += ' col-lg-' + this.labellg;
15136 contentCfg.cls += ' col-lg-' + (12 - this.labellg);
15139 if(this.labelmd > 0){
15140 labelCfg.cls += ' col-md-' + this.labelmd;
15141 contentCfg.cls += ' col-md-' + (12 - this.labelmd);
15144 if(this.labelsm > 0){
15145 labelCfg.cls += ' col-sm-' + this.labelsm;
15146 contentCfg.cls += ' col-sm-' + (12 - this.labelsm);
15149 if(this.labelxs > 0){
15150 labelCfg.cls += ' col-xs-' + this.labelxs;
15151 contentCfg.cls += ' col-xs-' + (12 - this.labelxs);
15155 } else if ( this.fieldLabel.length) {
15159 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
15160 tooltip : 'This field is required'
15164 cls : 'control-label',
15165 html : this.fieldLabel
15176 if(this.indicatorpos == 'right'){
15180 cls : 'control-label',
15181 html : this.fieldLabel,
15185 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
15186 tooltip : 'This field is required'
15203 var settings = this;
15205 ['xs','sm','md','lg'].map(function(size){
15206 if (settings[size]) {
15207 cfg.cls += ' col-' + size + '-' + settings[size];
15214 initTouchView : function()
15216 this.renderTouchView();
15218 this.touchViewEl.on('scroll', function(){
15219 this.el.dom.scrollTop = 0;
15222 this.originalValue = this.getValue();
15224 this.triggerEl = this.el.select('span.dropdown-toggle',true).first();
15226 this.inputEl().on("click", this.showTouchView, this);
15227 if (this.triggerEl) {
15228 this.triggerEl.on("click", this.showTouchView, this);
15232 this.touchViewFooterEl.select('.roo-touch-view-cancel', true).first().on('click', this.hideTouchView, this);
15233 this.touchViewFooterEl.select('.roo-touch-view-ok', true).first().on('click', this.setTouchViewValue, this);
15235 this.maskEl = new Roo.LoadMask(this.touchViewEl, { store : this.store, msgCls: 'roo-el-mask-msg' });
15237 this.store.on('beforeload', this.onTouchViewBeforeLoad, this);
15238 this.store.on('load', this.onTouchViewLoad, this);
15239 this.store.on('loadexception', this.onTouchViewLoadException, this);
15241 if(this.hiddenName){
15243 this.hiddenField = this.el.select('input.form-hidden-field',true).first();
15245 this.hiddenField.dom.value =
15246 this.hiddenValue !== undefined ? this.hiddenValue :
15247 this.value !== undefined ? this.value : '';
15249 this.el.dom.removeAttribute('name');
15250 this.hiddenField.dom.setAttribute('name', this.hiddenName);
15254 this.choices = this.el.select('ul.roo-select2-choices', true).first();
15255 this.searchField = this.el.select('ul li.roo-select2-search-field', true).first();
15258 if(this.removable && !this.multiple){
15259 var close = this.closeTriggerEl();
15261 close.setVisibilityMode(Roo.Element.DISPLAY).hide();
15262 close.on('click', this.removeBtnClick, this, close);
15266 * fix the bug in Safari iOS8
15268 this.inputEl().on("focus", function(e){
15269 document.activeElement.blur();
15272 this._touchViewMask = Roo.DomHelper.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
15279 renderTouchView : function()
15281 this.touchViewEl = Roo.get(document.body).createChild(Roo.bootstrap.ComboBox.touchViewTemplate);
15282 this.touchViewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15284 this.touchViewHeaderEl = this.touchViewEl.select('.modal-header', true).first();
15285 this.touchViewHeaderEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15287 this.touchViewBodyEl = this.touchViewEl.select('.modal-body', true).first();
15288 this.touchViewBodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15289 this.touchViewBodyEl.setStyle('overflow', 'auto');
15291 this.touchViewListGroup = this.touchViewBodyEl.select('.list-group', true).first();
15292 this.touchViewListGroup.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15294 this.touchViewFooterEl = this.touchViewEl.select('.modal-footer', true).first();
15295 this.touchViewFooterEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
15299 showTouchView : function()
15305 this.touchViewHeaderEl.hide();
15307 if(this.modalTitle.length){
15308 this.touchViewHeaderEl.dom.innerHTML = this.modalTitle;
15309 this.touchViewHeaderEl.show();
15312 this.touchViewEl.setStyle('z-index', Roo.bootstrap.Modal.zIndex++);
15313 this.touchViewEl.show();
15315 this.touchViewEl.select('.modal-dialog', true).first().setStyle({ margin : '0px', width : '100%'});
15317 //this.touchViewEl.select('.modal-dialog > .modal-content', true).first().setSize(
15318 // Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15320 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15322 if(this.modalTitle.length){
15323 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15326 this.touchViewBodyEl.setHeight(bodyHeight);
15330 (function(){ _this.touchViewEl.addClass('in'); }).defer(50);
15332 this.touchViewEl.addClass('in');
15335 if(this._touchViewMask){
15336 Roo.get(document.body).addClass("x-body-masked");
15337 this._touchViewMask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
15338 this._touchViewMask.setStyle('z-index', 10000);
15339 this._touchViewMask.addClass('show');
15342 this.doTouchViewQuery();
15346 hideTouchView : function()
15348 this.touchViewEl.removeClass('in');
15352 (function(){ _this.touchViewEl.setStyle('display', 'none'); }).defer(150);
15354 this.touchViewEl.setStyle('display', 'none');
15357 if(this._touchViewMask){
15358 this._touchViewMask.removeClass('show');
15359 Roo.get(document.body).removeClass("x-body-masked");
15363 setTouchViewValue : function()
15370 Roo.each(this.tickItems, function(o){
15375 this.hideTouchView();
15378 doTouchViewQuery : function()
15387 if(this.fireEvent('beforequery', qe) ===false || qe.cancel){
15391 if(!this.alwaysQuery || this.mode == 'local'){
15392 this.onTouchViewLoad();
15399 onTouchViewBeforeLoad : function(combo,opts)
15405 onTouchViewLoad : function()
15407 if(this.store.getCount() < 1){
15408 this.onTouchViewEmptyResults();
15412 this.clearTouchView();
15414 var rawValue = this.getRawValue();
15416 var template = (this.multiple) ? Roo.bootstrap.ComboBox.listItemCheckbox : Roo.bootstrap.ComboBox.listItemRadio;
15418 this.tickItems = [];
15420 this.store.data.each(function(d, rowIndex){
15421 var row = this.touchViewListGroup.createChild(template);
15423 if(typeof(d.data.cls) != 'undefined' && d.data.cls.length){
15424 row.addClass(d.data.cls);
15427 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15430 html : d.data[this.displayField]
15433 if(this.fireEvent('touchviewdisplay', this, cfg) !== false){
15434 row.select('.roo-combobox-list-group-item-value', true).first().dom.innerHTML = cfg.html;
15437 row.removeClass('selected');
15438 if(!this.multiple && this.valueField &&
15439 typeof(d.data[this.valueField]) != 'undefined' && d.data[this.valueField] == this.getValue())
15442 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15443 row.addClass('selected');
15446 if(this.multiple && this.valueField &&
15447 typeof(d.data[this.valueField]) != 'undefined' && this.getValue().indexOf(d.data[this.valueField]) != -1)
15451 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15452 this.tickItems.push(d.data);
15455 row.on('click', this.onTouchViewClick, this, {row : row, rowIndex : rowIndex});
15459 var firstChecked = this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).first();
15461 var bodyHeight = Roo.lib.Dom.getViewHeight() - this.touchViewFooterEl.getHeight() + this.touchViewBodyEl.getPadding('tb');
15463 if(this.modalTitle.length){
15464 bodyHeight = bodyHeight - this.touchViewHeaderEl.getHeight();
15467 var listHeight = this.touchViewListGroup.getHeight() + this.touchViewBodyEl.getPadding('tb') * 2;
15469 if(this.mobile_restrict_height && listHeight < bodyHeight){
15470 this.touchViewBodyEl.setHeight(listHeight);
15475 if(firstChecked && listHeight > bodyHeight){
15476 (function() { firstChecked.findParent('li').scrollIntoView(_this.touchViewListGroup.dom); }).defer(500);
15481 onTouchViewLoadException : function()
15483 this.hideTouchView();
15486 onTouchViewEmptyResults : function()
15488 this.clearTouchView();
15490 this.touchViewListGroup.createChild(Roo.bootstrap.ComboBox.emptyResult);
15492 this.touchViewListGroup.select('.roo-combobox-touch-view-empty-result', true).first().dom.innerHTML = this.emptyResultText;
15496 clearTouchView : function()
15498 this.touchViewListGroup.dom.innerHTML = '';
15501 onTouchViewClick : function(e, el, o)
15503 e.preventDefault();
15506 var rowIndex = o.rowIndex;
15508 var r = this.store.getAt(rowIndex);
15510 if(this.fireEvent('beforeselect', this, r, rowIndex) !== false){
15512 if(!this.multiple){
15513 Roo.each(this.touchViewListGroup.select('.list-group-item > .roo-combobox-list-group-item-box > input:checked', true).elements, function(c){
15514 c.dom.removeAttribute('checked');
15517 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15519 this.setFromData(r.data);
15521 var close = this.closeTriggerEl();
15527 this.hideTouchView();
15529 this.fireEvent('select', this, r, rowIndex);
15534 if(this.valueField && typeof(r.data[this.valueField]) != 'undefined' && this.getValue().indexOf(r.data[this.valueField]) != -1){
15535 row.select('.roo-combobox-list-group-item-box > input', true).first().dom.removeAttribute('checked');
15536 this.tickItems.splice(this.tickItems.indexOf(r.data), 1);
15540 row.select('.roo-combobox-list-group-item-box > input', true).first().attr('checked', true);
15541 this.addItem(r.data);
15542 this.tickItems.push(r.data);
15546 getAutoCreateNativeIOS : function()
15549 cls: 'form-group' //input-group,
15554 cls : 'roo-ios-select'
15558 combobox.name = this.name;
15561 if (this.disabled) {
15562 combobox.disabled = true;
15565 var settings = this;
15567 ['xs','sm','md','lg'].map(function(size){
15568 if (settings[size]) {
15569 cfg.cls += ' col-' + size + '-' + settings[size];
15579 initIOSView : function()
15581 this.store.on('load', this.onIOSViewLoad, this);
15586 onIOSViewLoad : function()
15588 if(this.store.getCount() < 1){
15592 this.clearIOSView();
15594 if(this.allowBlank) {
15596 var default_text = '-- SELECT --';
15598 if(this.placeholder.length){
15599 default_text = this.placeholder;
15602 if(this.emptyTitle.length){
15603 default_text += ' - ' + this.emptyTitle + ' -';
15606 var opt = this.inputEl().createChild({
15609 html : default_text
15613 o[this.valueField] = 0;
15614 o[this.displayField] = default_text;
15616 this.ios_options.push({
15623 this.store.data.each(function(d, rowIndex){
15627 if(this.displayField && typeof(d.data[this.displayField]) != 'undefined'){
15628 html = d.data[this.displayField];
15633 if(this.valueField && typeof(d.data[this.valueField]) != 'undefined'){
15634 value = d.data[this.valueField];
15643 if(this.value == d.data[this.valueField]){
15644 option['selected'] = true;
15647 var opt = this.inputEl().createChild(option);
15649 this.ios_options.push({
15656 this.inputEl().on('change', function(){
15657 this.fireEvent('select', this);
15662 clearIOSView: function()
15664 this.inputEl().dom.innerHTML = '';
15666 this.ios_options = [];
15669 setIOSValue: function(v)
15673 if(!this.ios_options){
15677 Roo.each(this.ios_options, function(opts){
15679 opts.el.dom.removeAttribute('selected');
15681 if(opts.data[this.valueField] != v){
15685 opts.el.dom.setAttribute('selected', true);
15691 * @cfg {Boolean} grow
15695 * @cfg {Number} growMin
15699 * @cfg {Number} growMax
15708 Roo.apply(Roo.bootstrap.ComboBox, {
15712 cls: 'modal-header',
15734 cls: 'list-group-item',
15738 cls: 'roo-combobox-list-group-item-value'
15742 cls: 'roo-combobox-list-group-item-box pull-xs-right radio-inline radio radio-info',
15756 listItemCheckbox : {
15758 cls: 'list-group-item',
15762 cls: 'roo-combobox-list-group-item-value'
15766 cls: 'roo-combobox-list-group-item-box pull-xs-right checkbox-inline checkbox checkbox-info',
15782 cls: 'alert alert-danger roo-combobox-touch-view-empty-result'
15787 cls: 'modal-footer',
15795 cls: 'col-xs-6 text-left',
15798 cls: 'btn btn-danger roo-touch-view-cancel',
15804 cls: 'col-xs-6 text-right',
15807 cls: 'btn btn-success roo-touch-view-ok',
15818 Roo.apply(Roo.bootstrap.ComboBox, {
15820 touchViewTemplate : {
15822 cls: 'modal fade roo-combobox-touch-view',
15826 cls: 'modal-dialog',
15827 style : 'position:fixed', // we have to fix position....
15831 cls: 'modal-content',
15833 Roo.bootstrap.ComboBox.header,
15834 Roo.bootstrap.ComboBox.body,
15835 Roo.bootstrap.ComboBox.footer
15844 * Ext JS Library 1.1.1
15845 * Copyright(c) 2006-2007, Ext JS, LLC.
15847 * Originally Released Under LGPL - original licence link has changed is not relivant.
15850 * <script type="text/javascript">
15855 * @extends Roo.util.Observable
15856 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
15857 * This class also supports single and multi selection modes. <br>
15858 * Create a data model bound view:
15860 var store = new Roo.data.Store(...);
15862 var view = new Roo.View({
15864 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
15866 singleSelect: true,
15867 selectedClass: "ydataview-selected",
15871 // listen for node click?
15872 view.on("click", function(vw, index, node, e){
15873 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
15877 dataModel.load("foobar.xml");
15879 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
15881 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
15882 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
15884 * Note: old style constructor is still suported (container, template, config)
15887 * Create a new View
15888 * @param {Object} config The config object
15891 Roo.View = function(config, depreciated_tpl, depreciated_config){
15893 this.parent = false;
15895 if (typeof(depreciated_tpl) == 'undefined') {
15896 // new way.. - universal constructor.
15897 Roo.apply(this, config);
15898 this.el = Roo.get(this.el);
15901 this.el = Roo.get(config);
15902 this.tpl = depreciated_tpl;
15903 Roo.apply(this, depreciated_config);
15905 this.wrapEl = this.el.wrap().wrap();
15906 ///this.el = this.wrapEla.appendChild(document.createElement("div"));
15909 if(typeof(this.tpl) == "string"){
15910 this.tpl = new Roo.Template(this.tpl);
15912 // support xtype ctors..
15913 this.tpl = new Roo.factory(this.tpl, Roo);
15917 this.tpl.compile();
15922 * @event beforeclick
15923 * Fires before a click is processed. Returns false to cancel the default action.
15924 * @param {Roo.View} this
15925 * @param {Number} index The index of the target node
15926 * @param {HTMLElement} node The target node
15927 * @param {Roo.EventObject} e The raw event object
15929 "beforeclick" : true,
15932 * Fires when a template node is clicked.
15933 * @param {Roo.View} this
15934 * @param {Number} index The index of the target node
15935 * @param {HTMLElement} node The target node
15936 * @param {Roo.EventObject} e The raw event object
15941 * Fires when a template node is double clicked.
15942 * @param {Roo.View} this
15943 * @param {Number} index The index of the target node
15944 * @param {HTMLElement} node The target node
15945 * @param {Roo.EventObject} e The raw event object
15949 * @event contextmenu
15950 * Fires when a template node is right clicked.
15951 * @param {Roo.View} this
15952 * @param {Number} index The index of the target node
15953 * @param {HTMLElement} node The target node
15954 * @param {Roo.EventObject} e The raw event object
15956 "contextmenu" : true,
15958 * @event selectionchange
15959 * Fires when the selected nodes change.
15960 * @param {Roo.View} this
15961 * @param {Array} selections Array of the selected nodes
15963 "selectionchange" : true,
15966 * @event beforeselect
15967 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
15968 * @param {Roo.View} this
15969 * @param {HTMLElement} node The node to be selected
15970 * @param {Array} selections Array of currently selected nodes
15972 "beforeselect" : true,
15974 * @event preparedata
15975 * Fires on every row to render, to allow you to change the data.
15976 * @param {Roo.View} this
15977 * @param {Object} data to be rendered (change this)
15979 "preparedata" : true
15987 "click": this.onClick,
15988 "dblclick": this.onDblClick,
15989 "contextmenu": this.onContextMenu,
15993 this.selections = [];
15995 this.cmp = new Roo.CompositeElementLite([]);
15997 this.store = Roo.factory(this.store, Roo.data);
15998 this.setStore(this.store, true);
16001 if ( this.footer && this.footer.xtype) {
16003 var fctr = this.wrapEl.appendChild(document.createElement("div"));
16005 this.footer.dataSource = this.store;
16006 this.footer.container = fctr;
16007 this.footer = Roo.factory(this.footer, Roo);
16008 fctr.insertFirst(this.el);
16010 // this is a bit insane - as the paging toolbar seems to detach the el..
16011 // dom.parentNode.parentNode.parentNode
16012 // they get detached?
16016 Roo.View.superclass.constructor.call(this);
16021 Roo.extend(Roo.View, Roo.util.Observable, {
16024 * @cfg {Roo.data.Store} store Data store to load data from.
16029 * @cfg {String|Roo.Element} el The container element.
16034 * @cfg {String|Roo.Template} tpl The template used by this View
16038 * @cfg {String} dataName the named area of the template to use as the data area
16039 * Works with domtemplates roo-name="name"
16043 * @cfg {String} selectedClass The css class to add to selected nodes
16045 selectedClass : "x-view-selected",
16047 * @cfg {String} emptyText The empty text to show when nothing is loaded.
16052 * @cfg {String} text to display on mask (default Loading)
16056 * @cfg {Boolean} multiSelect Allow multiple selection
16058 multiSelect : false,
16060 * @cfg {Boolean} singleSelect Allow single selection
16062 singleSelect: false,
16065 * @cfg {Boolean} toggleSelect - selecting
16067 toggleSelect : false,
16070 * @cfg {Boolean} tickable - selecting
16075 * Returns the element this view is bound to.
16076 * @return {Roo.Element}
16078 getEl : function(){
16079 return this.wrapEl;
16085 * Refreshes the view. - called by datachanged on the store. - do not call directly.
16087 refresh : function(){
16088 //Roo.log('refresh');
16091 // if we are using something like 'domtemplate', then
16092 // the what gets used is:
16093 // t.applySubtemplate(NAME, data, wrapping data..)
16094 // the outer template then get' applied with
16095 // the store 'extra data'
16096 // and the body get's added to the
16097 // roo-name="data" node?
16098 // <span class='roo-tpl-{name}'></span> ?????
16102 this.clearSelections();
16103 this.el.update("");
16105 var records = this.store.getRange();
16106 if(records.length < 1) {
16108 // is this valid?? = should it render a template??
16110 this.el.update(this.emptyText);
16114 if (this.dataName) {
16115 this.el.update(t.apply(this.store.meta)); //????
16116 el = this.el.child('.roo-tpl-' + this.dataName);
16119 for(var i = 0, len = records.length; i < len; i++){
16120 var data = this.prepareData(records[i].data, i, records[i]);
16121 this.fireEvent("preparedata", this, data, i, records[i]);
16123 var d = Roo.apply({}, data);
16126 Roo.apply(d, {'roo-id' : Roo.id()});
16130 Roo.each(this.parent.item, function(item){
16131 if(item[_this.parent.valueField] != data[_this.parent.valueField]){
16134 Roo.apply(d, {'roo-data-checked' : 'checked'});
16138 html[html.length] = Roo.util.Format.trim(
16140 t.applySubtemplate(this.dataName, d, this.store.meta) :
16147 el.update(html.join(""));
16148 this.nodes = el.dom.childNodes;
16149 this.updateIndexes(0);
16154 * Function to override to reformat the data that is sent to
16155 * the template for each node.
16156 * DEPRICATED - use the preparedata event handler.
16157 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
16158 * a JSON object for an UpdateManager bound view).
16160 prepareData : function(data, index, record)
16162 this.fireEvent("preparedata", this, data, index, record);
16166 onUpdate : function(ds, record){
16167 // Roo.log('on update');
16168 this.clearSelections();
16169 var index = this.store.indexOf(record);
16170 var n = this.nodes[index];
16171 this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
16172 n.parentNode.removeChild(n);
16173 this.updateIndexes(index, index);
16179 onAdd : function(ds, records, index)
16181 //Roo.log(['on Add', ds, records, index] );
16182 this.clearSelections();
16183 if(this.nodes.length == 0){
16187 var n = this.nodes[index];
16188 for(var i = 0, len = records.length; i < len; i++){
16189 var d = this.prepareData(records[i].data, i, records[i]);
16191 this.tpl.insertBefore(n, d);
16194 this.tpl.append(this.el, d);
16197 this.updateIndexes(index);
16200 onRemove : function(ds, record, index){
16201 // Roo.log('onRemove');
16202 this.clearSelections();
16203 var el = this.dataName ?
16204 this.el.child('.roo-tpl-' + this.dataName) :
16207 el.dom.removeChild(this.nodes[index]);
16208 this.updateIndexes(index);
16212 * Refresh an individual node.
16213 * @param {Number} index
16215 refreshNode : function(index){
16216 this.onUpdate(this.store, this.store.getAt(index));
16219 updateIndexes : function(startIndex, endIndex){
16220 var ns = this.nodes;
16221 startIndex = startIndex || 0;
16222 endIndex = endIndex || ns.length - 1;
16223 for(var i = startIndex; i <= endIndex; i++){
16224 ns[i].nodeIndex = i;
16229 * Changes the data store this view uses and refresh the view.
16230 * @param {Store} store
16232 setStore : function(store, initial){
16233 if(!initial && this.store){
16234 this.store.un("datachanged", this.refresh);
16235 this.store.un("add", this.onAdd);
16236 this.store.un("remove", this.onRemove);
16237 this.store.un("update", this.onUpdate);
16238 this.store.un("clear", this.refresh);
16239 this.store.un("beforeload", this.onBeforeLoad);
16240 this.store.un("load", this.onLoad);
16241 this.store.un("loadexception", this.onLoad);
16245 store.on("datachanged", this.refresh, this);
16246 store.on("add", this.onAdd, this);
16247 store.on("remove", this.onRemove, this);
16248 store.on("update", this.onUpdate, this);
16249 store.on("clear", this.refresh, this);
16250 store.on("beforeload", this.onBeforeLoad, this);
16251 store.on("load", this.onLoad, this);
16252 store.on("loadexception", this.onLoad, this);
16260 * onbeforeLoad - masks the loading area.
16263 onBeforeLoad : function(store,opts)
16265 //Roo.log('onBeforeLoad');
16267 this.el.update("");
16269 this.el.mask(this.mask ? this.mask : "Loading" );
16271 onLoad : function ()
16278 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
16279 * @param {HTMLElement} node
16280 * @return {HTMLElement} The template node
16282 findItemFromChild : function(node){
16283 var el = this.dataName ?
16284 this.el.child('.roo-tpl-' + this.dataName,true) :
16287 if(!node || node.parentNode == el){
16290 var p = node.parentNode;
16291 while(p && p != el){
16292 if(p.parentNode == el){
16301 onClick : function(e){
16302 var item = this.findItemFromChild(e.getTarget());
16304 var index = this.indexOf(item);
16305 if(this.onItemClick(item, index, e) !== false){
16306 this.fireEvent("click", this, index, item, e);
16309 this.clearSelections();
16314 onContextMenu : function(e){
16315 var item = this.findItemFromChild(e.getTarget());
16317 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
16322 onDblClick : function(e){
16323 var item = this.findItemFromChild(e.getTarget());
16325 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
16329 onItemClick : function(item, index, e)
16331 if(this.fireEvent("beforeclick", this, index, item, e) === false){
16334 if (this.toggleSelect) {
16335 var m = this.isSelected(item) ? 'unselect' : 'select';
16338 _t[m](item, true, false);
16341 if(this.multiSelect || this.singleSelect){
16342 if(this.multiSelect && e.shiftKey && this.lastSelection){
16343 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
16345 this.select(item, this.multiSelect && e.ctrlKey);
16346 this.lastSelection = item;
16349 if(!this.tickable){
16350 e.preventDefault();
16358 * Get the number of selected nodes.
16361 getSelectionCount : function(){
16362 return this.selections.length;
16366 * Get the currently selected nodes.
16367 * @return {Array} An array of HTMLElements
16369 getSelectedNodes : function(){
16370 return this.selections;
16374 * Get the indexes of the selected nodes.
16377 getSelectedIndexes : function(){
16378 var indexes = [], s = this.selections;
16379 for(var i = 0, len = s.length; i < len; i++){
16380 indexes.push(s[i].nodeIndex);
16386 * Clear all selections
16387 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
16389 clearSelections : function(suppressEvent){
16390 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
16391 this.cmp.elements = this.selections;
16392 this.cmp.removeClass(this.selectedClass);
16393 this.selections = [];
16394 if(!suppressEvent){
16395 this.fireEvent("selectionchange", this, this.selections);
16401 * Returns true if the passed node is selected
16402 * @param {HTMLElement/Number} node The node or node index
16403 * @return {Boolean}
16405 isSelected : function(node){
16406 var s = this.selections;
16410 node = this.getNode(node);
16411 return s.indexOf(node) !== -1;
16416 * @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
16417 * @param {Boolean} keepExisting (optional) true to keep existing selections
16418 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16420 select : function(nodeInfo, keepExisting, suppressEvent){
16421 if(nodeInfo instanceof Array){
16423 this.clearSelections(true);
16425 for(var i = 0, len = nodeInfo.length; i < len; i++){
16426 this.select(nodeInfo[i], true, true);
16430 var node = this.getNode(nodeInfo);
16431 if(!node || this.isSelected(node)){
16432 return; // already selected.
16435 this.clearSelections(true);
16438 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
16439 Roo.fly(node).addClass(this.selectedClass);
16440 this.selections.push(node);
16441 if(!suppressEvent){
16442 this.fireEvent("selectionchange", this, this.selections);
16450 * @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
16451 * @param {Boolean} keepExisting (optional) true IGNORED (for campatibility with select)
16452 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
16454 unselect : function(nodeInfo, keepExisting, suppressEvent)
16456 if(nodeInfo instanceof Array){
16457 Roo.each(this.selections, function(s) {
16458 this.unselect(s, nodeInfo);
16462 var node = this.getNode(nodeInfo);
16463 if(!node || !this.isSelected(node)){
16464 //Roo.log("not selected");
16465 return; // not selected.
16469 Roo.each(this.selections, function(s) {
16471 Roo.fly(node).removeClass(this.selectedClass);
16478 this.selections= ns;
16479 this.fireEvent("selectionchange", this, this.selections);
16483 * Gets a template node.
16484 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16485 * @return {HTMLElement} The node or null if it wasn't found
16487 getNode : function(nodeInfo){
16488 if(typeof nodeInfo == "string"){
16489 return document.getElementById(nodeInfo);
16490 }else if(typeof nodeInfo == "number"){
16491 return this.nodes[nodeInfo];
16497 * Gets a range template nodes.
16498 * @param {Number} startIndex
16499 * @param {Number} endIndex
16500 * @return {Array} An array of nodes
16502 getNodes : function(start, end){
16503 var ns = this.nodes;
16504 start = start || 0;
16505 end = typeof end == "undefined" ? ns.length - 1 : end;
16508 for(var i = start; i <= end; i++){
16512 for(var i = start; i >= end; i--){
16520 * Finds the index of the passed node
16521 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
16522 * @return {Number} The index of the node or -1
16524 indexOf : function(node){
16525 node = this.getNode(node);
16526 if(typeof node.nodeIndex == "number"){
16527 return node.nodeIndex;
16529 var ns = this.nodes;
16530 for(var i = 0, len = ns.length; i < len; i++){
16541 * based on jquery fullcalendar
16545 Roo.bootstrap = Roo.bootstrap || {};
16547 * @class Roo.bootstrap.Calendar
16548 * @extends Roo.bootstrap.Component
16549 * Bootstrap Calendar class
16550 * @cfg {Boolean} loadMask (true|false) default false
16551 * @cfg {Object} header generate the user specific header of the calendar, default false
16554 * Create a new Container
16555 * @param {Object} config The config object
16560 Roo.bootstrap.Calendar = function(config){
16561 Roo.bootstrap.Calendar.superclass.constructor.call(this, config);
16565 * Fires when a date is selected
16566 * @param {DatePicker} this
16567 * @param {Date} date The selected date
16571 * @event monthchange
16572 * Fires when the displayed month changes
16573 * @param {DatePicker} this
16574 * @param {Date} date The selected month
16576 'monthchange': true,
16578 * @event evententer
16579 * Fires when mouse over an event
16580 * @param {Calendar} this
16581 * @param {event} Event
16583 'evententer': true,
16585 * @event eventleave
16586 * Fires when the mouse leaves an
16587 * @param {Calendar} this
16590 'eventleave': true,
16592 * @event eventclick
16593 * Fires when the mouse click an
16594 * @param {Calendar} this
16603 Roo.extend(Roo.bootstrap.Calendar, Roo.bootstrap.Component, {
16606 * @cfg {Number} startDay
16607 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
16615 getAutoCreate : function(){
16618 var fc_button = function(name, corner, style, content ) {
16619 return Roo.apply({},{
16621 cls : 'fc-button fc-button-'+name+' fc-state-default ' +
16623 'fc-corner-' + corner.split(' ').join(' fc-corner-') :
16626 html : '<SPAN class="fc-text-'+style+ '">'+content +'</SPAN>',
16637 style : 'width:100%',
16644 cls : 'fc-header-left',
16646 fc_button('prev', 'left', 'arrow', '‹' ),
16647 fc_button('next', 'right', 'arrow', '›' ),
16648 { tag: 'span', cls: 'fc-header-space' },
16649 fc_button('today', 'left right', '', 'today' ) // neds state disabled..
16657 cls : 'fc-header-center',
16661 cls: 'fc-header-title',
16664 html : 'month / year'
16672 cls : 'fc-header-right',
16674 /* fc_button('month', 'left', '', 'month' ),
16675 fc_button('week', '', '', 'week' ),
16676 fc_button('day', 'right', '', 'day' )
16688 header = this.header;
16691 var cal_heads = function() {
16693 // fixme - handle this.
16695 for (var i =0; i < Date.dayNames.length; i++) {
16696 var d = Date.dayNames[i];
16699 cls : 'fc-day-header fc-' + d.substring(0,3).toLowerCase() + ' fc-widget-header',
16700 html : d.substring(0,3)
16704 ret[0].cls += ' fc-first';
16705 ret[6].cls += ' fc-last';
16708 var cal_cell = function(n) {
16711 cls : 'fc-day fc-'+n + ' fc-widget-content', ///fc-other-month fc-past
16716 cls: 'fc-day-number',
16720 cls: 'fc-day-content',
16724 style: 'position: relative;' // height: 17px;
16736 var cal_rows = function() {
16739 for (var r = 0; r < 6; r++) {
16746 for (var i =0; i < Date.dayNames.length; i++) {
16747 var d = Date.dayNames[i];
16748 row.cn.push(cal_cell(d.substring(0,3).toLowerCase()));
16751 row.cn[0].cls+=' fc-first';
16752 row.cn[0].cn[0].style = 'min-height:90px';
16753 row.cn[6].cls+=' fc-last';
16757 ret[0].cls += ' fc-first';
16758 ret[4].cls += ' fc-prev-last';
16759 ret[5].cls += ' fc-last';
16766 cls: 'fc-border-separate',
16767 style : 'width:100%',
16775 cls : 'fc-first fc-last',
16793 cls : 'fc-content',
16794 style : "position: relative;",
16797 cls : 'fc-view fc-view-month fc-grid',
16798 style : 'position: relative',
16799 unselectable : 'on',
16802 cls : 'fc-event-container',
16803 style : 'position:absolute;z-index:8;top:0;left:0;'
16821 initEvents : function()
16824 throw "can not find store for calendar";
16830 style: "text-align:center",
16834 style: "background-color:white;width:50%;margin:250 auto",
16838 src: Roo.rootURL + '/images/ux/lightbox/loading.gif'
16849 this.maskEl = Roo.DomHelper.append(this.el.select('.fc-content', true).first(), mark, true);
16851 var size = this.el.select('.fc-content', true).first().getSize();
16852 this.maskEl.setSize(size.width, size.height);
16853 this.maskEl.enableDisplayMode("block");
16854 if(!this.loadMask){
16855 this.maskEl.hide();
16858 this.store = Roo.factory(this.store, Roo.data);
16859 this.store.on('load', this.onLoad, this);
16860 this.store.on('beforeload', this.onBeforeLoad, this);
16864 this.cells = this.el.select('.fc-day',true);
16865 //Roo.log(this.cells);
16866 this.textNodes = this.el.query('.fc-day-number');
16867 this.cells.addClassOnOver('fc-state-hover');
16869 this.el.select('.fc-button-prev',true).on('click', this.showPrevMonth, this);
16870 this.el.select('.fc-button-next',true).on('click', this.showNextMonth, this);
16871 this.el.select('.fc-button-today',true).on('click', this.showToday, this);
16872 this.el.select('.fc-button',true).addClassOnOver('fc-state-hover');
16874 this.on('monthchange', this.onMonthChange, this);
16876 this.update(new Date().clearTime());
16879 resize : function() {
16880 var sz = this.el.getSize();
16882 this.el.select('.fc-day-header',true).setWidth(sz.width / 7);
16883 this.el.select('.fc-day-content div',true).setHeight(34);
16888 showPrevMonth : function(e){
16889 this.update(this.activeDate.add("mo", -1));
16891 showToday : function(e){
16892 this.update(new Date().clearTime());
16895 showNextMonth : function(e){
16896 this.update(this.activeDate.add("mo", 1));
16900 showPrevYear : function(){
16901 this.update(this.activeDate.add("y", -1));
16905 showNextYear : function(){
16906 this.update(this.activeDate.add("y", 1));
16911 update : function(date)
16913 var vd = this.activeDate;
16914 this.activeDate = date;
16915 // if(vd && this.el){
16916 // var t = date.getTime();
16917 // if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
16918 // Roo.log('using add remove');
16920 // this.fireEvent('monthchange', this, date);
16922 // this.cells.removeClass("fc-state-highlight");
16923 // this.cells.each(function(c){
16924 // if(c.dateValue == t){
16925 // c.addClass("fc-state-highlight");
16926 // setTimeout(function(){
16927 // try{c.dom.firstChild.focus();}catch(e){}
16937 var days = date.getDaysInMonth();
16939 var firstOfMonth = date.getFirstDateOfMonth();
16940 var startingPos = firstOfMonth.getDay()-this.startDay;
16942 if(startingPos < this.startDay){
16946 var pm = date.add(Date.MONTH, -1);
16947 var prevStart = pm.getDaysInMonth()-startingPos;
16949 this.cells = this.el.select('.fc-day',true);
16950 this.textNodes = this.el.query('.fc-day-number');
16951 this.cells.addClassOnOver('fc-state-hover');
16953 var cells = this.cells.elements;
16954 var textEls = this.textNodes;
16956 Roo.each(cells, function(cell){
16957 cell.removeClass([ 'fc-past', 'fc-other-month', 'fc-future', 'fc-state-highlight', 'fc-state-disabled']);
16960 days += startingPos;
16962 // convert everything to numbers so it's fast
16963 var day = 86400000;
16964 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
16967 //Roo.log(prevStart);
16969 var today = new Date().clearTime().getTime();
16970 var sel = date.clearTime().getTime();
16971 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
16972 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
16973 var ddMatch = this.disabledDatesRE;
16974 var ddText = this.disabledDatesText;
16975 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
16976 var ddaysText = this.disabledDaysText;
16977 var format = this.format;
16979 var setCellClass = function(cal, cell){
16983 //Roo.log('set Cell Class');
16985 var t = d.getTime();
16989 cell.dateValue = t;
16991 cell.className += " fc-today";
16992 cell.className += " fc-state-highlight";
16993 cell.title = cal.todayText;
16996 // disable highlight in other month..
16997 //cell.className += " fc-state-highlight";
17002 cell.className = " fc-state-disabled";
17003 cell.title = cal.minText;
17007 cell.className = " fc-state-disabled";
17008 cell.title = cal.maxText;
17012 if(ddays.indexOf(d.getDay()) != -1){
17013 cell.title = ddaysText;
17014 cell.className = " fc-state-disabled";
17017 if(ddMatch && format){
17018 var fvalue = d.dateFormat(format);
17019 if(ddMatch.test(fvalue)){
17020 cell.title = ddText.replace("%0", fvalue);
17021 cell.className = " fc-state-disabled";
17025 if (!cell.initialClassName) {
17026 cell.initialClassName = cell.dom.className;
17029 cell.dom.className = cell.initialClassName + ' ' + cell.className;
17034 for(; i < startingPos; i++) {
17035 textEls[i].innerHTML = (++prevStart);
17036 d.setDate(d.getDate()+1);
17038 cells[i].className = "fc-past fc-other-month";
17039 setCellClass(this, cells[i]);
17044 for(; i < days; i++){
17045 intDay = i - startingPos + 1;
17046 textEls[i].innerHTML = (intDay);
17047 d.setDate(d.getDate()+1);
17049 cells[i].className = ''; // "x-date-active";
17050 setCellClass(this, cells[i]);
17054 for(; i < 42; i++) {
17055 textEls[i].innerHTML = (++extraDays);
17056 d.setDate(d.getDate()+1);
17058 cells[i].className = "fc-future fc-other-month";
17059 setCellClass(this, cells[i]);
17062 this.el.select('.fc-header-title h2',true).update(Date.monthNames[date.getMonth()] + " " + date.getFullYear());
17064 var totalRows = Math.ceil((date.getDaysInMonth() + date.getFirstDateOfMonth().getDay()) / 7);
17066 this.el.select('tr.fc-week.fc-prev-last',true).removeClass('fc-last');
17067 this.el.select('tr.fc-week.fc-next-last',true).addClass('fc-last').show();
17069 if(totalRows != 6){
17070 this.el.select('tr.fc-week.fc-last',true).removeClass('fc-last').addClass('fc-next-last').hide();
17071 this.el.select('tr.fc-week.fc-prev-last',true).addClass('fc-last');
17074 this.fireEvent('monthchange', this, date);
17078 if(!this.internalRender){
17079 var main = this.el.dom.firstChild;
17080 var w = main.offsetWidth;
17081 this.el.setWidth(w + this.el.getBorderWidth("lr"));
17082 Roo.fly(main).setWidth(w);
17083 this.internalRender = true;
17084 // opera does not respect the auto grow header center column
17085 // then, after it gets a width opera refuses to recalculate
17086 // without a second pass
17087 if(Roo.isOpera && !this.secondPass){
17088 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
17089 this.secondPass = true;
17090 this.update.defer(10, this, [date]);
17097 findCell : function(dt) {
17098 dt = dt.clearTime().getTime();
17100 this.cells.each(function(c){
17101 //Roo.log("check " +c.dateValue + '?=' + dt);
17102 if(c.dateValue == dt){
17112 findCells : function(ev) {
17113 var s = ev.start.clone().clearTime().getTime();
17115 var e= ev.end.clone().clearTime().getTime();
17118 this.cells.each(function(c){
17119 ////Roo.log("check " +c.dateValue + '<' + e + ' > ' + s);
17121 if(c.dateValue > e){
17124 if(c.dateValue < s){
17133 // findBestRow: function(cells)
17137 // for (var i =0 ; i < cells.length;i++) {
17138 // ret = Math.max(cells[i].rows || 0,ret);
17145 addItem : function(ev)
17147 // look for vertical location slot in
17148 var cells = this.findCells(ev);
17150 // ev.row = this.findBestRow(cells);
17152 // work out the location.
17156 for(var i =0; i < cells.length; i++) {
17158 cells[i].row = cells[0].row;
17161 cells[i].row = cells[i].row + 1;
17171 if (crow.start.getY() == cells[i].getY()) {
17173 crow.end = cells[i];
17190 cells[0].events.push(ev);
17192 this.calevents.push(ev);
17195 clearEvents: function() {
17197 if(!this.calevents){
17201 Roo.each(this.cells.elements, function(c){
17207 Roo.each(this.calevents, function(e) {
17208 Roo.each(e.els, function(el) {
17209 el.un('mouseenter' ,this.onEventEnter, this);
17210 el.un('mouseleave' ,this.onEventLeave, this);
17215 Roo.each(Roo.select('.fc-more-event', true).elements, function(e){
17221 renderEvents: function()
17225 this.cells.each(function(c) {
17234 if(c.row != c.events.length){
17235 r = 4 - (4 - (c.row - c.events.length));
17238 c.events = ev.slice(0, r);
17239 c.more = ev.slice(r);
17241 if(c.more.length && c.more.length == 1){
17242 c.events.push(c.more.pop());
17245 c.row = (c.row - ev.length) + c.events.length + ((c.more.length) ? 1 : 0);
17249 this.cells.each(function(c) {
17251 c.select('.fc-day-content div',true).first().setHeight(Math.max(34, c.row * 20));
17254 for (var e = 0; e < c.events.length; e++){
17255 var ev = c.events[e];
17256 var rows = ev.rows;
17258 for(var i = 0; i < rows.length; i++) {
17260 // how many rows should it span..
17263 cls : 'roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable',
17264 style : 'position: absolute', // left: 387px; width: 121px; top: 359px;
17266 unselectable : "on",
17269 cls: 'fc-event-inner',
17273 // cls: 'fc-event-time',
17274 // html : cells.length > 1 ? '' : ev.time
17278 cls: 'fc-event-title',
17279 html : String.format('{0}', ev.title)
17286 cls: 'ui-resizable-handle ui-resizable-e',
17287 html : '  '
17294 cfg.cls += ' fc-event-start';
17296 if ((i+1) == rows.length) {
17297 cfg.cls += ' fc-event-end';
17300 var ctr = _this.el.select('.fc-event-container',true).first();
17301 var cg = ctr.createChild(cfg);
17303 var sbox = rows[i].start.select('.fc-day-content',true).first().getBox();
17304 var ebox = rows[i].end.select('.fc-day-content',true).first().getBox();
17306 var r = (c.more.length) ? 1 : 0;
17307 cg.setXY([sbox.x +2, sbox.y + ((c.row - c.events.length - r + e) * 20)]);
17308 cg.setWidth(ebox.right - sbox.x -2);
17310 cg.on('mouseenter' ,_this.onEventEnter, _this, ev);
17311 cg.on('mouseleave' ,_this.onEventLeave, _this, ev);
17312 cg.on('click', _this.onEventClick, _this, ev);
17323 cls : 'fc-more-event roo-dynamic fc-event fc-event-hori fc-event-draggable ui-draggable fc-event-start fc-event-end',
17324 style : 'position: absolute',
17325 unselectable : "on",
17328 cls: 'fc-event-inner',
17332 cls: 'fc-event-title',
17340 cls: 'ui-resizable-handle ui-resizable-e',
17341 html : '  '
17347 var ctr = _this.el.select('.fc-event-container',true).first();
17348 var cg = ctr.createChild(cfg);
17350 var sbox = c.select('.fc-day-content',true).first().getBox();
17351 var ebox = c.select('.fc-day-content',true).first().getBox();
17353 cg.setXY([sbox.x +2, sbox.y +((c.row - 1) * 20)]);
17354 cg.setWidth(ebox.right - sbox.x -2);
17356 cg.on('click', _this.onMoreEventClick, _this, c.more);
17366 onEventEnter: function (e, el,event,d) {
17367 this.fireEvent('evententer', this, el, event);
17370 onEventLeave: function (e, el,event,d) {
17371 this.fireEvent('eventleave', this, el, event);
17374 onEventClick: function (e, el,event,d) {
17375 this.fireEvent('eventclick', this, el, event);
17378 onMonthChange: function () {
17382 onMoreEventClick: function(e, el, more)
17386 this.calpopover.placement = 'right';
17387 this.calpopover.setTitle('More');
17389 this.calpopover.setContent('');
17391 var ctr = this.calpopover.el.select('.popover-content', true).first();
17393 Roo.each(more, function(m){
17395 cls : 'fc-event-hori fc-event-draggable',
17398 var cg = ctr.createChild(cfg);
17400 cg.on('click', _this.onEventClick, _this, m);
17403 this.calpopover.show(el);
17408 onLoad: function ()
17410 this.calevents = [];
17413 if(this.store.getCount() > 0){
17414 this.store.data.each(function(d){
17417 start: (typeof(d.data.start_dt) === 'string') ? new Date.parseDate(d.data.start_dt, 'Y-m-d H:i:s') : d.data.start_dt,
17418 end : (typeof(d.data.end_dt) === 'string') ? new Date.parseDate(d.data.end_dt, 'Y-m-d H:i:s') : d.data.end_dt,
17419 time : d.data.start_time,
17420 title : d.data.title,
17421 description : d.data.description,
17422 venue : d.data.venue
17427 this.renderEvents();
17429 if(this.calevents.length && this.loadMask){
17430 this.maskEl.hide();
17434 onBeforeLoad: function()
17436 this.clearEvents();
17438 this.maskEl.show();
17452 * @class Roo.bootstrap.Popover
17453 * @extends Roo.bootstrap.Component
17454 * Bootstrap Popover class
17455 * @cfg {String} html contents of the popover (or false to use children..)
17456 * @cfg {String} title of popover (or false to hide)
17457 * @cfg {String} placement how it is placed
17458 * @cfg {String} trigger click || hover (or false to trigger manually)
17459 * @cfg {String} over what (parent or false to trigger manually.)
17460 * @cfg {Number} delay - delay before showing
17463 * Create a new Popover
17464 * @param {Object} config The config object
17467 Roo.bootstrap.Popover = function(config){
17468 Roo.bootstrap.Popover.superclass.constructor.call(this, config);
17474 * After the popover show
17476 * @param {Roo.bootstrap.Popover} this
17481 * After the popover hide
17483 * @param {Roo.bootstrap.Popover} this
17489 Roo.extend(Roo.bootstrap.Popover, Roo.bootstrap.Component, {
17491 title: 'Fill in a title',
17494 placement : 'right',
17495 trigger : 'hover', // hover
17501 can_build_overlaid : false,
17503 getChildContainer : function()
17505 return this.el.select('.popover-content',true).first();
17508 getAutoCreate : function(){
17511 cls : 'popover roo-dynamic',
17512 style: 'display:block',
17518 cls : 'popover-inner',
17522 cls: 'popover-title',
17526 cls : 'popover-content',
17537 setTitle: function(str)
17540 this.el.select('.popover-title',true).first().dom.innerHTML = str;
17542 setContent: function(str)
17545 this.el.select('.popover-content',true).first().dom.innerHTML = str;
17547 // as it get's added to the bottom of the page.
17548 onRender : function(ct, position)
17550 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
17552 var cfg = Roo.apply({}, this.getAutoCreate());
17556 cfg.cls += ' ' + this.cls;
17559 cfg.style = this.style;
17561 //Roo.log("adding to ");
17562 this.el = Roo.get(document.body).createChild(cfg, position);
17563 // Roo.log(this.el);
17568 initEvents : function()
17570 this.el.select('.popover-title',true).setVisibilityMode(Roo.Element.DISPLAY);
17571 this.el.enableDisplayMode('block');
17573 if (this.over === false) {
17576 if (this.triggers === false) {
17579 var on_el = (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17580 var triggers = this.trigger ? this.trigger.split(' ') : [];
17581 Roo.each(triggers, function(trigger) {
17583 if (trigger == 'click') {
17584 on_el.on('click', this.toggle, this);
17585 } else if (trigger != 'manual') {
17586 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
17587 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
17589 on_el.on(eventIn ,this.enter, this);
17590 on_el.on(eventOut, this.leave, this);
17601 toggle : function () {
17602 this.hoverState == 'in' ? this.leave() : this.enter();
17605 enter : function () {
17607 clearTimeout(this.timeout);
17609 this.hoverState = 'in';
17611 if (!this.delay || !this.delay.show) {
17616 this.timeout = setTimeout(function () {
17617 if (_t.hoverState == 'in') {
17620 }, this.delay.show)
17623 leave : function() {
17624 clearTimeout(this.timeout);
17626 this.hoverState = 'out';
17628 if (!this.delay || !this.delay.hide) {
17633 this.timeout = setTimeout(function () {
17634 if (_t.hoverState == 'out') {
17637 }, this.delay.hide)
17640 show : function (on_el)
17643 on_el= (this.over == 'parent') ? this.parent().el : Roo.get(this.over);
17647 this.el.select('.popover-title',true).first().dom.innerHtml = this.title;
17648 if (this.html !== false) {
17649 this.el.select('.popover-content',true).first().dom.innerHtml = this.html;
17651 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
17652 if (!this.title.length) {
17653 this.el.select('.popover-title',true).hide();
17656 var placement = typeof this.placement == 'function' ?
17657 this.placement.call(this, this.el, on_el) :
17660 var autoToken = /\s?auto?\s?/i;
17661 var autoPlace = autoToken.test(placement);
17663 placement = placement.replace(autoToken, '') || 'top';
17667 //this.el.setXY([0,0]);
17669 this.el.dom.style.display='block';
17670 this.el.addClass(placement);
17672 //this.el.appendTo(on_el);
17674 var p = this.getPosition();
17675 var box = this.el.getBox();
17680 var align = Roo.bootstrap.Popover.alignment[placement];
17683 this.el.alignTo(on_el, align[0],align[1]);
17684 //var arrow = this.el.select('.arrow',true).first();
17685 //arrow.set(align[2],
17687 this.el.addClass('in');
17690 if (this.el.hasClass('fade')) {
17694 this.hoverState = 'in';
17696 this.fireEvent('show', this);
17701 this.el.setXY([0,0]);
17702 this.el.removeClass('in');
17704 this.hoverState = null;
17706 this.fireEvent('hide', this);
17711 Roo.bootstrap.Popover.alignment = {
17712 'left' : ['r-l', [-10,0], 'right'],
17713 'right' : ['l-r', [10,0], 'left'],
17714 'bottom' : ['t-b', [0,10], 'top'],
17715 'top' : [ 'b-t', [0,-10], 'bottom']
17726 * @class Roo.bootstrap.Progress
17727 * @extends Roo.bootstrap.Component
17728 * Bootstrap Progress class
17729 * @cfg {Boolean} striped striped of the progress bar
17730 * @cfg {Boolean} active animated of the progress bar
17734 * Create a new Progress
17735 * @param {Object} config The config object
17738 Roo.bootstrap.Progress = function(config){
17739 Roo.bootstrap.Progress.superclass.constructor.call(this, config);
17742 Roo.extend(Roo.bootstrap.Progress, Roo.bootstrap.Component, {
17747 getAutoCreate : function(){
17755 cfg.cls += ' progress-striped';
17759 cfg.cls += ' active';
17778 * @class Roo.bootstrap.ProgressBar
17779 * @extends Roo.bootstrap.Component
17780 * Bootstrap ProgressBar class
17781 * @cfg {Number} aria_valuenow aria-value now
17782 * @cfg {Number} aria_valuemin aria-value min
17783 * @cfg {Number} aria_valuemax aria-value max
17784 * @cfg {String} label label for the progress bar
17785 * @cfg {String} panel (success | info | warning | danger )
17786 * @cfg {String} role role of the progress bar
17787 * @cfg {String} sr_only text
17791 * Create a new ProgressBar
17792 * @param {Object} config The config object
17795 Roo.bootstrap.ProgressBar = function(config){
17796 Roo.bootstrap.ProgressBar.superclass.constructor.call(this, config);
17799 Roo.extend(Roo.bootstrap.ProgressBar, Roo.bootstrap.Component, {
17803 aria_valuemax : 100,
17809 getAutoCreate : function()
17814 cls: 'progress-bar',
17815 style: 'width:' + Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%'
17827 cfg.role = this.role;
17830 if(this.aria_valuenow){
17831 cfg['aria-valuenow'] = this.aria_valuenow;
17834 if(this.aria_valuemin){
17835 cfg['aria-valuemin'] = this.aria_valuemin;
17838 if(this.aria_valuemax){
17839 cfg['aria-valuemax'] = this.aria_valuemax;
17842 if(this.label && !this.sr_only){
17843 cfg.html = this.label;
17847 cfg.cls += ' progress-bar-' + this.panel;
17853 update : function(aria_valuenow)
17855 this.aria_valuenow = aria_valuenow;
17857 this.el.setStyle('width', Math.ceil((this.aria_valuenow / this.aria_valuemax) * 100) + '%');
17872 * @class Roo.bootstrap.TabGroup
17873 * @extends Roo.bootstrap.Column
17874 * Bootstrap Column class
17875 * @cfg {String} navId the navigation id (for use with navbars) - will be auto generated if it does not exist..
17876 * @cfg {Boolean} carousel true to make the group behave like a carousel
17877 * @cfg {Boolean} bullets show bullets for the panels
17878 * @cfg {Boolean} autoslide (true|false) auto slide .. default false
17879 * @cfg {Number} timer auto slide timer .. default 0 millisecond
17880 * @cfg {Boolean} showarrow (true|false) show arrow default true
17883 * Create a new TabGroup
17884 * @param {Object} config The config object
17887 Roo.bootstrap.TabGroup = function(config){
17888 Roo.bootstrap.TabGroup.superclass.constructor.call(this, config);
17890 this.navId = Roo.id();
17893 Roo.bootstrap.TabGroup.register(this);
17897 Roo.extend(Roo.bootstrap.TabGroup, Roo.bootstrap.Column, {
17900 transition : false,
17905 slideOnTouch : false,
17908 getAutoCreate : function()
17910 var cfg = Roo.apply({}, Roo.bootstrap.TabGroup.superclass.getAutoCreate.call(this));
17912 cfg.cls += ' tab-content';
17914 if (this.carousel) {
17915 cfg.cls += ' carousel slide';
17918 cls : 'carousel-inner',
17922 if(this.bullets && !Roo.isTouch){
17925 cls : 'carousel-bullets',
17929 if(this.bullets_cls){
17930 bullets.cls = bullets.cls + ' ' + this.bullets_cls;
17937 cfg.cn[0].cn.push(bullets);
17940 if(this.showarrow){
17941 cfg.cn[0].cn.push({
17943 class : 'carousel-arrow',
17947 class : 'carousel-prev',
17951 class : 'fa fa-chevron-left'
17957 class : 'carousel-next',
17961 class : 'fa fa-chevron-right'
17974 initEvents: function()
17976 // if(Roo.isTouch && this.slideOnTouch && !this.showarrow){
17977 // this.el.on("touchstart", this.onTouchStart, this);
17980 if(this.autoslide){
17983 this.slideFn = window.setInterval(function() {
17984 _this.showPanelNext();
17988 if(this.showarrow){
17989 this.el.select('.carousel-prev', true).first().on('click', this.showPanelPrev, this);
17990 this.el.select('.carousel-next', true).first().on('click', this.showPanelNext, this);
17996 // onTouchStart : function(e, el, o)
17998 // if(!this.slideOnTouch || !Roo.isTouch || Roo.get(e.getTarget()).hasClass('roo-button-text')){
18002 // this.showPanelNext();
18006 getChildContainer : function()
18008 return this.carousel ? this.el.select('.carousel-inner', true).first() : this.el;
18012 * register a Navigation item
18013 * @param {Roo.bootstrap.NavItem} the navitem to add
18015 register : function(item)
18017 this.tabs.push( item);
18018 item.navId = this.navId; // not really needed..
18023 getActivePanel : function()
18026 Roo.each(this.tabs, function(t) {
18036 getPanelByName : function(n)
18039 Roo.each(this.tabs, function(t) {
18040 if (t.tabId == n) {
18048 indexOfPanel : function(p)
18051 Roo.each(this.tabs, function(t,i) {
18052 if (t.tabId == p.tabId) {
18061 * show a specific panel
18062 * @param {Roo.bootstrap.TabPanel|number|string} panel to change to (use the tabId to specify a specific one)
18063 * @return {boolean} false if panel was not shown (invalid entry or beforedeactivate fails.)
18065 showPanel : function (pan)
18067 if(this.transition || typeof(pan) == 'undefined'){
18068 Roo.log("waiting for the transitionend");
18072 if (typeof(pan) == 'number') {
18073 pan = this.tabs[pan];
18076 if (typeof(pan) == 'string') {
18077 pan = this.getPanelByName(pan);
18080 var cur = this.getActivePanel();
18083 Roo.log('pan or acitve pan is undefined');
18087 if (pan.tabId == this.getActivePanel().tabId) {
18091 if (false === cur.fireEvent('beforedeactivate')) {
18095 if(this.bullets > 0 && !Roo.isTouch){
18096 this.setActiveBullet(this.indexOfPanel(pan));
18099 if (this.carousel && typeof(Roo.get(document.body).dom.style.transition) != 'undefined') {
18101 this.transition = true;
18102 var dir = this.indexOfPanel(pan) > this.indexOfPanel(cur) ? 'next' : 'prev';
18103 var lr = dir == 'next' ? 'left' : 'right';
18104 pan.el.addClass(dir); // or prev
18105 pan.el.dom.offsetWidth; // find the offset with - causing a reflow?
18106 cur.el.addClass(lr); // or right
18107 pan.el.addClass(lr);
18110 cur.el.on('transitionend', function() {
18111 Roo.log("trans end?");
18113 pan.el.removeClass([lr,dir]);
18114 pan.setActive(true);
18116 cur.el.removeClass([lr]);
18117 cur.setActive(false);
18119 _this.transition = false;
18121 }, this, { single: true } );
18126 cur.setActive(false);
18127 pan.setActive(true);
18132 showPanelNext : function()
18134 var i = this.indexOfPanel(this.getActivePanel());
18136 if (i >= this.tabs.length - 1 && !this.autoslide) {
18140 if (i >= this.tabs.length - 1 && this.autoslide) {
18144 this.showPanel(this.tabs[i+1]);
18147 showPanelPrev : function()
18149 var i = this.indexOfPanel(this.getActivePanel());
18151 if (i < 1 && !this.autoslide) {
18155 if (i < 1 && this.autoslide) {
18156 i = this.tabs.length;
18159 this.showPanel(this.tabs[i-1]);
18163 addBullet: function()
18165 if(!this.bullets || Roo.isTouch){
18168 var ctr = this.el.select('.carousel-bullets',true).first();
18169 var i = this.el.select('.carousel-bullets .bullet',true).getCount() ;
18170 var bullet = ctr.createChild({
18171 cls : 'bullet bullet-' + i
18172 },ctr.dom.lastChild);
18177 bullet.on('click', (function(e, el, o, ii, t){
18179 e.preventDefault();
18181 this.showPanel(ii);
18183 if(this.autoslide && this.slideFn){
18184 clearInterval(this.slideFn);
18185 this.slideFn = window.setInterval(function() {
18186 _this.showPanelNext();
18190 }).createDelegate(this, [i, bullet], true));
18195 setActiveBullet : function(i)
18201 Roo.each(this.el.select('.bullet', true).elements, function(el){
18202 el.removeClass('selected');
18205 var bullet = this.el.select('.bullet-' + i, true).first();
18211 bullet.addClass('selected');
18222 Roo.apply(Roo.bootstrap.TabGroup, {
18226 * register a Navigation Group
18227 * @param {Roo.bootstrap.NavGroup} the navgroup to add
18229 register : function(navgrp)
18231 this.groups[navgrp.navId] = navgrp;
18235 * fetch a Navigation Group based on the navigation ID
18236 * if one does not exist , it will get created.
18237 * @param {string} the navgroup to add
18238 * @returns {Roo.bootstrap.NavGroup} the navgroup
18240 get: function(navId) {
18241 if (typeof(this.groups[navId]) == 'undefined') {
18242 this.register(new Roo.bootstrap.TabGroup({ navId : navId }));
18244 return this.groups[navId] ;
18259 * @class Roo.bootstrap.TabPanel
18260 * @extends Roo.bootstrap.Component
18261 * Bootstrap TabPanel class
18262 * @cfg {Boolean} active panel active
18263 * @cfg {String} html panel content
18264 * @cfg {String} tabId unique tab ID (will be autogenerated if not set. - used to match TabItem to Panel)
18265 * @cfg {String} navId The Roo.bootstrap.NavGroup which triggers show hide ()
18266 * @cfg {String} href click to link..
18270 * Create a new TabPanel
18271 * @param {Object} config The config object
18274 Roo.bootstrap.TabPanel = function(config){
18275 Roo.bootstrap.TabPanel.superclass.constructor.call(this, config);
18279 * Fires when the active status changes
18280 * @param {Roo.bootstrap.TabPanel} this
18281 * @param {Boolean} state the new state
18286 * @event beforedeactivate
18287 * Fires before a tab is de-activated - can be used to do validation on a form.
18288 * @param {Roo.bootstrap.TabPanel} this
18289 * @return {Boolean} false if there is an error
18292 'beforedeactivate': true
18295 this.tabId = this.tabId || Roo.id();
18299 Roo.extend(Roo.bootstrap.TabPanel, Roo.bootstrap.Component, {
18307 getAutoCreate : function(){
18310 // item is needed for carousel - not sure if it has any effect otherwise
18311 cls: 'tab-pane item' + ((this.href.length) ? ' clickable ' : ''),
18312 html: this.html || ''
18316 cfg.cls += ' active';
18320 cfg.tabId = this.tabId;
18327 initEvents: function()
18329 var p = this.parent();
18331 this.navId = this.navId || p.navId;
18333 if (typeof(this.navId) != 'undefined') {
18334 // not really needed.. but just in case.. parent should be a NavGroup.
18335 var tg = Roo.bootstrap.TabGroup.get(this.navId);
18339 var i = tg.tabs.length - 1;
18341 if(this.active && tg.bullets > 0 && i < tg.bullets){
18342 tg.setActiveBullet(i);
18346 this.el.on('click', this.onClick, this);
18349 this.el.on("touchstart", this.onTouchStart, this);
18350 this.el.on("touchmove", this.onTouchMove, this);
18351 this.el.on("touchend", this.onTouchEnd, this);
18356 onRender : function(ct, position)
18358 Roo.bootstrap.TabPanel.superclass.onRender.call(this, ct, position);
18361 setActive : function(state)
18363 Roo.log("panel - set active " + this.tabId + "=" + state);
18365 this.active = state;
18367 this.el.removeClass('active');
18369 } else if (!this.el.hasClass('active')) {
18370 this.el.addClass('active');
18373 this.fireEvent('changed', this, state);
18376 onClick : function(e)
18378 e.preventDefault();
18380 if(!this.href.length){
18384 window.location.href = this.href;
18393 onTouchStart : function(e)
18395 this.swiping = false;
18397 this.startX = e.browserEvent.touches[0].clientX;
18398 this.startY = e.browserEvent.touches[0].clientY;
18401 onTouchMove : function(e)
18403 this.swiping = true;
18405 this.endX = e.browserEvent.touches[0].clientX;
18406 this.endY = e.browserEvent.touches[0].clientY;
18409 onTouchEnd : function(e)
18416 var tabGroup = this.parent();
18418 if(this.endX > this.startX){ // swiping right
18419 tabGroup.showPanelPrev();
18423 if(this.startX > this.endX){ // swiping left
18424 tabGroup.showPanelNext();
18443 * @class Roo.bootstrap.DateField
18444 * @extends Roo.bootstrap.Input
18445 * Bootstrap DateField class
18446 * @cfg {Number} weekStart default 0
18447 * @cfg {String} viewMode default empty, (months|years)
18448 * @cfg {String} minViewMode default empty, (months|years)
18449 * @cfg {Number} startDate default -Infinity
18450 * @cfg {Number} endDate default Infinity
18451 * @cfg {Boolean} todayHighlight default false
18452 * @cfg {Boolean} todayBtn default false
18453 * @cfg {Boolean} calendarWeeks default false
18454 * @cfg {Object} daysOfWeekDisabled default empty
18455 * @cfg {Boolean} singleMode default false (true | false)
18457 * @cfg {Boolean} keyboardNavigation default true
18458 * @cfg {String} language default en
18461 * Create a new DateField
18462 * @param {Object} config The config object
18465 Roo.bootstrap.DateField = function(config){
18466 Roo.bootstrap.DateField.superclass.constructor.call(this, config);
18470 * Fires when this field show.
18471 * @param {Roo.bootstrap.DateField} this
18472 * @param {Mixed} date The date value
18477 * Fires when this field hide.
18478 * @param {Roo.bootstrap.DateField} this
18479 * @param {Mixed} date The date value
18484 * Fires when select a date.
18485 * @param {Roo.bootstrap.DateField} this
18486 * @param {Mixed} date The date value
18490 * @event beforeselect
18491 * Fires when before select a date.
18492 * @param {Roo.bootstrap.DateField} this
18493 * @param {Mixed} date The date value
18495 beforeselect : true
18499 Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, {
18502 * @cfg {String} format
18503 * The default date format string which can be overriden for localization support. The format must be
18504 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
18508 * @cfg {String} altFormats
18509 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
18510 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
18512 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
18520 todayHighlight : false,
18526 keyboardNavigation: true,
18528 calendarWeeks: false,
18530 startDate: -Infinity,
18534 daysOfWeekDisabled: [],
18538 singleMode : false,
18540 UTCDate: function()
18542 return new Date(Date.UTC.apply(Date, arguments));
18545 UTCToday: function()
18547 var today = new Date();
18548 return this.UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
18551 getDate: function() {
18552 var d = this.getUTCDate();
18553 return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
18556 getUTCDate: function() {
18560 setDate: function(d) {
18561 this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
18564 setUTCDate: function(d) {
18566 this.setValue(this.formatDate(this.date));
18569 onRender: function(ct, position)
18572 Roo.bootstrap.DateField.superclass.onRender.call(this, ct, position);
18574 this.language = this.language || 'en';
18575 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : this.language.split('-')[0];
18576 this.language = this.language in Roo.bootstrap.DateField.dates ? this.language : "en";
18578 this.isRTL = Roo.bootstrap.DateField.dates[this.language].rtl || false;
18579 this.format = this.format || 'm/d/y';
18580 this.isInline = false;
18581 this.isInput = true;
18582 this.component = this.el.select('.add-on', true).first() || false;
18583 this.component = (this.component && this.component.length === 0) ? false : this.component;
18584 this.hasInput = this.component && this.inputEl().length;
18586 if (typeof(this.minViewMode === 'string')) {
18587 switch (this.minViewMode) {
18589 this.minViewMode = 1;
18592 this.minViewMode = 2;
18595 this.minViewMode = 0;
18600 if (typeof(this.viewMode === 'string')) {
18601 switch (this.viewMode) {
18614 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.DateField.template);
18616 // this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.DateField.template);
18618 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18620 this.picker().on('mousedown', this.onMousedown, this);
18621 this.picker().on('click', this.onClick, this);
18623 this.picker().addClass('datepicker-dropdown');
18625 this.startViewMode = this.viewMode;
18627 if(this.singleMode){
18628 Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){
18629 v.setVisibilityMode(Roo.Element.DISPLAY);
18633 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
18634 v.setStyle('width', '189px');
18638 Roo.each(this.picker().select('tfoot th.today', true).elements, function(v){
18639 if(!this.calendarWeeks){
18644 v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18645 v.attr('colspan', function(i, val){
18646 return parseInt(val) + 1;
18651 this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
18653 this.setStartDate(this.startDate);
18654 this.setEndDate(this.endDate);
18656 this.setDaysOfWeekDisabled(this.daysOfWeekDisabled);
18663 if(this.isInline) {
18668 picker : function()
18670 return this.pickerEl;
18671 // return this.el.select('.datepicker', true).first();
18674 fillDow: function()
18676 var dowCnt = this.weekStart;
18685 if(this.calendarWeeks){
18693 while (dowCnt < this.weekStart + 7) {
18697 html: Roo.bootstrap.DateField.dates[this.language].daysMin[(dowCnt++)%7]
18701 this.picker().select('>.datepicker-days thead', true).first().createChild(dow);
18704 fillMonths: function()
18707 var months = this.picker().select('>.datepicker-months td', true).first();
18709 months.dom.innerHTML = '';
18715 html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
18718 months.createChild(month);
18725 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;
18727 if (this.date < this.startDate) {
18728 this.viewDate = new Date(this.startDate);
18729 } else if (this.date > this.endDate) {
18730 this.viewDate = new Date(this.endDate);
18732 this.viewDate = new Date(this.date);
18740 var d = new Date(this.viewDate),
18741 year = d.getUTCFullYear(),
18742 month = d.getUTCMonth(),
18743 startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
18744 startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
18745 endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
18746 endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
18747 currentDate = this.date && this.date.valueOf(),
18748 today = this.UTCToday();
18750 this.picker().select('>.datepicker-days thead th.switch', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].months[month]+' '+year;
18752 // this.picker().select('>tfoot th.today', true).first().dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today;
18754 // this.picker.select('>tfoot th.today').
18755 // .text(dates[this.language].today)
18756 // .toggle(this.todayBtn !== false);
18758 this.updateNavArrows();
18761 var prevMonth = this.UTCDate(year, month-1, 28,0,0,0,0),
18763 day = prevMonth.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
18765 prevMonth.setUTCDate(day);
18767 prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
18769 var nextMonth = new Date(prevMonth);
18771 nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
18773 nextMonth = nextMonth.valueOf();
18775 var fillMonths = false;
18777 this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = '';
18779 while(prevMonth.valueOf() <= nextMonth) {
18782 if (prevMonth.getUTCDay() === this.weekStart) {
18784 this.picker().select('>.datepicker-days tbody',true).first().createChild(fillMonths);
18792 if(this.calendarWeeks){
18793 // ISO 8601: First week contains first thursday.
18794 // ISO also states week starts on Monday, but we can be more abstract here.
18796 // Start of current week: based on weekstart/current date
18797 ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
18798 // Thursday of this week
18799 th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
18800 // First Thursday of year, year from thursday
18801 yth = new Date(+(yth = this.UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
18802 // Calendar week: ms between thursdays, div ms per day, div 7 days
18803 calWeek = (th - yth) / 864e5 / 7 + 1;
18805 fillMonths.cn.push({
18813 if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
18815 } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
18818 if (this.todayHighlight &&
18819 prevMonth.getUTCFullYear() == today.getFullYear() &&
18820 prevMonth.getUTCMonth() == today.getMonth() &&
18821 prevMonth.getUTCDate() == today.getDate()) {
18822 clsName += ' today';
18825 if (currentDate && prevMonth.valueOf() === currentDate) {
18826 clsName += ' active';
18829 if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
18830 this.daysOfWeekDisabled.indexOf(prevMonth.getUTCDay()) !== -1) {
18831 clsName += ' disabled';
18834 fillMonths.cn.push({
18836 cls: 'day ' + clsName,
18837 html: prevMonth.getDate()
18840 prevMonth.setDate(prevMonth.getDate()+1);
18843 var currentYear = this.date && this.date.getUTCFullYear();
18844 var currentMonth = this.date && this.date.getUTCMonth();
18846 this.picker().select('>.datepicker-months th.switch',true).first().dom.innerHTML = year;
18848 Roo.each(this.picker().select('>.datepicker-months tbody span',true).elements, function(v,k){
18849 v.removeClass('active');
18851 if(currentYear === year && k === currentMonth){
18852 v.addClass('active');
18855 if (year < startYear || year > endYear || (year == startYear && k < startMonth) || (year == endYear && k > endMonth)) {
18856 v.addClass('disabled');
18862 year = parseInt(year/10, 10) * 10;
18864 this.picker().select('>.datepicker-years th.switch', true).first().dom.innerHTML = year + '-' + (year + 9);
18866 this.picker().select('>.datepicker-years tbody td',true).first().dom.innerHTML = '';
18869 for (var i = -1; i < 11; i++) {
18870 this.picker().select('>.datepicker-years tbody td',true).first().createChild({
18872 cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
18880 showMode: function(dir)
18883 this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
18886 Roo.each(this.picker().select('>div',true).elements, function(v){
18887 v.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
18890 this.picker().select('>.datepicker-'+Roo.bootstrap.DateField.modes[this.viewMode].clsName, true).first().show();
18895 if(this.isInline) {
18899 this.picker().removeClass(['bottom', 'top']);
18901 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
18903 * place to the top of element!
18907 this.picker().addClass('top');
18908 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
18913 this.picker().addClass('bottom');
18915 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
18918 parseDate : function(value)
18920 if(!value || value instanceof Date){
18923 var v = Date.parseDate(value, this.format);
18924 if (!v && (this.useIso || value.match(/^(\d{4})-0?(\d+)-0?(\d+)/))) {
18925 v = Date.parseDate(value, 'Y-m-d');
18927 if(!v && this.altFormats){
18928 if(!this.altFormatsArray){
18929 this.altFormatsArray = this.altFormats.split("|");
18931 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
18932 v = Date.parseDate(value, this.altFormatsArray[i]);
18938 formatDate : function(date, fmt)
18940 return (!date || !(date instanceof Date)) ?
18941 date : date.dateFormat(fmt || this.format);
18944 onFocus : function()
18946 Roo.bootstrap.DateField.superclass.onFocus.call(this);
18950 onBlur : function()
18952 Roo.bootstrap.DateField.superclass.onBlur.call(this);
18954 var d = this.inputEl().getValue();
18961 showPopup : function()
18963 this.picker().show();
18967 this.fireEvent('showpopup', this, this.date);
18970 hidePopup : function()
18972 if(this.isInline) {
18975 this.picker().hide();
18976 this.viewMode = this.startViewMode;
18979 this.fireEvent('hidepopup', this, this.date);
18983 onMousedown: function(e)
18985 e.stopPropagation();
18986 e.preventDefault();
18991 Roo.bootstrap.DateField.superclass.keyup.call(this);
18995 setValue: function(v)
18997 if(this.fireEvent('beforeselect', this, v) !== false){
18998 var d = new Date(this.parseDate(v) ).clearTime();
19000 if(isNaN(d.getTime())){
19001 this.date = this.viewDate = '';
19002 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
19006 v = this.formatDate(d);
19008 Roo.bootstrap.DateField.superclass.setValue.call(this, v);
19010 this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000);
19014 this.fireEvent('select', this, this.date);
19018 getValue: function()
19020 return this.formatDate(this.date);
19023 fireKey: function(e)
19025 if (!this.picker().isVisible()){
19026 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19032 var dateChanged = false,
19034 newDate, newViewDate;
19039 e.preventDefault();
19043 if (!this.keyboardNavigation) {
19046 dir = e.keyCode == 37 ? -1 : 1;
19049 newDate = this.moveYear(this.date, dir);
19050 newViewDate = this.moveYear(this.viewDate, dir);
19051 } else if (e.shiftKey){
19052 newDate = this.moveMonth(this.date, dir);
19053 newViewDate = this.moveMonth(this.viewDate, dir);
19055 newDate = new Date(this.date);
19056 newDate.setUTCDate(this.date.getUTCDate() + dir);
19057 newViewDate = new Date(this.viewDate);
19058 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
19060 if (this.dateWithinRange(newDate)){
19061 this.date = newDate;
19062 this.viewDate = newViewDate;
19063 this.setValue(this.formatDate(this.date));
19065 e.preventDefault();
19066 dateChanged = true;
19071 if (!this.keyboardNavigation) {
19074 dir = e.keyCode == 38 ? -1 : 1;
19076 newDate = this.moveYear(this.date, dir);
19077 newViewDate = this.moveYear(this.viewDate, dir);
19078 } else if (e.shiftKey){
19079 newDate = this.moveMonth(this.date, dir);
19080 newViewDate = this.moveMonth(this.viewDate, dir);
19082 newDate = new Date(this.date);
19083 newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
19084 newViewDate = new Date(this.viewDate);
19085 newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
19087 if (this.dateWithinRange(newDate)){
19088 this.date = newDate;
19089 this.viewDate = newViewDate;
19090 this.setValue(this.formatDate(this.date));
19092 e.preventDefault();
19093 dateChanged = true;
19097 this.setValue(this.formatDate(this.date));
19099 e.preventDefault();
19102 this.setValue(this.formatDate(this.date));
19116 onClick: function(e)
19118 e.stopPropagation();
19119 e.preventDefault();
19121 var target = e.getTarget();
19123 if(target.nodeName.toLowerCase() === 'i'){
19124 target = Roo.get(target).dom.parentNode;
19127 var nodeName = target.nodeName;
19128 var className = target.className;
19129 var html = target.innerHTML;
19130 //Roo.log(nodeName);
19132 switch(nodeName.toLowerCase()) {
19134 switch(className) {
19140 var dir = Roo.bootstrap.DateField.modes[this.viewMode].navStep * (className == 'prev' ? -1 : 1);
19141 switch(this.viewMode){
19143 this.viewDate = this.moveMonth(this.viewDate, dir);
19147 this.viewDate = this.moveYear(this.viewDate, dir);
19153 var date = new Date();
19154 this.date = this.UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
19156 this.setValue(this.formatDate(this.date));
19163 if (className.indexOf('disabled') < 0) {
19164 this.viewDate.setUTCDate(1);
19165 if (className.indexOf('month') > -1) {
19166 this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html));
19168 var year = parseInt(html, 10) || 0;
19169 this.viewDate.setUTCFullYear(year);
19173 if(this.singleMode){
19174 this.setValue(this.formatDate(this.viewDate));
19185 //Roo.log(className);
19186 if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){
19187 var day = parseInt(html, 10) || 1;
19188 var year = this.viewDate.getUTCFullYear(),
19189 month = this.viewDate.getUTCMonth();
19191 if (className.indexOf('old') > -1) {
19198 } else if (className.indexOf('new') > -1) {
19206 //Roo.log([year,month,day]);
19207 this.date = this.UTCDate(year, month, day,0,0,0,0);
19208 this.viewDate = this.UTCDate(year, month, Math.min(28, day),0,0,0,0);
19210 //Roo.log(this.formatDate(this.date));
19211 this.setValue(this.formatDate(this.date));
19218 setStartDate: function(startDate)
19220 this.startDate = startDate || -Infinity;
19221 if (this.startDate !== -Infinity) {
19222 this.startDate = this.parseDate(this.startDate);
19225 this.updateNavArrows();
19228 setEndDate: function(endDate)
19230 this.endDate = endDate || Infinity;
19231 if (this.endDate !== Infinity) {
19232 this.endDate = this.parseDate(this.endDate);
19235 this.updateNavArrows();
19238 setDaysOfWeekDisabled: function(daysOfWeekDisabled)
19240 this.daysOfWeekDisabled = daysOfWeekDisabled || [];
19241 if (typeof(this.daysOfWeekDisabled) !== 'object') {
19242 this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
19244 this.daysOfWeekDisabled = this.daysOfWeekDisabled.map(function (d) {
19245 return parseInt(d, 10);
19248 this.updateNavArrows();
19251 updateNavArrows: function()
19253 if(this.singleMode){
19257 var d = new Date(this.viewDate),
19258 year = d.getUTCFullYear(),
19259 month = d.getUTCMonth();
19261 Roo.each(this.picker().select('.prev', true).elements, function(v){
19263 switch (this.viewMode) {
19266 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
19272 if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
19279 Roo.each(this.picker().select('.next', true).elements, function(v){
19281 switch (this.viewMode) {
19284 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
19290 if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
19298 moveMonth: function(date, dir)
19303 var new_date = new Date(date.valueOf()),
19304 day = new_date.getUTCDate(),
19305 month = new_date.getUTCMonth(),
19306 mag = Math.abs(dir),
19308 dir = dir > 0 ? 1 : -1;
19311 // If going back one month, make sure month is not current month
19312 // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
19314 return new_date.getUTCMonth() == month;
19316 // If going forward one month, make sure month is as expected
19317 // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
19319 return new_date.getUTCMonth() != new_month;
19321 new_month = month + dir;
19322 new_date.setUTCMonth(new_month);
19323 // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
19324 if (new_month < 0 || new_month > 11) {
19325 new_month = (new_month + 12) % 12;
19328 // For magnitudes >1, move one month at a time...
19329 for (var i=0; i<mag; i++) {
19330 // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
19331 new_date = this.moveMonth(new_date, dir);
19333 // ...then reset the day, keeping it in the new month
19334 new_month = new_date.getUTCMonth();
19335 new_date.setUTCDate(day);
19337 return new_month != new_date.getUTCMonth();
19340 // Common date-resetting loop -- if date is beyond end of month, make it
19343 new_date.setUTCDate(--day);
19344 new_date.setUTCMonth(new_month);
19349 moveYear: function(date, dir)
19351 return this.moveMonth(date, dir*12);
19354 dateWithinRange: function(date)
19356 return date >= this.startDate && date <= this.endDate;
19362 this.picker().remove();
19365 validateValue : function(value)
19367 if(this.getVisibilityEl().hasClass('hidden')){
19371 if(value.length < 1) {
19372 if(this.allowBlank){
19378 if(value.length < this.minLength){
19381 if(value.length > this.maxLength){
19385 var vt = Roo.form.VTypes;
19386 if(!vt[this.vtype](value, this)){
19390 if(typeof this.validator == "function"){
19391 var msg = this.validator(value);
19397 if(this.regex && !this.regex.test(value)){
19401 if(typeof(this.parseDate(value)) == 'undefined'){
19405 if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) {
19409 if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) {
19419 this.date = this.viewDate = '';
19421 Roo.bootstrap.DateField.superclass.setValue.call(this, '');
19426 Roo.apply(Roo.bootstrap.DateField, {
19437 html: '<i class="fa fa-arrow-left"/>'
19447 html: '<i class="fa fa-arrow-right"/>'
19489 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
19490 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
19491 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
19492 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
19493 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
19506 navFnc: 'FullYear',
19511 navFnc: 'FullYear',
19516 Roo.apply(Roo.bootstrap.DateField, {
19520 cls: 'datepicker dropdown-menu roo-dynamic',
19524 cls: 'datepicker-days',
19528 cls: 'table-condensed',
19530 Roo.bootstrap.DateField.head,
19534 Roo.bootstrap.DateField.footer
19541 cls: 'datepicker-months',
19545 cls: 'table-condensed',
19547 Roo.bootstrap.DateField.head,
19548 Roo.bootstrap.DateField.content,
19549 Roo.bootstrap.DateField.footer
19556 cls: 'datepicker-years',
19560 cls: 'table-condensed',
19562 Roo.bootstrap.DateField.head,
19563 Roo.bootstrap.DateField.content,
19564 Roo.bootstrap.DateField.footer
19583 * @class Roo.bootstrap.TimeField
19584 * @extends Roo.bootstrap.Input
19585 * Bootstrap DateField class
19589 * Create a new TimeField
19590 * @param {Object} config The config object
19593 Roo.bootstrap.TimeField = function(config){
19594 Roo.bootstrap.TimeField.superclass.constructor.call(this, config);
19598 * Fires when this field show.
19599 * @param {Roo.bootstrap.DateField} thisthis
19600 * @param {Mixed} date The date value
19605 * Fires when this field hide.
19606 * @param {Roo.bootstrap.DateField} this
19607 * @param {Mixed} date The date value
19612 * Fires when select a date.
19613 * @param {Roo.bootstrap.DateField} this
19614 * @param {Mixed} date The date value
19620 Roo.extend(Roo.bootstrap.TimeField, Roo.bootstrap.Input, {
19623 * @cfg {String} format
19624 * The default time format string which can be overriden for localization support. The format must be
19625 * valid according to {@link Date#parseDate} (defaults to 'H:i').
19629 onRender: function(ct, position)
19632 Roo.bootstrap.TimeField.superclass.onRender.call(this, ct, position);
19634 this.el.select('>.input-group', true).first().createChild(Roo.bootstrap.TimeField.template);
19636 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19638 this.pop = this.picker().select('>.datepicker-time',true).first();
19639 this.pop.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
19641 this.picker().on('mousedown', this.onMousedown, this);
19642 this.picker().on('click', this.onClick, this);
19644 this.picker().addClass('datepicker-dropdown');
19649 this.pop.select('span.hours-up', true).first().on('click', this.onIncrementHours, this);
19650 this.pop.select('span.hours-down', true).first().on('click', this.onDecrementHours, this);
19651 this.pop.select('span.minutes-up', true).first().on('click', this.onIncrementMinutes, this);
19652 this.pop.select('span.minutes-down', true).first().on('click', this.onDecrementMinutes, this);
19653 this.pop.select('button.period', true).first().on('click', this.onTogglePeriod, this);
19654 this.pop.select('button.ok', true).first().on('click', this.setTime, this);
19658 fireKey: function(e){
19659 if (!this.picker().isVisible()){
19660 if (e.keyCode == 27) { // allow escape to hide and re-show picker
19666 e.preventDefault();
19674 this.onTogglePeriod();
19677 this.onIncrementMinutes();
19680 this.onDecrementMinutes();
19689 onClick: function(e) {
19690 e.stopPropagation();
19691 e.preventDefault();
19694 picker : function()
19696 return this.el.select('.datepicker', true).first();
19699 fillTime: function()
19701 var time = this.pop.select('tbody', true).first();
19703 time.dom.innerHTML = '';
19718 cls: 'hours-up glyphicon glyphicon-chevron-up'
19738 cls: 'minutes-up glyphicon glyphicon-chevron-up'
19759 cls: 'timepicker-hour',
19774 cls: 'timepicker-minute',
19789 cls: 'btn btn-primary period',
19811 cls: 'hours-down glyphicon glyphicon-chevron-down'
19831 cls: 'minutes-down glyphicon glyphicon-chevron-down'
19849 this.time = (typeof(this.time) === 'undefined') ? new Date() : this.time;
19856 var hours = this.time.getHours();
19857 var minutes = this.time.getMinutes();
19870 hours = hours - 12;
19874 hours = '0' + hours;
19878 minutes = '0' + minutes;
19881 this.pop.select('.timepicker-hour', true).first().dom.innerHTML = hours;
19882 this.pop.select('.timepicker-minute', true).first().dom.innerHTML = minutes;
19883 this.pop.select('button', true).first().dom.innerHTML = period;
19889 this.picker().removeClass(['bottom-left', 'bottom-right', 'top-left', 'top-right']);
19891 var cls = ['bottom'];
19893 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){ // top
19900 if((Roo.lib.Dom.getViewWidth() + Roo.get(document.body).getScroll().left) - (this.inputEl().getLeft() + this.picker().getWidth()) < 0){ // left
19905 this.picker().addClass(cls.join('-'));
19909 Roo.each(cls, function(c){
19911 _this.picker().setTop(_this.inputEl().getHeight());
19915 _this.picker().setTop(0 - _this.picker().getHeight());
19920 _this.picker().setLeft(_this.inputEl().getLeft() + _this.inputEl().getWidth() - _this.el.getLeft() - _this.picker().getWidth());
19924 _this.picker().setLeft(_this.inputEl().getLeft() - _this.el.getLeft());
19931 onFocus : function()
19933 Roo.bootstrap.TimeField.superclass.onFocus.call(this);
19937 onBlur : function()
19939 Roo.bootstrap.TimeField.superclass.onBlur.call(this);
19945 this.picker().show();
19950 this.fireEvent('show', this, this.date);
19955 this.picker().hide();
19958 this.fireEvent('hide', this, this.date);
19961 setTime : function()
19964 this.setValue(this.time.format(this.format));
19966 this.fireEvent('select', this, this.date);
19971 onMousedown: function(e){
19972 e.stopPropagation();
19973 e.preventDefault();
19976 onIncrementHours: function()
19978 Roo.log('onIncrementHours');
19979 this.time = this.time.add(Date.HOUR, 1);
19984 onDecrementHours: function()
19986 Roo.log('onDecrementHours');
19987 this.time = this.time.add(Date.HOUR, -1);
19991 onIncrementMinutes: function()
19993 Roo.log('onIncrementMinutes');
19994 this.time = this.time.add(Date.MINUTE, 1);
19998 onDecrementMinutes: function()
20000 Roo.log('onDecrementMinutes');
20001 this.time = this.time.add(Date.MINUTE, -1);
20005 onTogglePeriod: function()
20007 Roo.log('onTogglePeriod');
20008 this.time = this.time.add(Date.HOUR, 12);
20015 Roo.apply(Roo.bootstrap.TimeField, {
20045 cls: 'btn btn-info ok',
20057 Roo.apply(Roo.bootstrap.TimeField, {
20061 cls: 'datepicker dropdown-menu',
20065 cls: 'datepicker-time',
20069 cls: 'table-condensed',
20071 Roo.bootstrap.TimeField.content,
20072 Roo.bootstrap.TimeField.footer
20091 * @class Roo.bootstrap.MonthField
20092 * @extends Roo.bootstrap.Input
20093 * Bootstrap MonthField class
20095 * @cfg {String} language default en
20098 * Create a new MonthField
20099 * @param {Object} config The config object
20102 Roo.bootstrap.MonthField = function(config){
20103 Roo.bootstrap.MonthField.superclass.constructor.call(this, config);
20108 * Fires when this field show.
20109 * @param {Roo.bootstrap.MonthField} this
20110 * @param {Mixed} date The date value
20115 * Fires when this field hide.
20116 * @param {Roo.bootstrap.MonthField} this
20117 * @param {Mixed} date The date value
20122 * Fires when select a date.
20123 * @param {Roo.bootstrap.MonthField} this
20124 * @param {String} oldvalue The old value
20125 * @param {String} newvalue The new value
20131 Roo.extend(Roo.bootstrap.MonthField, Roo.bootstrap.Input, {
20133 onRender: function(ct, position)
20136 Roo.bootstrap.MonthField.superclass.onRender.call(this, ct, position);
20138 this.language = this.language || 'en';
20139 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : this.language.split('-')[0];
20140 this.language = this.language in Roo.bootstrap.MonthField.dates ? this.language : "en";
20142 this.isRTL = Roo.bootstrap.MonthField.dates[this.language].rtl || false;
20143 this.isInline = false;
20144 this.isInput = true;
20145 this.component = this.el.select('.add-on', true).first() || false;
20146 this.component = (this.component && this.component.length === 0) ? false : this.component;
20147 this.hasInput = this.component && this.inputEL().length;
20149 this.pickerEl = Roo.get(document.body).createChild(Roo.bootstrap.MonthField.template);
20151 this.picker().setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
20153 this.picker().on('mousedown', this.onMousedown, this);
20154 this.picker().on('click', this.onClick, this);
20156 this.picker().addClass('datepicker-dropdown');
20158 Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){
20159 v.setStyle('width', '189px');
20166 if(this.isInline) {
20172 setValue: function(v, suppressEvent)
20174 var o = this.getValue();
20176 Roo.bootstrap.MonthField.superclass.setValue.call(this, v);
20180 if(suppressEvent !== true){
20181 this.fireEvent('select', this, o, v);
20186 getValue: function()
20191 onClick: function(e)
20193 e.stopPropagation();
20194 e.preventDefault();
20196 var target = e.getTarget();
20198 if(target.nodeName.toLowerCase() === 'i'){
20199 target = Roo.get(target).dom.parentNode;
20202 var nodeName = target.nodeName;
20203 var className = target.className;
20204 var html = target.innerHTML;
20206 if(nodeName.toLowerCase() != 'span' || className.indexOf('disabled') > -1 || className.indexOf('month') == -1){
20210 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].monthsShort.indexOf(html);
20212 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20218 picker : function()
20220 return this.pickerEl;
20223 fillMonths: function()
20226 var months = this.picker().select('>.datepicker-months td', true).first();
20228 months.dom.innerHTML = '';
20234 html: Roo.bootstrap.MonthField.dates[this.language].monthsShort[i++]
20237 months.createChild(month);
20246 if(typeof(this.vIndex) == 'undefined' && this.value.length){
20247 this.vIndex = Roo.bootstrap.MonthField.dates[this.language].months.indexOf(this.value);
20250 Roo.each(this.pickerEl.select('> .datepicker-months tbody > tr > td > span', true).elements, function(e, k){
20251 e.removeClass('active');
20253 if(typeof(_this.vIndex) != 'undefined' && k == _this.vIndex){
20254 e.addClass('active');
20261 if(this.isInline) {
20265 this.picker().removeClass(['bottom', 'top']);
20267 if((Roo.lib.Dom.getViewHeight() + Roo.get(document.body).getScroll().top) - (this.inputEl().getBottom() + this.picker().getHeight()) < 0){
20269 * place to the top of element!
20273 this.picker().addClass('top');
20274 this.picker().setTop(this.inputEl().getTop() - this.picker().getHeight()).setLeft(this.inputEl().getLeft());
20279 this.picker().addClass('bottom');
20281 this.picker().setTop(this.inputEl().getBottom()).setLeft(this.inputEl().getLeft());
20284 onFocus : function()
20286 Roo.bootstrap.MonthField.superclass.onFocus.call(this);
20290 onBlur : function()
20292 Roo.bootstrap.MonthField.superclass.onBlur.call(this);
20294 var d = this.inputEl().getValue();
20303 this.picker().show();
20304 this.picker().select('>.datepicker-months', true).first().show();
20308 this.fireEvent('show', this, this.date);
20313 if(this.isInline) {
20316 this.picker().hide();
20317 this.fireEvent('hide', this, this.date);
20321 onMousedown: function(e)
20323 e.stopPropagation();
20324 e.preventDefault();
20329 Roo.bootstrap.MonthField.superclass.keyup.call(this);
20333 fireKey: function(e)
20335 if (!this.picker().isVisible()){
20336 if (e.keyCode == 27) {// allow escape to hide and re-show picker
20347 e.preventDefault();
20351 dir = e.keyCode == 37 ? -1 : 1;
20353 this.vIndex = this.vIndex + dir;
20355 if(this.vIndex < 0){
20359 if(this.vIndex > 11){
20363 if(isNaN(this.vIndex)){
20367 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20373 dir = e.keyCode == 38 ? -1 : 1;
20375 this.vIndex = this.vIndex + dir * 4;
20377 if(this.vIndex < 0){
20381 if(this.vIndex > 11){
20385 if(isNaN(this.vIndex)){
20389 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20394 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20395 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20399 e.preventDefault();
20402 if(typeof(this.vIndex) != 'undefined' && !isNaN(this.vIndex)){
20403 this.setValue(Roo.bootstrap.MonthField.dates[this.language].months[this.vIndex]);
20419 this.picker().remove();
20424 Roo.apply(Roo.bootstrap.MonthField, {
20443 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
20444 monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
20449 Roo.apply(Roo.bootstrap.MonthField, {
20453 cls: 'datepicker dropdown-menu roo-dynamic',
20457 cls: 'datepicker-months',
20461 cls: 'table-condensed',
20463 Roo.bootstrap.DateField.content
20483 * @class Roo.bootstrap.CheckBox
20484 * @extends Roo.bootstrap.Input
20485 * Bootstrap CheckBox class
20487 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
20488 * @cfg {String} inputValue The value that should go into the generated input element's value when checked.
20489 * @cfg {String} boxLabel The text that appears beside the checkbox
20490 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the checkbox
20491 * @cfg {Boolean} checked initnal the element
20492 * @cfg {Boolean} inline inline the element (default false)
20493 * @cfg {String} groupId the checkbox group id // normal just use for checkbox
20494 * @cfg {String} tooltip label tooltip
20497 * Create a new CheckBox
20498 * @param {Object} config The config object
20501 Roo.bootstrap.CheckBox = function(config){
20502 Roo.bootstrap.CheckBox.superclass.constructor.call(this, config);
20507 * Fires when the element is checked or unchecked.
20508 * @param {Roo.bootstrap.CheckBox} this This input
20509 * @param {Boolean} checked The new checked value
20514 * Fires when the element is click.
20515 * @param {Roo.bootstrap.CheckBox} this This input
20522 Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input, {
20524 inputType: 'checkbox',
20533 getAutoCreate : function()
20535 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
20541 cfg.cls = 'form-group ' + this.inputType; //input-group
20544 cfg.cls += ' ' + this.inputType + '-inline';
20550 type : this.inputType,
20551 value : this.inputValue,
20552 cls : 'roo-' + this.inputType, //'form-box',
20553 placeholder : this.placeholder || ''
20557 if(this.inputType != 'radio'){
20561 cls : 'roo-hidden-value',
20562 value : this.checked ? this.inputValue : this.valueOff
20567 if (this.weight) { // Validity check?
20568 cfg.cls += " " + this.inputType + "-" + this.weight;
20571 if (this.disabled) {
20572 input.disabled=true;
20576 input.checked = this.checked;
20581 input.name = this.name;
20583 if(this.inputType != 'radio'){
20584 hidden.name = this.name;
20585 input.name = '_hidden_' + this.name;
20590 input.cls += ' input-' + this.size;
20595 ['xs','sm','md','lg'].map(function(size){
20596 if (settings[size]) {
20597 cfg.cls += ' col-' + size + '-' + settings[size];
20601 var inputblock = input;
20603 if (this.before || this.after) {
20606 cls : 'input-group',
20611 inputblock.cn.push({
20613 cls : 'input-group-addon',
20618 inputblock.cn.push(input);
20620 if(this.inputType != 'radio'){
20621 inputblock.cn.push(hidden);
20625 inputblock.cn.push({
20627 cls : 'input-group-addon',
20634 if (align ==='left' && this.fieldLabel.length) {
20635 // Roo.log("left and has label");
20640 cls : 'control-label',
20641 html : this.fieldLabel
20651 if(this.labelWidth > 12){
20652 cfg.cn[0].style = "width: " + this.labelWidth + 'px';
20655 if(this.labelWidth < 13 && this.labelmd == 0){
20656 this.labelmd = this.labelWidth;
20659 if(this.labellg > 0){
20660 cfg.cn[0].cls += ' col-lg-' + this.labellg;
20661 cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
20664 if(this.labelmd > 0){
20665 cfg.cn[0].cls += ' col-md-' + this.labelmd;
20666 cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
20669 if(this.labelsm > 0){
20670 cfg.cn[0].cls += ' col-sm-' + this.labelsm;
20671 cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
20674 if(this.labelxs > 0){
20675 cfg.cn[0].cls += ' col-xs-' + this.labelxs;
20676 cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
20679 } else if ( this.fieldLabel.length) {
20680 // Roo.log(" label");
20684 tag: this.boxLabel ? 'span' : 'label',
20686 cls: 'control-label box-input-label',
20687 //cls : 'input-group-addon',
20688 html : this.fieldLabel
20697 // Roo.log(" no label && no align");
20698 cfg.cn = [ inputblock ] ;
20704 var boxLabelCfg = {
20706 //'for': id, // box label is handled by onclick - so no for...
20708 html: this.boxLabel
20712 boxLabelCfg.tooltip = this.tooltip;
20715 cfg.cn.push(boxLabelCfg);
20718 if(this.inputType != 'radio'){
20719 cfg.cn.push(hidden);
20727 * return the real input element.
20729 inputEl: function ()
20731 return this.el.select('input.roo-' + this.inputType,true).first();
20733 hiddenEl: function ()
20735 return this.el.select('input.roo-hidden-value',true).first();
20738 labelEl: function()
20740 return this.el.select('label.control-label',true).first();
20742 /* depricated... */
20746 return this.labelEl();
20749 boxLabelEl: function()
20751 return this.el.select('label.box-label',true).first();
20754 initEvents : function()
20756 // Roo.bootstrap.CheckBox.superclass.initEvents.call(this);
20758 this.inputEl().on('click', this.onClick, this);
20760 if (this.boxLabel) {
20761 this.el.select('label.box-label',true).first().on('click', this.onClick, this);
20764 this.startValue = this.getValue();
20767 Roo.bootstrap.CheckBox.register(this);
20771 onClick : function(e)
20773 if(this.fireEvent('click', this, e) !== false){
20774 this.setChecked(!this.checked);
20779 setChecked : function(state,suppressEvent)
20781 this.startValue = this.getValue();
20783 if(this.inputType == 'radio'){
20785 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20786 e.dom.checked = false;
20789 this.inputEl().dom.checked = true;
20791 this.inputEl().dom.value = this.inputValue;
20793 if(suppressEvent !== true){
20794 this.fireEvent('check', this, true);
20802 this.checked = state;
20804 this.inputEl().dom.checked = state;
20807 this.hiddenEl().dom.value = state ? this.inputValue : this.valueOff;
20809 if(suppressEvent !== true){
20810 this.fireEvent('check', this, state);
20816 getValue : function()
20818 if(this.inputType == 'radio'){
20819 return this.getGroupValue();
20822 return this.hiddenEl().dom.value;
20826 getGroupValue : function()
20828 if(typeof(this.el.up('form').child('input[name='+this.name+']:checked', true)) == 'undefined'){
20832 return this.el.up('form').child('input[name='+this.name+']:checked', true).value;
20835 setValue : function(v,suppressEvent)
20837 if(this.inputType == 'radio'){
20838 this.setGroupValue(v, suppressEvent);
20842 this.setChecked(((typeof(v) == 'undefined') ? this.checked : (String(v) === String(this.inputValue))), suppressEvent);
20847 setGroupValue : function(v, suppressEvent)
20849 this.startValue = this.getValue();
20851 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20852 e.dom.checked = false;
20854 if(e.dom.value == v){
20855 e.dom.checked = true;
20859 if(suppressEvent !== true){
20860 this.fireEvent('check', this, true);
20868 validate : function()
20870 if(this.getVisibilityEl().hasClass('hidden')){
20876 (this.inputType == 'radio' && this.validateRadio()) ||
20877 (this.inputType == 'checkbox' && this.validateCheckbox())
20883 this.markInvalid();
20887 validateRadio : function()
20889 if(this.getVisibilityEl().hasClass('hidden')){
20893 if(this.allowBlank){
20899 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20900 if(!e.dom.checked){
20912 validateCheckbox : function()
20915 return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
20916 //return (this.getValue() == this.inputValue) ? true : false;
20919 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20927 for(var i in group){
20928 if(group[i].el.isVisible(true)){
20936 for(var i in group){
20941 r = (group[i].getValue() == group[i].inputValue) ? true : false;
20948 * Mark this field as valid
20950 markValid : function()
20954 this.fireEvent('valid', this);
20956 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
20959 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
20966 if(this.inputType == 'radio'){
20967 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
20968 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
20969 e.findParent('.form-group', false, true).addClass(_this.validClass);
20976 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20977 this.el.findParent('.form-group', false, true).addClass(this.validClass);
20981 var group = Roo.bootstrap.CheckBox.get(this.groupId);
20987 for(var i in group){
20988 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
20989 group[i].el.findParent('.form-group', false, true).addClass(this.validClass);
20994 * Mark this field as invalid
20995 * @param {String} msg The validation message
20997 markInvalid : function(msg)
20999 if(this.allowBlank){
21005 this.fireEvent('invalid', this, msg);
21007 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21010 label = Roo.bootstrap.FieldLabel.get(this.groupId + '-group');
21014 label.markInvalid();
21017 if(this.inputType == 'radio'){
21018 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21019 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
21020 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
21027 this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21028 this.el.findParent('.form-group', false, true).addClass(this.invalidClass);
21032 var group = Roo.bootstrap.CheckBox.get(this.groupId);
21038 for(var i in group){
21039 group[i].el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21040 group[i].el.findParent('.form-group', false, true).addClass(this.invalidClass);
21045 clearInvalid : function()
21047 Roo.bootstrap.Input.prototype.clearInvalid.call(this);
21049 // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
21051 var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
21053 if (label && label.iconEl) {
21054 label.iconEl.removeClass(label.validClass);
21055 label.iconEl.removeClass(label.invalidClass);
21059 disable : function()
21061 if(this.inputType != 'radio'){
21062 Roo.bootstrap.CheckBox.superclass.disable.call(this);
21069 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21070 _this.getActionEl().addClass(this.disabledClass);
21071 e.dom.disabled = true;
21075 this.disabled = true;
21076 this.fireEvent("disable", this);
21080 enable : function()
21082 if(this.inputType != 'radio'){
21083 Roo.bootstrap.CheckBox.superclass.enable.call(this);
21090 Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
21091 _this.getActionEl().removeClass(this.disabledClass);
21092 e.dom.disabled = false;
21096 this.disabled = false;
21097 this.fireEvent("enable", this);
21101 setBoxLabel : function(v)
21106 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21112 Roo.apply(Roo.bootstrap.CheckBox, {
21117 * register a CheckBox Group
21118 * @param {Roo.bootstrap.CheckBox} the CheckBox to add
21120 register : function(checkbox)
21122 if(typeof(this.groups[checkbox.groupId]) == 'undefined'){
21123 this.groups[checkbox.groupId] = {};
21126 if(this.groups[checkbox.groupId].hasOwnProperty(checkbox.name)){
21130 this.groups[checkbox.groupId][checkbox.name] = checkbox;
21134 * fetch a CheckBox Group based on the group ID
21135 * @param {string} the group ID
21136 * @returns {Roo.bootstrap.CheckBox} the CheckBox group
21138 get: function(groupId) {
21139 if (typeof(this.groups[groupId]) == 'undefined') {
21143 return this.groups[groupId] ;
21156 * @class Roo.bootstrap.Radio
21157 * @extends Roo.bootstrap.Component
21158 * Bootstrap Radio class
21159 * @cfg {String} boxLabel - the label associated
21160 * @cfg {String} value - the value of radio
21163 * Create a new Radio
21164 * @param {Object} config The config object
21166 Roo.bootstrap.Radio = function(config){
21167 Roo.bootstrap.Radio.superclass.constructor.call(this, config);
21171 Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.Component, {
21177 getAutoCreate : function()
21181 cls : 'form-group radio',
21186 html : this.boxLabel
21194 initEvents : function()
21196 this.parent().register(this);
21198 this.el.on('click', this.onClick, this);
21202 onClick : function(e)
21204 if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
21205 this.setChecked(true);
21209 setChecked : function(state, suppressEvent)
21211 this.parent().setValue(this.value, suppressEvent);
21215 setBoxLabel : function(v)
21220 this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
21235 * @class Roo.bootstrap.SecurePass
21236 * @extends Roo.bootstrap.Input
21237 * Bootstrap SecurePass class
21241 * Create a new SecurePass
21242 * @param {Object} config The config object
21245 Roo.bootstrap.SecurePass = function (config) {
21246 // these go here, so the translation tool can replace them..
21248 PwdEmpty: "Please type a password, and then retype it to confirm.",
21249 PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21250 PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21251 PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21252 IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21253 FNInPwd: "Your password can't contain your first name. Please type a different password.",
21254 LNInPwd: "Your password can't contain your last name. Please type a different password.",
21255 TooWeak: "Your password is Too Weak."
21257 this.meterLabel = "Password strength:";
21258 this.pwdStrengths = ["Too Weak", "Weak", "Medium", "Strong"];
21259 this.meterClass = [
21260 "roo-password-meter-tooweak",
21261 "roo-password-meter-weak",
21262 "roo-password-meter-medium",
21263 "roo-password-meter-strong",
21264 "roo-password-meter-grey"
21269 Roo.bootstrap.SecurePass.superclass.constructor.call(this, config);
21272 Roo.extend(Roo.bootstrap.SecurePass, Roo.bootstrap.Input, {
21274 * @cfg {String/Object} errors A Error spec, or true for a default spec (defaults to
21276 * PwdEmpty: "Please type a password, and then retype it to confirm.",
21277 * PwdShort: "Your password must be at least 6 characters long. Please type a different password.",
21278 * PwdLong: "Your password can't contain more than 16 characters. Please type a different password.",
21279 * PwdBadChar: "The password contains characters that aren't allowed. Please type a different password.",
21280 * IDInPwd: "Your password can't include the part of your ID. Please type a different password.",
21281 * FNInPwd: "Your password can't contain your first name. Please type a different password.",
21282 * LNInPwd: "Your password can't contain your last name. Please type a different password."
21292 * @cfg {String/Object} Label for the strength meter (defaults to
21293 * 'Password strength:')
21298 * @cfg {String/Object} pwdStrengths A pwdStrengths spec, or true for a default spec (defaults to
21299 * ['Weak', 'Medium', 'Strong'])
21302 pwdStrengths: false,
21315 initEvents: function ()
21317 Roo.bootstrap.SecurePass.superclass.initEvents.call(this);
21319 if (this.el.is('input[type=password]') && Roo.isSafari) {
21320 this.el.on('keydown', this.SafariOnKeyDown, this);
21323 this.el.on('keyup', this.checkStrength, this, {buffer: 50});
21326 onRender: function (ct, position)
21328 Roo.bootstrap.SecurePass.superclass.onRender.call(this, ct, position);
21329 this.wrap = this.el.wrap({cls: 'x-form-field-wrap'});
21330 this.trigger = this.wrap.createChild({tag: 'div', cls: 'StrengthMeter ' + this.triggerClass});
21332 this.trigger.createChild({
21337 cls: 'roo-password-meter-grey col-xs-12',
21340 //width: this.meterWidth + 'px'
21344 cls: 'roo-password-meter-text'
21350 if (this.hideTrigger) {
21351 this.trigger.setDisplayed(false);
21353 this.setSize(this.width || '', this.height || '');
21356 onDestroy: function ()
21358 if (this.trigger) {
21359 this.trigger.removeAllListeners();
21360 this.trigger.remove();
21363 this.wrap.remove();
21365 Roo.bootstrap.TriggerField.superclass.onDestroy.call(this);
21368 checkStrength: function ()
21370 var pwd = this.inputEl().getValue();
21371 if (pwd == this._lastPwd) {
21376 if (this.ClientSideStrongPassword(pwd)) {
21378 } else if (this.ClientSideMediumPassword(pwd)) {
21380 } else if (this.ClientSideWeakPassword(pwd)) {
21386 Roo.log('strength1: ' + strength);
21388 //var pm = this.trigger.child('div/div/div').dom;
21389 var pm = this.trigger.child('div/div');
21390 pm.removeClass(this.meterClass);
21391 pm.addClass(this.meterClass[strength]);
21394 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21396 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21398 this._lastPwd = pwd;
21402 Roo.bootstrap.SecurePass.superclass.reset.call(this);
21404 this._lastPwd = '';
21406 var pm = this.trigger.child('div/div');
21407 pm.removeClass(this.meterClass);
21408 pm.addClass('roo-password-meter-grey');
21411 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21414 this.inputEl().dom.type='password';
21417 validateValue: function (value)
21420 if (!Roo.bootstrap.SecurePass.superclass.validateValue.call(this, value)) {
21423 if (value.length == 0) {
21424 if (this.allowBlank) {
21425 this.clearInvalid();
21429 this.markInvalid(this.errors.PwdEmpty);
21430 this.errorMsg = this.errors.PwdEmpty;
21438 if ('[\x21-\x7e]*'.match(value)) {
21439 this.markInvalid(this.errors.PwdBadChar);
21440 this.errorMsg = this.errors.PwdBadChar;
21443 if (value.length < 6) {
21444 this.markInvalid(this.errors.PwdShort);
21445 this.errorMsg = this.errors.PwdShort;
21448 if (value.length > 16) {
21449 this.markInvalid(this.errors.PwdLong);
21450 this.errorMsg = this.errors.PwdLong;
21454 if (this.ClientSideStrongPassword(value)) {
21456 } else if (this.ClientSideMediumPassword(value)) {
21458 } else if (this.ClientSideWeakPassword(value)) {
21465 if (strength < 2) {
21466 //this.markInvalid(this.errors.TooWeak);
21467 this.errorMsg = this.errors.TooWeak;
21472 console.log('strength2: ' + strength);
21474 //var pm = this.trigger.child('div/div/div').dom;
21476 var pm = this.trigger.child('div/div');
21477 pm.removeClass(this.meterClass);
21478 pm.addClass(this.meterClass[strength]);
21480 var pt = this.trigger.child('/div').child('>*[class=roo-password-meter-text]').dom;
21482 pt.innerHTML = this.meterLabel + ' ' + this.pwdStrengths[strength];
21484 this.errorMsg = '';
21488 CharacterSetChecks: function (type)
21491 this.fResult = false;
21494 isctype: function (character, type)
21497 case this.kCapitalLetter:
21498 if (character >= 'A' && character <= 'Z') {
21503 case this.kSmallLetter:
21504 if (character >= 'a' && character <= 'z') {
21510 if (character >= '0' && character <= '9') {
21515 case this.kPunctuation:
21516 if ('!@#$%^&*()_+-=\'";:[{]}|.>,</?`~'.indexOf(character) >= 0) {
21527 IsLongEnough: function (pwd, size)
21529 return !(pwd == null || isNaN(size) || pwd.length < size);
21532 SpansEnoughCharacterSets: function (word, nb)
21534 if (!this.IsLongEnough(word, nb))
21539 var characterSetChecks = new Array(
21540 new this.CharacterSetChecks(this.kCapitalLetter), new this.CharacterSetChecks(this.kSmallLetter),
21541 new this.CharacterSetChecks(this.kDigit), new this.CharacterSetChecks(this.kPunctuation)
21544 for (var index = 0; index < word.length; ++index) {
21545 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21546 if (!characterSetChecks[nCharSet].fResult && this.isctype(word.charAt(index), characterSetChecks[nCharSet].type)) {
21547 characterSetChecks[nCharSet].fResult = true;
21554 for (var nCharSet = 0; nCharSet < characterSetChecks.length; ++nCharSet) {
21555 if (characterSetChecks[nCharSet].fResult) {
21560 if (nCharSets < nb) {
21566 ClientSideStrongPassword: function (pwd)
21568 return this.IsLongEnough(pwd, 8) && this.SpansEnoughCharacterSets(pwd, 3);
21571 ClientSideMediumPassword: function (pwd)
21573 return this.IsLongEnough(pwd, 7) && this.SpansEnoughCharacterSets(pwd, 2);
21576 ClientSideWeakPassword: function (pwd)
21578 return this.IsLongEnough(pwd, 6) || !this.IsLongEnough(pwd, 0);
21581 })//<script type="text/javascript">
21584 * Based Ext JS Library 1.1.1
21585 * Copyright(c) 2006-2007, Ext JS, LLC.
21591 * @class Roo.HtmlEditorCore
21592 * @extends Roo.Component
21593 * Provides a the editing component for the HTML editors in Roo. (bootstrap and Roo.form)
21595 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
21598 Roo.HtmlEditorCore = function(config){
21601 Roo.HtmlEditorCore.superclass.constructor.call(this, config);
21606 * @event initialize
21607 * Fires when the editor is fully initialized (including the iframe)
21608 * @param {Roo.HtmlEditorCore} this
21613 * Fires when the editor is first receives the focus. Any insertion must wait
21614 * until after this event.
21615 * @param {Roo.HtmlEditorCore} this
21619 * @event beforesync
21620 * Fires before the textarea is updated with content from the editor iframe. Return false
21621 * to cancel the sync.
21622 * @param {Roo.HtmlEditorCore} this
21623 * @param {String} html
21627 * @event beforepush
21628 * Fires before the iframe editor is updated with content from the textarea. Return false
21629 * to cancel the push.
21630 * @param {Roo.HtmlEditorCore} this
21631 * @param {String} html
21636 * Fires when the textarea is updated with content from the editor iframe.
21637 * @param {Roo.HtmlEditorCore} this
21638 * @param {String} html
21643 * Fires when the iframe editor is updated with content from the textarea.
21644 * @param {Roo.HtmlEditorCore} this
21645 * @param {String} html
21650 * @event editorevent
21651 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
21652 * @param {Roo.HtmlEditorCore} this
21658 // at this point this.owner is set, so we can start working out the whitelisted / blacklisted elements
21660 // defaults : white / black...
21661 this.applyBlacklists();
21668 Roo.extend(Roo.HtmlEditorCore, Roo.Component, {
21672 * @cfg {Roo.form.HtmlEditor|Roo.bootstrap.HtmlEditor} the owner field
21678 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
21683 * @cfg {Number} height (in pixels)
21687 * @cfg {Number} width (in pixels)
21692 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
21695 stylesheets: false,
21700 // private properties
21701 validationEvent : false,
21703 initialized : false,
21705 sourceEditMode : false,
21706 onFocus : Roo.emptyFn,
21708 hideMode:'offsets',
21712 // blacklist + whitelisted elements..
21719 * Protected method that will not generally be called directly. It
21720 * is called when the editor initializes the iframe with HTML contents. Override this method if you
21721 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
21723 getDocMarkup : function(){
21727 // inherit styels from page...??
21728 if (this.stylesheets === false) {
21730 Roo.get(document.head).select('style').each(function(node) {
21731 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21734 Roo.get(document.head).select('link').each(function(node) {
21735 st += node.dom.outerHTML || new XMLSerializer().serializeToString(node.dom);
21738 } else if (!this.stylesheets.length) {
21740 st = '<style type="text/css">' +
21741 'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21744 st = '<style type="text/css">' +
21749 st += '<style type="text/css">' +
21750 'IMG { cursor: pointer } ' +
21753 var cls = 'roo-htmleditor-body';
21755 if(this.bodyCls.length){
21756 cls += ' ' + this.bodyCls;
21759 return '<html><head>' + st +
21760 //<style type="text/css">' +
21761 //'body{border:0;margin:0;padding:3px;height:98%;cursor:text;}' +
21763 ' </head><body class="' + cls + '"></body></html>';
21767 onRender : function(ct, position)
21770 //Roo.HtmlEditorCore.superclass.onRender.call(this, ct, position);
21771 this.el = this.owner.inputEl ? this.owner.inputEl() : this.owner.el;
21774 this.el.dom.style.border = '0 none';
21775 this.el.dom.setAttribute('tabIndex', -1);
21776 this.el.addClass('x-hidden hide');
21780 if(Roo.isIE){ // fix IE 1px bogus margin
21781 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
21785 this.frameId = Roo.id();
21789 var iframe = this.owner.wrap.createChild({
21791 cls: 'form-control', // bootstrap..
21793 name: this.frameId,
21794 frameBorder : 'no',
21795 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
21800 this.iframe = iframe.dom;
21802 this.assignDocWin();
21804 this.doc.designMode = 'on';
21807 this.doc.write(this.getDocMarkup());
21811 var task = { // must defer to wait for browser to be ready
21813 //console.log("run task?" + this.doc.readyState);
21814 this.assignDocWin();
21815 if(this.doc.body || this.doc.readyState == 'complete'){
21817 this.doc.designMode="on";
21821 Roo.TaskMgr.stop(task);
21822 this.initEditor.defer(10, this);
21829 Roo.TaskMgr.start(task);
21834 onResize : function(w, h)
21836 Roo.log('resize: ' +w + ',' + h );
21837 //Roo.HtmlEditorCore.superclass.onResize.apply(this, arguments);
21841 if(typeof w == 'number'){
21843 this.iframe.style.width = w + 'px';
21845 if(typeof h == 'number'){
21847 this.iframe.style.height = h + 'px';
21849 (this.doc.body || this.doc.documentElement).style.height = (h - (this.iframePad*2)) + 'px';
21856 * Toggles the editor between standard and source edit mode.
21857 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
21859 toggleSourceEdit : function(sourceEditMode){
21861 this.sourceEditMode = sourceEditMode === true;
21863 if(this.sourceEditMode){
21865 Roo.get(this.iframe).addClass(['x-hidden','hide']); //FIXME - what's the BS styles for these
21868 Roo.get(this.iframe).removeClass(['x-hidden','hide']);
21869 //this.iframe.className = '';
21872 //this.setSize(this.owner.wrap.getSize());
21873 //this.fireEvent('editmodechange', this, this.sourceEditMode);
21880 * Protected method that will not generally be called directly. If you need/want
21881 * custom HTML cleanup, this is the method you should override.
21882 * @param {String} html The HTML to be cleaned
21883 * return {String} The cleaned HTML
21885 cleanHtml : function(html){
21886 html = String(html);
21887 if(html.length > 5){
21888 if(Roo.isSafari){ // strip safari nonsense
21889 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
21892 if(html == ' '){
21899 * HTML Editor -> Textarea
21900 * Protected method that will not generally be called directly. Syncs the contents
21901 * of the editor iframe with the textarea.
21903 syncValue : function(){
21904 if(this.initialized){
21905 var bd = (this.doc.body || this.doc.documentElement);
21906 //this.cleanUpPaste(); -- this is done else where and causes havoc..
21907 var html = bd.innerHTML;
21909 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
21910 var m = bs ? bs.match(/text-align:(.*?);/i) : false;
21912 html = '<div style="'+m[0]+'">' + html + '</div>';
21915 html = this.cleanHtml(html);
21916 // fix up the special chars.. normaly like back quotes in word...
21917 // however we do not want to do this with chinese..
21918 html = html.replace(/([\x80-\uffff])/g, function (a, b) {
21919 var cc = b.charCodeAt();
21921 (cc >= 0x4E00 && cc < 0xA000 ) ||
21922 (cc >= 0x3400 && cc < 0x4E00 ) ||
21923 (cc >= 0xf900 && cc < 0xfb00 )
21929 if(this.owner.fireEvent('beforesync', this, html) !== false){
21930 this.el.dom.value = html;
21931 this.owner.fireEvent('sync', this, html);
21937 * Protected method that will not generally be called directly. Pushes the value of the textarea
21938 * into the iframe editor.
21940 pushValue : function(){
21941 if(this.initialized){
21942 var v = this.el.dom.value.trim();
21944 // if(v.length < 1){
21948 if(this.owner.fireEvent('beforepush', this, v) !== false){
21949 var d = (this.doc.body || this.doc.documentElement);
21951 this.cleanUpPaste();
21952 this.el.dom.value = d.innerHTML;
21953 this.owner.fireEvent('push', this, v);
21959 deferFocus : function(){
21960 this.focus.defer(10, this);
21964 focus : function(){
21965 if(this.win && !this.sourceEditMode){
21972 assignDocWin: function()
21974 var iframe = this.iframe;
21977 this.doc = iframe.contentWindow.document;
21978 this.win = iframe.contentWindow;
21980 // if (!Roo.get(this.frameId)) {
21983 // this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21984 // this.win = Roo.get(this.frameId).dom.contentWindow;
21986 if (!Roo.get(this.frameId) && !iframe.contentDocument) {
21990 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
21991 this.win = (iframe.contentWindow || Roo.get(this.frameId).dom.contentWindow);
21996 initEditor : function(){
21997 //console.log("INIT EDITOR");
21998 this.assignDocWin();
22002 this.doc.designMode="on";
22004 this.doc.write(this.getDocMarkup());
22007 var dbody = (this.doc.body || this.doc.documentElement);
22008 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
22009 // this copies styles from the containing element into thsi one..
22010 // not sure why we need all of this..
22011 //var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
22013 //var ss = this.el.getStyles( 'background-image', 'background-repeat');
22014 //ss['background-attachment'] = 'fixed'; // w3c
22015 dbody.bgProperties = 'fixed'; // ie
22016 //Roo.DomHelper.applyStyles(dbody, ss);
22017 Roo.EventManager.on(this.doc, {
22018 //'mousedown': this.onEditorEvent,
22019 'mouseup': this.onEditorEvent,
22020 'dblclick': this.onEditorEvent,
22021 'click': this.onEditorEvent,
22022 'keyup': this.onEditorEvent,
22027 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
22029 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
22030 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
22032 this.initialized = true;
22034 this.owner.fireEvent('initialize', this);
22039 onDestroy : function(){
22045 //for (var i =0; i < this.toolbars.length;i++) {
22046 // // fixme - ask toolbars for heights?
22047 // this.toolbars[i].onDestroy();
22050 //this.wrap.dom.innerHTML = '';
22051 //this.wrap.remove();
22056 onFirstFocus : function(){
22058 this.assignDocWin();
22061 this.activated = true;
22064 if(Roo.isGecko){ // prevent silly gecko errors
22066 var s = this.win.getSelection();
22067 if(!s.focusNode || s.focusNode.nodeType != 3){
22068 var r = s.getRangeAt(0);
22069 r.selectNodeContents((this.doc.body || this.doc.documentElement));
22074 this.execCmd('useCSS', true);
22075 this.execCmd('styleWithCSS', false);
22078 this.owner.fireEvent('activate', this);
22082 adjustFont: function(btn){
22083 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
22084 //if(Roo.isSafari){ // safari
22087 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
22088 if(Roo.isSafari){ // safari
22089 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
22090 v = (v < 10) ? 10 : v;
22091 v = (v > 48) ? 48 : v;
22092 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
22097 v = Math.max(1, v+adjust);
22099 this.execCmd('FontSize', v );
22102 onEditorEvent : function(e)
22104 this.owner.fireEvent('editorevent', this, e);
22105 // this.updateToolbar();
22106 this.syncValue(); //we can not sync so often.. sync cleans, so this breaks stuff
22109 insertTag : function(tg)
22111 // could be a bit smarter... -> wrap the current selected tRoo..
22112 if (tg.toLowerCase() == 'span' || tg.toLowerCase() == 'code') {
22114 range = this.createRange(this.getSelection());
22115 var wrappingNode = this.doc.createElement(tg.toLowerCase());
22116 wrappingNode.appendChild(range.extractContents());
22117 range.insertNode(wrappingNode);
22124 this.execCmd("formatblock", tg);
22128 insertText : function(txt)
22132 var range = this.createRange();
22133 range.deleteContents();
22134 //alert(Sender.getAttribute('label'));
22136 range.insertNode(this.doc.createTextNode(txt));
22142 * Executes a Midas editor command on the editor document and performs necessary focus and
22143 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
22144 * @param {String} cmd The Midas command
22145 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22147 relayCmd : function(cmd, value){
22149 this.execCmd(cmd, value);
22150 this.owner.fireEvent('editorevent', this);
22151 //this.updateToolbar();
22152 this.owner.deferFocus();
22156 * Executes a Midas editor command directly on the editor document.
22157 * For visual commands, you should use {@link #relayCmd} instead.
22158 * <b>This should only be called after the editor is initialized.</b>
22159 * @param {String} cmd The Midas command
22160 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
22162 execCmd : function(cmd, value){
22163 this.doc.execCommand(cmd, false, value === undefined ? null : value);
22170 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
22172 * @param {String} text | dom node..
22174 insertAtCursor : function(text)
22177 if(!this.activated){
22183 var r = this.doc.selection.createRange();
22194 if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
22198 // from jquery ui (MIT licenced)
22200 var win = this.win;
22202 if (win.getSelection && win.getSelection().getRangeAt) {
22203 range = win.getSelection().getRangeAt(0);
22204 node = typeof(text) == 'string' ? range.createContextualFragment(text) : text;
22205 range.insertNode(node);
22206 } else if (win.document.selection && win.document.selection.createRange) {
22207 // no firefox support
22208 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22209 win.document.selection.createRange().pasteHTML(txt);
22211 // no firefox support
22212 var txt = typeof(text) == 'string' ? text : text.outerHTML;
22213 this.execCmd('InsertHTML', txt);
22222 mozKeyPress : function(e){
22224 var c = e.getCharCode(), cmd;
22227 c = String.fromCharCode(c).toLowerCase();
22241 this.cleanUpPaste.defer(100, this);
22249 e.preventDefault();
22257 fixKeys : function(){ // load time branching for fastest keydown performance
22259 return function(e){
22260 var k = e.getKey(), r;
22263 r = this.doc.selection.createRange();
22266 r.pasteHTML('    ');
22273 r = this.doc.selection.createRange();
22275 var target = r.parentElement();
22276 if(!target || target.tagName.toLowerCase() != 'li'){
22278 r.pasteHTML('<br />');
22284 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22285 this.cleanUpPaste.defer(100, this);
22291 }else if(Roo.isOpera){
22292 return function(e){
22293 var k = e.getKey();
22297 this.execCmd('InsertHTML','    ');
22300 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22301 this.cleanUpPaste.defer(100, this);
22306 }else if(Roo.isSafari){
22307 return function(e){
22308 var k = e.getKey();
22312 this.execCmd('InsertText','\t');
22316 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
22317 this.cleanUpPaste.defer(100, this);
22325 getAllAncestors: function()
22327 var p = this.getSelectedNode();
22330 a.push(p); // push blank onto stack..
22331 p = this.getParentElement();
22335 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
22339 a.push(this.doc.body);
22343 lastSelNode : false,
22346 getSelection : function()
22348 this.assignDocWin();
22349 return Roo.isIE ? this.doc.selection : this.win.getSelection();
22352 getSelectedNode: function()
22354 // this may only work on Gecko!!!
22356 // should we cache this!!!!
22361 var range = this.createRange(this.getSelection()).cloneRange();
22364 var parent = range.parentElement();
22366 var testRange = range.duplicate();
22367 testRange.moveToElementText(parent);
22368 if (testRange.inRange(range)) {
22371 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
22374 parent = parent.parentElement;
22379 // is ancestor a text element.
22380 var ac = range.commonAncestorContainer;
22381 if (ac.nodeType == 3) {
22382 ac = ac.parentNode;
22385 var ar = ac.childNodes;
22388 var other_nodes = [];
22389 var has_other_nodes = false;
22390 for (var i=0;i<ar.length;i++) {
22391 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
22394 // fullly contained node.
22396 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
22401 // probably selected..
22402 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
22403 other_nodes.push(ar[i]);
22407 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
22412 has_other_nodes = true;
22414 if (!nodes.length && other_nodes.length) {
22415 nodes= other_nodes;
22417 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
22423 createRange: function(sel)
22425 // this has strange effects when using with
22426 // top toolbar - not sure if it's a great idea.
22427 //this.editor.contentWindow.focus();
22428 if (typeof sel != "undefined") {
22430 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
22432 return this.doc.createRange();
22435 return this.doc.createRange();
22438 getParentElement: function()
22441 this.assignDocWin();
22442 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
22444 var range = this.createRange(sel);
22447 var p = range.commonAncestorContainer;
22448 while (p.nodeType == 3) { // text node
22459 * Range intersection.. the hard stuff...
22463 * [ -- selected range --- ]
22467 * if end is before start or hits it. fail.
22468 * if start is after end or hits it fail.
22470 * if either hits (but other is outside. - then it's not
22476 // @see http://www.thismuchiknow.co.uk/?p=64.
22477 rangeIntersectsNode : function(range, node)
22479 var nodeRange = node.ownerDocument.createRange();
22481 nodeRange.selectNode(node);
22483 nodeRange.selectNodeContents(node);
22486 var rangeStartRange = range.cloneRange();
22487 rangeStartRange.collapse(true);
22489 var rangeEndRange = range.cloneRange();
22490 rangeEndRange.collapse(false);
22492 var nodeStartRange = nodeRange.cloneRange();
22493 nodeStartRange.collapse(true);
22495 var nodeEndRange = nodeRange.cloneRange();
22496 nodeEndRange.collapse(false);
22498 return rangeStartRange.compareBoundaryPoints(
22499 Range.START_TO_START, nodeEndRange) == -1 &&
22500 rangeEndRange.compareBoundaryPoints(
22501 Range.START_TO_START, nodeStartRange) == 1;
22505 rangeCompareNode : function(range, node)
22507 var nodeRange = node.ownerDocument.createRange();
22509 nodeRange.selectNode(node);
22511 nodeRange.selectNodeContents(node);
22515 range.collapse(true);
22517 nodeRange.collapse(true);
22519 var ss = range.compareBoundaryPoints( Range.START_TO_START, nodeRange);
22520 var ee = range.compareBoundaryPoints( Range.END_TO_END, nodeRange);
22522 //Roo.log(node.tagName + ': ss='+ss +', ee='+ee)
22524 var nodeIsBefore = ss == 1;
22525 var nodeIsAfter = ee == -1;
22527 if (nodeIsBefore && nodeIsAfter) {
22530 if (!nodeIsBefore && nodeIsAfter) {
22531 return 1; //right trailed.
22534 if (nodeIsBefore && !nodeIsAfter) {
22535 return 2; // left trailed.
22541 // private? - in a new class?
22542 cleanUpPaste : function()
22544 // cleans up the whole document..
22545 Roo.log('cleanuppaste');
22547 this.cleanUpChildren(this.doc.body);
22548 var clean = this.cleanWordChars(this.doc.body.innerHTML);
22549 if (clean != this.doc.body.innerHTML) {
22550 this.doc.body.innerHTML = clean;
22555 cleanWordChars : function(input) {// change the chars to hex code
22556 var he = Roo.HtmlEditorCore;
22558 var output = input;
22559 Roo.each(he.swapCodes, function(sw) {
22560 var swapper = new RegExp("\\u" + sw[0].toString(16), "g"); // hex codes
22562 output = output.replace(swapper, sw[1]);
22569 cleanUpChildren : function (n)
22571 if (!n.childNodes.length) {
22574 for (var i = n.childNodes.length-1; i > -1 ; i--) {
22575 this.cleanUpChild(n.childNodes[i]);
22582 cleanUpChild : function (node)
22585 //console.log(node);
22586 if (node.nodeName == "#text") {
22587 // clean up silly Windows -- stuff?
22590 if (node.nodeName == "#comment") {
22591 node.parentNode.removeChild(node);
22592 // clean up silly Windows -- stuff?
22595 var lcname = node.tagName.toLowerCase();
22596 // we ignore whitelists... ?? = not really the way to go, but we probably have not got a full
22597 // whitelist of tags..
22599 if (this.black.indexOf(lcname) > -1 && this.clearUp ) {
22601 node.parentNode.removeChild(node);
22606 var remove_keep_children= Roo.HtmlEditorCore.remove.indexOf(node.tagName.toLowerCase()) > -1;
22608 // remove <a name=....> as rendering on yahoo mailer is borked with this.
22609 // this will have to be flaged elsewhere - perhaps ablack=name... on the mailer..
22611 //if (node.tagName.toLowerCase() == 'a' && !node.hasAttribute('href')) {
22612 // remove_keep_children = true;
22615 if (remove_keep_children) {
22616 this.cleanUpChildren(node);
22617 // inserts everything just before this node...
22618 while (node.childNodes.length) {
22619 var cn = node.childNodes[0];
22620 node.removeChild(cn);
22621 node.parentNode.insertBefore(cn, node);
22623 node.parentNode.removeChild(node);
22627 if (!node.attributes || !node.attributes.length) {
22628 this.cleanUpChildren(node);
22632 function cleanAttr(n,v)
22635 if (v.match(/^\./) || v.match(/^\//)) {
22638 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/) || v.match(/^ftp:/)) {
22641 if (v.match(/^#/)) {
22644 // Roo.log("(REMOVE TAG)"+ node.tagName +'.' + n + '=' + v);
22645 node.removeAttribute(n);
22649 var cwhite = this.cwhite;
22650 var cblack = this.cblack;
22652 function cleanStyle(n,v)
22654 if (v.match(/expression/)) { //XSS?? should we even bother..
22655 node.removeAttribute(n);
22659 var parts = v.split(/;/);
22662 Roo.each(parts, function(p) {
22663 p = p.replace(/^\s+/g,'').replace(/\s+$/g,'');
22667 var l = p.split(':').shift().replace(/\s+/g,'');
22668 l = l.replace(/^\s+/g,'').replace(/\s+$/g,'');
22670 if ( cwhite.length && cblack.indexOf(l) > -1) {
22671 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22672 //node.removeAttribute(n);
22676 // only allow 'c whitelisted system attributes'
22677 if ( cwhite.length && cwhite.indexOf(l) < 0) {
22678 // Roo.log('(REMOVE CSS)' + node.tagName +'.' + n + ':'+l + '=' + v);
22679 //node.removeAttribute(n);
22689 if (clean.length) {
22690 node.setAttribute(n, clean.join(';'));
22692 node.removeAttribute(n);
22698 for (var i = node.attributes.length-1; i > -1 ; i--) {
22699 var a = node.attributes[i];
22702 if (a.name.toLowerCase().substr(0,2)=='on') {
22703 node.removeAttribute(a.name);
22706 if (Roo.HtmlEditorCore.ablack.indexOf(a.name.toLowerCase()) > -1) {
22707 node.removeAttribute(a.name);
22710 if (Roo.HtmlEditorCore.aclean.indexOf(a.name.toLowerCase()) > -1) {
22711 cleanAttr(a.name,a.value); // fixme..
22714 if (a.name == 'style') {
22715 cleanStyle(a.name,a.value);
22718 /// clean up MS crap..
22719 // tecnically this should be a list of valid class'es..
22722 if (a.name == 'class') {
22723 if (a.value.match(/^Mso/)) {
22724 node.className = '';
22727 if (a.value.match(/^body$/)) {
22728 node.className = '';
22739 this.cleanUpChildren(node);
22745 * Clean up MS wordisms...
22747 cleanWord : function(node)
22752 this.cleanWord(this.doc.body);
22755 if (node.nodeName == "#text") {
22756 // clean up silly Windows -- stuff?
22759 if (node.nodeName == "#comment") {
22760 node.parentNode.removeChild(node);
22761 // clean up silly Windows -- stuff?
22765 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
22766 node.parentNode.removeChild(node);
22770 // remove - but keep children..
22771 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|font)/)) {
22772 while (node.childNodes.length) {
22773 var cn = node.childNodes[0];
22774 node.removeChild(cn);
22775 node.parentNode.insertBefore(cn, node);
22777 node.parentNode.removeChild(node);
22778 this.iterateChildren(node, this.cleanWord);
22782 if (node.className.length) {
22784 var cn = node.className.split(/\W+/);
22786 Roo.each(cn, function(cls) {
22787 if (cls.match(/Mso[a-zA-Z]+/)) {
22792 node.className = cna.length ? cna.join(' ') : '';
22794 node.removeAttribute("class");
22798 if (node.hasAttribute("lang")) {
22799 node.removeAttribute("lang");
22802 if (node.hasAttribute("style")) {
22804 var styles = node.getAttribute("style").split(";");
22806 Roo.each(styles, function(s) {
22807 if (!s.match(/:/)) {
22810 var kv = s.split(":");
22811 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
22814 // what ever is left... we allow.
22817 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22818 if (!nstyle.length) {
22819 node.removeAttribute('style');
22822 this.iterateChildren(node, this.cleanWord);
22828 * iterateChildren of a Node, calling fn each time, using this as the scole..
22829 * @param {DomNode} node node to iterate children of.
22830 * @param {Function} fn method of this class to call on each item.
22832 iterateChildren : function(node, fn)
22834 if (!node.childNodes.length) {
22837 for (var i = node.childNodes.length-1; i > -1 ; i--) {
22838 fn.call(this, node.childNodes[i])
22844 * cleanTableWidths.
22846 * Quite often pasting from word etc.. results in tables with column and widths.
22847 * This does not work well on fluid HTML layouts - like emails. - so this code should hunt an destroy them..
22850 cleanTableWidths : function(node)
22855 this.cleanTableWidths(this.doc.body);
22860 if (node.nodeName == "#text" || node.nodeName == "#comment") {
22863 Roo.log(node.tagName);
22864 if (!node.tagName.toLowerCase().match(/^(table|td|tr)$/)) {
22865 this.iterateChildren(node, this.cleanTableWidths);
22868 if (node.hasAttribute('width')) {
22869 node.removeAttribute('width');
22873 if (node.hasAttribute("style")) {
22876 var styles = node.getAttribute("style").split(";");
22878 Roo.each(styles, function(s) {
22879 if (!s.match(/:/)) {
22882 var kv = s.split(":");
22883 if (kv[0].match(/^\s*(width|min-width)\s*$/)) {
22886 // what ever is left... we allow.
22889 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
22890 if (!nstyle.length) {
22891 node.removeAttribute('style');
22895 this.iterateChildren(node, this.cleanTableWidths);
22903 domToHTML : function(currentElement, depth, nopadtext) {
22905 depth = depth || 0;
22906 nopadtext = nopadtext || false;
22908 if (!currentElement) {
22909 return this.domToHTML(this.doc.body);
22912 //Roo.log(currentElement);
22914 var allText = false;
22915 var nodeName = currentElement.nodeName;
22916 var tagName = Roo.util.Format.htmlEncode(currentElement.tagName);
22918 if (nodeName == '#text') {
22920 return nopadtext ? currentElement.nodeValue : currentElement.nodeValue.trim();
22925 if (nodeName != 'BODY') {
22928 // Prints the node tagName, such as <A>, <IMG>, etc
22931 for(i = 0; i < currentElement.attributes.length;i++) {
22933 var aname = currentElement.attributes.item(i).name;
22934 if (!currentElement.attributes.item(i).value.length) {
22937 attr.push(aname + '="' + Roo.util.Format.htmlEncode(currentElement.attributes.item(i).value) + '"' );
22940 ret = "<"+currentElement.tagName+ ( attr.length ? (' ' + attr.join(' ') ) : '') + ">";
22949 if (['IMG', 'BR', 'HR', 'INPUT'].indexOf(tagName) > -1) {
22952 if (['PRE', 'TEXTAREA', 'TD', 'A', 'SPAN'].indexOf(tagName) > -1) { // or code?
22957 // Traverse the tree
22959 var currentElementChild = currentElement.childNodes.item(i);
22960 var allText = true;
22961 var innerHTML = '';
22963 while (currentElementChild) {
22964 // Formatting code (indent the tree so it looks nice on the screen)
22965 var nopad = nopadtext;
22966 if (lastnode == 'SPAN') {
22970 if (currentElementChild.nodeName == '#text') {
22971 var toadd = Roo.util.Format.htmlEncode(currentElementChild.nodeValue);
22972 toadd = nopadtext ? toadd : toadd.trim();
22973 if (!nopad && toadd.length > 80) {
22974 innerHTML += "\n" + (new Array( depth + 1 )).join( " " );
22976 innerHTML += toadd;
22979 currentElementChild = currentElement.childNodes.item(i);
22985 innerHTML += nopad ? '' : "\n" + (new Array( depth + 1 )).join( " " );
22987 // Recursively traverse the tree structure of the child node
22988 innerHTML += this.domToHTML(currentElementChild, depth+1, nopadtext);
22989 lastnode = currentElementChild.nodeName;
22991 currentElementChild=currentElement.childNodes.item(i);
22997 // The remaining code is mostly for formatting the tree
22998 ret+= nopadtext ? '' : "\n" + (new Array( depth )).join( " " );
23003 ret+= "</"+tagName+">";
23009 applyBlacklists : function()
23011 var w = typeof(this.owner.white) != 'undefined' && this.owner.white ? this.owner.white : [];
23012 var b = typeof(this.owner.black) != 'undefined' && this.owner.black ? this.owner.black : [];
23016 Roo.each(Roo.HtmlEditorCore.white, function(tag) {
23017 if (b.indexOf(tag) > -1) {
23020 this.white.push(tag);
23024 Roo.each(w, function(tag) {
23025 if (b.indexOf(tag) > -1) {
23028 if (this.white.indexOf(tag) > -1) {
23031 this.white.push(tag);
23036 Roo.each(Roo.HtmlEditorCore.black, function(tag) {
23037 if (w.indexOf(tag) > -1) {
23040 this.black.push(tag);
23044 Roo.each(b, function(tag) {
23045 if (w.indexOf(tag) > -1) {
23048 if (this.black.indexOf(tag) > -1) {
23051 this.black.push(tag);
23056 w = typeof(this.owner.cwhite) != 'undefined' && this.owner.cwhite ? this.owner.cwhite : [];
23057 b = typeof(this.owner.cblack) != 'undefined' && this.owner.cblack ? this.owner.cblack : [];
23061 Roo.each(Roo.HtmlEditorCore.cwhite, function(tag) {
23062 if (b.indexOf(tag) > -1) {
23065 this.cwhite.push(tag);
23069 Roo.each(w, function(tag) {
23070 if (b.indexOf(tag) > -1) {
23073 if (this.cwhite.indexOf(tag) > -1) {
23076 this.cwhite.push(tag);
23081 Roo.each(Roo.HtmlEditorCore.cblack, function(tag) {
23082 if (w.indexOf(tag) > -1) {
23085 this.cblack.push(tag);
23089 Roo.each(b, function(tag) {
23090 if (w.indexOf(tag) > -1) {
23093 if (this.cblack.indexOf(tag) > -1) {
23096 this.cblack.push(tag);
23101 setStylesheets : function(stylesheets)
23103 if(typeof(stylesheets) == 'string'){
23104 Roo.get(this.iframe.contentDocument.head).createChild({
23106 rel : 'stylesheet',
23115 Roo.each(stylesheets, function(s) {
23120 Roo.get(_this.iframe.contentDocument.head).createChild({
23122 rel : 'stylesheet',
23131 removeStylesheets : function()
23135 Roo.each(Roo.get(_this.iframe.contentDocument.head).select('link[rel=stylesheet]', true).elements, function(s){
23140 setStyle : function(style)
23142 Roo.get(this.iframe.contentDocument.head).createChild({
23151 // hide stuff that is not compatible
23165 * @event specialkey
23169 * @cfg {String} fieldClass @hide
23172 * @cfg {String} focusClass @hide
23175 * @cfg {String} autoCreate @hide
23178 * @cfg {String} inputType @hide
23181 * @cfg {String} invalidClass @hide
23184 * @cfg {String} invalidText @hide
23187 * @cfg {String} msgFx @hide
23190 * @cfg {String} validateOnBlur @hide
23194 Roo.HtmlEditorCore.white = [
23195 'area', 'br', 'img', 'input', 'hr', 'wbr',
23197 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
23198 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
23199 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
23200 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
23201 'table', 'ul', 'xmp',
23203 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
23206 'dir', 'menu', 'ol', 'ul', 'dl',
23212 Roo.HtmlEditorCore.black = [
23213 // 'embed', 'object', // enable - backend responsiblity to clean thiese
23215 'base', 'basefont', 'bgsound', 'blink', 'body',
23216 'frame', 'frameset', 'head', 'html', 'ilayer',
23217 'iframe', 'layer', 'link', 'meta', 'object',
23218 'script', 'style' ,'title', 'xml' // clean later..
23220 Roo.HtmlEditorCore.clean = [
23221 'script', 'style', 'title', 'xml'
23223 Roo.HtmlEditorCore.remove = [
23228 Roo.HtmlEditorCore.ablack = [
23232 Roo.HtmlEditorCore.aclean = [
23233 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
23237 Roo.HtmlEditorCore.pwhite= [
23238 'http', 'https', 'mailto'
23241 // white listed style attributes.
23242 Roo.HtmlEditorCore.cwhite= [
23243 // 'text-align', /// default is to allow most things..
23249 // black listed style attributes.
23250 Roo.HtmlEditorCore.cblack= [
23251 // 'font-size' -- this can be set by the project
23255 Roo.HtmlEditorCore.swapCodes =[
23274 * @class Roo.bootstrap.HtmlEditor
23275 * @extends Roo.bootstrap.TextArea
23276 * Bootstrap HtmlEditor class
23279 * Create a new HtmlEditor
23280 * @param {Object} config The config object
23283 Roo.bootstrap.HtmlEditor = function(config){
23284 Roo.bootstrap.HtmlEditor.superclass.constructor.call(this, config);
23285 if (!this.toolbars) {
23286 this.toolbars = [];
23289 this.editorcore = new Roo.HtmlEditorCore(Roo.apply({ owner : this} , config));
23292 * @event initialize
23293 * Fires when the editor is fully initialized (including the iframe)
23294 * @param {HtmlEditor} this
23299 * Fires when the editor is first receives the focus. Any insertion must wait
23300 * until after this event.
23301 * @param {HtmlEditor} this
23305 * @event beforesync
23306 * Fires before the textarea is updated with content from the editor iframe. Return false
23307 * to cancel the sync.
23308 * @param {HtmlEditor} this
23309 * @param {String} html
23313 * @event beforepush
23314 * Fires before the iframe editor is updated with content from the textarea. Return false
23315 * to cancel the push.
23316 * @param {HtmlEditor} this
23317 * @param {String} html
23322 * Fires when the textarea is updated with content from the editor iframe.
23323 * @param {HtmlEditor} this
23324 * @param {String} html
23329 * Fires when the iframe editor is updated with content from the textarea.
23330 * @param {HtmlEditor} this
23331 * @param {String} html
23335 * @event editmodechange
23336 * Fires when the editor switches edit modes
23337 * @param {HtmlEditor} this
23338 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
23340 editmodechange: true,
23342 * @event editorevent
23343 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
23344 * @param {HtmlEditor} this
23348 * @event firstfocus
23349 * Fires when on first focus - needed by toolbars..
23350 * @param {HtmlEditor} this
23355 * Auto save the htmlEditor value as a file into Events
23356 * @param {HtmlEditor} this
23360 * @event savedpreview
23361 * preview the saved version of htmlEditor
23362 * @param {HtmlEditor} this
23369 Roo.extend(Roo.bootstrap.HtmlEditor, Roo.bootstrap.TextArea, {
23373 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
23378 * @cfg {Array} buttons Array of toolbar's buttons. - defaults to empty
23383 * @cfg {String} resizable 's' or 'se' or 'e' - wrapps the element in a
23388 * @cfg {Number} height (in pixels)
23392 * @cfg {Number} width (in pixels)
23397 * @cfg {Array} stylesheets url of stylesheets. set to [] to disable stylesheets.
23400 stylesheets: false,
23405 // private properties
23406 validationEvent : false,
23408 initialized : false,
23411 onFocus : Roo.emptyFn,
23413 hideMode:'offsets',
23415 tbContainer : false,
23419 toolbarContainer :function() {
23420 return this.wrap.select('.x-html-editor-tb',true).first();
23424 * Protected method that will not generally be called directly. It
23425 * is called when the editor creates its toolbar. Override this method if you need to
23426 * add custom toolbar buttons.
23427 * @param {HtmlEditor} editor
23429 createToolbar : function(){
23430 Roo.log('renewing');
23431 Roo.log("create toolbars");
23433 this.toolbars = [ new Roo.bootstrap.htmleditor.ToolbarStandard({editor: this} ) ];
23434 this.toolbars[0].render(this.toolbarContainer());
23438 // if (!editor.toolbars || !editor.toolbars.length) {
23439 // editor.toolbars = [ new Roo.bootstrap.HtmlEditor.ToolbarStandard() ]; // can be empty?
23442 // for (var i =0 ; i < editor.toolbars.length;i++) {
23443 // editor.toolbars[i] = Roo.factory(
23444 // typeof(editor.toolbars[i]) == 'string' ?
23445 // { xtype: editor.toolbars[i]} : editor.toolbars[i],
23446 // Roo.bootstrap.HtmlEditor);
23447 // editor.toolbars[i].init(editor);
23453 onRender : function(ct, position)
23455 // Roo.log("Call onRender: " + this.xtype);
23457 Roo.bootstrap.HtmlEditor.superclass.onRender.call(this, ct, position);
23459 this.wrap = this.inputEl().wrap({
23460 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
23463 this.editorcore.onRender(ct, position);
23465 if (this.resizable) {
23466 this.resizeEl = new Roo.Resizable(this.wrap, {
23470 minHeight : this.height,
23471 height: this.height,
23472 handles : this.resizable,
23475 resize : function(r, w, h) {
23476 _t.onResize(w,h); // -something
23482 this.createToolbar(this);
23485 if(!this.width && this.resizable){
23486 this.setSize(this.wrap.getSize());
23488 if (this.resizeEl) {
23489 this.resizeEl.resizeTo.defer(100, this.resizeEl,[ this.width,this.height ] );
23490 // should trigger onReize..
23496 onResize : function(w, h)
23498 Roo.log('resize: ' +w + ',' + h );
23499 Roo.bootstrap.HtmlEditor.superclass.onResize.apply(this, arguments);
23503 if(this.inputEl() ){
23504 if(typeof w == 'number'){
23505 var aw = w - this.wrap.getFrameWidth('lr');
23506 this.inputEl().setWidth(this.adjustWidth('textarea', aw));
23509 if(typeof h == 'number'){
23510 var tbh = -11; // fixme it needs to tool bar size!
23511 for (var i =0; i < this.toolbars.length;i++) {
23512 // fixme - ask toolbars for heights?
23513 tbh += this.toolbars[i].el.getHeight();
23514 //if (this.toolbars[i].footer) {
23515 // tbh += this.toolbars[i].footer.el.getHeight();
23523 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23524 ah -= 5; // knock a few pixes off for look..
23525 this.inputEl().setHeight(this.adjustWidth('textarea', ah));
23529 Roo.log('onResize:' + [w,h,ew,eh].join(',') );
23530 this.editorcore.onResize(ew,eh);
23535 * Toggles the editor between standard and source edit mode.
23536 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23538 toggleSourceEdit : function(sourceEditMode)
23540 this.editorcore.toggleSourceEdit(sourceEditMode);
23542 if(this.editorcore.sourceEditMode){
23543 Roo.log('editor - showing textarea');
23546 // Roo.log(this.syncValue());
23548 this.inputEl().removeClass(['hide', 'x-hidden']);
23549 this.inputEl().dom.removeAttribute('tabIndex');
23550 this.inputEl().focus();
23552 Roo.log('editor - hiding textarea');
23554 // Roo.log(this.pushValue());
23557 this.inputEl().addClass(['hide', 'x-hidden']);
23558 this.inputEl().dom.setAttribute('tabIndex', -1);
23559 //this.deferFocus();
23562 if(this.resizable){
23563 this.setSize(this.wrap.getSize());
23566 this.fireEvent('editmodechange', this, this.editorcore.sourceEditMode);
23569 // private (for BoxComponent)
23570 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23572 // private (for BoxComponent)
23573 getResizeEl : function(){
23577 // private (for BoxComponent)
23578 getPositionEl : function(){
23583 initEvents : function(){
23584 this.originalValue = this.getValue();
23588 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23591 // markInvalid : Roo.emptyFn,
23593 // * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23596 // clearInvalid : Roo.emptyFn,
23598 setValue : function(v){
23599 Roo.bootstrap.HtmlEditor.superclass.setValue.call(this, v);
23600 this.editorcore.pushValue();
23605 deferFocus : function(){
23606 this.focus.defer(10, this);
23610 focus : function(){
23611 this.editorcore.focus();
23617 onDestroy : function(){
23623 for (var i =0; i < this.toolbars.length;i++) {
23624 // fixme - ask toolbars for heights?
23625 this.toolbars[i].onDestroy();
23628 this.wrap.dom.innerHTML = '';
23629 this.wrap.remove();
23634 onFirstFocus : function(){
23635 //Roo.log("onFirstFocus");
23636 this.editorcore.onFirstFocus();
23637 for (var i =0; i < this.toolbars.length;i++) {
23638 this.toolbars[i].onFirstFocus();
23644 syncValue : function()
23646 this.editorcore.syncValue();
23649 pushValue : function()
23651 this.editorcore.pushValue();
23655 // hide stuff that is not compatible
23669 * @event specialkey
23673 * @cfg {String} fieldClass @hide
23676 * @cfg {String} focusClass @hide
23679 * @cfg {String} autoCreate @hide
23682 * @cfg {String} inputType @hide
23685 * @cfg {String} invalidClass @hide
23688 * @cfg {String} invalidText @hide
23691 * @cfg {String} msgFx @hide
23694 * @cfg {String} validateOnBlur @hide
23703 Roo.namespace('Roo.bootstrap.htmleditor');
23705 * @class Roo.bootstrap.HtmlEditorToolbar1
23710 new Roo.bootstrap.HtmlEditor({
23713 new Roo.bootstrap.HtmlEditorToolbar1({
23714 disable : { fonts: 1 , format: 1, ..., ... , ...],
23720 * @cfg {Object} disable List of elements to disable..
23721 * @cfg {Array} btns List of additional buttons.
23725 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
23728 Roo.bootstrap.htmleditor.ToolbarStandard = function(config)
23731 Roo.apply(this, config);
23733 // default disabled, based on 'good practice'..
23734 this.disable = this.disable || {};
23735 Roo.applyIf(this.disable, {
23738 specialElements : true
23740 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.constructor.call(this, config);
23742 this.editor = config.editor;
23743 this.editorcore = config.editor.editorcore;
23745 this.buttons = new Roo.util.MixedCollection(false, function(o) { return o.cmd; });
23747 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
23748 // dont call parent... till later.
23750 Roo.extend(Roo.bootstrap.htmleditor.ToolbarStandard, Roo.bootstrap.NavSimplebar, {
23755 editorcore : false,
23760 "h1","h2","h3","h4","h5","h6",
23762 "abbr", "acronym", "address", "cite", "samp", "var",
23766 onRender : function(ct, position)
23768 // Roo.log("Call onRender: " + this.xtype);
23770 Roo.bootstrap.htmleditor.ToolbarStandard.superclass.onRender.call(this, ct, position);
23772 this.el.dom.style.marginBottom = '0';
23774 var editorcore = this.editorcore;
23775 var editor= this.editor;
23778 var btn = function(id,cmd , toggle, handler, html){
23780 var event = toggle ? 'toggle' : 'click';
23785 xns: Roo.bootstrap,
23788 enableToggle:toggle !== false,
23790 pressed : toggle ? false : null,
23793 a.listeners[toggle ? 'toggle' : 'click'] = function() {
23794 handler ? handler.call(_this,this) :_this.onBtnClick.call(_this, cmd || id);
23800 // var cb_box = function...
23805 xns: Roo.bootstrap,
23806 glyphicon : 'font',
23810 xns: Roo.bootstrap,
23814 Roo.each(this.formats, function(f) {
23815 style.menu.items.push({
23817 xns: Roo.bootstrap,
23818 html : '<'+ f+' style="margin:2px">'+f +'</'+ f+'>',
23823 editorcore.insertTag(this.tagname);
23830 children.push(style);
23832 btn('bold',false,true);
23833 btn('italic',false,true);
23834 btn('align-left', 'justifyleft',true);
23835 btn('align-center', 'justifycenter',true);
23836 btn('align-right' , 'justifyright',true);
23837 btn('link', false, false, function(btn) {
23838 //Roo.log("create link?");
23839 var url = prompt(this.createLinkText, this.defaultLinkValue);
23840 if(url && url != 'http:/'+'/'){
23841 this.editorcore.relayCmd('createlink', url);
23844 btn('list','insertunorderedlist',true);
23845 btn('pencil', false,true, function(btn){
23847 this.toggleSourceEdit(btn.pressed);
23850 if (this.editor.btns.length > 0) {
23851 for (var i = 0; i<this.editor.btns.length; i++) {
23852 children.push(this.editor.btns[i]);
23860 xns: Roo.bootstrap,
23865 xns: Roo.bootstrap,
23870 cog.menu.items.push({
23872 xns: Roo.bootstrap,
23873 html : Clean styles,
23878 editorcore.insertTag(this.tagname);
23887 this.xtype = 'NavSimplebar';
23889 for(var i=0;i< children.length;i++) {
23891 this.buttons.add(this.addxtypeChild(children[i]));
23895 editor.on('editorevent', this.updateToolbar, this);
23897 onBtnClick : function(id)
23899 this.editorcore.relayCmd(id);
23900 this.editorcore.focus();
23904 * Protected method that will not generally be called directly. It triggers
23905 * a toolbar update by reading the markup state of the current selection in the editor.
23907 updateToolbar: function(){
23909 if(!this.editorcore.activated){
23910 this.editor.onFirstFocus(); // is this neeed?
23914 var btns = this.buttons;
23915 var doc = this.editorcore.doc;
23916 btns.get('bold').setActive(doc.queryCommandState('bold'));
23917 btns.get('italic').setActive(doc.queryCommandState('italic'));
23918 //btns.get('underline').setActive(doc.queryCommandState('underline'));
23920 btns.get('align-left').setActive(doc.queryCommandState('justifyleft'));
23921 btns.get('align-center').setActive(doc.queryCommandState('justifycenter'));
23922 btns.get('align-right').setActive(doc.queryCommandState('justifyright'));
23924 //btns[frameId + '-insertorderedlist').setActive(doc.queryCommandState('insertorderedlist'));
23925 btns.get('list').setActive(doc.queryCommandState('insertunorderedlist'));
23928 var ans = this.editorcore.getAllAncestors();
23929 if (this.formatCombo) {
23932 var store = this.formatCombo.store;
23933 this.formatCombo.setValue("");
23934 for (var i =0; i < ans.length;i++) {
23935 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
23937 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
23945 // hides menus... - so this cant be on a menu...
23946 Roo.bootstrap.MenuMgr.hideAll();
23948 Roo.bootstrap.MenuMgr.hideAll();
23949 //this.editorsyncValue();
23951 onFirstFocus: function() {
23952 this.buttons.each(function(item){
23956 toggleSourceEdit : function(sourceEditMode){
23959 if(sourceEditMode){
23960 Roo.log("disabling buttons");
23961 this.buttons.each( function(item){
23962 if(item.cmd != 'pencil'){
23968 Roo.log("enabling buttons");
23969 if(this.editorcore.initialized){
23970 this.buttons.each( function(item){
23976 Roo.log("calling toggole on editor");
23977 // tell the editor that it's been pressed..
23978 this.editor.toggleSourceEdit(sourceEditMode);
23988 * @class Roo.bootstrap.Table.AbstractSelectionModel
23989 * @extends Roo.util.Observable
23990 * Abstract base class for grid SelectionModels. It provides the interface that should be
23991 * implemented by descendant classes. This class should not be directly instantiated.
23994 Roo.bootstrap.Table.AbstractSelectionModel = function(){
23995 this.locked = false;
23996 Roo.bootstrap.Table.AbstractSelectionModel.superclass.constructor.call(this);
24000 Roo.extend(Roo.bootstrap.Table.AbstractSelectionModel, Roo.util.Observable, {
24001 /** @ignore Called by the grid automatically. Do not call directly. */
24002 init : function(grid){
24008 * Locks the selections.
24011 this.locked = true;
24015 * Unlocks the selections.
24017 unlock : function(){
24018 this.locked = false;
24022 * Returns true if the selections are locked.
24023 * @return {Boolean}
24025 isLocked : function(){
24026 return this.locked;
24030 * @extends Roo.bootstrap.Table.AbstractSelectionModel
24031 * @class Roo.bootstrap.Table.RowSelectionModel
24032 * The default SelectionModel used by {@link Roo.bootstrap.Table}.
24033 * It supports multiple selections and keyboard selection/navigation.
24035 * @param {Object} config
24038 Roo.bootstrap.Table.RowSelectionModel = function(config){
24039 Roo.apply(this, config);
24040 this.selections = new Roo.util.MixedCollection(false, function(o){
24045 this.lastActive = false;
24049 * @event selectionchange
24050 * Fires when the selection changes
24051 * @param {SelectionModel} this
24053 "selectionchange" : true,
24055 * @event afterselectionchange
24056 * Fires after the selection changes (eg. by key press or clicking)
24057 * @param {SelectionModel} this
24059 "afterselectionchange" : true,
24061 * @event beforerowselect
24062 * Fires when a row is selected being selected, return false to cancel.
24063 * @param {SelectionModel} this
24064 * @param {Number} rowIndex The selected index
24065 * @param {Boolean} keepExisting False if other selections will be cleared
24067 "beforerowselect" : true,
24070 * Fires when a row is selected.
24071 * @param {SelectionModel} this
24072 * @param {Number} rowIndex The selected index
24073 * @param {Roo.data.Record} r The record
24075 "rowselect" : true,
24077 * @event rowdeselect
24078 * Fires when a row is deselected.
24079 * @param {SelectionModel} this
24080 * @param {Number} rowIndex The selected index
24082 "rowdeselect" : true
24084 Roo.bootstrap.Table.RowSelectionModel.superclass.constructor.call(this);
24085 this.locked = false;
24088 Roo.extend(Roo.bootstrap.Table.RowSelectionModel, Roo.bootstrap.Table.AbstractSelectionModel, {
24090 * @cfg {Boolean} singleSelect
24091 * True to allow selection of only one row at a time (defaults to false)
24093 singleSelect : false,
24096 initEvents : function()
24099 //if(!this.grid.enableDragDrop && !this.grid.enableDrag){
24100 // this.growclickrid.on("mousedown", this.handleMouseDown, this);
24101 //}else{ // allow click to work like normal
24102 // this.grid.on("rowclick", this.handleDragableRowClick, this);
24104 //this.grid.on("rowdblclick", this.handleMouseDBClick, this);
24105 this.grid.on("rowclick", this.handleMouseDown, this);
24107 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
24108 "up" : function(e){
24110 this.selectPrevious(e.shiftKey);
24111 }else if(this.last !== false && this.lastActive !== false){
24112 var last = this.last;
24113 this.selectRange(this.last, this.lastActive-1);
24114 this.grid.getView().focusRow(this.lastActive);
24115 if(last !== false){
24119 this.selectFirstRow();
24121 this.fireEvent("afterselectionchange", this);
24123 "down" : function(e){
24125 this.selectNext(e.shiftKey);
24126 }else if(this.last !== false && this.lastActive !== false){
24127 var last = this.last;
24128 this.selectRange(this.last, this.lastActive+1);
24129 this.grid.getView().focusRow(this.lastActive);
24130 if(last !== false){
24134 this.selectFirstRow();
24136 this.fireEvent("afterselectionchange", this);
24140 this.grid.store.on('load', function(){
24141 this.selections.clear();
24144 var view = this.grid.view;
24145 view.on("refresh", this.onRefresh, this);
24146 view.on("rowupdated", this.onRowUpdated, this);
24147 view.on("rowremoved", this.onRemove, this);
24152 onRefresh : function()
24154 var ds = this.grid.store, i, v = this.grid.view;
24155 var s = this.selections;
24156 s.each(function(r){
24157 if((i = ds.indexOfId(r.id)) != -1){
24166 onRemove : function(v, index, r){
24167 this.selections.remove(r);
24171 onRowUpdated : function(v, index, r){
24172 if(this.isSelected(r)){
24173 v.onRowSelect(index);
24179 * @param {Array} records The records to select
24180 * @param {Boolean} keepExisting (optional) True to keep existing selections
24182 selectRecords : function(records, keepExisting)
24185 this.clearSelections();
24187 var ds = this.grid.store;
24188 for(var i = 0, len = records.length; i < len; i++){
24189 this.selectRow(ds.indexOf(records[i]), true);
24194 * Gets the number of selected rows.
24197 getCount : function(){
24198 return this.selections.length;
24202 * Selects the first row in the grid.
24204 selectFirstRow : function(){
24209 * Select the last row.
24210 * @param {Boolean} keepExisting (optional) True to keep existing selections
24212 selectLastRow : function(keepExisting){
24213 //this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
24214 this.selectRow(this.grid.store.getCount() - 1, keepExisting);
24218 * Selects the row immediately following the last selected row.
24219 * @param {Boolean} keepExisting (optional) True to keep existing selections
24221 selectNext : function(keepExisting)
24223 if(this.last !== false && (this.last+1) < this.grid.store.getCount()){
24224 this.selectRow(this.last+1, keepExisting);
24225 this.grid.getView().focusRow(this.last);
24230 * Selects the row that precedes the last selected row.
24231 * @param {Boolean} keepExisting (optional) True to keep existing selections
24233 selectPrevious : function(keepExisting){
24235 this.selectRow(this.last-1, keepExisting);
24236 this.grid.getView().focusRow(this.last);
24241 * Returns the selected records
24242 * @return {Array} Array of selected records
24244 getSelections : function(){
24245 return [].concat(this.selections.items);
24249 * Returns the first selected record.
24252 getSelected : function(){
24253 return this.selections.itemAt(0);
24258 * Clears all selections.
24260 clearSelections : function(fast)
24266 var ds = this.grid.store;
24267 var s = this.selections;
24268 s.each(function(r){
24269 this.deselectRow(ds.indexOfId(r.id));
24273 this.selections.clear();
24280 * Selects all rows.
24282 selectAll : function(){
24286 this.selections.clear();
24287 for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
24288 this.selectRow(i, true);
24293 * Returns True if there is a selection.
24294 * @return {Boolean}
24296 hasSelection : function(){
24297 return this.selections.length > 0;
24301 * Returns True if the specified row is selected.
24302 * @param {Number/Record} record The record or index of the record to check
24303 * @return {Boolean}
24305 isSelected : function(index){
24306 var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
24307 return (r && this.selections.key(r.id) ? true : false);
24311 * Returns True if the specified record id is selected.
24312 * @param {String} id The id of record to check
24313 * @return {Boolean}
24315 isIdSelected : function(id){
24316 return (this.selections.key(id) ? true : false);
24321 handleMouseDBClick : function(e, t){
24325 handleMouseDown : function(e, t)
24327 var rowIndex = this.grid.headerShow ? t.dom.rowIndex - 1 : t.dom.rowIndex ; // first row is header???
24328 if(this.isLocked() || rowIndex < 0 ){
24331 if(e.shiftKey && this.last !== false){
24332 var last = this.last;
24333 this.selectRange(last, rowIndex, e.ctrlKey);
24334 this.last = last; // reset the last
24338 var isSelected = this.isSelected(rowIndex);
24339 //Roo.log("select row:" + rowIndex);
24341 this.deselectRow(rowIndex);
24343 this.selectRow(rowIndex, true);
24347 if(e.button !== 0 && isSelected){
24348 alert('rowIndex 2: ' + rowIndex);
24349 view.focusRow(rowIndex);
24350 }else if(e.ctrlKey && isSelected){
24351 this.deselectRow(rowIndex);
24352 }else if(!isSelected){
24353 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
24354 view.focusRow(rowIndex);
24358 this.fireEvent("afterselectionchange", this);
24361 handleDragableRowClick : function(grid, rowIndex, e)
24363 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
24364 this.selectRow(rowIndex, false);
24365 grid.view.focusRow(rowIndex);
24366 this.fireEvent("afterselectionchange", this);
24371 * Selects multiple rows.
24372 * @param {Array} rows Array of the indexes of the row to select
24373 * @param {Boolean} keepExisting (optional) True to keep existing selections
24375 selectRows : function(rows, keepExisting){
24377 this.clearSelections();
24379 for(var i = 0, len = rows.length; i < len; i++){
24380 this.selectRow(rows[i], true);
24385 * Selects a range of rows. All rows in between startRow and endRow are also selected.
24386 * @param {Number} startRow The index of the first row in the range
24387 * @param {Number} endRow The index of the last row in the range
24388 * @param {Boolean} keepExisting (optional) True to retain existing selections
24390 selectRange : function(startRow, endRow, keepExisting){
24395 this.clearSelections();
24397 if(startRow <= endRow){
24398 for(var i = startRow; i <= endRow; i++){
24399 this.selectRow(i, true);
24402 for(var i = startRow; i >= endRow; i--){
24403 this.selectRow(i, true);
24409 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
24410 * @param {Number} startRow The index of the first row in the range
24411 * @param {Number} endRow The index of the last row in the range
24413 deselectRange : function(startRow, endRow, preventViewNotify){
24417 for(var i = startRow; i <= endRow; i++){
24418 this.deselectRow(i, preventViewNotify);
24424 * @param {Number} row The index of the row to select
24425 * @param {Boolean} keepExisting (optional) True to keep existing selections
24427 selectRow : function(index, keepExisting, preventViewNotify)
24429 if(this.locked || (index < 0 || index > this.grid.store.getCount())) {
24432 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
24433 if(!keepExisting || this.singleSelect){
24434 this.clearSelections();
24437 var r = this.grid.store.getAt(index);
24438 //console.log('selectRow - record id :' + r.id);
24440 this.selections.add(r);
24441 this.last = this.lastActive = index;
24442 if(!preventViewNotify){
24443 var proxy = new Roo.Element(
24444 this.grid.getRowDom(index)
24446 proxy.addClass('bg-info info');
24448 this.fireEvent("rowselect", this, index, r);
24449 this.fireEvent("selectionchange", this);
24455 * @param {Number} row The index of the row to deselect
24457 deselectRow : function(index, preventViewNotify)
24462 if(this.last == index){
24465 if(this.lastActive == index){
24466 this.lastActive = false;
24469 var r = this.grid.store.getAt(index);
24474 this.selections.remove(r);
24475 //.console.log('deselectRow - record id :' + r.id);
24476 if(!preventViewNotify){
24478 var proxy = new Roo.Element(
24479 this.grid.getRowDom(index)
24481 proxy.removeClass('bg-info info');
24483 this.fireEvent("rowdeselect", this, index);
24484 this.fireEvent("selectionchange", this);
24488 restoreLast : function(){
24490 this.last = this._last;
24495 acceptsNav : function(row, col, cm){
24496 return !cm.isHidden(col) && cm.isCellEditable(col, row);
24500 onEditorKey : function(field, e){
24501 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
24506 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
24508 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
24510 }else if(k == e.ENTER && !e.ctrlKey){
24514 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
24516 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
24518 }else if(k == e.ESC){
24522 g.startEditing(newCell[0], newCell[1]);
24528 * Ext JS Library 1.1.1
24529 * Copyright(c) 2006-2007, Ext JS, LLC.
24531 * Originally Released Under LGPL - original licence link has changed is not relivant.
24534 * <script type="text/javascript">
24538 * @class Roo.bootstrap.PagingToolbar
24539 * @extends Roo.bootstrap.NavSimplebar
24540 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
24542 * Create a new PagingToolbar
24543 * @param {Object} config The config object
24544 * @param {Roo.data.Store} store
24546 Roo.bootstrap.PagingToolbar = function(config)
24548 // old args format still supported... - xtype is prefered..
24549 // created from xtype...
24551 this.ds = config.dataSource;
24553 if (config.store && !this.ds) {
24554 this.store= Roo.factory(config.store, Roo.data);
24555 this.ds = this.store;
24556 this.ds.xmodule = this.xmodule || false;
24559 this.toolbarItems = [];
24560 if (config.items) {
24561 this.toolbarItems = config.items;
24564 Roo.bootstrap.PagingToolbar.superclass.constructor.call(this, config);
24569 this.bind(this.ds);
24572 this.navgroup = new Roo.bootstrap.NavGroup({ cls: 'pagination' });
24576 Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
24578 * @cfg {Roo.data.Store} dataSource
24579 * The underlying data store providing the paged data
24582 * @cfg {String/HTMLElement/Element} container
24583 * container The id or element that will contain the toolbar
24586 * @cfg {Boolean} displayInfo
24587 * True to display the displayMsg (defaults to false)
24590 * @cfg {Number} pageSize
24591 * The number of records to display per page (defaults to 20)
24595 * @cfg {String} displayMsg
24596 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
24598 displayMsg : 'Displaying {0} - {1} of {2}',
24600 * @cfg {String} emptyMsg
24601 * The message to display when no records are found (defaults to "No data to display")
24603 emptyMsg : 'No data to display',
24605 * Customizable piece of the default paging text (defaults to "Page")
24608 beforePageText : "Page",
24610 * Customizable piece of the default paging text (defaults to "of %0")
24613 afterPageText : "of {0}",
24615 * Customizable piece of the default paging text (defaults to "First Page")
24618 firstText : "First Page",
24620 * Customizable piece of the default paging text (defaults to "Previous Page")
24623 prevText : "Previous Page",
24625 * Customizable piece of the default paging text (defaults to "Next Page")
24628 nextText : "Next Page",
24630 * Customizable piece of the default paging text (defaults to "Last Page")
24633 lastText : "Last Page",
24635 * Customizable piece of the default paging text (defaults to "Refresh")
24638 refreshText : "Refresh",
24642 onRender : function(ct, position)
24644 Roo.bootstrap.PagingToolbar.superclass.onRender.call(this, ct, position);
24645 this.navgroup.parentId = this.id;
24646 this.navgroup.onRender(this.el, null);
24647 // add the buttons to the navgroup
24649 if(this.displayInfo){
24650 this.el.select('ul.navbar-nav',true).first().createChild({cls:'x-paging-info'});
24651 this.displayEl = this.el.select('.x-paging-info', true).first();
24652 // var navel = this.navgroup.addItem( { tagtype : 'span', html : '', cls : 'x-paging-info', preventDefault : true } );
24653 // this.displayEl = navel.el.select('span',true).first();
24659 Roo.each(_this.buttons, function(e){ // this might need to use render????
24660 Roo.factory(e).render(_this.el);
24664 Roo.each(_this.toolbarItems, function(e) {
24665 _this.navgroup.addItem(e);
24669 this.first = this.navgroup.addItem({
24670 tooltip: this.firstText,
24672 icon : 'fa fa-backward',
24674 preventDefault: true,
24675 listeners : { click : this.onClick.createDelegate(this, ["first"]) }
24678 this.prev = this.navgroup.addItem({
24679 tooltip: this.prevText,
24681 icon : 'fa fa-step-backward',
24683 preventDefault: true,
24684 listeners : { click : this.onClick.createDelegate(this, ["prev"]) }
24686 //this.addSeparator();
24689 var field = this.navgroup.addItem( {
24691 cls : 'x-paging-position',
24693 html : this.beforePageText +
24694 '<input type="text" size="3" value="1" class="x-grid-page-number">' +
24695 '<span class="x-paging-after">' + String.format(this.afterPageText, 1) + '</span>'
24698 this.field = field.el.select('input', true).first();
24699 this.field.on("keydown", this.onPagingKeydown, this);
24700 this.field.on("focus", function(){this.dom.select();});
24703 this.afterTextEl = field.el.select('.x-paging-after',true).first();
24704 //this.field.setHeight(18);
24705 //this.addSeparator();
24706 this.next = this.navgroup.addItem({
24707 tooltip: this.nextText,
24709 html : ' <i class="fa fa-step-forward">',
24711 preventDefault: true,
24712 listeners : { click : this.onClick.createDelegate(this, ["next"]) }
24714 this.last = this.navgroup.addItem({
24715 tooltip: this.lastText,
24716 icon : 'fa fa-forward',
24719 preventDefault: true,
24720 listeners : { click : this.onClick.createDelegate(this, ["last"]) }
24722 //this.addSeparator();
24723 this.loading = this.navgroup.addItem({
24724 tooltip: this.refreshText,
24725 icon: 'fa fa-refresh',
24726 preventDefault: true,
24727 listeners : { click : this.onClick.createDelegate(this, ["refresh"]) }
24733 updateInfo : function(){
24734 if(this.displayEl){
24735 var count = (typeof(this.getCount) == 'undefined') ? this.ds.getCount() : this.getCount();
24736 var msg = count == 0 ?
24740 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
24742 this.displayEl.update(msg);
24747 onLoad : function(ds, r, o)
24749 this.cursor = o.params.start ? o.params.start : 0;
24751 var d = this.getPageData(),
24756 this.afterTextEl.dom.innerHTML = String.format(this.afterPageText, d.pages);
24757 this.field.dom.value = ap;
24758 this.first.setDisabled(ap == 1);
24759 this.prev.setDisabled(ap == 1);
24760 this.next.setDisabled(ap == ps);
24761 this.last.setDisabled(ap == ps);
24762 this.loading.enable();
24767 getPageData : function(){
24768 var total = this.ds.getTotalCount();
24771 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
24772 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
24777 onLoadError : function(){
24778 this.loading.enable();
24782 onPagingKeydown : function(e){
24783 var k = e.getKey();
24784 var d = this.getPageData();
24786 var v = this.field.dom.value, pageNum;
24787 if(!v || isNaN(pageNum = parseInt(v, 10))){
24788 this.field.dom.value = d.activePage;
24791 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
24792 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24795 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))
24797 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
24798 this.field.dom.value = pageNum;
24799 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
24802 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
24804 var v = this.field.dom.value, pageNum;
24805 var increment = (e.shiftKey) ? 10 : 1;
24806 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN) {
24809 if(!v || isNaN(pageNum = parseInt(v, 10))) {
24810 this.field.dom.value = d.activePage;
24813 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
24815 this.field.dom.value = parseInt(v, 10) + increment;
24816 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
24817 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
24824 beforeLoad : function(){
24826 this.loading.disable();
24831 onClick : function(which){
24840 ds.load({params:{start: 0, limit: this.pageSize}});
24843 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
24846 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
24849 var total = ds.getTotalCount();
24850 var extra = total % this.pageSize;
24851 var lastStart = extra ? (total - extra) : total-this.pageSize;
24852 ds.load({params:{start: lastStart, limit: this.pageSize}});
24855 ds.load({params:{start: this.cursor, limit: this.pageSize}});
24861 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
24862 * @param {Roo.data.Store} store The data store to unbind
24864 unbind : function(ds){
24865 ds.un("beforeload", this.beforeLoad, this);
24866 ds.un("load", this.onLoad, this);
24867 ds.un("loadexception", this.onLoadError, this);
24868 ds.un("remove", this.updateInfo, this);
24869 ds.un("add", this.updateInfo, this);
24870 this.ds = undefined;
24874 * Binds the paging toolbar to the specified {@link Roo.data.Store}
24875 * @param {Roo.data.Store} store The data store to bind
24877 bind : function(ds){
24878 ds.on("beforeload", this.beforeLoad, this);
24879 ds.on("load", this.onLoad, this);
24880 ds.on("loadexception", this.onLoadError, this);
24881 ds.on("remove", this.updateInfo, this);
24882 ds.on("add", this.updateInfo, this);
24893 * @class Roo.bootstrap.MessageBar
24894 * @extends Roo.bootstrap.Component
24895 * Bootstrap MessageBar class
24896 * @cfg {String} html contents of the MessageBar
24897 * @cfg {String} weight (info | success | warning | danger) default info
24898 * @cfg {String} beforeClass insert the bar before the given class
24899 * @cfg {Boolean} closable (true | false) default false
24900 * @cfg {Boolean} fixed (true | false) default false, fix the bar at the top
24903 * Create a new Element
24904 * @param {Object} config The config object
24907 Roo.bootstrap.MessageBar = function(config){
24908 Roo.bootstrap.MessageBar.superclass.constructor.call(this, config);
24911 Roo.extend(Roo.bootstrap.MessageBar, Roo.bootstrap.Component, {
24917 beforeClass: 'bootstrap-sticky-wrap',
24919 getAutoCreate : function(){
24923 cls: 'alert alert-dismissable alert-' + this.weight,
24928 html: this.html || ''
24934 cfg.cls += ' alert-messages-fixed';
24948 onRender : function(ct, position)
24950 Roo.bootstrap.Component.superclass.onRender.call(this, ct, position);
24953 var cfg = Roo.apply({}, this.getAutoCreate());
24957 cfg.cls += ' ' + this.cls;
24960 cfg.style = this.style;
24962 this.el = Roo.get(document.body).createChild(cfg, Roo.select('.'+this.beforeClass, true).first());
24964 this.el.setVisibilityMode(Roo.Element.DISPLAY);
24967 this.el.select('>button.close').on('click', this.hide, this);
24973 if (!this.rendered) {
24979 this.fireEvent('show', this);
24985 if (!this.rendered) {
24991 this.fireEvent('hide', this);
24994 update : function()
24996 // var e = this.el.dom.firstChild;
24998 // if(this.closable){
24999 // e = e.nextSibling;
25002 // e.data = this.html || '';
25004 this.el.select('>.message', true).first().dom.innerHTML = this.html || '';
25020 * @class Roo.bootstrap.Graph
25021 * @extends Roo.bootstrap.Component
25022 * Bootstrap Graph class
25026 @cfg {String} graphtype bar | vbar | pie
25027 @cfg {number} g_x coodinator | centre x (pie)
25028 @cfg {number} g_y coodinator | centre y (pie)
25029 @cfg {number} g_r radius (pie)
25030 @cfg {number} g_height height of the chart (respected by all elements in the set)
25031 @cfg {number} g_width width of the chart (respected by all elements in the set)
25032 @cfg {Object} title The title of the chart
25035 -opts (object) options for the chart
25037 o type (string) type of endings of the bar. Default: 'square'. Other options are: 'round', 'sharp', 'soft'.
25038 o gutter (number)(string) default '20%' (WHAT DOES IT DO?)
25040 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.
25041 o stacked (boolean) whether or not to tread values as in a stacked bar chart
25043 o stretch (boolean)
25045 -opts (object) options for the pie
25048 o startAngle (number)
25049 o endAngle (number)
25053 * Create a new Input
25054 * @param {Object} config The config object
25057 Roo.bootstrap.Graph = function(config){
25058 Roo.bootstrap.Graph.superclass.constructor.call(this, config);
25064 * The img click event for the img.
25065 * @param {Roo.EventObject} e
25071 Roo.extend(Roo.bootstrap.Graph, Roo.bootstrap.Component, {
25082 //g_colors: this.colors,
25089 getAutoCreate : function(){
25100 onRender : function(ct,position){
25103 Roo.bootstrap.Graph.superclass.onRender.call(this,ct,position);
25105 if (typeof(Raphael) == 'undefined') {
25106 Roo.bootstrap.MessageBox.alert("Error","Raphael is not availabe");
25110 this.raphael = Raphael(this.el.dom);
25112 // data1 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25113 // data2 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25114 // data3 = [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55], [12, 20, 30]],
25115 // txtattr = { font: "12px 'Fontin Sans', Fontin-Sans, sans-serif" };
25117 r.text(160, 10, "Single Series Chart").attr(txtattr);
25118 r.text(480, 10, "Multiline Series Chart").attr(txtattr);
25119 r.text(160, 250, "Multiple Series Stacked Chart").attr(txtattr);
25120 r.text(480, 250, 'Multiline Series Stacked Vertical Chart. Type "round"').attr(txtattr);
25122 r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]], 0, {type: "sharp"});
25123 r.barchart(330, 10, 300, 220, data1);
25124 r.barchart(10, 250, 300, 220, data2, {stacked: true});
25125 r.barchart(330, 250, 300, 220, data3, {stacked: true, type: "round"});
25128 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25129 // r.barchart(30, 30, 560, 250, xdata, {
25130 // labels : [55, 20, 13, 32, 5, 1, 2, 10,5 , 10],
25131 // axis : "0 0 1 1",
25132 // axisxlabels : xdata
25133 // //yvalues : cols,
25136 // var xdata = [55, 20, 13, 32, 5, 1, 2, 10,5 , 10];
25138 // this.load(null,xdata,{
25139 // axis : "0 0 1 1",
25140 // axisxlabels : xdata
25145 load : function(graphtype,xdata,opts)
25147 this.raphael.clear();
25149 graphtype = this.graphtype;
25154 var r = this.raphael,
25155 fin = function () {
25156 this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
25158 fout = function () {
25159 this.flag.animate({opacity: 0}, 300, function () {this.remove();});
25161 pfin = function() {
25162 this.sector.stop();
25163 this.sector.scale(1.1, 1.1, this.cx, this.cy);
25166 this.label[0].stop();
25167 this.label[0].attr({ r: 7.5 });
25168 this.label[1].attr({ "font-weight": 800 });
25171 pfout = function() {
25172 this.sector.animate({ transform: 's1 1 ' + this.cx + ' ' + this.cy }, 500, "bounce");
25175 this.label[0].animate({ r: 5 }, 500, "bounce");
25176 this.label[1].attr({ "font-weight": 400 });
25182 this.raphael.barchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25185 this.raphael.hbarchart(this.g_x,this.g_y,this.g_width,this.g_height,xdata,opts).hover(fin,fout);
25188 // opts = { legend: ["%% - Enterprise Users", "% - ddd","Chrome Users"], legendpos: "west",
25189 // href: ["http://raphaeljs.com", "http://g.raphaeljs.com"]};
25191 this.raphael.piechart(this.g_x,this.g_y,this.g_r,xdata,opts).hover(pfin, pfout);
25198 this.raphael.text(this.title.x, this.title.y, this.title.text).attr(this.title.attr);
25203 setTitle: function(o)
25208 initEvents: function() {
25211 this.el.on('click', this.onClick, this);
25215 onClick : function(e)
25217 Roo.log('img onclick');
25218 this.fireEvent('click', this, e);
25230 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25233 * @class Roo.bootstrap.dash.NumberBox
25234 * @extends Roo.bootstrap.Component
25235 * Bootstrap NumberBox class
25236 * @cfg {String} headline Box headline
25237 * @cfg {String} content Box content
25238 * @cfg {String} icon Box icon
25239 * @cfg {String} footer Footer text
25240 * @cfg {String} fhref Footer href
25243 * Create a new NumberBox
25244 * @param {Object} config The config object
25248 Roo.bootstrap.dash.NumberBox = function(config){
25249 Roo.bootstrap.dash.NumberBox.superclass.constructor.call(this, config);
25253 Roo.extend(Roo.bootstrap.dash.NumberBox, Roo.bootstrap.Component, {
25262 getAutoCreate : function(){
25266 cls : 'small-box ',
25274 cls : 'roo-headline',
25275 html : this.headline
25279 cls : 'roo-content',
25280 html : this.content
25294 cls : 'ion ' + this.icon
25303 cls : 'small-box-footer',
25304 href : this.fhref || '#',
25308 cfg.cn.push(footer);
25315 onRender : function(ct,position){
25316 Roo.bootstrap.dash.NumberBox.superclass.onRender.call(this,ct,position);
25323 setHeadline: function (value)
25325 this.el.select('.roo-headline',true).first().dom.innerHTML = value;
25328 setFooter: function (value, href)
25330 this.el.select('a.small-box-footer',true).first().dom.innerHTML = value;
25333 this.el.select('a.small-box-footer',true).first().attr('href', href);
25338 setContent: function (value)
25340 this.el.select('.roo-content',true).first().dom.innerHTML = value;
25343 initEvents: function()
25357 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25360 * @class Roo.bootstrap.dash.TabBox
25361 * @extends Roo.bootstrap.Component
25362 * Bootstrap TabBox class
25363 * @cfg {String} title Title of the TabBox
25364 * @cfg {String} icon Icon of the TabBox
25365 * @cfg {Boolean} showtabs (true|false) show the tabs default true
25366 * @cfg {Boolean} tabScrollable (true|false) tab scrollable when mobile view default false
25369 * Create a new TabBox
25370 * @param {Object} config The config object
25374 Roo.bootstrap.dash.TabBox = function(config){
25375 Roo.bootstrap.dash.TabBox.superclass.constructor.call(this, config);
25380 * When a pane is added
25381 * @param {Roo.bootstrap.dash.TabPane} pane
25385 * @event activatepane
25386 * When a pane is activated
25387 * @param {Roo.bootstrap.dash.TabPane} pane
25389 "activatepane" : true
25397 Roo.extend(Roo.bootstrap.dash.TabBox, Roo.bootstrap.Component, {
25402 tabScrollable : false,
25404 getChildContainer : function()
25406 return this.el.select('.tab-content', true).first();
25409 getAutoCreate : function(){
25413 cls: 'pull-left header',
25421 cls: 'fa ' + this.icon
25427 cls: 'nav nav-tabs pull-right',
25433 if(this.tabScrollable){
25440 cls: 'nav nav-tabs pull-right',
25451 cls: 'nav-tabs-custom',
25456 cls: 'tab-content no-padding',
25464 initEvents : function()
25466 //Roo.log('add add pane handler');
25467 this.on('addpane', this.onAddPane, this);
25470 * Updates the box title
25471 * @param {String} html to set the title to.
25473 setTitle : function(value)
25475 this.el.select('.nav-tabs .header', true).first().dom.innerHTML = value;
25477 onAddPane : function(pane)
25479 this.panes.push(pane);
25480 //Roo.log('addpane');
25482 // tabs are rendere left to right..
25483 if(!this.showtabs){
25487 var ctr = this.el.select('.nav-tabs', true).first();
25490 var existing = ctr.select('.nav-tab',true);
25491 var qty = existing.getCount();;
25494 var tab = ctr.createChild({
25496 cls : 'nav-tab' + (qty ? '' : ' active'),
25504 }, qty ? existing.first().dom : ctr.select('.header', true).first().dom );
25507 tab.on('click', this.onTabClick.createDelegate(this, [pane], true));
25509 pane.el.addClass('active');
25514 onTabClick : function(ev,un,ob,pane)
25516 //Roo.log('tab - prev default');
25517 ev.preventDefault();
25520 this.el.select('.nav-tabs li.nav-tab', true).removeClass('active');
25521 pane.tab.addClass('active');
25522 //Roo.log(pane.title);
25523 this.getChildContainer().select('.tab-pane',true).removeClass('active');
25524 // technically we should have a deactivate event.. but maybe add later.
25525 // and it should not de-activate the selected tab...
25526 this.fireEvent('activatepane', pane);
25527 pane.el.addClass('active');
25528 pane.fireEvent('activate');
25533 getActivePane : function()
25536 Roo.each(this.panes, function(p) {
25537 if(p.el.hasClass('active')){
25558 Roo.bootstrap.dash = Roo.bootstrap.dash || {};
25560 * @class Roo.bootstrap.TabPane
25561 * @extends Roo.bootstrap.Component
25562 * Bootstrap TabPane class
25563 * @cfg {Boolean} active (false | true) Default false
25564 * @cfg {String} title title of panel
25568 * Create a new TabPane
25569 * @param {Object} config The config object
25572 Roo.bootstrap.dash.TabPane = function(config){
25573 Roo.bootstrap.dash.TabPane.superclass.constructor.call(this, config);
25579 * When a pane is activated
25580 * @param {Roo.bootstrap.dash.TabPane} pane
25587 Roo.extend(Roo.bootstrap.dash.TabPane, Roo.bootstrap.Component, {
25592 // the tabBox that this is attached to.
25595 getAutoCreate : function()
25603 cfg.cls += ' active';
25608 initEvents : function()
25610 //Roo.log('trigger add pane handler');
25611 this.parent().fireEvent('addpane', this)
25615 * Updates the tab title
25616 * @param {String} html to set the title to.
25618 setTitle: function(str)
25624 this.tab.select('a', true).first().dom.innerHTML = str;
25641 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25644 * @class Roo.bootstrap.menu.Menu
25645 * @extends Roo.bootstrap.Component
25646 * Bootstrap Menu class - container for Menu
25647 * @cfg {String} html Text of the menu
25648 * @cfg {String} weight (default | primary | success | info | warning | danger | inverse)
25649 * @cfg {String} icon Font awesome icon
25650 * @cfg {String} pos Menu align to (top | bottom) default bottom
25654 * Create a new Menu
25655 * @param {Object} config The config object
25659 Roo.bootstrap.menu.Menu = function(config){
25660 Roo.bootstrap.menu.Menu.superclass.constructor.call(this, config);
25664 * @event beforeshow
25665 * Fires before this menu is displayed
25666 * @param {Roo.bootstrap.menu.Menu} this
25670 * @event beforehide
25671 * Fires before this menu is hidden
25672 * @param {Roo.bootstrap.menu.Menu} this
25677 * Fires after this menu is displayed
25678 * @param {Roo.bootstrap.menu.Menu} this
25683 * Fires after this menu is hidden
25684 * @param {Roo.bootstrap.menu.Menu} this
25689 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
25690 * @param {Roo.bootstrap.menu.Menu} this
25691 * @param {Roo.EventObject} e
25698 Roo.extend(Roo.bootstrap.menu.Menu, Roo.bootstrap.Component, {
25702 weight : 'default',
25707 getChildContainer : function() {
25708 if(this.isSubMenu){
25712 return this.el.select('ul.dropdown-menu', true).first();
25715 getAutoCreate : function()
25720 cls : 'roo-menu-text',
25728 cls : 'fa ' + this.icon
25739 cls : 'dropdown-button btn btn-' + this.weight,
25744 cls : 'dropdown-toggle btn btn-' + this.weight,
25754 cls : 'dropdown-menu'
25760 if(this.pos == 'top'){
25761 cfg.cls += ' dropup';
25764 if(this.isSubMenu){
25767 cls : 'dropdown-menu'
25774 onRender : function(ct, position)
25776 this.isSubMenu = ct.hasClass('dropdown-submenu');
25778 Roo.bootstrap.menu.Menu.superclass.onRender.call(this, ct, position);
25781 initEvents : function()
25783 if(this.isSubMenu){
25787 this.hidden = true;
25789 this.triggerEl = this.el.select('button.dropdown-toggle', true).first();
25790 this.triggerEl.on('click', this.onTriggerPress, this);
25792 this.buttonEl = this.el.select('button.dropdown-button', true).first();
25793 this.buttonEl.on('click', this.onClick, this);
25799 if(this.isSubMenu){
25803 return this.el.select('ul.dropdown-menu', true).first();
25806 onClick : function(e)
25808 this.fireEvent("click", this, e);
25811 onTriggerPress : function(e)
25813 if (this.isVisible()) {
25820 isVisible : function(){
25821 return !this.hidden;
25826 this.fireEvent("beforeshow", this);
25828 this.hidden = false;
25829 this.el.addClass('open');
25831 Roo.get(document).on("mouseup", this.onMouseUp, this);
25833 this.fireEvent("show", this);
25840 this.fireEvent("beforehide", this);
25842 this.hidden = true;
25843 this.el.removeClass('open');
25845 Roo.get(document).un("mouseup", this.onMouseUp);
25847 this.fireEvent("hide", this);
25850 onMouseUp : function()
25864 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
25867 * @class Roo.bootstrap.menu.Item
25868 * @extends Roo.bootstrap.Component
25869 * Bootstrap MenuItem class
25870 * @cfg {Boolean} submenu (true | false) default false
25871 * @cfg {String} html text of the item
25872 * @cfg {String} href the link
25873 * @cfg {Boolean} disable (true | false) default false
25874 * @cfg {Boolean} preventDefault (true | false) default true
25875 * @cfg {String} icon Font awesome icon
25876 * @cfg {String} pos Submenu align to (left | right) default right
25880 * Create a new Item
25881 * @param {Object} config The config object
25885 Roo.bootstrap.menu.Item = function(config){
25886 Roo.bootstrap.menu.Item.superclass.constructor.call(this, config);
25890 * Fires when the mouse is hovering over this menu
25891 * @param {Roo.bootstrap.menu.Item} this
25892 * @param {Roo.EventObject} e
25897 * Fires when the mouse exits this menu
25898 * @param {Roo.bootstrap.menu.Item} this
25899 * @param {Roo.EventObject} e
25905 * The raw click event for the entire grid.
25906 * @param {Roo.EventObject} e
25912 Roo.extend(Roo.bootstrap.menu.Item, Roo.bootstrap.Component, {
25917 preventDefault: true,
25922 getAutoCreate : function()
25927 cls : 'roo-menu-item-text',
25935 cls : 'fa ' + this.icon
25944 href : this.href || '#',
25951 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'disabled' : (cfg.cls + ' disabled');
25955 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'dropdown-submenu' : (cfg.cls + ' dropdown-submenu');
25957 if(this.pos == 'left'){
25958 cfg.cls = (typeof(cfg.cls) == 'undefined') ? 'pull-left' : (cfg.cls + ' pull-left');
25965 initEvents : function()
25967 this.el.on('mouseover', this.onMouseOver, this);
25968 this.el.on('mouseout', this.onMouseOut, this);
25970 this.el.select('a', true).first().on('click', this.onClick, this);
25974 onClick : function(e)
25976 if(this.preventDefault){
25977 e.preventDefault();
25980 this.fireEvent("click", this, e);
25983 onMouseOver : function(e)
25985 if(this.submenu && this.pos == 'left'){
25986 this.el.select('ul.dropdown-menu', true).first().setLeft(this.el.select('ul.dropdown-menu', true).first().getWidth() * -1);
25989 this.fireEvent("mouseover", this, e);
25992 onMouseOut : function(e)
25994 this.fireEvent("mouseout", this, e);
26006 Roo.bootstrap.menu = Roo.bootstrap.menu || {};
26009 * @class Roo.bootstrap.menu.Separator
26010 * @extends Roo.bootstrap.Component
26011 * Bootstrap Separator class
26014 * Create a new Separator
26015 * @param {Object} config The config object
26019 Roo.bootstrap.menu.Separator = function(config){
26020 Roo.bootstrap.menu.Separator.superclass.constructor.call(this, config);
26023 Roo.extend(Roo.bootstrap.menu.Separator, Roo.bootstrap.Component, {
26025 getAutoCreate : function(){
26046 * @class Roo.bootstrap.Tooltip
26047 * Bootstrap Tooltip class
26048 * This is basic at present - all componets support it by default, however they should add tooltipEl() method
26049 * to determine which dom element triggers the tooltip.
26051 * It needs to add support for additional attributes like tooltip-position
26054 * Create a new Toolti
26055 * @param {Object} config The config object
26058 Roo.bootstrap.Tooltip = function(config){
26059 Roo.bootstrap.Tooltip.superclass.constructor.call(this, config);
26061 this.alignment = Roo.bootstrap.Tooltip.alignment;
26063 if(typeof(config) != 'undefined' && typeof(config.alignment) != 'undefined'){
26064 this.alignment = config.alignment;
26069 Roo.apply(Roo.bootstrap.Tooltip, {
26071 * @function init initialize tooltip monitoring.
26075 currentTip : false,
26076 currentRegion : false,
26082 Roo.get(document).on('mouseover', this.enter ,this);
26083 Roo.get(document).on('mouseout', this.leave, this);
26086 this.currentTip = new Roo.bootstrap.Tooltip();
26089 enter : function(ev)
26091 var dom = ev.getTarget();
26093 //Roo.log(['enter',dom]);
26094 var el = Roo.fly(dom);
26095 if (this.currentEl) {
26097 //Roo.log(this.currentEl);
26098 //Roo.log(this.currentEl.contains(dom));
26099 if (this.currentEl == el) {
26102 if (dom != this.currentEl.dom && this.currentEl.contains(dom)) {
26108 if (this.currentTip.el) {
26109 this.currentTip.el.setVisibilityMode(Roo.Element.DISPLAY).hide(); // force hiding...
26113 if(!el || el.dom == document){
26119 // you can not look for children, as if el is the body.. then everythign is the child..
26120 if (!el.attr('tooltip')) { //
26121 if (!el.select("[tooltip]").elements.length) {
26124 // is the mouse over this child...?
26125 bindEl = el.select("[tooltip]").first();
26126 var xy = ev.getXY();
26127 if (!bindEl.getRegion().contains( { top : xy[1] ,right : xy[0] , bottom : xy[1], left : xy[0]})) {
26128 //Roo.log("not in region.");
26131 //Roo.log("child element over..");
26134 this.currentEl = bindEl;
26135 this.currentTip.bind(bindEl);
26136 this.currentRegion = Roo.lib.Region.getRegion(dom);
26137 this.currentTip.enter();
26140 leave : function(ev)
26142 var dom = ev.getTarget();
26143 //Roo.log(['leave',dom]);
26144 if (!this.currentEl) {
26149 if (dom != this.currentEl.dom) {
26152 var xy = ev.getXY();
26153 if (this.currentRegion.contains( new Roo.lib.Region( xy[1], xy[0] ,xy[1], xy[0] ))) {
26156 // only activate leave if mouse cursor is outside... bounding box..
26161 if (this.currentTip) {
26162 this.currentTip.leave();
26164 //Roo.log('clear currentEl');
26165 this.currentEl = false;
26170 'left' : ['r-l', [-2,0], 'right'],
26171 'right' : ['l-r', [2,0], 'left'],
26172 'bottom' : ['t-b', [0,2], 'top'],
26173 'top' : [ 'b-t', [0,-2], 'bottom']
26179 Roo.extend(Roo.bootstrap.Tooltip, Roo.bootstrap.Component, {
26184 delay : null, // can be { show : 300 , hide: 500}
26188 hoverState : null, //???
26190 placement : 'bottom',
26194 getAutoCreate : function(){
26201 cls : 'tooltip-arrow'
26204 cls : 'tooltip-inner'
26211 bind : function(el)
26217 enter : function () {
26219 if (this.timeout != null) {
26220 clearTimeout(this.timeout);
26223 this.hoverState = 'in';
26224 //Roo.log("enter - show");
26225 if (!this.delay || !this.delay.show) {
26230 this.timeout = setTimeout(function () {
26231 if (_t.hoverState == 'in') {
26234 }, this.delay.show);
26238 clearTimeout(this.timeout);
26240 this.hoverState = 'out';
26241 if (!this.delay || !this.delay.hide) {
26247 this.timeout = setTimeout(function () {
26248 //Roo.log("leave - timeout");
26250 if (_t.hoverState == 'out') {
26252 Roo.bootstrap.Tooltip.currentEl = false;
26257 show : function (msg)
26260 this.render(document.body);
26263 //Roo.log([this.bindEl, this.bindEl.attr('tooltip')]);
26265 var tip = msg || this.bindEl.attr('tooltip') || this.bindEl.select("[tooltip]").first().attr('tooltip');
26267 this.el.select('.tooltip-inner',true).first().dom.innerHTML = tip;
26269 this.el.removeClass(['fade','top','bottom', 'left', 'right','in']);
26271 var placement = typeof this.placement == 'function' ?
26272 this.placement.call(this, this.el, on_el) :
26275 var autoToken = /\s?auto?\s?/i;
26276 var autoPlace = autoToken.test(placement);
26278 placement = placement.replace(autoToken, '') || 'top';
26282 //this.el.setXY([0,0]);
26284 //this.el.dom.style.display='block';
26286 //this.el.appendTo(on_el);
26288 var p = this.getPosition();
26289 var box = this.el.getBox();
26295 var align = this.alignment[placement];
26297 var xy = this.el.getAlignToXY(this.bindEl, align[0], align[1]);
26299 if(placement == 'top' || placement == 'bottom'){
26301 placement = 'right';
26304 if(xy[0] + this.el.getWidth() > Roo.lib.Dom.getViewWidth()){
26305 placement = 'left';
26308 var scroll = Roo.select('body', true).first().getScroll();
26310 if(xy[1] > Roo.lib.Dom.getViewHeight() + scroll.top - this.el.getHeight()){
26314 align = this.alignment[placement];
26317 this.el.alignTo(this.bindEl, align[0],align[1]);
26318 //var arrow = this.el.select('.arrow',true).first();
26319 //arrow.set(align[2],
26321 this.el.addClass(placement);
26323 this.el.addClass('in fade');
26325 this.hoverState = null;
26327 if (this.el.hasClass('fade')) {
26338 //this.el.setXY([0,0]);
26339 this.el.removeClass('in');
26355 * @class Roo.bootstrap.LocationPicker
26356 * @extends Roo.bootstrap.Component
26357 * Bootstrap LocationPicker class
26358 * @cfg {Number} latitude Position when init default 0
26359 * @cfg {Number} longitude Position when init default 0
26360 * @cfg {Number} zoom default 15
26361 * @cfg {String} mapTypeId default google.maps.MapTypeId.ROADMAP
26362 * @cfg {Boolean} mapTypeControl default false
26363 * @cfg {Boolean} disableDoubleClickZoom default false
26364 * @cfg {Boolean} scrollwheel default true
26365 * @cfg {Boolean} streetViewControl default false
26366 * @cfg {Number} radius default 0
26367 * @cfg {String} locationName
26368 * @cfg {Boolean} draggable default true
26369 * @cfg {Boolean} enableAutocomplete default false
26370 * @cfg {Boolean} enableReverseGeocode default true
26371 * @cfg {String} markerTitle
26374 * Create a new LocationPicker
26375 * @param {Object} config The config object
26379 Roo.bootstrap.LocationPicker = function(config){
26381 Roo.bootstrap.LocationPicker.superclass.constructor.call(this, config);
26386 * Fires when the picker initialized.
26387 * @param {Roo.bootstrap.LocationPicker} this
26388 * @param {Google Location} location
26392 * @event positionchanged
26393 * Fires when the picker position changed.
26394 * @param {Roo.bootstrap.LocationPicker} this
26395 * @param {Google Location} location
26397 positionchanged : true,
26400 * Fires when the map resize.
26401 * @param {Roo.bootstrap.LocationPicker} this
26406 * Fires when the map show.
26407 * @param {Roo.bootstrap.LocationPicker} this
26412 * Fires when the map hide.
26413 * @param {Roo.bootstrap.LocationPicker} this
26418 * Fires when click the map.
26419 * @param {Roo.bootstrap.LocationPicker} this
26420 * @param {Map event} e
26424 * @event mapRightClick
26425 * Fires when right click the map.
26426 * @param {Roo.bootstrap.LocationPicker} this
26427 * @param {Map event} e
26429 mapRightClick : true,
26431 * @event markerClick
26432 * Fires when click the marker.
26433 * @param {Roo.bootstrap.LocationPicker} this
26434 * @param {Map event} e
26436 markerClick : true,
26438 * @event markerRightClick
26439 * Fires when right click the marker.
26440 * @param {Roo.bootstrap.LocationPicker} this
26441 * @param {Map event} e
26443 markerRightClick : true,
26445 * @event OverlayViewDraw
26446 * Fires when OverlayView Draw
26447 * @param {Roo.bootstrap.LocationPicker} this
26449 OverlayViewDraw : true,
26451 * @event OverlayViewOnAdd
26452 * Fires when OverlayView Draw
26453 * @param {Roo.bootstrap.LocationPicker} this
26455 OverlayViewOnAdd : true,
26457 * @event OverlayViewOnRemove
26458 * Fires when OverlayView Draw
26459 * @param {Roo.bootstrap.LocationPicker} this
26461 OverlayViewOnRemove : true,
26463 * @event OverlayViewShow
26464 * Fires when OverlayView Draw
26465 * @param {Roo.bootstrap.LocationPicker} this
26466 * @param {Pixel} cpx
26468 OverlayViewShow : true,
26470 * @event OverlayViewHide
26471 * Fires when OverlayView Draw
26472 * @param {Roo.bootstrap.LocationPicker} this
26474 OverlayViewHide : true,
26476 * @event loadexception
26477 * Fires when load google lib failed.
26478 * @param {Roo.bootstrap.LocationPicker} this
26480 loadexception : true
26485 Roo.extend(Roo.bootstrap.LocationPicker, Roo.bootstrap.Component, {
26487 gMapContext: false,
26493 mapTypeControl: false,
26494 disableDoubleClickZoom: false,
26496 streetViewControl: false,
26500 enableAutocomplete: false,
26501 enableReverseGeocode: true,
26504 getAutoCreate: function()
26509 cls: 'roo-location-picker'
26515 initEvents: function(ct, position)
26517 if(!this.el.getWidth() || this.isApplied()){
26521 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26526 initial: function()
26528 if(typeof(google) == 'undefined' || typeof(google.maps) == 'undefined'){
26529 this.fireEvent('loadexception', this);
26533 if(!this.mapTypeId){
26534 this.mapTypeId = google.maps.MapTypeId.ROADMAP;
26537 this.gMapContext = this.GMapContext();
26539 this.initOverlayView();
26541 this.OverlayView = new Roo.bootstrap.LocationPicker.OverlayView(this.gMapContext.map);
26545 google.maps.event.addListener(this.gMapContext.marker, "dragend", function(event) {
26546 _this.setPosition(_this.gMapContext.marker.position);
26549 google.maps.event.addListener(this.gMapContext.map, 'click', function(event){
26550 _this.fireEvent('mapClick', this, event);
26554 google.maps.event.addListener(this.gMapContext.map, 'rightclick', function(event){
26555 _this.fireEvent('mapRightClick', this, event);
26559 google.maps.event.addListener(this.gMapContext.marker, 'click', function(event){
26560 _this.fireEvent('markerClick', this, event);
26564 google.maps.event.addListener(this.gMapContext.marker, 'rightclick', function(event){
26565 _this.fireEvent('markerRightClick', this, event);
26569 this.setPosition(this.gMapContext.location);
26571 this.fireEvent('initial', this, this.gMapContext.location);
26574 initOverlayView: function()
26578 Roo.bootstrap.LocationPicker.OverlayView.prototype = Roo.apply(new google.maps.OverlayView(), {
26582 _this.fireEvent('OverlayViewDraw', _this);
26587 _this.fireEvent('OverlayViewOnAdd', _this);
26590 onRemove: function()
26592 _this.fireEvent('OverlayViewOnRemove', _this);
26595 show: function(cpx)
26597 _this.fireEvent('OverlayViewShow', _this, cpx);
26602 _this.fireEvent('OverlayViewHide', _this);
26608 fromLatLngToContainerPixel: function(event)
26610 return this.OverlayView.getProjection().fromLatLngToContainerPixel(event.latLng);
26613 isApplied: function()
26615 return this.getGmapContext() == false ? false : true;
26618 getGmapContext: function()
26620 return (typeof(this.gMapContext) == 'undefined') ? false : this.gMapContext;
26623 GMapContext: function()
26625 var position = new google.maps.LatLng(this.latitude, this.longitude);
26627 var _map = new google.maps.Map(this.el.dom, {
26630 mapTypeId: this.mapTypeId,
26631 mapTypeControl: this.mapTypeControl,
26632 disableDoubleClickZoom: this.disableDoubleClickZoom,
26633 scrollwheel: this.scrollwheel,
26634 streetViewControl: this.streetViewControl,
26635 locationName: this.locationName,
26636 draggable: this.draggable,
26637 enableAutocomplete: this.enableAutocomplete,
26638 enableReverseGeocode: this.enableReverseGeocode
26641 var _marker = new google.maps.Marker({
26642 position: position,
26644 title: this.markerTitle,
26645 draggable: this.draggable
26652 location: position,
26653 radius: this.radius,
26654 locationName: this.locationName,
26655 addressComponents: {
26656 formatted_address: null,
26657 addressLine1: null,
26658 addressLine2: null,
26660 streetNumber: null,
26664 stateOrProvince: null
26667 domContainer: this.el.dom,
26668 geodecoder: new google.maps.Geocoder()
26672 drawCircle: function(center, radius, options)
26674 if (this.gMapContext.circle != null) {
26675 this.gMapContext.circle.setMap(null);
26679 options = Roo.apply({}, options, {
26680 strokeColor: "#0000FF",
26681 strokeOpacity: .35,
26683 fillColor: "#0000FF",
26687 options.map = this.gMapContext.map;
26688 options.radius = radius;
26689 options.center = center;
26690 this.gMapContext.circle = new google.maps.Circle(options);
26691 return this.gMapContext.circle;
26697 setPosition: function(location)
26699 this.gMapContext.location = location;
26700 this.gMapContext.marker.setPosition(location);
26701 this.gMapContext.map.panTo(location);
26702 this.drawCircle(location, this.gMapContext.radius, {});
26706 if (this.gMapContext.settings.enableReverseGeocode) {
26707 this.gMapContext.geodecoder.geocode({
26708 latLng: this.gMapContext.location
26709 }, function(results, status) {
26711 if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
26712 _this.gMapContext.locationName = results[0].formatted_address;
26713 _this.gMapContext.addressComponents = _this.address_component_from_google_geocode(results[0].address_components);
26715 _this.fireEvent('positionchanged', this, location);
26722 this.fireEvent('positionchanged', this, location);
26727 google.maps.event.trigger(this.gMapContext.map, "resize");
26729 this.gMapContext.map.setCenter(this.gMapContext.marker.position);
26731 this.fireEvent('resize', this);
26734 setPositionByLatLng: function(latitude, longitude)
26736 this.setPosition(new google.maps.LatLng(latitude, longitude));
26739 getCurrentPosition: function()
26742 latitude: this.gMapContext.location.lat(),
26743 longitude: this.gMapContext.location.lng()
26747 getAddressName: function()
26749 return this.gMapContext.locationName;
26752 getAddressComponents: function()
26754 return this.gMapContext.addressComponents;
26757 address_component_from_google_geocode: function(address_components)
26761 for (var i = 0; i < address_components.length; i++) {
26762 var component = address_components[i];
26763 if (component.types.indexOf("postal_code") >= 0) {
26764 result.postalCode = component.short_name;
26765 } else if (component.types.indexOf("street_number") >= 0) {
26766 result.streetNumber = component.short_name;
26767 } else if (component.types.indexOf("route") >= 0) {
26768 result.streetName = component.short_name;
26769 } else if (component.types.indexOf("neighborhood") >= 0) {
26770 result.city = component.short_name;
26771 } else if (component.types.indexOf("locality") >= 0) {
26772 result.city = component.short_name;
26773 } else if (component.types.indexOf("sublocality") >= 0) {
26774 result.district = component.short_name;
26775 } else if (component.types.indexOf("administrative_area_level_1") >= 0) {
26776 result.stateOrProvince = component.short_name;
26777 } else if (component.types.indexOf("country") >= 0) {
26778 result.country = component.short_name;
26782 result.addressLine1 = [ result.streetNumber, result.streetName ].join(" ").trim();
26783 result.addressLine2 = "";
26787 setZoomLevel: function(zoom)
26789 this.gMapContext.map.setZoom(zoom);
26802 this.fireEvent('show', this);
26813 this.fireEvent('hide', this);
26818 Roo.apply(Roo.bootstrap.LocationPicker, {
26820 OverlayView : function(map, options)
26822 options = options || {};
26836 * @class Roo.bootstrap.Alert
26837 * @extends Roo.bootstrap.Component
26838 * Bootstrap Alert class
26839 * @cfg {String} title The title of alert
26840 * @cfg {String} html The content of alert
26841 * @cfg {String} weight ( success | info | warning | danger )
26842 * @cfg {String} faicon font-awesomeicon
26845 * Create a new alert
26846 * @param {Object} config The config object
26850 Roo.bootstrap.Alert = function(config){
26851 Roo.bootstrap.Alert.superclass.constructor.call(this, config);
26855 Roo.extend(Roo.bootstrap.Alert, Roo.bootstrap.Component, {
26862 getAutoCreate : function()
26871 cls : 'roo-alert-icon'
26876 cls : 'roo-alert-title',
26881 cls : 'roo-alert-text',
26888 cfg.cn[0].cls += ' fa ' + this.faicon;
26892 cfg.cls += ' alert-' + this.weight;
26898 initEvents: function()
26900 this.el.setVisibilityMode(Roo.Element.DISPLAY);
26903 setTitle : function(str)
26905 this.el.select('.roo-alert-title',true).first().dom.innerHTML = str;
26908 setText : function(str)
26910 this.el.select('.roo-alert-text',true).first().dom.innerHTML = str;
26913 setWeight : function(weight)
26916 this.el.select('.alert',true).first().removeClass('alert-' + this.weight);
26919 this.weight = weight;
26921 this.el.select('.alert',true).first().addClass('alert-' + this.weight);
26924 setIcon : function(icon)
26927 this.el.select('.roo-alert-icon',true).first().removeClass(['fa', 'fa-' + this.faicon]);
26930 this.faicon = icon;
26932 this.el.select('.roo-alert-icon',true).first().addClass(['fa', 'fa-' + this.faicon]);
26953 * @class Roo.bootstrap.UploadCropbox
26954 * @extends Roo.bootstrap.Component
26955 * Bootstrap UploadCropbox class
26956 * @cfg {String} emptyText show when image has been loaded
26957 * @cfg {String} rotateNotify show when image too small to rotate
26958 * @cfg {Number} errorTimeout default 3000
26959 * @cfg {Number} minWidth default 300
26960 * @cfg {Number} minHeight default 300
26961 * @cfg {Array} buttons default ['rotateLeft', 'pictureBtn', 'rotateRight']
26962 * @cfg {Boolean} isDocument (true|false) default false
26963 * @cfg {String} url action url
26964 * @cfg {String} paramName default 'imageUpload'
26965 * @cfg {String} method default POST
26966 * @cfg {Boolean} loadMask (true|false) default true
26967 * @cfg {Boolean} loadingText default 'Loading...'
26970 * Create a new UploadCropbox
26971 * @param {Object} config The config object
26974 Roo.bootstrap.UploadCropbox = function(config){
26975 Roo.bootstrap.UploadCropbox.superclass.constructor.call(this, config);
26979 * @event beforeselectfile
26980 * Fire before select file
26981 * @param {Roo.bootstrap.UploadCropbox} this
26983 "beforeselectfile" : true,
26986 * Fire after initEvent
26987 * @param {Roo.bootstrap.UploadCropbox} this
26992 * Fire after initEvent
26993 * @param {Roo.bootstrap.UploadCropbox} this
26994 * @param {String} data
26999 * Fire when preparing the file data
27000 * @param {Roo.bootstrap.UploadCropbox} this
27001 * @param {Object} file
27006 * Fire when get exception
27007 * @param {Roo.bootstrap.UploadCropbox} this
27008 * @param {XMLHttpRequest} xhr
27010 "exception" : true,
27012 * @event beforeloadcanvas
27013 * Fire before load the canvas
27014 * @param {Roo.bootstrap.UploadCropbox} this
27015 * @param {String} src
27017 "beforeloadcanvas" : true,
27020 * Fire when trash image
27021 * @param {Roo.bootstrap.UploadCropbox} this
27026 * Fire when download the image
27027 * @param {Roo.bootstrap.UploadCropbox} this
27031 * @event footerbuttonclick
27032 * Fire when footerbuttonclick
27033 * @param {Roo.bootstrap.UploadCropbox} this
27034 * @param {String} type
27036 "footerbuttonclick" : true,
27040 * @param {Roo.bootstrap.UploadCropbox} this
27045 * Fire when rotate the image
27046 * @param {Roo.bootstrap.UploadCropbox} this
27047 * @param {String} pos
27052 * Fire when inspect the file
27053 * @param {Roo.bootstrap.UploadCropbox} this
27054 * @param {Object} file
27059 * Fire when xhr upload the file
27060 * @param {Roo.bootstrap.UploadCropbox} this
27061 * @param {Object} data
27066 * Fire when arrange the file data
27067 * @param {Roo.bootstrap.UploadCropbox} this
27068 * @param {Object} formData
27073 this.buttons = this.buttons || Roo.bootstrap.UploadCropbox.footer.STANDARD;
27076 Roo.extend(Roo.bootstrap.UploadCropbox, Roo.bootstrap.Component, {
27078 emptyText : 'Click to upload image',
27079 rotateNotify : 'Image is too small to rotate',
27080 errorTimeout : 3000,
27094 cropType : 'image/jpeg',
27096 canvasLoaded : false,
27097 isDocument : false,
27099 paramName : 'imageUpload',
27101 loadingText : 'Loading...',
27104 getAutoCreate : function()
27108 cls : 'roo-upload-cropbox',
27112 cls : 'roo-upload-cropbox-selector',
27117 cls : 'roo-upload-cropbox-body',
27118 style : 'cursor:pointer',
27122 cls : 'roo-upload-cropbox-preview'
27126 cls : 'roo-upload-cropbox-thumb'
27130 cls : 'roo-upload-cropbox-empty-notify',
27131 html : this.emptyText
27135 cls : 'roo-upload-cropbox-error-notify alert alert-danger',
27136 html : this.rotateNotify
27142 cls : 'roo-upload-cropbox-footer',
27145 cls : 'btn-group btn-group-justified roo-upload-cropbox-btn-group',
27155 onRender : function(ct, position)
27157 Roo.bootstrap.UploadCropbox.superclass.onRender.call(this, ct, position);
27159 if (this.buttons.length) {
27161 Roo.each(this.buttons, function(bb) {
27163 var btn = this.el.select('.roo-upload-cropbox-footer div.roo-upload-cropbox-btn-group').first().createChild(bb);
27165 btn.on('click', this.onFooterButtonClick.createDelegate(this, [bb.action], true));
27171 this.maskEl = this.el;
27175 initEvents : function()
27177 this.urlAPI = (window.createObjectURL && window) ||
27178 (window.URL && URL.revokeObjectURL && URL) ||
27179 (window.webkitURL && webkitURL);
27181 this.bodyEl = this.el.select('.roo-upload-cropbox-body', true).first();
27182 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27184 this.selectorEl = this.el.select('.roo-upload-cropbox-selector', true).first();
27185 this.selectorEl.hide();
27187 this.previewEl = this.el.select('.roo-upload-cropbox-preview', true).first();
27188 this.previewEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27190 this.thumbEl = this.el.select('.roo-upload-cropbox-thumb', true).first();
27191 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27192 this.thumbEl.hide();
27194 this.notifyEl = this.el.select('.roo-upload-cropbox-empty-notify', true).first();
27195 this.notifyEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27197 this.errorEl = this.el.select('.roo-upload-cropbox-error-notify', true).first();
27198 this.errorEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27199 this.errorEl.hide();
27201 this.footerEl = this.el.select('.roo-upload-cropbox-footer', true).first();
27202 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
27203 this.footerEl.hide();
27205 this.setThumbBoxSize();
27211 this.fireEvent('initial', this);
27218 window.addEventListener("resize", function() { _this.resize(); } );
27220 this.bodyEl.on('click', this.beforeSelectFile, this);
27223 this.bodyEl.on('touchstart', this.onTouchStart, this);
27224 this.bodyEl.on('touchmove', this.onTouchMove, this);
27225 this.bodyEl.on('touchend', this.onTouchEnd, this);
27229 this.bodyEl.on('mousedown', this.onMouseDown, this);
27230 this.bodyEl.on('mousemove', this.onMouseMove, this);
27231 var mousewheel = (/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel';
27232 this.bodyEl.on(mousewheel, this.onMouseWheel, this);
27233 Roo.get(document).on('mouseup', this.onMouseUp, this);
27236 this.selectorEl.on('change', this.onFileSelected, this);
27242 this.baseScale = 1;
27244 this.baseRotate = 1;
27245 this.dragable = false;
27246 this.pinching = false;
27249 this.cropData = false;
27250 this.notifyEl.dom.innerHTML = this.emptyText;
27252 this.selectorEl.dom.value = '';
27256 resize : function()
27258 if(this.fireEvent('resize', this) != false){
27259 this.setThumbBoxPosition();
27260 this.setCanvasPosition();
27264 onFooterButtonClick : function(e, el, o, type)
27267 case 'rotate-left' :
27268 this.onRotateLeft(e);
27270 case 'rotate-right' :
27271 this.onRotateRight(e);
27274 this.beforeSelectFile(e);
27289 this.fireEvent('footerbuttonclick', this, type);
27292 beforeSelectFile : function(e)
27294 e.preventDefault();
27296 if(this.fireEvent('beforeselectfile', this) != false){
27297 this.selectorEl.dom.click();
27301 onFileSelected : function(e)
27303 e.preventDefault();
27305 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
27309 var file = this.selectorEl.dom.files[0];
27311 if(this.fireEvent('inspect', this, file) != false){
27312 this.prepare(file);
27317 trash : function(e)
27319 this.fireEvent('trash', this);
27322 download : function(e)
27324 this.fireEvent('download', this);
27327 loadCanvas : function(src)
27329 if(this.fireEvent('beforeloadcanvas', this, src) != false){
27333 this.imageEl = document.createElement('img');
27337 this.imageEl.addEventListener("load", function(){ _this.onLoadCanvas(); });
27339 this.imageEl.src = src;
27343 onLoadCanvas : function()
27345 this.imageEl.OriginWidth = this.imageEl.naturalWidth || this.imageEl.width;
27346 this.imageEl.OriginHeight = this.imageEl.naturalHeight || this.imageEl.height;
27348 this.bodyEl.un('click', this.beforeSelectFile, this);
27350 this.notifyEl.hide();
27351 this.thumbEl.show();
27352 this.footerEl.show();
27354 this.baseRotateLevel();
27356 if(this.isDocument){
27357 this.setThumbBoxSize();
27360 this.setThumbBoxPosition();
27362 this.baseScaleLevel();
27368 this.canvasLoaded = true;
27371 this.maskEl.unmask();
27376 setCanvasPosition : function()
27378 if(!this.canvasEl){
27382 var pw = Math.ceil((this.bodyEl.getWidth() - this.canvasEl.width) / 2);
27383 var ph = Math.ceil((this.bodyEl.getHeight() - this.canvasEl.height) / 2);
27385 this.previewEl.setLeft(pw);
27386 this.previewEl.setTop(ph);
27390 onMouseDown : function(e)
27394 this.dragable = true;
27395 this.pinching = false;
27397 if(this.isDocument && (this.canvasEl.width < this.thumbEl.getWidth() || this.canvasEl.height < this.thumbEl.getHeight())){
27398 this.dragable = false;
27402 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27403 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27407 onMouseMove : function(e)
27411 if(!this.canvasLoaded){
27415 if (!this.dragable){
27419 var minX = Math.ceil(this.thumbEl.getLeft(true));
27420 var minY = Math.ceil(this.thumbEl.getTop(true));
27422 var maxX = Math.ceil(minX + this.thumbEl.getWidth() - this.canvasEl.width);
27423 var maxY = Math.ceil(minY + this.thumbEl.getHeight() - this.canvasEl.height);
27425 var x = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27426 var y = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27428 x = x - this.mouseX;
27429 y = y - this.mouseY;
27431 var bgX = Math.ceil(x + this.previewEl.getLeft(true));
27432 var bgY = Math.ceil(y + this.previewEl.getTop(true));
27434 bgX = (minX < bgX) ? minX : ((maxX > bgX) ? maxX : bgX);
27435 bgY = (minY < bgY) ? minY : ((maxY > bgY) ? maxY : bgY);
27437 this.previewEl.setLeft(bgX);
27438 this.previewEl.setTop(bgY);
27440 this.mouseX = Roo.isTouch ? e.browserEvent.touches[0].pageX : e.getPageX();
27441 this.mouseY = Roo.isTouch ? e.browserEvent.touches[0].pageY : e.getPageY();
27444 onMouseUp : function(e)
27448 this.dragable = false;
27451 onMouseWheel : function(e)
27455 this.startScale = this.scale;
27457 this.scale = (e.getWheelDelta() == 1) ? (this.scale + 1) : (this.scale - 1);
27459 if(!this.zoomable()){
27460 this.scale = this.startScale;
27469 zoomable : function()
27471 var minScale = this.thumbEl.getWidth() / this.minWidth;
27473 if(this.minWidth < this.minHeight){
27474 minScale = this.thumbEl.getHeight() / this.minHeight;
27477 var width = Math.ceil(this.imageEl.OriginWidth * this.getScaleLevel() / minScale);
27478 var height = Math.ceil(this.imageEl.OriginHeight * this.getScaleLevel() / minScale);
27482 (this.rotate == 0 || this.rotate == 180) &&
27484 width > this.imageEl.OriginWidth ||
27485 height > this.imageEl.OriginHeight ||
27486 (width < this.minWidth && height < this.minHeight)
27494 (this.rotate == 90 || this.rotate == 270) &&
27496 width > this.imageEl.OriginWidth ||
27497 height > this.imageEl.OriginHeight ||
27498 (width < this.minHeight && height < this.minWidth)
27505 !this.isDocument &&
27506 (this.rotate == 0 || this.rotate == 180) &&
27508 width < this.minWidth ||
27509 width > this.imageEl.OriginWidth ||
27510 height < this.minHeight ||
27511 height > this.imageEl.OriginHeight
27518 !this.isDocument &&
27519 (this.rotate == 90 || this.rotate == 270) &&
27521 width < this.minHeight ||
27522 width > this.imageEl.OriginWidth ||
27523 height < this.minWidth ||
27524 height > this.imageEl.OriginHeight
27534 onRotateLeft : function(e)
27536 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27538 var minScale = this.thumbEl.getWidth() / this.minWidth;
27540 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27541 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27543 this.startScale = this.scale;
27545 while (this.getScaleLevel() < minScale){
27547 this.scale = this.scale + 1;
27549 if(!this.zoomable()){
27554 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27555 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27560 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27567 this.scale = this.startScale;
27569 this.onRotateFail();
27574 this.rotate = (this.rotate < 90) ? 270 : this.rotate - 90;
27576 if(this.isDocument){
27577 this.setThumbBoxSize();
27578 this.setThumbBoxPosition();
27579 this.setCanvasPosition();
27584 this.fireEvent('rotate', this, 'left');
27588 onRotateRight : function(e)
27590 if(!this.isDocument && (this.canvasEl.height < this.thumbEl.getWidth() || this.canvasEl.width < this.thumbEl.getHeight())){
27592 var minScale = this.thumbEl.getWidth() / this.minWidth;
27594 var bw = Math.ceil(this.canvasEl.width / this.getScaleLevel());
27595 var bh = Math.ceil(this.canvasEl.height / this.getScaleLevel());
27597 this.startScale = this.scale;
27599 while (this.getScaleLevel() < minScale){
27601 this.scale = this.scale + 1;
27603 if(!this.zoomable()){
27608 Math.ceil(bw * this.getScaleLevel()) < this.thumbEl.getHeight() ||
27609 Math.ceil(bh * this.getScaleLevel()) < this.thumbEl.getWidth()
27614 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27621 this.scale = this.startScale;
27623 this.onRotateFail();
27628 this.rotate = (this.rotate > 180) ? 0 : this.rotate + 90;
27630 if(this.isDocument){
27631 this.setThumbBoxSize();
27632 this.setThumbBoxPosition();
27633 this.setCanvasPosition();
27638 this.fireEvent('rotate', this, 'right');
27641 onRotateFail : function()
27643 this.errorEl.show(true);
27647 (function() { _this.errorEl.hide(true); }).defer(this.errorTimeout);
27652 this.previewEl.dom.innerHTML = '';
27654 var canvasEl = document.createElement("canvas");
27656 var contextEl = canvasEl.getContext("2d");
27658 canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27659 canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27660 var center = this.imageEl.OriginWidth / 2;
27662 if(this.imageEl.OriginWidth < this.imageEl.OriginHeight){
27663 canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27664 canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27665 center = this.imageEl.OriginHeight / 2;
27668 contextEl.scale(this.getScaleLevel(), this.getScaleLevel());
27670 contextEl.translate(center, center);
27671 contextEl.rotate(this.rotate * Math.PI / 180);
27673 contextEl.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27675 this.canvasEl = document.createElement("canvas");
27677 this.contextEl = this.canvasEl.getContext("2d");
27679 switch (this.rotate) {
27682 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27683 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27685 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27690 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27691 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27693 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27694 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);
27698 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27703 this.canvasEl.width = this.imageEl.OriginWidth * this.getScaleLevel();
27704 this.canvasEl.height = this.imageEl.OriginHeight * this.getScaleLevel();
27706 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27707 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);
27711 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);
27716 this.canvasEl.width = this.imageEl.OriginHeight * this.getScaleLevel();
27717 this.canvasEl.height = this.imageEl.OriginWidth * this.getScaleLevel();
27719 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
27720 this.contextEl.drawImage(canvasEl, 0, 0, this.canvasEl.width, this.canvasEl.height, 0, 0, this.canvasEl.width, this.canvasEl.height);
27724 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);
27731 this.previewEl.appendChild(this.canvasEl);
27733 this.setCanvasPosition();
27738 if(!this.canvasLoaded){
27742 var imageCanvas = document.createElement("canvas");
27744 var imageContext = imageCanvas.getContext("2d");
27746 imageCanvas.width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27747 imageCanvas.height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? this.imageEl.OriginWidth : this.imageEl.OriginHeight;
27749 var center = imageCanvas.width / 2;
27751 imageContext.translate(center, center);
27753 imageContext.rotate(this.rotate * Math.PI / 180);
27755 imageContext.drawImage(this.imageEl, 0, 0, this.imageEl.OriginWidth, this.imageEl.OriginHeight, center * -1, center * -1, this.imageEl.OriginWidth, this.imageEl.OriginHeight);
27757 var canvas = document.createElement("canvas");
27759 var context = canvas.getContext("2d");
27761 canvas.width = this.minWidth;
27762 canvas.height = this.minHeight;
27764 switch (this.rotate) {
27767 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27768 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27770 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27771 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27773 var targetWidth = this.minWidth - 2 * x;
27774 var targetHeight = this.minHeight - 2 * y;
27778 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27779 scale = targetWidth / width;
27782 if(x > 0 && y == 0){
27783 scale = targetHeight / height;
27786 if(x > 0 && y > 0){
27787 scale = targetWidth / width;
27789 if(width < height){
27790 scale = targetHeight / height;
27794 context.scale(scale, scale);
27796 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27797 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27799 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27800 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27802 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27807 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27808 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27810 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27811 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27813 var targetWidth = this.minWidth - 2 * x;
27814 var targetHeight = this.minHeight - 2 * y;
27818 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27819 scale = targetWidth / width;
27822 if(x > 0 && y == 0){
27823 scale = targetHeight / height;
27826 if(x > 0 && y > 0){
27827 scale = targetWidth / width;
27829 if(width < height){
27830 scale = targetHeight / height;
27834 context.scale(scale, scale);
27836 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27837 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27839 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27840 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27842 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27844 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27849 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getWidth() / this.getScaleLevel());
27850 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getHeight() / this.getScaleLevel());
27852 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27853 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27855 var targetWidth = this.minWidth - 2 * x;
27856 var targetHeight = this.minHeight - 2 * y;
27860 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27861 scale = targetWidth / width;
27864 if(x > 0 && y == 0){
27865 scale = targetHeight / height;
27868 if(x > 0 && y > 0){
27869 scale = targetWidth / width;
27871 if(width < height){
27872 scale = targetHeight / height;
27876 context.scale(scale, scale);
27878 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27879 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27881 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27882 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27884 sx += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27885 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight) : 0;
27887 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27892 var width = (this.thumbEl.getWidth() / this.getScaleLevel() > this.imageEl.OriginHeight) ? this.imageEl.OriginHeight : (this.thumbEl.getWidth() / this.getScaleLevel());
27893 var height = (this.thumbEl.getHeight() / this.getScaleLevel() > this.imageEl.OriginWidth) ? this.imageEl.OriginWidth : (this.thumbEl.getHeight() / this.getScaleLevel());
27895 var x = (this.thumbEl.getLeft(true) > this.previewEl.getLeft(true)) ? 0 : ((this.previewEl.getLeft(true) - this.thumbEl.getLeft(true)) / this.getScaleLevel());
27896 var y = (this.thumbEl.getTop(true) > this.previewEl.getTop(true)) ? 0 : ((this.previewEl.getTop(true) - this.thumbEl.getTop(true)) / this.getScaleLevel());
27898 var targetWidth = this.minWidth - 2 * x;
27899 var targetHeight = this.minHeight - 2 * y;
27903 if((x == 0 && y == 0) || (x == 0 && y > 0)){
27904 scale = targetWidth / width;
27907 if(x > 0 && y == 0){
27908 scale = targetHeight / height;
27911 if(x > 0 && y > 0){
27912 scale = targetWidth / width;
27914 if(width < height){
27915 scale = targetHeight / height;
27919 context.scale(scale, scale);
27921 var sx = Math.min(this.canvasEl.width - this.thumbEl.getWidth(), this.thumbEl.getLeft(true) - this.previewEl.getLeft(true));
27922 var sy = Math.min(this.canvasEl.height - this.thumbEl.getHeight(), this.thumbEl.getTop(true) - this.previewEl.getTop(true));
27924 sx = sx < 0 ? 0 : (sx / this.getScaleLevel());
27925 sy = sy < 0 ? 0 : (sy / this.getScaleLevel());
27927 sy += (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? 0 : Math.abs(this.imageEl.OriginWidth - this.imageEl.OriginHeight);
27929 context.drawImage(imageCanvas, sx, sy, width, height, x, y, width, height);
27936 this.cropData = canvas.toDataURL(this.cropType);
27938 if(this.fireEvent('crop', this, this.cropData) !== false){
27939 this.process(this.file, this.cropData);
27946 setThumbBoxSize : function()
27950 if(this.isDocument && typeof(this.imageEl) != 'undefined'){
27951 width = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.max(this.minWidth, this.minHeight) : Math.min(this.minWidth, this.minHeight);
27952 height = (this.imageEl.OriginWidth > this.imageEl.OriginHeight) ? Math.min(this.minWidth, this.minHeight) : Math.max(this.minWidth, this.minHeight);
27954 this.minWidth = width;
27955 this.minHeight = height;
27957 if(this.rotate == 90 || this.rotate == 270){
27958 this.minWidth = height;
27959 this.minHeight = width;
27964 width = Math.ceil(this.minWidth * height / this.minHeight);
27966 if(this.minWidth > this.minHeight){
27968 height = Math.ceil(this.minHeight * width / this.minWidth);
27971 this.thumbEl.setStyle({
27972 width : width + 'px',
27973 height : height + 'px'
27980 setThumbBoxPosition : function()
27982 var x = Math.ceil((this.bodyEl.getWidth() - this.thumbEl.getWidth()) / 2 );
27983 var y = Math.ceil((this.bodyEl.getHeight() - this.thumbEl.getHeight()) / 2);
27985 this.thumbEl.setLeft(x);
27986 this.thumbEl.setTop(y);
27990 baseRotateLevel : function()
27992 this.baseRotate = 1;
27995 typeof(this.exif) != 'undefined' &&
27996 typeof(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != 'undefined' &&
27997 [1, 3, 6, 8].indexOf(this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']]) != -1
27999 this.baseRotate = this.exif[Roo.bootstrap.UploadCropbox['tags']['Orientation']];
28002 this.rotate = Roo.bootstrap.UploadCropbox['Orientation'][this.baseRotate];
28006 baseScaleLevel : function()
28010 if(this.isDocument){
28012 if(this.baseRotate == 6 || this.baseRotate == 8){
28014 height = this.thumbEl.getHeight();
28015 this.baseScale = height / this.imageEl.OriginWidth;
28017 if(this.imageEl.OriginHeight * this.baseScale > this.thumbEl.getWidth()){
28018 width = this.thumbEl.getWidth();
28019 this.baseScale = width / this.imageEl.OriginHeight;
28025 height = this.thumbEl.getHeight();
28026 this.baseScale = height / this.imageEl.OriginHeight;
28028 if(this.imageEl.OriginWidth * this.baseScale > this.thumbEl.getWidth()){
28029 width = this.thumbEl.getWidth();
28030 this.baseScale = width / this.imageEl.OriginWidth;
28036 if(this.baseRotate == 6 || this.baseRotate == 8){
28038 width = this.thumbEl.getHeight();
28039 this.baseScale = width / this.imageEl.OriginHeight;
28041 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getWidth()){
28042 height = this.thumbEl.getWidth();
28043 this.baseScale = height / this.imageEl.OriginHeight;
28046 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28047 height = this.thumbEl.getWidth();
28048 this.baseScale = height / this.imageEl.OriginHeight;
28050 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getHeight()){
28051 width = this.thumbEl.getHeight();
28052 this.baseScale = width / this.imageEl.OriginWidth;
28059 width = this.thumbEl.getWidth();
28060 this.baseScale = width / this.imageEl.OriginWidth;
28062 if(this.imageEl.OriginHeight * this.baseScale < this.thumbEl.getHeight()){
28063 height = this.thumbEl.getHeight();
28064 this.baseScale = height / this.imageEl.OriginHeight;
28067 if(this.imageEl.OriginWidth > this.imageEl.OriginHeight){
28069 height = this.thumbEl.getHeight();
28070 this.baseScale = height / this.imageEl.OriginHeight;
28072 if(this.imageEl.OriginWidth * this.baseScale < this.thumbEl.getWidth()){
28073 width = this.thumbEl.getWidth();
28074 this.baseScale = width / this.imageEl.OriginWidth;
28082 getScaleLevel : function()
28084 return this.baseScale * Math.pow(1.1, this.scale);
28087 onTouchStart : function(e)
28089 if(!this.canvasLoaded){
28090 this.beforeSelectFile(e);
28094 var touches = e.browserEvent.touches;
28100 if(touches.length == 1){
28101 this.onMouseDown(e);
28105 if(touches.length != 2){
28111 for(var i = 0, finger; finger = touches[i]; i++){
28112 coords.push(finger.pageX, finger.pageY);
28115 var x = Math.pow(coords[0] - coords[2], 2);
28116 var y = Math.pow(coords[1] - coords[3], 2);
28118 this.startDistance = Math.sqrt(x + y);
28120 this.startScale = this.scale;
28122 this.pinching = true;
28123 this.dragable = false;
28127 onTouchMove : function(e)
28129 if(!this.pinching && !this.dragable){
28133 var touches = e.browserEvent.touches;
28140 this.onMouseMove(e);
28146 for(var i = 0, finger; finger = touches[i]; i++){
28147 coords.push(finger.pageX, finger.pageY);
28150 var x = Math.pow(coords[0] - coords[2], 2);
28151 var y = Math.pow(coords[1] - coords[3], 2);
28153 this.endDistance = Math.sqrt(x + y);
28155 this.scale = this.startScale + Math.floor(Math.log(this.endDistance / this.startDistance) / Math.log(1.1));
28157 if(!this.zoomable()){
28158 this.scale = this.startScale;
28166 onTouchEnd : function(e)
28168 this.pinching = false;
28169 this.dragable = false;
28173 process : function(file, crop)
28176 this.maskEl.mask(this.loadingText);
28179 this.xhr = new XMLHttpRequest();
28181 file.xhr = this.xhr;
28183 this.xhr.open(this.method, this.url, true);
28186 "Accept": "application/json",
28187 "Cache-Control": "no-cache",
28188 "X-Requested-With": "XMLHttpRequest"
28191 for (var headerName in headers) {
28192 var headerValue = headers[headerName];
28194 this.xhr.setRequestHeader(headerName, headerValue);
28200 this.xhr.onload = function()
28202 _this.xhrOnLoad(_this.xhr);
28205 this.xhr.onerror = function()
28207 _this.xhrOnError(_this.xhr);
28210 var formData = new FormData();
28212 formData.append('returnHTML', 'NO');
28215 formData.append('crop', crop);
28218 if(typeof(file) != 'undefined' && (typeof(file.id) == 'undefined' || file.id * 1 < 1)){
28219 formData.append(this.paramName, file, file.name);
28222 if(typeof(file.filename) != 'undefined'){
28223 formData.append('filename', file.filename);
28226 if(typeof(file.mimetype) != 'undefined'){
28227 formData.append('mimetype', file.mimetype);
28230 if(this.fireEvent('arrange', this, formData) != false){
28231 this.xhr.send(formData);
28235 xhrOnLoad : function(xhr)
28238 this.maskEl.unmask();
28241 if (xhr.readyState !== 4) {
28242 this.fireEvent('exception', this, xhr);
28246 var response = Roo.decode(xhr.responseText);
28248 if(!response.success){
28249 this.fireEvent('exception', this, xhr);
28253 var response = Roo.decode(xhr.responseText);
28255 this.fireEvent('upload', this, response);
28259 xhrOnError : function()
28262 this.maskEl.unmask();
28265 Roo.log('xhr on error');
28267 var response = Roo.decode(xhr.responseText);
28273 prepare : function(file)
28276 this.maskEl.mask(this.loadingText);
28282 if(typeof(file) === 'string'){
28283 this.loadCanvas(file);
28287 if(!file || !this.urlAPI){
28292 this.cropType = file.type;
28296 if(this.fireEvent('prepare', this, this.file) != false){
28298 var reader = new FileReader();
28300 reader.onload = function (e) {
28301 if (e.target.error) {
28302 Roo.log(e.target.error);
28306 var buffer = e.target.result,
28307 dataView = new DataView(buffer),
28309 maxOffset = dataView.byteLength - 4,
28313 if (dataView.getUint16(0) === 0xffd8) {
28314 while (offset < maxOffset) {
28315 markerBytes = dataView.getUint16(offset);
28317 if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) || markerBytes === 0xfffe) {
28318 markerLength = dataView.getUint16(offset + 2) + 2;
28319 if (offset + markerLength > dataView.byteLength) {
28320 Roo.log('Invalid meta data: Invalid segment size.');
28324 if(markerBytes == 0xffe1){
28325 _this.parseExifData(
28332 offset += markerLength;
28342 var url = _this.urlAPI.createObjectURL(_this.file);
28344 _this.loadCanvas(url);
28349 reader.readAsArrayBuffer(this.file);
28355 parseExifData : function(dataView, offset, length)
28357 var tiffOffset = offset + 10,
28361 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28362 // No Exif data, might be XMP data instead
28366 // Check for the ASCII code for "Exif" (0x45786966):
28367 if (dataView.getUint32(offset + 4) !== 0x45786966) {
28368 // No Exif data, might be XMP data instead
28371 if (tiffOffset + 8 > dataView.byteLength) {
28372 Roo.log('Invalid Exif data: Invalid segment size.');
28375 // Check for the two null bytes:
28376 if (dataView.getUint16(offset + 8) !== 0x0000) {
28377 Roo.log('Invalid Exif data: Missing byte alignment offset.');
28380 // Check the byte alignment:
28381 switch (dataView.getUint16(tiffOffset)) {
28383 littleEndian = true;
28386 littleEndian = false;
28389 Roo.log('Invalid Exif data: Invalid byte alignment marker.');
28392 // Check for the TIFF tag marker (0x002A):
28393 if (dataView.getUint16(tiffOffset + 2, littleEndian) !== 0x002A) {
28394 Roo.log('Invalid Exif data: Missing TIFF marker.');
28397 // Retrieve the directory offset bytes, usually 0x00000008 or 8 decimal:
28398 dirOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
28400 this.parseExifTags(
28403 tiffOffset + dirOffset,
28408 parseExifTags : function(dataView, tiffOffset, dirOffset, littleEndian)
28413 if (dirOffset + 6 > dataView.byteLength) {
28414 Roo.log('Invalid Exif data: Invalid directory offset.');
28417 tagsNumber = dataView.getUint16(dirOffset, littleEndian);
28418 dirEndOffset = dirOffset + 2 + 12 * tagsNumber;
28419 if (dirEndOffset + 4 > dataView.byteLength) {
28420 Roo.log('Invalid Exif data: Invalid directory size.');
28423 for (i = 0; i < tagsNumber; i += 1) {
28427 dirOffset + 2 + 12 * i, // tag offset
28431 // Return the offset to the next directory:
28432 return dataView.getUint32(dirEndOffset, littleEndian);
28435 parseExifTag : function (dataView, tiffOffset, offset, littleEndian)
28437 var tag = dataView.getUint16(offset, littleEndian);
28439 this.exif[tag] = this.getExifValue(
28443 dataView.getUint16(offset + 2, littleEndian), // tag type
28444 dataView.getUint32(offset + 4, littleEndian), // tag length
28449 getExifValue : function (dataView, tiffOffset, offset, type, length, littleEndian)
28451 var tagType = Roo.bootstrap.UploadCropbox.exifTagTypes[type],
28460 Roo.log('Invalid Exif data: Invalid tag type.');
28464 tagSize = tagType.size * length;
28465 // Determine if the value is contained in the dataOffset bytes,
28466 // or if the value at the dataOffset is a pointer to the actual data:
28467 dataOffset = tagSize > 4 ?
28468 tiffOffset + dataView.getUint32(offset + 8, littleEndian) : (offset + 8);
28469 if (dataOffset + tagSize > dataView.byteLength) {
28470 Roo.log('Invalid Exif data: Invalid data offset.');
28473 if (length === 1) {
28474 return tagType.getValue(dataView, dataOffset, littleEndian);
28477 for (i = 0; i < length; i += 1) {
28478 values[i] = tagType.getValue(dataView, dataOffset + i * tagType.size, littleEndian);
28481 if (tagType.ascii) {
28483 // Concatenate the chars:
28484 for (i = 0; i < values.length; i += 1) {
28486 // Ignore the terminating NULL byte(s):
28487 if (c === '\u0000') {
28499 Roo.apply(Roo.bootstrap.UploadCropbox, {
28501 'Orientation': 0x0112
28505 1: 0, //'top-left',
28507 3: 180, //'bottom-right',
28508 // 4: 'bottom-left',
28510 6: 90, //'right-top',
28511 // 7: 'right-bottom',
28512 8: 270 //'left-bottom'
28516 // byte, 8-bit unsigned int:
28518 getValue: function (dataView, dataOffset) {
28519 return dataView.getUint8(dataOffset);
28523 // ascii, 8-bit byte:
28525 getValue: function (dataView, dataOffset) {
28526 return String.fromCharCode(dataView.getUint8(dataOffset));
28531 // short, 16 bit int:
28533 getValue: function (dataView, dataOffset, littleEndian) {
28534 return dataView.getUint16(dataOffset, littleEndian);
28538 // long, 32 bit int:
28540 getValue: function (dataView, dataOffset, littleEndian) {
28541 return dataView.getUint32(dataOffset, littleEndian);
28545 // rational = two long values, first is numerator, second is denominator:
28547 getValue: function (dataView, dataOffset, littleEndian) {
28548 return dataView.getUint32(dataOffset, littleEndian) /
28549 dataView.getUint32(dataOffset + 4, littleEndian);
28553 // slong, 32 bit signed int:
28555 getValue: function (dataView, dataOffset, littleEndian) {
28556 return dataView.getInt32(dataOffset, littleEndian);
28560 // srational, two slongs, first is numerator, second is denominator:
28562 getValue: function (dataView, dataOffset, littleEndian) {
28563 return dataView.getInt32(dataOffset, littleEndian) /
28564 dataView.getInt32(dataOffset + 4, littleEndian);
28574 cls : 'btn-group roo-upload-cropbox-rotate-left',
28575 action : 'rotate-left',
28579 cls : 'btn btn-default',
28580 html : '<i class="fa fa-undo"></i>'
28586 cls : 'btn-group roo-upload-cropbox-picture',
28587 action : 'picture',
28591 cls : 'btn btn-default',
28592 html : '<i class="fa fa-picture-o"></i>'
28598 cls : 'btn-group roo-upload-cropbox-rotate-right',
28599 action : 'rotate-right',
28603 cls : 'btn btn-default',
28604 html : '<i class="fa fa-repeat"></i>'
28612 cls : 'btn-group roo-upload-cropbox-rotate-left',
28613 action : 'rotate-left',
28617 cls : 'btn btn-default',
28618 html : '<i class="fa fa-undo"></i>'
28624 cls : 'btn-group roo-upload-cropbox-download',
28625 action : 'download',
28629 cls : 'btn btn-default',
28630 html : '<i class="fa fa-download"></i>'
28636 cls : 'btn-group roo-upload-cropbox-crop',
28641 cls : 'btn btn-default',
28642 html : '<i class="fa fa-crop"></i>'
28648 cls : 'btn-group roo-upload-cropbox-trash',
28653 cls : 'btn btn-default',
28654 html : '<i class="fa fa-trash"></i>'
28660 cls : 'btn-group roo-upload-cropbox-rotate-right',
28661 action : 'rotate-right',
28665 cls : 'btn btn-default',
28666 html : '<i class="fa fa-repeat"></i>'
28674 cls : 'btn-group roo-upload-cropbox-rotate-left',
28675 action : 'rotate-left',
28679 cls : 'btn btn-default',
28680 html : '<i class="fa fa-undo"></i>'
28686 cls : 'btn-group roo-upload-cropbox-rotate-right',
28687 action : 'rotate-right',
28691 cls : 'btn btn-default',
28692 html : '<i class="fa fa-repeat"></i>'
28705 * @class Roo.bootstrap.DocumentManager
28706 * @extends Roo.bootstrap.Component
28707 * Bootstrap DocumentManager class
28708 * @cfg {String} paramName default 'imageUpload'
28709 * @cfg {String} toolTipName default 'filename'
28710 * @cfg {String} method default POST
28711 * @cfg {String} url action url
28712 * @cfg {Number} boxes number of boxes, 0 is no limit.. default 0
28713 * @cfg {Boolean} multiple multiple upload default true
28714 * @cfg {Number} thumbSize default 300
28715 * @cfg {String} fieldLabel
28716 * @cfg {Number} labelWidth default 4
28717 * @cfg {String} labelAlign (left|top) default left
28718 * @cfg {Boolean} editable (true|false) allow edit when upload a image default true
28719 * @cfg {Number} labellg set the width of label (1-12)
28720 * @cfg {Number} labelmd set the width of label (1-12)
28721 * @cfg {Number} labelsm set the width of label (1-12)
28722 * @cfg {Number} labelxs set the width of label (1-12)
28725 * Create a new DocumentManager
28726 * @param {Object} config The config object
28729 Roo.bootstrap.DocumentManager = function(config){
28730 Roo.bootstrap.DocumentManager.superclass.constructor.call(this, config);
28733 this.delegates = [];
28738 * Fire when initial the DocumentManager
28739 * @param {Roo.bootstrap.DocumentManager} this
28744 * inspect selected file
28745 * @param {Roo.bootstrap.DocumentManager} this
28746 * @param {File} file
28751 * Fire when xhr load exception
28752 * @param {Roo.bootstrap.DocumentManager} this
28753 * @param {XMLHttpRequest} xhr
28755 "exception" : true,
28757 * @event afterupload
28758 * Fire when xhr load exception
28759 * @param {Roo.bootstrap.DocumentManager} this
28760 * @param {XMLHttpRequest} xhr
28762 "afterupload" : true,
28765 * prepare the form data
28766 * @param {Roo.bootstrap.DocumentManager} this
28767 * @param {Object} formData
28772 * Fire when remove the file
28773 * @param {Roo.bootstrap.DocumentManager} this
28774 * @param {Object} file
28779 * Fire after refresh the file
28780 * @param {Roo.bootstrap.DocumentManager} this
28785 * Fire after click the image
28786 * @param {Roo.bootstrap.DocumentManager} this
28787 * @param {Object} file
28792 * Fire when upload a image and editable set to true
28793 * @param {Roo.bootstrap.DocumentManager} this
28794 * @param {Object} file
28798 * @event beforeselectfile
28799 * Fire before select file
28800 * @param {Roo.bootstrap.DocumentManager} this
28802 "beforeselectfile" : true,
28805 * Fire before process file
28806 * @param {Roo.bootstrap.DocumentManager} this
28807 * @param {Object} file
28811 * @event previewrendered
28812 * Fire when preview rendered
28813 * @param {Roo.bootstrap.DocumentManager} this
28814 * @param {Object} file
28816 "previewrendered" : true,
28819 "previewResize" : true
28824 Roo.extend(Roo.bootstrap.DocumentManager, Roo.bootstrap.Component, {
28833 paramName : 'imageUpload',
28834 toolTipName : 'filename',
28837 labelAlign : 'left',
28847 getAutoCreate : function()
28849 var managerWidget = {
28851 cls : 'roo-document-manager',
28855 cls : 'roo-document-manager-selector',
28860 cls : 'roo-document-manager-uploader',
28864 cls : 'roo-document-manager-upload-btn',
28865 html : '<i class="fa fa-plus"></i>'
28876 cls : 'column col-md-12',
28881 if(this.fieldLabel.length){
28886 cls : 'column col-md-12',
28887 html : this.fieldLabel
28891 cls : 'column col-md-12',
28896 if(this.labelAlign == 'left'){
28901 html : this.fieldLabel
28910 if(this.labelWidth > 12){
28911 content[0].style = "width: " + this.labelWidth + 'px';
28914 if(this.labelWidth < 13 && this.labelmd == 0){
28915 this.labelmd = this.labelWidth;
28918 if(this.labellg > 0){
28919 content[0].cls += ' col-lg-' + this.labellg;
28920 content[1].cls += ' col-lg-' + (12 - this.labellg);
28923 if(this.labelmd > 0){
28924 content[0].cls += ' col-md-' + this.labelmd;
28925 content[1].cls += ' col-md-' + (12 - this.labelmd);
28928 if(this.labelsm > 0){
28929 content[0].cls += ' col-sm-' + this.labelsm;
28930 content[1].cls += ' col-sm-' + (12 - this.labelsm);
28933 if(this.labelxs > 0){
28934 content[0].cls += ' col-xs-' + this.labelxs;
28935 content[1].cls += ' col-xs-' + (12 - this.labelxs);
28943 cls : 'row clearfix',
28951 initEvents : function()
28953 this.managerEl = this.el.select('.roo-document-manager', true).first();
28954 this.managerEl.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28956 this.selectorEl = this.el.select('.roo-document-manager-selector', true).first();
28957 this.selectorEl.hide();
28960 this.selectorEl.attr('multiple', 'multiple');
28963 this.selectorEl.on('change', this.onFileSelected, this);
28965 this.uploader = this.el.select('.roo-document-manager-uploader', true).first();
28966 this.uploader.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
28968 this.uploader.on('click', this.onUploaderClick, this);
28970 this.renderProgressDialog();
28974 window.addEventListener("resize", function() { _this.refresh(); } );
28976 this.fireEvent('initial', this);
28979 renderProgressDialog : function()
28983 this.progressDialog = new Roo.bootstrap.Modal({
28984 cls : 'roo-document-manager-progress-dialog',
28985 allow_close : false,
28995 btnclick : function() {
28996 _this.uploadCancel();
29002 this.progressDialog.render(Roo.get(document.body));
29004 this.progress = new Roo.bootstrap.Progress({
29005 cls : 'roo-document-manager-progress',
29010 this.progress.render(this.progressDialog.getChildContainer());
29012 this.progressBar = new Roo.bootstrap.ProgressBar({
29013 cls : 'roo-document-manager-progress-bar',
29016 aria_valuemax : 12,
29020 this.progressBar.render(this.progress.getChildContainer());
29023 onUploaderClick : function(e)
29025 e.preventDefault();
29027 if(this.fireEvent('beforeselectfile', this) != false){
29028 this.selectorEl.dom.click();
29033 onFileSelected : function(e)
29035 e.preventDefault();
29037 if(typeof(this.selectorEl.dom.files) == 'undefined' || !this.selectorEl.dom.files.length){
29041 Roo.each(this.selectorEl.dom.files, function(file){
29042 if(this.fireEvent('inspect', this, file) != false){
29043 this.files.push(file);
29053 this.selectorEl.dom.value = '';
29055 if(!this.files || !this.files.length){
29059 if(this.boxes > 0 && this.files.length > this.boxes){
29060 this.files = this.files.slice(0, this.boxes);
29063 this.uploader.show();
29065 if(this.boxes > 0 && this.files.length > this.boxes - 1){
29066 this.uploader.hide();
29075 Roo.each(this.files, function(file){
29077 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29078 var f = this.renderPreview(file);
29083 if(file.type.indexOf('image') != -1){
29084 this.delegates.push(
29086 _this.process(file);
29087 }).createDelegate(this)
29095 _this.process(file);
29096 }).createDelegate(this)
29101 this.files = files;
29103 this.delegates = this.delegates.concat(docs);
29105 if(!this.delegates.length){
29110 this.progressBar.aria_valuemax = this.delegates.length;
29117 arrange : function()
29119 if(!this.delegates.length){
29120 this.progressDialog.hide();
29125 var delegate = this.delegates.shift();
29127 this.progressDialog.show();
29129 this.progressDialog.setTitle((this.progressBar.aria_valuemax - this.delegates.length) + ' / ' + this.progressBar.aria_valuemax);
29131 this.progressBar.update(this.progressBar.aria_valuemax - this.delegates.length);
29136 refresh : function()
29138 this.uploader.show();
29140 if(this.boxes > 0 && this.files.length > this.boxes - 1){
29141 this.uploader.hide();
29144 Roo.isTouch ? this.closable(false) : this.closable(true);
29146 this.fireEvent('refresh', this);
29149 onRemove : function(e, el, o)
29151 e.preventDefault();
29153 this.fireEvent('remove', this, o);
29157 remove : function(o)
29161 Roo.each(this.files, function(file){
29162 if(typeof(file.id) == 'undefined' || file.id * 1 < 1 || file.id != o.id){
29171 this.files = files;
29178 Roo.each(this.files, function(file){
29183 file.target.remove();
29192 onClick : function(e, el, o)
29194 e.preventDefault();
29196 this.fireEvent('click', this, o);
29200 closable : function(closable)
29202 Roo.each(this.managerEl.select('.roo-document-manager-preview > button.close', true).elements, function(el){
29204 el.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
29216 xhrOnLoad : function(xhr)
29218 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29222 if (xhr.readyState !== 4) {
29224 this.fireEvent('exception', this, xhr);
29228 var response = Roo.decode(xhr.responseText);
29230 if(!response.success){
29232 this.fireEvent('exception', this, xhr);
29236 var file = this.renderPreview(response.data);
29238 this.files.push(file);
29242 this.fireEvent('afterupload', this, xhr);
29246 xhrOnError : function(xhr)
29248 Roo.log('xhr on error');
29250 var response = Roo.decode(xhr.responseText);
29257 process : function(file)
29259 if(this.fireEvent('process', this, file) !== false){
29260 if(this.editable && file.type.indexOf('image') != -1){
29261 this.fireEvent('edit', this, file);
29265 this.uploadStart(file, false);
29272 uploadStart : function(file, crop)
29274 this.xhr = new XMLHttpRequest();
29276 if(typeof(file.id) != 'undefined' && file.id * 1 > 0){
29281 file.xhr = this.xhr;
29283 this.managerEl.createChild({
29285 cls : 'roo-document-manager-loading',
29289 tooltip : file.name,
29290 cls : 'roo-document-manager-thumb',
29291 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29297 this.xhr.open(this.method, this.url, true);
29300 "Accept": "application/json",
29301 "Cache-Control": "no-cache",
29302 "X-Requested-With": "XMLHttpRequest"
29305 for (var headerName in headers) {
29306 var headerValue = headers[headerName];
29308 this.xhr.setRequestHeader(headerName, headerValue);
29314 this.xhr.onload = function()
29316 _this.xhrOnLoad(_this.xhr);
29319 this.xhr.onerror = function()
29321 _this.xhrOnError(_this.xhr);
29324 var formData = new FormData();
29326 formData.append('returnHTML', 'NO');
29329 formData.append('crop', crop);
29332 formData.append(this.paramName, file, file.name);
29339 if(this.fireEvent('prepare', this, formData, options) != false){
29341 if(options.manually){
29345 this.xhr.send(formData);
29349 this.uploadCancel();
29352 uploadCancel : function()
29358 this.delegates = [];
29360 Roo.each(this.managerEl.select('.roo-document-manager-loading', true).elements, function(el){
29367 renderPreview : function(file)
29369 if(typeof(file.target) != 'undefined' && file.target){
29373 var img_src = encodeURI(baseURL +'/Images/Thumb/' + this.thumbSize + '/' + file.id + '/' + file.filename);
29375 var previewEl = this.managerEl.createChild({
29377 cls : 'roo-document-manager-preview',
29381 tooltip : file[this.toolTipName],
29382 cls : 'roo-document-manager-thumb',
29383 html : '<img tooltip="' + file[this.toolTipName] + '" src="' + img_src + '">'
29388 html : '<i class="fa fa-times-circle"></i>'
29393 var close = previewEl.select('button.close', true).first();
29395 close.on('click', this.onRemove, this, file);
29397 file.target = previewEl;
29399 var image = previewEl.select('img', true).first();
29403 image.dom.addEventListener("load", function(){ _this.onPreviewLoad(file, image); });
29405 image.on('click', this.onClick, this, file);
29407 this.fireEvent('previewrendered', this, file);
29413 onPreviewLoad : function(file, image)
29415 if(typeof(file.target) == 'undefined' || !file.target){
29419 var width = image.dom.naturalWidth || image.dom.width;
29420 var height = image.dom.naturalHeight || image.dom.height;
29422 if(!this.previewResize) {
29426 if(width > height){
29427 file.target.addClass('wide');
29431 file.target.addClass('tall');
29436 uploadFromSource : function(file, crop)
29438 this.xhr = new XMLHttpRequest();
29440 this.managerEl.createChild({
29442 cls : 'roo-document-manager-loading',
29446 tooltip : file.name,
29447 cls : 'roo-document-manager-thumb',
29448 html : '<i class="fa fa-circle-o-notch fa-spin"></i>'
29454 this.xhr.open(this.method, this.url, true);
29457 "Accept": "application/json",
29458 "Cache-Control": "no-cache",
29459 "X-Requested-With": "XMLHttpRequest"
29462 for (var headerName in headers) {
29463 var headerValue = headers[headerName];
29465 this.xhr.setRequestHeader(headerName, headerValue);
29471 this.xhr.onload = function()
29473 _this.xhrOnLoad(_this.xhr);
29476 this.xhr.onerror = function()
29478 _this.xhrOnError(_this.xhr);
29481 var formData = new FormData();
29483 formData.append('returnHTML', 'NO');
29485 formData.append('crop', crop);
29487 if(typeof(file.filename) != 'undefined'){
29488 formData.append('filename', file.filename);
29491 if(typeof(file.mimetype) != 'undefined'){
29492 formData.append('mimetype', file.mimetype);
29497 if(this.fireEvent('prepare', this, formData) != false){
29498 this.xhr.send(formData);
29508 * @class Roo.bootstrap.DocumentViewer
29509 * @extends Roo.bootstrap.Component
29510 * Bootstrap DocumentViewer class
29511 * @cfg {Boolean} showDownload (true|false) show download button (default true)
29512 * @cfg {Boolean} showTrash (true|false) show trash button (default true)
29515 * Create a new DocumentViewer
29516 * @param {Object} config The config object
29519 Roo.bootstrap.DocumentViewer = function(config){
29520 Roo.bootstrap.DocumentViewer.superclass.constructor.call(this, config);
29525 * Fire after initEvent
29526 * @param {Roo.bootstrap.DocumentViewer} this
29532 * @param {Roo.bootstrap.DocumentViewer} this
29537 * Fire after download button
29538 * @param {Roo.bootstrap.DocumentViewer} this
29543 * Fire after trash button
29544 * @param {Roo.bootstrap.DocumentViewer} this
29551 Roo.extend(Roo.bootstrap.DocumentViewer, Roo.bootstrap.Component, {
29553 showDownload : true,
29557 getAutoCreate : function()
29561 cls : 'roo-document-viewer',
29565 cls : 'roo-document-viewer-body',
29569 cls : 'roo-document-viewer-thumb',
29573 cls : 'roo-document-viewer-image'
29581 cls : 'roo-document-viewer-footer',
29584 cls : 'btn-group btn-group-justified roo-document-viewer-btn-group',
29588 cls : 'btn-group roo-document-viewer-download',
29592 cls : 'btn btn-default',
29593 html : '<i class="fa fa-download"></i>'
29599 cls : 'btn-group roo-document-viewer-trash',
29603 cls : 'btn btn-default',
29604 html : '<i class="fa fa-trash"></i>'
29617 initEvents : function()
29619 this.bodyEl = this.el.select('.roo-document-viewer-body', true).first();
29620 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
29622 this.thumbEl = this.el.select('.roo-document-viewer-thumb', true).first();
29623 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
29625 this.imageEl = this.el.select('.roo-document-viewer-image', true).first();
29626 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
29628 this.footerEl = this.el.select('.roo-document-viewer-footer', true).first();
29629 this.footerEl.setVisibilityMode(Roo.Element.DISPLAY);
29631 this.downloadBtn = this.el.select('.roo-document-viewer-download', true).first();
29632 this.downloadBtn.setVisibilityMode(Roo.Element.DISPLAY);
29634 this.trashBtn = this.el.select('.roo-document-viewer-trash', true).first();
29635 this.trashBtn.setVisibilityMode(Roo.Element.DISPLAY);
29637 this.bodyEl.on('click', this.onClick, this);
29638 this.downloadBtn.on('click', this.onDownload, this);
29639 this.trashBtn.on('click', this.onTrash, this);
29641 this.downloadBtn.hide();
29642 this.trashBtn.hide();
29644 if(this.showDownload){
29645 this.downloadBtn.show();
29648 if(this.showTrash){
29649 this.trashBtn.show();
29652 if(!this.showDownload && !this.showTrash) {
29653 this.footerEl.hide();
29658 initial : function()
29660 this.fireEvent('initial', this);
29664 onClick : function(e)
29666 e.preventDefault();
29668 this.fireEvent('click', this);
29671 onDownload : function(e)
29673 e.preventDefault();
29675 this.fireEvent('download', this);
29678 onTrash : function(e)
29680 e.preventDefault();
29682 this.fireEvent('trash', this);
29694 * @class Roo.bootstrap.NavProgressBar
29695 * @extends Roo.bootstrap.Component
29696 * Bootstrap NavProgressBar class
29699 * Create a new nav progress bar
29700 * @param {Object} config The config object
29703 Roo.bootstrap.NavProgressBar = function(config){
29704 Roo.bootstrap.NavProgressBar.superclass.constructor.call(this, config);
29706 this.bullets = this.bullets || [];
29708 // Roo.bootstrap.NavProgressBar.register(this);
29712 * Fires when the active item changes
29713 * @param {Roo.bootstrap.NavProgressBar} this
29714 * @param {Roo.bootstrap.NavProgressItem} selected The item selected
29715 * @param {Roo.bootstrap.NavProgressItem} prev The previously selected item
29722 Roo.extend(Roo.bootstrap.NavProgressBar, Roo.bootstrap.Component, {
29727 getAutoCreate : function()
29729 var cfg = Roo.apply({}, Roo.bootstrap.NavProgressBar.superclass.getAutoCreate.call(this));
29733 cls : 'roo-navigation-bar-group',
29737 cls : 'roo-navigation-top-bar'
29741 cls : 'roo-navigation-bullets-bar',
29745 cls : 'roo-navigation-bar'
29752 cls : 'roo-navigation-bottom-bar'
29762 initEvents: function()
29767 onRender : function(ct, position)
29769 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
29771 if(this.bullets.length){
29772 Roo.each(this.bullets, function(b){
29781 addItem : function(cfg)
29783 var item = new Roo.bootstrap.NavProgressItem(cfg);
29785 item.parentId = this.id;
29786 item.render(this.el.select('.roo-navigation-bar', true).first(), null);
29789 var top = new Roo.bootstrap.Element({
29791 cls : 'roo-navigation-bar-text'
29794 var bottom = new Roo.bootstrap.Element({
29796 cls : 'roo-navigation-bar-text'
29799 top.onRender(this.el.select('.roo-navigation-top-bar', true).first(), null);
29800 bottom.onRender(this.el.select('.roo-navigation-bottom-bar', true).first(), null);
29802 var topText = new Roo.bootstrap.Element({
29804 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? cfg.html : ''
29807 var bottomText = new Roo.bootstrap.Element({
29809 html : (typeof(cfg.position) != 'undefined' && cfg.position == 'top') ? '' : cfg.html
29812 topText.onRender(top.el, null);
29813 bottomText.onRender(bottom.el, null);
29816 item.bottomEl = bottom;
29819 this.barItems.push(item);
29824 getActive : function()
29826 var active = false;
29828 Roo.each(this.barItems, function(v){
29830 if (!v.isActive()) {
29842 setActiveItem : function(item)
29846 Roo.each(this.barItems, function(v){
29847 if (v.rid == item.rid) {
29851 if (v.isActive()) {
29852 v.setActive(false);
29857 item.setActive(true);
29859 this.fireEvent('changed', this, item, prev);
29862 getBarItem: function(rid)
29866 Roo.each(this.barItems, function(e) {
29867 if (e.rid != rid) {
29878 indexOfItem : function(item)
29882 Roo.each(this.barItems, function(v, i){
29884 if (v.rid != item.rid) {
29895 setActiveNext : function()
29897 var i = this.indexOfItem(this.getActive());
29899 if (i > this.barItems.length) {
29903 this.setActiveItem(this.barItems[i+1]);
29906 setActivePrev : function()
29908 var i = this.indexOfItem(this.getActive());
29914 this.setActiveItem(this.barItems[i-1]);
29917 format : function()
29919 if(!this.barItems.length){
29923 var width = 100 / this.barItems.length;
29925 Roo.each(this.barItems, function(i){
29926 i.el.setStyle('width', width + '%');
29927 i.topEl.el.setStyle('width', width + '%');
29928 i.bottomEl.el.setStyle('width', width + '%');
29937 * Nav Progress Item
29942 * @class Roo.bootstrap.NavProgressItem
29943 * @extends Roo.bootstrap.Component
29944 * Bootstrap NavProgressItem class
29945 * @cfg {String} rid the reference id
29946 * @cfg {Boolean} active (true|false) Is item active default false
29947 * @cfg {Boolean} disabled (true|false) Is item active default false
29948 * @cfg {String} html
29949 * @cfg {String} position (top|bottom) text position default bottom
29950 * @cfg {String} icon show icon instead of number
29953 * Create a new NavProgressItem
29954 * @param {Object} config The config object
29956 Roo.bootstrap.NavProgressItem = function(config){
29957 Roo.bootstrap.NavProgressItem.superclass.constructor.call(this, config);
29962 * The raw click event for the entire grid.
29963 * @param {Roo.bootstrap.NavProgressItem} this
29964 * @param {Roo.EventObject} e
29971 Roo.extend(Roo.bootstrap.NavProgressItem, Roo.bootstrap.Component, {
29977 position : 'bottom',
29980 getAutoCreate : function()
29982 var iconCls = 'roo-navigation-bar-item-icon';
29984 iconCls += ((this.icon) ? (' ' + this.icon) : (' step-number')) ;
29988 cls: 'roo-navigation-bar-item',
29998 cfg.cls += ' active';
30001 cfg.cls += ' disabled';
30007 disable : function()
30009 this.setDisabled(true);
30012 enable : function()
30014 this.setDisabled(false);
30017 initEvents: function()
30019 this.iconEl = this.el.select('.roo-navigation-bar-item-icon', true).first();
30021 this.iconEl.on('click', this.onClick, this);
30024 onClick : function(e)
30026 e.preventDefault();
30032 if(this.fireEvent('click', this, e) === false){
30036 this.parent().setActiveItem(this);
30039 isActive: function ()
30041 return this.active;
30044 setActive : function(state)
30046 if(this.active == state){
30050 this.active = state;
30053 this.el.addClass('active');
30057 this.el.removeClass('active');
30062 setDisabled : function(state)
30064 if(this.disabled == state){
30068 this.disabled = state;
30071 this.el.addClass('disabled');
30075 this.el.removeClass('disabled');
30078 tooltipEl : function()
30080 return this.el.select('.roo-navigation-bar-item-icon', true).first();;
30093 * @class Roo.bootstrap.FieldLabel
30094 * @extends Roo.bootstrap.Component
30095 * Bootstrap FieldLabel class
30096 * @cfg {String} html contents of the element
30097 * @cfg {String} tag tag of the element default label
30098 * @cfg {String} cls class of the element
30099 * @cfg {String} target label target
30100 * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
30101 * @cfg {String} invalidClass default "text-warning"
30102 * @cfg {String} validClass default "text-success"
30103 * @cfg {String} iconTooltip default "This field is required"
30104 * @cfg {String} indicatorpos (left|right) default left
30107 * Create a new FieldLabel
30108 * @param {Object} config The config object
30111 Roo.bootstrap.FieldLabel = function(config){
30112 Roo.bootstrap.Element.superclass.constructor.call(this, config);
30117 * Fires after the field has been marked as invalid.
30118 * @param {Roo.form.FieldLabel} this
30119 * @param {String} msg The validation message
30124 * Fires after the field has been validated with no errors.
30125 * @param {Roo.form.FieldLabel} this
30131 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component, {
30138 invalidClass : 'has-warning',
30139 validClass : 'has-success',
30140 iconTooltip : 'This field is required',
30141 indicatorpos : 'left',
30143 getAutoCreate : function(){
30146 if (!this.allowBlank) {
30152 cls : 'roo-bootstrap-field-label ' + this.cls,
30157 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
30158 tooltip : this.iconTooltip
30167 if(this.indicatorpos == 'right'){
30170 cls : 'roo-bootstrap-field-label ' + this.cls,
30179 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
30180 tooltip : this.iconTooltip
30189 initEvents: function()
30191 Roo.bootstrap.Element.superclass.initEvents.call(this);
30193 this.indicator = this.indicatorEl();
30195 if(this.indicator){
30196 this.indicator.removeClass('visible');
30197 this.indicator.addClass('invisible');
30200 Roo.bootstrap.FieldLabel.register(this);
30203 indicatorEl : function()
30205 var indicator = this.el.select('i.roo-required-indicator',true).first();
30216 * Mark this field as valid
30218 markValid : function()
30220 if(this.indicator){
30221 this.indicator.removeClass('visible');
30222 this.indicator.addClass('invisible');
30225 this.el.removeClass(this.invalidClass);
30227 this.el.addClass(this.validClass);
30229 this.fireEvent('valid', this);
30233 * Mark this field as invalid
30234 * @param {String} msg The validation message
30236 markInvalid : function(msg)
30238 if(this.indicator){
30239 this.indicator.removeClass('invisible');
30240 this.indicator.addClass('visible');
30243 this.el.removeClass(this.validClass);
30245 this.el.addClass(this.invalidClass);
30247 this.fireEvent('invalid', this, msg);
30253 Roo.apply(Roo.bootstrap.FieldLabel, {
30258 * register a FieldLabel Group
30259 * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
30261 register : function(label)
30263 if(this.groups.hasOwnProperty(label.target)){
30267 this.groups[label.target] = label;
30271 * fetch a FieldLabel Group based on the target
30272 * @param {string} target
30273 * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
30275 get: function(target) {
30276 if (typeof(this.groups[target]) == 'undefined') {
30280 return this.groups[target] ;
30289 * page DateSplitField.
30295 * @class Roo.bootstrap.DateSplitField
30296 * @extends Roo.bootstrap.Component
30297 * Bootstrap DateSplitField class
30298 * @cfg {string} fieldLabel - the label associated
30299 * @cfg {Number} labelWidth set the width of label (0-12)
30300 * @cfg {String} labelAlign (top|left)
30301 * @cfg {Boolean} dayAllowBlank (true|false) default false
30302 * @cfg {Boolean} monthAllowBlank (true|false) default false
30303 * @cfg {Boolean} yearAllowBlank (true|false) default false
30304 * @cfg {string} dayPlaceholder
30305 * @cfg {string} monthPlaceholder
30306 * @cfg {string} yearPlaceholder
30307 * @cfg {string} dayFormat default 'd'
30308 * @cfg {string} monthFormat default 'm'
30309 * @cfg {string} yearFormat default 'Y'
30310 * @cfg {Number} labellg set the width of label (1-12)
30311 * @cfg {Number} labelmd set the width of label (1-12)
30312 * @cfg {Number} labelsm set the width of label (1-12)
30313 * @cfg {Number} labelxs set the width of label (1-12)
30317 * Create a new DateSplitField
30318 * @param {Object} config The config object
30321 Roo.bootstrap.DateSplitField = function(config){
30322 Roo.bootstrap.DateSplitField.superclass.constructor.call(this, config);
30328 * getting the data of years
30329 * @param {Roo.bootstrap.DateSplitField} this
30330 * @param {Object} years
30335 * getting the data of days
30336 * @param {Roo.bootstrap.DateSplitField} this
30337 * @param {Object} days
30342 * Fires after the field has been marked as invalid.
30343 * @param {Roo.form.Field} this
30344 * @param {String} msg The validation message
30349 * Fires after the field has been validated with no errors.
30350 * @param {Roo.form.Field} this
30356 Roo.extend(Roo.bootstrap.DateSplitField, Roo.bootstrap.Component, {
30359 labelAlign : 'top',
30361 dayAllowBlank : false,
30362 monthAllowBlank : false,
30363 yearAllowBlank : false,
30364 dayPlaceholder : '',
30365 monthPlaceholder : '',
30366 yearPlaceholder : '',
30370 isFormField : true,
30376 getAutoCreate : function()
30380 cls : 'row roo-date-split-field-group',
30385 cls : 'form-hidden-field roo-date-split-field-group-value',
30391 var labelCls = 'col-md-12';
30392 var contentCls = 'col-md-4';
30394 if(this.fieldLabel){
30398 cls : 'column roo-date-split-field-label col-md-' + ((this.labelAlign == 'top') ? '12' : this.labelWidth),
30402 html : this.fieldLabel
30407 if(this.labelAlign == 'left'){
30409 if(this.labelWidth > 12){
30410 label.style = "width: " + this.labelWidth + 'px';
30413 if(this.labelWidth < 13 && this.labelmd == 0){
30414 this.labelmd = this.labelWidth;
30417 if(this.labellg > 0){
30418 labelCls = ' col-lg-' + this.labellg;
30419 contentCls = ' col-lg-' + ((12 - this.labellg) / 3);
30422 if(this.labelmd > 0){
30423 labelCls = ' col-md-' + this.labelmd;
30424 contentCls = ' col-md-' + ((12 - this.labelmd) / 3);
30427 if(this.labelsm > 0){
30428 labelCls = ' col-sm-' + this.labelsm;
30429 contentCls = ' col-sm-' + ((12 - this.labelsm) / 3);
30432 if(this.labelxs > 0){
30433 labelCls = ' col-xs-' + this.labelxs;
30434 contentCls = ' col-xs-' + ((12 - this.labelxs) / 3);
30438 label.cls += ' ' + labelCls;
30440 cfg.cn.push(label);
30443 Roo.each(['day', 'month', 'year'], function(t){
30446 cls : 'column roo-date-split-field-' + t + ' ' + contentCls
30453 inputEl: function ()
30455 return this.el.select('.roo-date-split-field-group-value', true).first();
30458 onRender : function(ct, position)
30462 Roo.bootstrap.NavProgressBar.superclass.onRender.call(this, ct, position);
30464 this.inputEl = this.el.select('.roo-date-split-field-group-value', true).first();
30466 this.dayField = new Roo.bootstrap.ComboBox({
30467 allowBlank : this.dayAllowBlank,
30468 alwaysQuery : true,
30469 displayField : 'value',
30472 forceSelection : true,
30474 placeholder : this.dayPlaceholder,
30475 selectOnFocus : true,
30476 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30477 triggerAction : 'all',
30479 valueField : 'value',
30480 store : new Roo.data.SimpleStore({
30481 data : (function() {
30483 _this.fireEvent('days', _this, days);
30486 fields : [ 'value' ]
30489 select : function (_self, record, index)
30491 _this.setValue(_this.getValue());
30496 this.dayField.render(this.el.select('.roo-date-split-field-day', true).first(), null);
30498 this.monthField = new Roo.bootstrap.MonthField({
30499 after : '<i class=\"fa fa-calendar\"></i>',
30500 allowBlank : this.monthAllowBlank,
30501 placeholder : this.monthPlaceholder,
30504 render : function (_self)
30506 this.el.select('span.input-group-addon', true).first().on('click', function(e){
30507 e.preventDefault();
30511 select : function (_self, oldvalue, newvalue)
30513 _this.setValue(_this.getValue());
30518 this.monthField.render(this.el.select('.roo-date-split-field-month', true).first(), null);
30520 this.yearField = new Roo.bootstrap.ComboBox({
30521 allowBlank : this.yearAllowBlank,
30522 alwaysQuery : true,
30523 displayField : 'value',
30526 forceSelection : true,
30528 placeholder : this.yearPlaceholder,
30529 selectOnFocus : true,
30530 tpl : '<div class="roo-select2-result"><b>{value}</b></div>',
30531 triggerAction : 'all',
30533 valueField : 'value',
30534 store : new Roo.data.SimpleStore({
30535 data : (function() {
30537 _this.fireEvent('years', _this, years);
30540 fields : [ 'value' ]
30543 select : function (_self, record, index)
30545 _this.setValue(_this.getValue());
30550 this.yearField.render(this.el.select('.roo-date-split-field-year', true).first(), null);
30553 setValue : function(v, format)
30555 this.inputEl.dom.value = v;
30557 var f = format || (this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat);
30559 var d = Date.parseDate(v, f);
30566 this.setDay(d.format(this.dayFormat));
30567 this.setMonth(d.format(this.monthFormat));
30568 this.setYear(d.format(this.yearFormat));
30575 setDay : function(v)
30577 this.dayField.setValue(v);
30578 this.inputEl.dom.value = this.getValue();
30583 setMonth : function(v)
30585 this.monthField.setValue(v, true);
30586 this.inputEl.dom.value = this.getValue();
30591 setYear : function(v)
30593 this.yearField.setValue(v);
30594 this.inputEl.dom.value = this.getValue();
30599 getDay : function()
30601 return this.dayField.getValue();
30604 getMonth : function()
30606 return this.monthField.getValue();
30609 getYear : function()
30611 return this.yearField.getValue();
30614 getValue : function()
30616 var f = this.yearFormat + '-' + this.monthFormat + '-' + this.dayFormat;
30618 var date = this.yearField.getValue() + '-' + this.monthField.getValue() + '-' + this.dayField.getValue();
30628 this.inputEl.dom.value = '';
30633 validate : function()
30635 var d = this.dayField.validate();
30636 var m = this.monthField.validate();
30637 var y = this.yearField.validate();
30642 (!this.dayAllowBlank && !d) ||
30643 (!this.monthAllowBlank && !m) ||
30644 (!this.yearAllowBlank && !y)
30649 if(this.dayAllowBlank && this.monthAllowBlank && this.yearAllowBlank){
30658 this.markInvalid();
30663 markValid : function()
30666 var label = this.el.select('label', true).first();
30667 var icon = this.el.select('i.fa-star', true).first();
30673 this.fireEvent('valid', this);
30677 * Mark this field as invalid
30678 * @param {String} msg The validation message
30680 markInvalid : function(msg)
30683 var label = this.el.select('label', true).first();
30684 var icon = this.el.select('i.fa-star', true).first();
30686 if(label && !icon){
30687 this.el.select('.roo-date-split-field-label', true).createChild({
30689 cls : 'text-danger fa fa-lg fa-star',
30690 tooltip : 'This field is required',
30691 style : 'margin-right:5px;'
30695 this.fireEvent('invalid', this, msg);
30698 clearInvalid : function()
30700 var label = this.el.select('label', true).first();
30701 var icon = this.el.select('i.fa-star', true).first();
30707 this.fireEvent('valid', this);
30710 getName: function()
30720 * http://masonry.desandro.com
30722 * The idea is to render all the bricks based on vertical width...
30724 * The original code extends 'outlayer' - we might need to use that....
30730 * @class Roo.bootstrap.LayoutMasonry
30731 * @extends Roo.bootstrap.Component
30732 * Bootstrap Layout Masonry class
30735 * Create a new Element
30736 * @param {Object} config The config object
30739 Roo.bootstrap.LayoutMasonry = function(config){
30741 Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
30745 Roo.bootstrap.LayoutMasonry.register(this);
30751 * Fire after layout the items
30752 * @param {Roo.bootstrap.LayoutMasonry} this
30753 * @param {Roo.EventObject} e
30760 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component, {
30763 * @cfg {Boolean} isLayoutInstant = no animation?
30765 isLayoutInstant : false, // needed?
30768 * @cfg {Number} boxWidth width of the columns
30773 * @cfg {Number} boxHeight - 0 for square, or fix it at a certian height
30778 * @cfg {Number} padWidth padding below box..
30783 * @cfg {Number} gutter gutter width..
30788 * @cfg {Number} maxCols maximum number of columns
30794 * @cfg {Boolean} isAutoInitial defalut true
30796 isAutoInitial : true,
30801 * @cfg {Boolean} isHorizontal defalut false
30803 isHorizontal : false,
30805 currentSize : null,
30811 bricks: null, //CompositeElement
30815 _isLayoutInited : false,
30817 // isAlternative : false, // only use for vertical layout...
30820 * @cfg {Number} alternativePadWidth padding below box..
30822 alternativePadWidth : 50,
30824 selectedBrick : [],
30826 getAutoCreate : function(){
30828 var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
30832 cls: 'blog-masonary-wrapper ' + this.cls,
30834 cls : 'mas-boxes masonary'
30841 getChildContainer: function( )
30843 if (this.boxesEl) {
30844 return this.boxesEl;
30847 this.boxesEl = this.el.select('.mas-boxes').first();
30849 return this.boxesEl;
30853 initEvents : function()
30857 if(this.isAutoInitial){
30858 Roo.log('hook children rendered');
30859 this.on('childrenrendered', function() {
30860 Roo.log('children rendered');
30866 initial : function()
30868 this.selectedBrick = [];
30870 this.currentSize = this.el.getBox(true);
30872 Roo.EventManager.onWindowResize(this.resize, this);
30874 if(!this.isAutoInitial){
30882 //this.layout.defer(500,this);
30886 resize : function()
30888 var cs = this.el.getBox(true);
30891 this.currentSize.width == cs.width &&
30892 this.currentSize.x == cs.x &&
30893 this.currentSize.height == cs.height &&
30894 this.currentSize.y == cs.y
30896 Roo.log("no change in with or X or Y");
30900 this.currentSize = cs;
30906 layout : function()
30908 this._resetLayout();
30910 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
30912 this.layoutItems( isInstant );
30914 this._isLayoutInited = true;
30916 this.fireEvent('layout', this);
30920 _resetLayout : function()
30922 if(this.isHorizontal){
30923 this.horizontalMeasureColumns();
30927 this.verticalMeasureColumns();
30931 verticalMeasureColumns : function()
30933 this.getContainerWidth();
30935 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30936 // this.colWidth = Math.floor(this.containerWidth * 0.8);
30940 var boxWidth = this.boxWidth + this.padWidth;
30942 if(this.containerWidth < this.boxWidth){
30943 boxWidth = this.containerWidth
30946 var containerWidth = this.containerWidth;
30948 var cols = Math.floor(containerWidth / boxWidth);
30950 this.cols = Math.max( cols, 1 );
30952 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
30954 var totalBoxWidth = this.cols * boxWidth - this.padWidth;
30956 var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
30958 this.colWidth = boxWidth + avail - this.padWidth;
30960 this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
30961 this.unitHeight = this.boxHeight > 0 ? this.boxHeight : this.unitWidth;
30964 horizontalMeasureColumns : function()
30966 this.getContainerWidth();
30968 var boxWidth = this.boxWidth;
30970 if(this.containerWidth < boxWidth){
30971 boxWidth = this.containerWidth;
30974 this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
30976 this.el.setHeight(boxWidth);
30980 getContainerWidth : function()
30982 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
30985 layoutItems : function( isInstant )
30987 Roo.log(this.bricks);
30989 var items = Roo.apply([], this.bricks);
30991 if(this.isHorizontal){
30992 this._horizontalLayoutItems( items , isInstant );
30996 // if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
30997 // this._verticalAlternativeLayoutItems( items , isInstant );
31001 this._verticalLayoutItems( items , isInstant );
31005 _verticalLayoutItems : function ( items , isInstant)
31007 if ( !items || !items.length ) {
31012 ['xs', 'xs', 'xs', 'tall'],
31013 ['xs', 'xs', 'tall'],
31014 ['xs', 'xs', 'sm'],
31015 ['xs', 'xs', 'xs'],
31021 ['sm', 'xs', 'xs'],
31025 ['tall', 'xs', 'xs', 'xs'],
31026 ['tall', 'xs', 'xs'],
31038 Roo.each(items, function(item, k){
31040 switch (item.size) {
31041 // these layouts take up a full box,
31052 boxes.push([item]);
31075 var filterPattern = function(box, length)
31083 var pattern = box.slice(0, length);
31087 Roo.each(pattern, function(i){
31088 format.push(i.size);
31091 Roo.each(standard, function(s){
31093 if(String(s) != String(format)){
31102 if(!match && length == 1){
31107 filterPattern(box, length - 1);
31111 queue.push(pattern);
31113 box = box.slice(length, box.length);
31115 filterPattern(box, 4);
31121 Roo.each(boxes, function(box, k){
31127 if(box.length == 1){
31132 filterPattern(box, 4);
31136 this._processVerticalLayoutQueue( queue, isInstant );
31140 // _verticalAlternativeLayoutItems : function( items , isInstant )
31142 // if ( !items || !items.length ) {
31146 // this._processVerticalAlternativeLayoutQueue( items, isInstant );
31150 _horizontalLayoutItems : function ( items , isInstant)
31152 if ( !items || !items.length || items.length < 3) {
31158 var eItems = items.slice(0, 3);
31160 items = items.slice(3, items.length);
31163 ['xs', 'xs', 'xs', 'wide'],
31164 ['xs', 'xs', 'wide'],
31165 ['xs', 'xs', 'sm'],
31166 ['xs', 'xs', 'xs'],
31172 ['sm', 'xs', 'xs'],
31176 ['wide', 'xs', 'xs', 'xs'],
31177 ['wide', 'xs', 'xs'],
31190 Roo.each(items, function(item, k){
31192 switch (item.size) {
31203 boxes.push([item]);
31227 var filterPattern = function(box, length)
31235 var pattern = box.slice(0, length);
31239 Roo.each(pattern, function(i){
31240 format.push(i.size);
31243 Roo.each(standard, function(s){
31245 if(String(s) != String(format)){
31254 if(!match && length == 1){
31259 filterPattern(box, length - 1);
31263 queue.push(pattern);
31265 box = box.slice(length, box.length);
31267 filterPattern(box, 4);
31273 Roo.each(boxes, function(box, k){
31279 if(box.length == 1){
31284 filterPattern(box, 4);
31291 var pos = this.el.getBox(true);
31295 var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31297 var hit_end = false;
31299 Roo.each(queue, function(box){
31303 Roo.each(box, function(b){
31305 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31315 Roo.each(box, function(b){
31317 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31320 mx = Math.max(mx, b.x);
31324 maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
31328 Roo.each(box, function(b){
31330 b.el.setVisibilityMode(Roo.Element.DISPLAY);
31344 this._processHorizontalLayoutQueue( prune, eItems, isInstant );
31347 /** Sets position of item in DOM
31348 * @param {Element} item
31349 * @param {Number} x - horizontal position
31350 * @param {Number} y - vertical position
31351 * @param {Boolean} isInstant - disables transitions
31353 _processVerticalLayoutQueue : function( queue, isInstant )
31355 var pos = this.el.getBox(true);
31360 for (var i = 0; i < this.cols; i++){
31364 Roo.each(queue, function(box, k){
31366 var col = k % this.cols;
31368 Roo.each(box, function(b,kk){
31370 b.el.position('absolute');
31372 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31373 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31375 if(b.size == 'md-left' || b.size == 'md-right'){
31376 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31377 height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31380 b.el.setWidth(width);
31381 b.el.setHeight(height);
31383 b.el.select('iframe',true).setSize(width,height);
31387 for (var i = 0; i < this.cols; i++){
31389 if(maxY[i] < maxY[col]){
31394 col = Math.min(col, i);
31398 x = pos.x + col * (this.colWidth + this.padWidth);
31402 var positions = [];
31404 switch (box.length){
31406 positions = this.getVerticalOneBoxColPositions(x, y, box);
31409 positions = this.getVerticalTwoBoxColPositions(x, y, box);
31412 positions = this.getVerticalThreeBoxColPositions(x, y, box);
31415 positions = this.getVerticalFourBoxColPositions(x, y, box);
31421 Roo.each(box, function(b,kk){
31423 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31425 var sz = b.el.getSize();
31427 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
31435 for (var i = 0; i < this.cols; i++){
31436 mY = Math.max(mY, maxY[i]);
31439 this.el.setHeight(mY - pos.y);
31443 // _processVerticalAlternativeLayoutQueue : function( items, isInstant )
31445 // var pos = this.el.getBox(true);
31448 // var maxX = pos.right;
31450 // var maxHeight = 0;
31452 // Roo.each(items, function(item, k){
31456 // item.el.position('absolute');
31458 // var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
31460 // item.el.setWidth(width);
31462 // var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
31464 // item.el.setHeight(height);
31467 // item.el.setXY([x, y], isInstant ? false : true);
31469 // item.el.setXY([maxX - width, y], isInstant ? false : true);
31472 // y = y + height + this.alternativePadWidth;
31474 // maxHeight = maxHeight + height + this.alternativePadWidth;
31478 // this.el.setHeight(maxHeight);
31482 _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
31484 var pos = this.el.getBox(true);
31489 var maxX = pos.right;
31491 this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
31493 var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
31495 Roo.each(queue, function(box, k){
31497 Roo.each(box, function(b, kk){
31499 b.el.position('absolute');
31501 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31502 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31504 if(b.size == 'md-left' || b.size == 'md-right'){
31505 width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
31506 height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
31509 b.el.setWidth(width);
31510 b.el.setHeight(height);
31518 var positions = [];
31520 switch (box.length){
31522 positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
31525 positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
31528 positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
31531 positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
31537 Roo.each(box, function(b,kk){
31539 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
31541 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
31549 _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
31551 Roo.each(eItems, function(b,k){
31553 b.size = (k == 0) ? 'sm' : 'xs';
31554 b.x = (k == 0) ? 2 : 1;
31555 b.y = (k == 0) ? 2 : 1;
31557 b.el.position('absolute');
31559 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
31561 b.el.setWidth(width);
31563 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
31565 b.el.setHeight(height);
31569 var positions = [];
31572 x : maxX - this.unitWidth * 2 - this.gutter,
31577 x : maxX - this.unitWidth,
31578 y : minY + (this.unitWidth + this.gutter) * 2
31582 x : maxX - this.unitWidth * 3 - this.gutter * 2,
31586 Roo.each(eItems, function(b,k){
31588 b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
31594 getVerticalOneBoxColPositions : function(x, y, box)
31598 var rand = Math.floor(Math.random() * ((4 - box[0].x)));
31600 if(box[0].size == 'md-left'){
31604 if(box[0].size == 'md-right'){
31609 x : x + (this.unitWidth + this.gutter) * rand,
31616 getVerticalTwoBoxColPositions : function(x, y, box)
31620 if(box[0].size == 'xs'){
31624 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
31628 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
31642 x : x + (this.unitWidth + this.gutter) * 2,
31643 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
31650 getVerticalThreeBoxColPositions : function(x, y, box)
31654 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31662 x : x + (this.unitWidth + this.gutter) * 1,
31667 x : x + (this.unitWidth + this.gutter) * 2,
31675 if(box[0].size == 'xs' && box[1].size == 'xs'){
31684 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
31688 x : x + (this.unitWidth + this.gutter) * 1,
31702 x : x + (this.unitWidth + this.gutter) * 2,
31707 x : x + (this.unitWidth + this.gutter) * 2,
31708 y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
31715 getVerticalFourBoxColPositions : function(x, y, box)
31719 if(box[0].size == 'xs'){
31728 y : y + (this.unitHeight + this.gutter) * 1
31733 y : y + (this.unitHeight + this.gutter) * 2
31737 x : x + (this.unitWidth + this.gutter) * 1,
31751 x : x + (this.unitWidth + this.gutter) * 2,
31756 x : x + (this.unitHeightunitWidth + this.gutter) * 2,
31757 y : y + (this.unitHeight + this.gutter) * 1
31761 x : x + (this.unitWidth + this.gutter) * 2,
31762 y : y + (this.unitWidth + this.gutter) * 2
31769 getHorizontalOneBoxColPositions : function(maxX, minY, box)
31773 if(box[0].size == 'md-left'){
31775 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31782 if(box[0].size == 'md-right'){
31784 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
31785 y : minY + (this.unitWidth + this.gutter) * 1
31791 var rand = Math.floor(Math.random() * (4 - box[0].y));
31794 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31795 y : minY + (this.unitWidth + this.gutter) * rand
31802 getHorizontalTwoBoxColPositions : function(maxX, minY, box)
31806 if(box[0].size == 'xs'){
31809 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31814 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31815 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
31823 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31828 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31829 y : minY + (this.unitWidth + this.gutter) * 2
31836 getHorizontalThreeBoxColPositions : function(maxX, minY, box)
31840 if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
31843 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31848 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31849 y : minY + (this.unitWidth + this.gutter) * 1
31853 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31854 y : minY + (this.unitWidth + this.gutter) * 2
31861 if(box[0].size == 'xs' && box[1].size == 'xs'){
31864 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31869 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31874 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31875 y : minY + (this.unitWidth + this.gutter) * 1
31883 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31888 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31889 y : minY + (this.unitWidth + this.gutter) * 2
31893 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31894 y : minY + (this.unitWidth + this.gutter) * 2
31901 getHorizontalFourBoxColPositions : function(maxX, minY, box)
31905 if(box[0].size == 'xs'){
31908 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31913 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31918 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),
31923 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
31924 y : minY + (this.unitWidth + this.gutter) * 1
31932 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
31937 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
31938 y : minY + (this.unitWidth + this.gutter) * 2
31942 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
31943 y : minY + (this.unitWidth + this.gutter) * 2
31947 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),
31948 y : minY + (this.unitWidth + this.gutter) * 2
31956 * remove a Masonry Brick
31957 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
31959 removeBrick : function(brick_id)
31965 for (var i = 0; i<this.bricks.length; i++) {
31966 if (this.bricks[i].id == brick_id) {
31967 this.bricks.splice(i,1);
31968 this.el.dom.removeChild(Roo.get(brick_id).dom);
31975 * adds a Masonry Brick
31976 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31978 addBrick : function(cfg)
31980 var cn = new Roo.bootstrap.MasonryBrick(cfg);
31981 //this.register(cn);
31982 cn.parentId = this.id;
31983 cn.onRender(this.el, null);
31988 * register a Masonry Brick
31989 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
31992 register : function(brick)
31994 this.bricks.push(brick);
31995 brick.masonryId = this.id;
31999 * clear all the Masonry Brick
32001 clearAll : function()
32004 //this.getChildContainer().dom.innerHTML = "";
32005 this.el.dom.innerHTML = '';
32008 getSelected : function()
32010 if (!this.selectedBrick) {
32014 return this.selectedBrick;
32018 Roo.apply(Roo.bootstrap.LayoutMasonry, {
32022 * register a Masonry Layout
32023 * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
32026 register : function(layout)
32028 this.groups[layout.id] = layout;
32031 * fetch a Masonry Layout based on the masonry layout ID
32032 * @param {string} the masonry layout to add
32033 * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
32036 get: function(layout_id) {
32037 if (typeof(this.groups[layout_id]) == 'undefined') {
32040 return this.groups[layout_id] ;
32052 * http://masonry.desandro.com
32054 * The idea is to render all the bricks based on vertical width...
32056 * The original code extends 'outlayer' - we might need to use that....
32062 * @class Roo.bootstrap.LayoutMasonryAuto
32063 * @extends Roo.bootstrap.Component
32064 * Bootstrap Layout Masonry class
32067 * Create a new Element
32068 * @param {Object} config The config object
32071 Roo.bootstrap.LayoutMasonryAuto = function(config){
32072 Roo.bootstrap.LayoutMasonryAuto.superclass.constructor.call(this, config);
32075 Roo.extend(Roo.bootstrap.LayoutMasonryAuto, Roo.bootstrap.Component, {
32078 * @cfg {Boolean} isFitWidth - resize the width..
32080 isFitWidth : false, // options..
32082 * @cfg {Boolean} isOriginLeft = left align?
32084 isOriginLeft : true,
32086 * @cfg {Boolean} isOriginTop = top align?
32088 isOriginTop : false,
32090 * @cfg {Boolean} isLayoutInstant = no animation?
32092 isLayoutInstant : false, // needed?
32094 * @cfg {Boolean} isResizingContainer = not sure if this is used..
32096 isResizingContainer : true,
32098 * @cfg {Number} columnWidth width of the columns
32104 * @cfg {Number} maxCols maximum number of columns
32109 * @cfg {Number} padHeight padding below box..
32115 * @cfg {Boolean} isAutoInitial defalut true
32118 isAutoInitial : true,
32124 initialColumnWidth : 0,
32125 currentSize : null,
32127 colYs : null, // array.
32134 bricks: null, //CompositeElement
32135 cols : 0, // array?
32136 // element : null, // wrapped now this.el
32137 _isLayoutInited : null,
32140 getAutoCreate : function(){
32144 cls: 'blog-masonary-wrapper ' + this.cls,
32146 cls : 'mas-boxes masonary'
32153 getChildContainer: function( )
32155 if (this.boxesEl) {
32156 return this.boxesEl;
32159 this.boxesEl = this.el.select('.mas-boxes').first();
32161 return this.boxesEl;
32165 initEvents : function()
32169 if(this.isAutoInitial){
32170 Roo.log('hook children rendered');
32171 this.on('childrenrendered', function() {
32172 Roo.log('children rendered');
32179 initial : function()
32181 this.reloadItems();
32183 this.currentSize = this.el.getBox(true);
32185 /// was window resize... - let's see if this works..
32186 Roo.EventManager.onWindowResize(this.resize, this);
32188 if(!this.isAutoInitial){
32193 this.layout.defer(500,this);
32196 reloadItems: function()
32198 this.bricks = this.el.select('.masonry-brick', true);
32200 this.bricks.each(function(b) {
32201 //Roo.log(b.getSize());
32202 if (!b.attr('originalwidth')) {
32203 b.attr('originalwidth', b.getSize().width);
32208 Roo.log(this.bricks.elements.length);
32211 resize : function()
32214 var cs = this.el.getBox(true);
32216 if (this.currentSize.width == cs.width && this.currentSize.x == cs.x ) {
32217 Roo.log("no change in with or X");
32220 this.currentSize = cs;
32224 layout : function()
32227 this._resetLayout();
32228 //this._manageStamps();
32230 // don't animate first layout
32231 var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
32232 this.layoutItems( isInstant );
32234 // flag for initalized
32235 this._isLayoutInited = true;
32238 layoutItems : function( isInstant )
32240 //var items = this._getItemsForLayout( this.items );
32241 // original code supports filtering layout items.. we just ignore it..
32243 this._layoutItems( this.bricks , isInstant );
32245 this._postLayout();
32247 _layoutItems : function ( items , isInstant)
32249 //this.fireEvent( 'layout', this, items );
32252 if ( !items || !items.elements.length ) {
32253 // no items, emit event with empty array
32258 items.each(function(item) {
32259 Roo.log("layout item");
32261 // get x/y object from method
32262 var position = this._getItemLayoutPosition( item );
32264 position.item = item;
32265 position.isInstant = isInstant; // || item.isLayoutInstant; << not set yet...
32266 queue.push( position );
32269 this._processLayoutQueue( queue );
32271 /** Sets position of item in DOM
32272 * @param {Element} item
32273 * @param {Number} x - horizontal position
32274 * @param {Number} y - vertical position
32275 * @param {Boolean} isInstant - disables transitions
32277 _processLayoutQueue : function( queue )
32279 for ( var i=0, len = queue.length; i < len; i++ ) {
32280 var obj = queue[i];
32281 obj.item.position('absolute');
32282 obj.item.setXY([obj.x,obj.y], obj.isInstant ? false : true);
32288 * Any logic you want to do after each layout,
32289 * i.e. size the container
32291 _postLayout : function()
32293 this.resizeContainer();
32296 resizeContainer : function()
32298 if ( !this.isResizingContainer ) {
32301 var size = this._getContainerSize();
32303 this.el.setSize(size.width,size.height);
32304 this.boxesEl.setSize(size.width,size.height);
32310 _resetLayout : function()
32312 //this.getSize(); // -- does not really do anything.. it probably applies left/right etc. to obuject but not used
32313 this.colWidth = this.el.getWidth();
32314 //this.gutter = this.el.getWidth();
32316 this.measureColumns();
32322 this.colYs.push( 0 );
32328 measureColumns : function()
32330 this.getContainerWidth();
32331 // if columnWidth is 0, default to outerWidth of first item
32332 if ( !this.columnWidth ) {
32333 var firstItem = this.bricks.first();
32334 Roo.log(firstItem);
32335 this.columnWidth = this.containerWidth;
32336 if (firstItem && firstItem.attr('originalwidth') ) {
32337 this.columnWidth = 1* (firstItem.attr('originalwidth') || firstItem.getWidth());
32339 // columnWidth fall back to item of first element
32340 Roo.log("set column width?");
32341 this.initialColumnWidth = this.columnWidth ;
32343 // if first elem has no width, default to size of container
32348 if (this.initialColumnWidth) {
32349 this.columnWidth = this.initialColumnWidth;
32354 // column width is fixed at the top - however if container width get's smaller we should
32357 // this bit calcs how man columns..
32359 var columnWidth = this.columnWidth += this.gutter;
32361 // calculate columns
32362 var containerWidth = this.containerWidth + this.gutter;
32364 var cols = (containerWidth - this.padWidth) / (columnWidth - this.padWidth);
32365 // fix rounding errors, typically with gutters
32366 var excess = columnWidth - containerWidth % columnWidth;
32369 // if overshoot is less than a pixel, round up, otherwise floor it
32370 var mathMethod = excess && excess < 1 ? 'round' : 'floor';
32371 cols = Math[ mathMethod ]( cols );
32372 this.cols = Math.max( cols, 1 );
32373 this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
32375 // padding positioning..
32376 var totalColWidth = this.cols * this.columnWidth;
32377 var padavail = this.containerWidth - totalColWidth;
32378 // so for 2 columns - we need 3 'pads'
32380 var padNeeded = (1+this.cols) * this.padWidth;
32382 var padExtra = Math.floor((padavail - padNeeded) / this.cols);
32384 this.columnWidth += padExtra
32385 //this.padWidth = Math.floor(padavail / ( this.cols));
32387 // adjust colum width so that padding is fixed??
32389 // we have 3 columns ... total = width * 3
32390 // we have X left over... that should be used by
32392 //if (this.expandC) {
32400 getContainerWidth : function()
32402 /* // container is parent if fit width
32403 var container = this.isFitWidth ? this.element.parentNode : this.element;
32404 // check that this.size and size are there
32405 // IE8 triggers resize on body size change, so they might not be
32407 var size = getSize( container ); //FIXME
32408 this.containerWidth = size && size.innerWidth; //FIXME
32411 this.containerWidth = this.el.getBox(true).width; //maybe use getComputedWidth
32415 _getItemLayoutPosition : function( item ) // what is item?
32417 // we resize the item to our columnWidth..
32419 item.setWidth(this.columnWidth);
32420 item.autoBoxAdjust = false;
32422 var sz = item.getSize();
32424 // how many columns does this brick span
32425 var remainder = this.containerWidth % this.columnWidth;
32427 var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
32428 // round if off by 1 pixel, otherwise use ceil
32429 var colSpan = Math[ mathMethod ]( sz.width / this.columnWidth );
32430 colSpan = Math.min( colSpan, this.cols );
32432 // normally this should be '1' as we dont' currently allow multi width columns..
32434 var colGroup = this._getColGroup( colSpan );
32435 // get the minimum Y value from the columns
32436 var minimumY = Math.min.apply( Math, colGroup );
32437 Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32439 var shortColIndex = colGroup.indexOf( minimumY ); // broken on ie8..?? probably...
32441 // position the brick
32443 x: this.currentSize.x + (this.padWidth /2) + ((this.columnWidth + this.padWidth )* shortColIndex),
32444 y: this.currentSize.y + minimumY + this.padHeight
32448 // apply setHeight to necessary columns
32449 var setHeight = minimumY + sz.height + this.padHeight;
32450 //Roo.log([ 'setHeight', minimumY, sz.height, setHeight ]);
32452 var setSpan = this.cols + 1 - colGroup.length;
32453 for ( var i = 0; i < setSpan; i++ ) {
32454 this.colYs[ shortColIndex + i ] = setHeight ;
32461 * @param {Number} colSpan - number of columns the element spans
32462 * @returns {Array} colGroup
32464 _getColGroup : function( colSpan )
32466 if ( colSpan < 2 ) {
32467 // if brick spans only one column, use all the column Ys
32472 // how many different places could this brick fit horizontally
32473 var groupCount = this.cols + 1 - colSpan;
32474 // for each group potential horizontal position
32475 for ( var i = 0; i < groupCount; i++ ) {
32476 // make an array of colY values for that one group
32477 var groupColYs = this.colYs.slice( i, i + colSpan );
32478 // and get the max value of the array
32479 colGroup[i] = Math.max.apply( Math, groupColYs );
32484 _manageStamp : function( stamp )
32486 var stampSize = stamp.getSize();
32487 var offset = stamp.getBox();
32488 // get the columns that this stamp affects
32489 var firstX = this.isOriginLeft ? offset.x : offset.right;
32490 var lastX = firstX + stampSize.width;
32491 var firstCol = Math.floor( firstX / this.columnWidth );
32492 firstCol = Math.max( 0, firstCol );
32494 var lastCol = Math.floor( lastX / this.columnWidth );
32495 // lastCol should not go over if multiple of columnWidth #425
32496 lastCol -= lastX % this.columnWidth ? 0 : 1;
32497 lastCol = Math.min( this.cols - 1, lastCol );
32499 // set colYs to bottom of the stamp
32500 var stampMaxY = ( this.isOriginTop ? offset.y : offset.bottom ) +
32503 for ( var i = firstCol; i <= lastCol; i++ ) {
32504 this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
32509 _getContainerSize : function()
32511 this.maxY = Math.max.apply( Math, this.colYs );
32516 if ( this.isFitWidth ) {
32517 size.width = this._getContainerFitWidth();
32523 _getContainerFitWidth : function()
32525 var unusedCols = 0;
32526 // count unused columns
32529 if ( this.colYs[i] !== 0 ) {
32534 // fit container to columns that have been used
32535 return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
32538 needsResizeLayout : function()
32540 var previousWidth = this.containerWidth;
32541 this.getContainerWidth();
32542 return previousWidth !== this.containerWidth;
32557 * @class Roo.bootstrap.MasonryBrick
32558 * @extends Roo.bootstrap.Component
32559 * Bootstrap MasonryBrick class
32562 * Create a new MasonryBrick
32563 * @param {Object} config The config object
32566 Roo.bootstrap.MasonryBrick = function(config){
32568 Roo.bootstrap.MasonryBrick.superclass.constructor.call(this, config);
32570 Roo.bootstrap.MasonryBrick.register(this);
32576 * When a MasonryBrick is clcik
32577 * @param {Roo.bootstrap.MasonryBrick} this
32578 * @param {Roo.EventObject} e
32584 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component, {
32587 * @cfg {String} title
32591 * @cfg {String} html
32595 * @cfg {String} bgimage
32599 * @cfg {String} videourl
32603 * @cfg {String} cls
32607 * @cfg {String} href
32611 * @cfg {String} size (xs|sm|md|md-left|md-right|tall|wide)
32616 * @cfg {String} placetitle (center|bottom)
32621 * @cfg {Boolean} isFitContainer defalut true
32623 isFitContainer : true,
32626 * @cfg {Boolean} preventDefault defalut false
32628 preventDefault : false,
32631 * @cfg {Boolean} inverse defalut false
32633 maskInverse : false,
32635 getAutoCreate : function()
32637 if(!this.isFitContainer){
32638 return this.getSplitAutoCreate();
32641 var cls = 'masonry-brick masonry-brick-full';
32643 if(this.href.length){
32644 cls += ' masonry-brick-link';
32647 if(this.bgimage.length){
32648 cls += ' masonry-brick-image';
32651 if(this.maskInverse){
32652 cls += ' mask-inverse';
32655 if(!this.html.length && !this.maskInverse && !this.videourl.length){
32656 cls += ' enable-mask';
32660 cls += ' masonry-' + this.size + '-brick';
32663 if(this.placetitle.length){
32665 switch (this.placetitle) {
32667 cls += ' masonry-center-title';
32670 cls += ' masonry-bottom-title';
32677 if(!this.html.length && !this.bgimage.length){
32678 cls += ' masonry-center-title';
32681 if(!this.html.length && this.bgimage.length){
32682 cls += ' masonry-bottom-title';
32687 cls += ' ' + this.cls;
32691 tag: (this.href.length) ? 'a' : 'div',
32696 cls: 'masonry-brick-mask'
32700 cls: 'masonry-brick-paragraph',
32706 if(this.href.length){
32707 cfg.href = this.href;
32710 var cn = cfg.cn[1].cn;
32712 if(this.title.length){
32715 cls: 'masonry-brick-title',
32720 if(this.html.length){
32723 cls: 'masonry-brick-text',
32728 if (!this.title.length && !this.html.length) {
32729 cfg.cn[1].cls += ' hide';
32732 if(this.bgimage.length){
32735 cls: 'masonry-brick-image-view',
32740 if(this.videourl.length){
32741 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32742 // youtube support only?
32745 cls: 'masonry-brick-image-view',
32748 allowfullscreen : true
32756 getSplitAutoCreate : function()
32758 var cls = 'masonry-brick masonry-brick-split';
32760 if(this.href.length){
32761 cls += ' masonry-brick-link';
32764 if(this.bgimage.length){
32765 cls += ' masonry-brick-image';
32769 cls += ' masonry-' + this.size + '-brick';
32772 switch (this.placetitle) {
32774 cls += ' masonry-center-title';
32777 cls += ' masonry-bottom-title';
32780 if(!this.bgimage.length){
32781 cls += ' masonry-center-title';
32784 if(this.bgimage.length){
32785 cls += ' masonry-bottom-title';
32791 cls += ' ' + this.cls;
32795 tag: (this.href.length) ? 'a' : 'div',
32800 cls: 'masonry-brick-split-head',
32804 cls: 'masonry-brick-paragraph',
32811 cls: 'masonry-brick-split-body',
32817 if(this.href.length){
32818 cfg.href = this.href;
32821 if(this.title.length){
32822 cfg.cn[0].cn[0].cn.push({
32824 cls: 'masonry-brick-title',
32829 if(this.html.length){
32830 cfg.cn[1].cn.push({
32832 cls: 'masonry-brick-text',
32837 if(this.bgimage.length){
32838 cfg.cn[0].cn.push({
32840 cls: 'masonry-brick-image-view',
32845 if(this.videourl.length){
32846 var vurl = this.videourl.replace(/https:\/\/youtu\.be/, 'https://www.youtube.com/embed/');
32847 // youtube support only?
32848 cfg.cn[0].cn.cn.push({
32850 cls: 'masonry-brick-image-view',
32853 allowfullscreen : true
32860 initEvents: function()
32862 switch (this.size) {
32895 this.el.on('touchstart', this.onTouchStart, this);
32896 this.el.on('touchmove', this.onTouchMove, this);
32897 this.el.on('touchend', this.onTouchEnd, this);
32898 this.el.on('contextmenu', this.onContextMenu, this);
32900 this.el.on('mouseenter' ,this.enter, this);
32901 this.el.on('mouseleave', this.leave, this);
32902 this.el.on('click', this.onClick, this);
32905 if (typeof(this.parent().bricks) == 'object' && this.parent().bricks != null) {
32906 this.parent().bricks.push(this);
32911 onClick: function(e, el)
32913 var time = this.endTimer - this.startTimer;
32914 // Roo.log(e.preventDefault());
32917 e.preventDefault();
32922 if(!this.preventDefault){
32926 e.preventDefault();
32928 if (this.activeClass != '') {
32929 this.selectBrick();
32932 this.fireEvent('click', this, e);
32935 enter: function(e, el)
32937 e.preventDefault();
32939 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32943 if(this.bgimage.length && this.html.length){
32944 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32948 leave: function(e, el)
32950 e.preventDefault();
32952 if(!this.isFitContainer || this.maskInverse || this.videourl.length){
32956 if(this.bgimage.length && this.html.length){
32957 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
32961 onTouchStart: function(e, el)
32963 // e.preventDefault();
32965 this.touchmoved = false;
32967 if(!this.isFitContainer){
32971 if(!this.bgimage.length || !this.html.length){
32975 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
32977 this.timer = new Date().getTime();
32981 onTouchMove: function(e, el)
32983 this.touchmoved = true;
32986 onContextMenu : function(e,el)
32988 e.preventDefault();
32989 e.stopPropagation();
32993 onTouchEnd: function(e, el)
32995 // e.preventDefault();
32997 if((new Date().getTime() - this.timer > 1000) || !this.href.length || this.touchmoved){
33004 if(!this.bgimage.length || !this.html.length){
33006 if(this.href.length){
33007 window.location.href = this.href;
33013 if(!this.isFitContainer){
33017 this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
33019 window.location.href = this.href;
33022 //selection on single brick only
33023 selectBrick : function() {
33025 if (!this.parentId) {
33029 var m = Roo.bootstrap.LayoutMasonry.get(this.parentId);
33030 var index = m.selectedBrick.indexOf(this.id);
33033 m.selectedBrick.splice(index,1);
33034 this.el.removeClass(this.activeClass);
33038 for(var i = 0; i < m.selectedBrick.length; i++) {
33039 var b = Roo.bootstrap.MasonryBrick.get(m.selectedBrick[i]);
33040 b.el.removeClass(b.activeClass);
33043 m.selectedBrick = [];
33045 m.selectedBrick.push(this.id);
33046 this.el.addClass(this.activeClass);
33050 isSelected : function(){
33051 return this.el.hasClass(this.activeClass);
33056 Roo.apply(Roo.bootstrap.MasonryBrick, {
33059 groups : new Roo.util.MixedCollection(false, function(o) { return o.el.id; }),
33061 * register a Masonry Brick
33062 * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
33065 register : function(brick)
33067 //this.groups[brick.id] = brick;
33068 this.groups.add(brick.id, brick);
33071 * fetch a masonry brick based on the masonry brick ID
33072 * @param {string} the masonry brick to add
33073 * @returns {Roo.bootstrap.MasonryBrick} the masonry brick
33076 get: function(brick_id)
33078 // if (typeof(this.groups[brick_id]) == 'undefined') {
33081 // return this.groups[brick_id] ;
33083 if(this.groups.key(brick_id)) {
33084 return this.groups.key(brick_id);
33102 * @class Roo.bootstrap.Brick
33103 * @extends Roo.bootstrap.Component
33104 * Bootstrap Brick class
33107 * Create a new Brick
33108 * @param {Object} config The config object
33111 Roo.bootstrap.Brick = function(config){
33112 Roo.bootstrap.Brick.superclass.constructor.call(this, config);
33118 * When a Brick is click
33119 * @param {Roo.bootstrap.Brick} this
33120 * @param {Roo.EventObject} e
33126 Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component, {
33129 * @cfg {String} title
33133 * @cfg {String} html
33137 * @cfg {String} bgimage
33141 * @cfg {String} cls
33145 * @cfg {String} href
33149 * @cfg {String} video
33153 * @cfg {Boolean} square
33157 getAutoCreate : function()
33159 var cls = 'roo-brick';
33161 if(this.href.length){
33162 cls += ' roo-brick-link';
33165 if(this.bgimage.length){
33166 cls += ' roo-brick-image';
33169 if(!this.html.length && !this.bgimage.length){
33170 cls += ' roo-brick-center-title';
33173 if(!this.html.length && this.bgimage.length){
33174 cls += ' roo-brick-bottom-title';
33178 cls += ' ' + this.cls;
33182 tag: (this.href.length) ? 'a' : 'div',
33187 cls: 'roo-brick-paragraph',
33193 if(this.href.length){
33194 cfg.href = this.href;
33197 var cn = cfg.cn[0].cn;
33199 if(this.title.length){
33202 cls: 'roo-brick-title',
33207 if(this.html.length){
33210 cls: 'roo-brick-text',
33217 if(this.bgimage.length){
33220 cls: 'roo-brick-image-view',
33228 initEvents: function()
33230 if(this.title.length || this.html.length){
33231 this.el.on('mouseenter' ,this.enter, this);
33232 this.el.on('mouseleave', this.leave, this);
33235 Roo.EventManager.onWindowResize(this.resize, this);
33237 if(this.bgimage.length){
33238 this.imageEl = this.el.select('.roo-brick-image-view', true).first();
33239 this.imageEl.on('load', this.onImageLoad, this);
33246 onImageLoad : function()
33251 resize : function()
33253 var paragraph = this.el.select('.roo-brick-paragraph', true).first();
33255 paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
33257 if(this.bgimage.length){
33258 var image = this.el.select('.roo-brick-image-view', true).first();
33260 image.setWidth(paragraph.getWidth());
33263 image.setHeight(paragraph.getWidth());
33266 this.el.setHeight(image.getHeight());
33267 paragraph.setHeight(image.getHeight());
33273 enter: function(e, el)
33275 e.preventDefault();
33277 if(this.bgimage.length){
33278 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
33279 this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
33283 leave: function(e, el)
33285 e.preventDefault();
33287 if(this.bgimage.length){
33288 this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
33289 this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
33304 * @class Roo.bootstrap.NumberField
33305 * @extends Roo.bootstrap.Input
33306 * Bootstrap NumberField class
33312 * Create a new NumberField
33313 * @param {Object} config The config object
33316 Roo.bootstrap.NumberField = function(config){
33317 Roo.bootstrap.NumberField.superclass.constructor.call(this, config);
33320 Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
33323 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
33325 allowDecimals : true,
33327 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
33329 decimalSeparator : ".",
33331 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
33333 decimalPrecision : 2,
33335 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
33337 allowNegative : true,
33340 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
33344 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
33346 minValue : Number.NEGATIVE_INFINITY,
33348 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
33350 maxValue : Number.MAX_VALUE,
33352 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
33354 minText : "The minimum value for this field is {0}",
33356 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
33358 maxText : "The maximum value for this field is {0}",
33360 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
33361 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
33363 nanText : "{0} is not a valid number",
33365 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
33367 thousandsDelimiter : false,
33369 * @cfg {String} valueAlign alignment of value
33371 valueAlign : "left",
33373 getAutoCreate : function()
33375 var hiddenInput = {
33379 cls: 'hidden-number-input'
33383 hiddenInput.name = this.name;
33388 var cfg = Roo.bootstrap.NumberField.superclass.getAutoCreate.call(this);
33390 this.name = hiddenInput.name;
33392 if(cfg.cn.length > 0) {
33393 cfg.cn.push(hiddenInput);
33400 initEvents : function()
33402 Roo.bootstrap.NumberField.superclass.initEvents.call(this);
33404 var allowed = "0123456789";
33406 if(this.allowDecimals){
33407 allowed += this.decimalSeparator;
33410 if(this.allowNegative){
33414 if(this.thousandsDelimiter) {
33418 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
33420 var keyPress = function(e){
33422 var k = e.getKey();
33424 var c = e.getCharCode();
33427 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
33428 allowed.indexOf(String.fromCharCode(c)) === -1
33434 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
33438 if(allowed.indexOf(String.fromCharCode(c)) === -1){
33443 this.el.on("keypress", keyPress, this);
33446 validateValue : function(value)
33449 if(!Roo.bootstrap.NumberField.superclass.validateValue.call(this, value)){
33453 var num = this.parseValue(value);
33456 this.markInvalid(String.format(this.nanText, value));
33460 if(num < this.minValue){
33461 this.markInvalid(String.format(this.minText, this.minValue));
33465 if(num > this.maxValue){
33466 this.markInvalid(String.format(this.maxText, this.maxValue));
33473 getValue : function()
33475 var v = this.hiddenEl().getValue();
33477 return this.fixPrecision(this.parseValue(v));
33480 parseValue : function(value)
33482 if(this.thousandsDelimiter) {
33484 r = new RegExp(",", "g");
33485 value = value.replace(r, "");
33488 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
33489 return isNaN(value) ? '' : value;
33492 fixPrecision : function(value)
33494 if(this.thousandsDelimiter) {
33496 r = new RegExp(",", "g");
33497 value = value.replace(r, "");
33500 var nan = isNaN(value);
33502 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
33503 return nan ? '' : value;
33505 return parseFloat(value).toFixed(this.decimalPrecision);
33508 setValue : function(v)
33510 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
33516 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
33518 this.inputEl().dom.value = (v == '') ? '' :
33519 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
33521 if(!this.allowZero && v === '0') {
33522 this.hiddenEl().dom.value = '';
33523 this.inputEl().dom.value = '';
33530 decimalPrecisionFcn : function(v)
33532 return Math.floor(v);
33535 beforeBlur : function()
33537 var v = this.parseValue(this.getRawValue());
33539 if(v || v === 0 || v === ''){
33544 hiddenEl : function()
33546 return this.el.select('input.hidden-number-input',true).first();
33558 * @class Roo.bootstrap.DocumentSlider
33559 * @extends Roo.bootstrap.Component
33560 * Bootstrap DocumentSlider class
33563 * Create a new DocumentViewer
33564 * @param {Object} config The config object
33567 Roo.bootstrap.DocumentSlider = function(config){
33568 Roo.bootstrap.DocumentSlider.superclass.constructor.call(this, config);
33575 * Fire after initEvent
33576 * @param {Roo.bootstrap.DocumentSlider} this
33581 * Fire after update
33582 * @param {Roo.bootstrap.DocumentSlider} this
33588 * @param {Roo.bootstrap.DocumentSlider} this
33594 Roo.extend(Roo.bootstrap.DocumentSlider, Roo.bootstrap.Component, {
33600 getAutoCreate : function()
33604 cls : 'roo-document-slider',
33608 cls : 'roo-document-slider-header',
33612 cls : 'roo-document-slider-header-title'
33618 cls : 'roo-document-slider-body',
33622 cls : 'roo-document-slider-prev',
33626 cls : 'fa fa-chevron-left'
33632 cls : 'roo-document-slider-thumb',
33636 cls : 'roo-document-slider-image'
33642 cls : 'roo-document-slider-next',
33646 cls : 'fa fa-chevron-right'
33658 initEvents : function()
33660 this.headerEl = this.el.select('.roo-document-slider-header', true).first();
33661 this.headerEl.setVisibilityMode(Roo.Element.DISPLAY);
33663 this.titleEl = this.el.select('.roo-document-slider-header .roo-document-slider-header-title', true).first();
33664 this.titleEl.setVisibilityMode(Roo.Element.DISPLAY);
33666 this.bodyEl = this.el.select('.roo-document-slider-body', true).first();
33667 this.bodyEl.setVisibilityMode(Roo.Element.DISPLAY);
33669 this.thumbEl = this.el.select('.roo-document-slider-thumb', true).first();
33670 this.thumbEl.setVisibilityMode(Roo.Element.DISPLAY);
33672 this.imageEl = this.el.select('.roo-document-slider-image', true).first();
33673 this.imageEl.setVisibilityMode(Roo.Element.DISPLAY);
33675 this.prevIndicator = this.el.select('.roo-document-slider-prev i', true).first();
33676 this.prevIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33678 this.nextIndicator = this.el.select('.roo-document-slider-next i', true).first();
33679 this.nextIndicator.setVisibilityMode(Roo.Element.DISPLAY);
33681 this.thumbEl.on('click', this.onClick, this);
33683 this.prevIndicator.on('click', this.prev, this);
33685 this.nextIndicator.on('click', this.next, this);
33689 initial : function()
33691 if(this.files.length){
33692 this.indicator = 1;
33696 this.fireEvent('initial', this);
33699 update : function()
33701 this.imageEl.attr('src', this.files[this.indicator - 1]);
33703 this.titleEl.dom.innerHTML = String.format('{0} / {1}', this.indicator, this.files.length);
33705 this.prevIndicator.show();
33707 if(this.indicator == 1){
33708 this.prevIndicator.hide();
33711 this.nextIndicator.show();
33713 if(this.indicator == this.files.length){
33714 this.nextIndicator.hide();
33717 this.thumbEl.scrollTo('top');
33719 this.fireEvent('update', this);
33722 onClick : function(e)
33724 e.preventDefault();
33726 this.fireEvent('click', this);
33731 e.preventDefault();
33733 this.indicator = Math.max(1, this.indicator - 1);
33740 e.preventDefault();
33742 this.indicator = Math.min(this.files.length, this.indicator + 1);
33756 * @class Roo.bootstrap.RadioSet
33757 * @extends Roo.bootstrap.Input
33758 * Bootstrap RadioSet class
33759 * @cfg {String} indicatorpos (left|right) default left
33760 * @cfg {Boolean} inline (true|false) inline the element (default true)
33761 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
33763 * Create a new RadioSet
33764 * @param {Object} config The config object
33767 Roo.bootstrap.RadioSet = function(config){
33769 Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
33773 Roo.bootstrap.RadioSet.register(this);
33778 * Fires when the element is checked or unchecked.
33779 * @param {Roo.bootstrap.RadioSet} this This radio
33780 * @param {Roo.bootstrap.Radio} item The checked item
33785 * Fires when the element is click.
33786 * @param {Roo.bootstrap.RadioSet} this This radio set
33787 * @param {Roo.bootstrap.Radio} item The checked item
33788 * @param {Roo.EventObject} e The event object
33795 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
33803 indicatorpos : 'left',
33805 getAutoCreate : function()
33809 cls : 'roo-radio-set-label',
33813 html : this.fieldLabel
33818 if(this.indicatorpos == 'left'){
33821 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
33822 tooltip : 'This field is required'
33827 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
33828 tooltip : 'This field is required'
33834 cls : 'roo-radio-set-items'
33837 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
33839 if (align === 'left' && this.fieldLabel.length) {
33842 cls : "roo-radio-set-right",
33848 if(this.labelWidth > 12){
33849 label.style = "width: " + this.labelWidth + 'px';
33852 if(this.labelWidth < 13 && this.labelmd == 0){
33853 this.labelmd = this.labelWidth;
33856 if(this.labellg > 0){
33857 label.cls += ' col-lg-' + this.labellg;
33858 items.cls += ' col-lg-' + (12 - this.labellg);
33861 if(this.labelmd > 0){
33862 label.cls += ' col-md-' + this.labelmd;
33863 items.cls += ' col-md-' + (12 - this.labelmd);
33866 if(this.labelsm > 0){
33867 label.cls += ' col-sm-' + this.labelsm;
33868 items.cls += ' col-sm-' + (12 - this.labelsm);
33871 if(this.labelxs > 0){
33872 label.cls += ' col-xs-' + this.labelxs;
33873 items.cls += ' col-xs-' + (12 - this.labelxs);
33879 cls : 'roo-radio-set',
33883 cls : 'roo-radio-set-input',
33886 value : this.value ? this.value : ''
33893 if(this.weight.length){
33894 cfg.cls += ' roo-radio-' + this.weight;
33898 cfg.cls += ' roo-radio-set-inline';
33902 ['xs','sm','md','lg'].map(function(size){
33903 if (settings[size]) {
33904 cfg.cls += ' col-' + size + '-' + settings[size];
33912 initEvents : function()
33914 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
33915 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
33917 if(!this.fieldLabel.length){
33918 this.labelEl.hide();
33921 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
33922 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
33924 this.indicator = this.indicatorEl();
33926 if(this.indicator){
33927 this.indicator.addClass('invisible');
33930 this.originalValue = this.getValue();
33934 inputEl: function ()
33936 return this.el.select('.roo-radio-set-input', true).first();
33939 getChildContainer : function()
33941 return this.itemsEl;
33944 register : function(item)
33946 this.radioes.push(item);
33950 validate : function()
33952 if(this.getVisibilityEl().hasClass('hidden')){
33958 Roo.each(this.radioes, function(i){
33967 if(this.allowBlank) {
33971 if(this.disabled || valid){
33976 this.markInvalid();
33981 markValid : function()
33983 if(this.labelEl.isVisible(true)){
33984 this.indicatorEl().removeClass('visible');
33985 this.indicatorEl().addClass('invisible');
33988 this.el.removeClass([this.invalidClass, this.validClass]);
33989 this.el.addClass(this.validClass);
33991 this.fireEvent('valid', this);
33994 markInvalid : function(msg)
33996 if(this.allowBlank || this.disabled){
34000 if(this.labelEl.isVisible(true)){
34001 this.indicatorEl().removeClass('invisible');
34002 this.indicatorEl().addClass('visible');
34005 this.el.removeClass([this.invalidClass, this.validClass]);
34006 this.el.addClass(this.invalidClass);
34008 this.fireEvent('invalid', this, msg);
34012 setValue : function(v, suppressEvent)
34014 if(this.value === v){
34021 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
34024 Roo.each(this.radioes, function(i){
34026 i.el.removeClass('checked');
34029 Roo.each(this.radioes, function(i){
34031 if(i.value === v || i.value.toString() === v.toString()){
34033 i.el.addClass('checked');
34035 if(suppressEvent !== true){
34036 this.fireEvent('check', this, i);
34047 clearInvalid : function(){
34049 if(!this.el || this.preventMark){
34053 this.el.removeClass([this.invalidClass]);
34055 this.fireEvent('valid', this);
34060 Roo.apply(Roo.bootstrap.RadioSet, {
34064 register : function(set)
34066 this.groups[set.name] = set;
34069 get: function(name)
34071 if (typeof(this.groups[name]) == 'undefined') {
34075 return this.groups[name] ;
34081 * Ext JS Library 1.1.1
34082 * Copyright(c) 2006-2007, Ext JS, LLC.
34084 * Originally Released Under LGPL - original licence link has changed is not relivant.
34087 * <script type="text/javascript">
34092 * @class Roo.bootstrap.SplitBar
34093 * @extends Roo.util.Observable
34094 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
34098 var split = new Roo.bootstrap.SplitBar("elementToDrag", "elementToSize",
34099 Roo.bootstrap.SplitBar.HORIZONTAL, Roo.bootstrap.SplitBar.LEFT);
34100 split.setAdapter(new Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter("container"));
34101 split.minSize = 100;
34102 split.maxSize = 600;
34103 split.animate = true;
34104 split.on('moved', splitterMoved);
34107 * Create a new SplitBar
34108 * @config {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
34109 * @config {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
34110 * @config {Number} orientation (optional) Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34111 * @config {Number} placement (optional) Either Roo.bootstrap.SplitBar.LEFT or Roo.bootstrap.SplitBar.RIGHT for horizontal or
34112 Roo.bootstrap.SplitBar.TOP or Roo.bootstrap.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
34113 position of the SplitBar).
34115 Roo.bootstrap.SplitBar = function(cfg){
34120 // dragElement : elm
34121 // resizingElement: el,
34123 // orientation : Either Roo.bootstrap.SplitBar.HORIZONTAL
34124 // placement : Roo.bootstrap.SplitBar.LEFT ,
34125 // existingProxy ???
34128 this.el = Roo.get(cfg.dragElement, true);
34129 this.el.dom.unselectable = "on";
34131 this.resizingEl = Roo.get(cfg.resizingElement, true);
34135 * The orientation of the split. Either Roo.bootstrap.SplitBar.HORIZONTAL or Roo.bootstrap.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
34136 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
34139 this.orientation = cfg.orientation || Roo.bootstrap.SplitBar.HORIZONTAL;
34142 * The minimum size of the resizing element. (Defaults to 0)
34148 * The maximum size of the resizing element. (Defaults to 2000)
34151 this.maxSize = 2000;
34154 * Whether to animate the transition to the new size
34157 this.animate = false;
34160 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
34163 this.useShim = false;
34168 if(!cfg.existingProxy){
34170 this.proxy = Roo.bootstrap.SplitBar.createProxy(this.orientation);
34172 this.proxy = Roo.get(cfg.existingProxy).dom;
34175 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
34178 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
34181 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
34184 this.dragSpecs = {};
34187 * @private The adapter to use to positon and resize elements
34189 this.adapter = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34190 this.adapter.init(this);
34192 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34194 this.placement = cfg.placement || (this.el.getX() > this.resizingEl.getX() ? Roo.bootstrap.SplitBar.LEFT : Roo.bootstrap.SplitBar.RIGHT);
34195 this.el.addClass("roo-splitbar-h");
34198 this.placement = cfg.placement || (this.el.getY() > this.resizingEl.getY() ? Roo.bootstrap.SplitBar.TOP : Roo.bootstrap.SplitBar.BOTTOM);
34199 this.el.addClass("roo-splitbar-v");
34205 * Fires when the splitter is moved (alias for {@link #event-moved})
34206 * @param {Roo.bootstrap.SplitBar} this
34207 * @param {Number} newSize the new width or height
34212 * Fires when the splitter is moved
34213 * @param {Roo.bootstrap.SplitBar} this
34214 * @param {Number} newSize the new width or height
34218 * @event beforeresize
34219 * Fires before the splitter is dragged
34220 * @param {Roo.bootstrap.SplitBar} this
34222 "beforeresize" : true,
34224 "beforeapply" : true
34227 Roo.util.Observable.call(this);
34230 Roo.extend(Roo.bootstrap.SplitBar, Roo.util.Observable, {
34231 onStartProxyDrag : function(x, y){
34232 this.fireEvent("beforeresize", this);
34234 var o = Roo.DomHelper.insertFirst(document.body, {cls: "roo-drag-overlay", html: " "}, true);
34236 o.enableDisplayMode("block");
34237 // all splitbars share the same overlay
34238 Roo.bootstrap.SplitBar.prototype.overlay = o;
34240 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
34241 this.overlay.show();
34242 Roo.get(this.proxy).setDisplayed("block");
34243 var size = this.adapter.getElementSize(this);
34244 this.activeMinSize = this.getMinimumSize();;
34245 this.activeMaxSize = this.getMaximumSize();;
34246 var c1 = size - this.activeMinSize;
34247 var c2 = Math.max(this.activeMaxSize - size, 0);
34248 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34249 this.dd.resetConstraints();
34250 this.dd.setXConstraint(
34251 this.placement == Roo.bootstrap.SplitBar.LEFT ? c1 : c2,
34252 this.placement == Roo.bootstrap.SplitBar.LEFT ? c2 : c1
34254 this.dd.setYConstraint(0, 0);
34256 this.dd.resetConstraints();
34257 this.dd.setXConstraint(0, 0);
34258 this.dd.setYConstraint(
34259 this.placement == Roo.bootstrap.SplitBar.TOP ? c1 : c2,
34260 this.placement == Roo.bootstrap.SplitBar.TOP ? c2 : c1
34263 this.dragSpecs.startSize = size;
34264 this.dragSpecs.startPoint = [x, y];
34265 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
34269 * @private Called after the drag operation by the DDProxy
34271 onEndProxyDrag : function(e){
34272 Roo.get(this.proxy).setDisplayed(false);
34273 var endPoint = Roo.lib.Event.getXY(e);
34275 this.overlay.hide();
34278 if(this.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34279 newSize = this.dragSpecs.startSize +
34280 (this.placement == Roo.bootstrap.SplitBar.LEFT ?
34281 endPoint[0] - this.dragSpecs.startPoint[0] :
34282 this.dragSpecs.startPoint[0] - endPoint[0]
34285 newSize = this.dragSpecs.startSize +
34286 (this.placement == Roo.bootstrap.SplitBar.TOP ?
34287 endPoint[1] - this.dragSpecs.startPoint[1] :
34288 this.dragSpecs.startPoint[1] - endPoint[1]
34291 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
34292 if(newSize != this.dragSpecs.startSize){
34293 if(this.fireEvent('beforeapply', this, newSize) !== false){
34294 this.adapter.setElementSize(this, newSize);
34295 this.fireEvent("moved", this, newSize);
34296 this.fireEvent("resize", this, newSize);
34302 * Get the adapter this SplitBar uses
34303 * @return The adapter object
34305 getAdapter : function(){
34306 return this.adapter;
34310 * Set the adapter this SplitBar uses
34311 * @param {Object} adapter A SplitBar adapter object
34313 setAdapter : function(adapter){
34314 this.adapter = adapter;
34315 this.adapter.init(this);
34319 * Gets the minimum size for the resizing element
34320 * @return {Number} The minimum size
34322 getMinimumSize : function(){
34323 return this.minSize;
34327 * Sets the minimum size for the resizing element
34328 * @param {Number} minSize The minimum size
34330 setMinimumSize : function(minSize){
34331 this.minSize = minSize;
34335 * Gets the maximum size for the resizing element
34336 * @return {Number} The maximum size
34338 getMaximumSize : function(){
34339 return this.maxSize;
34343 * Sets the maximum size for the resizing element
34344 * @param {Number} maxSize The maximum size
34346 setMaximumSize : function(maxSize){
34347 this.maxSize = maxSize;
34351 * Sets the initialize size for the resizing element
34352 * @param {Number} size The initial size
34354 setCurrentSize : function(size){
34355 var oldAnimate = this.animate;
34356 this.animate = false;
34357 this.adapter.setElementSize(this, size);
34358 this.animate = oldAnimate;
34362 * Destroy this splitbar.
34363 * @param {Boolean} removeEl True to remove the element
34365 destroy : function(removeEl){
34367 this.shim.remove();
34370 this.proxy.parentNode.removeChild(this.proxy);
34378 * @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.
34380 Roo.bootstrap.SplitBar.createProxy = function(dir){
34381 var proxy = new Roo.Element(document.createElement("div"));
34382 proxy.unselectable();
34383 var cls = 'roo-splitbar-proxy';
34384 proxy.addClass(cls + ' ' + (dir == Roo.bootstrap.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
34385 document.body.appendChild(proxy.dom);
34390 * @class Roo.bootstrap.SplitBar.BasicLayoutAdapter
34391 * Default Adapter. It assumes the splitter and resizing element are not positioned
34392 * elements and only gets/sets the width of the element. Generally used for table based layouts.
34394 Roo.bootstrap.SplitBar.BasicLayoutAdapter = function(){
34397 Roo.bootstrap.SplitBar.BasicLayoutAdapter.prototype = {
34398 // do nothing for now
34399 init : function(s){
34403 * Called before drag operations to get the current size of the resizing element.
34404 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34406 getElementSize : function(s){
34407 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34408 return s.resizingEl.getWidth();
34410 return s.resizingEl.getHeight();
34415 * Called after drag operations to set the size of the resizing element.
34416 * @param {Roo.bootstrap.SplitBar} s The SplitBar using this adapter
34417 * @param {Number} newSize The new size to set
34418 * @param {Function} onComplete A function to be invoked when resizing is complete
34420 setElementSize : function(s, newSize, onComplete){
34421 if(s.orientation == Roo.bootstrap.SplitBar.HORIZONTAL){
34423 s.resizingEl.setWidth(newSize);
34425 onComplete(s, newSize);
34428 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
34433 s.resizingEl.setHeight(newSize);
34435 onComplete(s, newSize);
34438 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
34445 *@class Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter
34446 * @extends Roo.bootstrap.SplitBar.BasicLayoutAdapter
34447 * Adapter that moves the splitter element to align with the resized sizing element.
34448 * Used with an absolute positioned SplitBar.
34449 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
34450 * document.body, make sure you assign an id to the body element.
34452 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter = function(container){
34453 this.basic = new Roo.bootstrap.SplitBar.BasicLayoutAdapter();
34454 this.container = Roo.get(container);
34457 Roo.bootstrap.SplitBar.AbsoluteLayoutAdapter.prototype = {
34458 init : function(s){
34459 this.basic.init(s);
34462 getElementSize : function(s){
34463 return this.basic.getElementSize(s);
34466 setElementSize : function(s, newSize, onComplete){
34467 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
34470 moveSplitter : function(s){
34471 var yes = Roo.bootstrap.SplitBar;
34472 switch(s.placement){
34474 s.el.setX(s.resizingEl.getRight());
34477 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
34480 s.el.setY(s.resizingEl.getBottom());
34483 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
34490 * Orientation constant - Create a vertical SplitBar
34494 Roo.bootstrap.SplitBar.VERTICAL = 1;
34497 * Orientation constant - Create a horizontal SplitBar
34501 Roo.bootstrap.SplitBar.HORIZONTAL = 2;
34504 * Placement constant - The resizing element is to the left of the splitter element
34508 Roo.bootstrap.SplitBar.LEFT = 1;
34511 * Placement constant - The resizing element is to the right of the splitter element
34515 Roo.bootstrap.SplitBar.RIGHT = 2;
34518 * Placement constant - The resizing element is positioned above the splitter element
34522 Roo.bootstrap.SplitBar.TOP = 3;
34525 * Placement constant - The resizing element is positioned under splitter element
34529 Roo.bootstrap.SplitBar.BOTTOM = 4;
34530 Roo.namespace("Roo.bootstrap.layout");/*
34532 * Ext JS Library 1.1.1
34533 * Copyright(c) 2006-2007, Ext JS, LLC.
34535 * Originally Released Under LGPL - original licence link has changed is not relivant.
34538 * <script type="text/javascript">
34542 * @class Roo.bootstrap.layout.Manager
34543 * @extends Roo.bootstrap.Component
34544 * Base class for layout managers.
34546 Roo.bootstrap.layout.Manager = function(config)
34548 Roo.bootstrap.layout.Manager.superclass.constructor.call(this,config);
34554 /** false to disable window resize monitoring @type Boolean */
34555 this.monitorWindowResize = true;
34560 * Fires when a layout is performed.
34561 * @param {Roo.LayoutManager} this
34565 * @event regionresized
34566 * Fires when the user resizes a region.
34567 * @param {Roo.LayoutRegion} region The resized region
34568 * @param {Number} newSize The new size (width for east/west, height for north/south)
34570 "regionresized" : true,
34572 * @event regioncollapsed
34573 * Fires when a region is collapsed.
34574 * @param {Roo.LayoutRegion} region The collapsed region
34576 "regioncollapsed" : true,
34578 * @event regionexpanded
34579 * Fires when a region is expanded.
34580 * @param {Roo.LayoutRegion} region The expanded region
34582 "regionexpanded" : true
34584 this.updating = false;
34587 this.el = Roo.get(config.el);
34593 Roo.extend(Roo.bootstrap.layout.Manager, Roo.bootstrap.Component, {
34598 monitorWindowResize : true,
34604 onRender : function(ct, position)
34607 this.el = Roo.get(ct);
34610 //this.fireEvent('render',this);
34614 initEvents: function()
34618 // ie scrollbar fix
34619 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
34620 document.body.scroll = "no";
34621 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
34622 this.el.position('relative');
34624 this.id = this.el.id;
34625 this.el.addClass("roo-layout-container");
34626 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
34627 if(this.el.dom != document.body ) {
34628 this.el.on('resize', this.layout,this);
34629 this.el.on('show', this.layout,this);
34635 * Returns true if this layout is currently being updated
34636 * @return {Boolean}
34638 isUpdating : function(){
34639 return this.updating;
34643 * Suspend the LayoutManager from doing auto-layouts while
34644 * making multiple add or remove calls
34646 beginUpdate : function(){
34647 this.updating = true;
34651 * Restore auto-layouts and optionally disable the manager from performing a layout
34652 * @param {Boolean} noLayout true to disable a layout update
34654 endUpdate : function(noLayout){
34655 this.updating = false;
34661 layout: function(){
34665 onRegionResized : function(region, newSize){
34666 this.fireEvent("regionresized", region, newSize);
34670 onRegionCollapsed : function(region){
34671 this.fireEvent("regioncollapsed", region);
34674 onRegionExpanded : function(region){
34675 this.fireEvent("regionexpanded", region);
34679 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
34680 * performs box-model adjustments.
34681 * @return {Object} The size as an object {width: (the width), height: (the height)}
34683 getViewSize : function()
34686 if(this.el.dom != document.body){
34687 size = this.el.getSize();
34689 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
34691 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
34692 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
34697 * Returns the Element this layout is bound to.
34698 * @return {Roo.Element}
34700 getEl : function(){
34705 * Returns the specified region.
34706 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
34707 * @return {Roo.LayoutRegion}
34709 getRegion : function(target){
34710 return this.regions[target.toLowerCase()];
34713 onWindowResize : function(){
34714 if(this.monitorWindowResize){
34721 * Ext JS Library 1.1.1
34722 * Copyright(c) 2006-2007, Ext JS, LLC.
34724 * Originally Released Under LGPL - original licence link has changed is not relivant.
34727 * <script type="text/javascript">
34730 * @class Roo.bootstrap.layout.Border
34731 * @extends Roo.bootstrap.layout.Manager
34732 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
34733 * please see: examples/bootstrap/nested.html<br><br>
34735 <b>The container the layout is rendered into can be either the body element or any other element.
34736 If it is not the body element, the container needs to either be an absolute positioned element,
34737 or you will need to add "position:relative" to the css of the container. You will also need to specify
34738 the container size if it is not the body element.</b>
34741 * Create a new Border
34742 * @param {Object} config Configuration options
34744 Roo.bootstrap.layout.Border = function(config){
34745 config = config || {};
34746 Roo.bootstrap.layout.Border.superclass.constructor.call(this, config);
34750 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34751 if(config[region]){
34752 config[region].region = region;
34753 this.addRegion(config[region]);
34759 Roo.bootstrap.layout.Border.regions = ["north","south","east","west","center"];
34761 Roo.extend(Roo.bootstrap.layout.Border, Roo.bootstrap.layout.Manager, {
34763 * Creates and adds a new region if it doesn't already exist.
34764 * @param {String} target The target region key (north, south, east, west or center).
34765 * @param {Object} config The regions config object
34766 * @return {BorderLayoutRegion} The new region
34768 addRegion : function(config)
34770 if(!this.regions[config.region]){
34771 var r = this.factory(config);
34772 this.bindRegion(r);
34774 return this.regions[config.region];
34778 bindRegion : function(r){
34779 this.regions[r.config.region] = r;
34781 r.on("visibilitychange", this.layout, this);
34782 r.on("paneladded", this.layout, this);
34783 r.on("panelremoved", this.layout, this);
34784 r.on("invalidated", this.layout, this);
34785 r.on("resized", this.onRegionResized, this);
34786 r.on("collapsed", this.onRegionCollapsed, this);
34787 r.on("expanded", this.onRegionExpanded, this);
34791 * Performs a layout update.
34793 layout : function()
34795 if(this.updating) {
34799 // render all the rebions if they have not been done alreayd?
34800 Roo.each(Roo.bootstrap.layout.Border.regions, function(region) {
34801 if(this.regions[region] && !this.regions[region].bodyEl){
34802 this.regions[region].onRender(this.el)
34806 var size = this.getViewSize();
34807 var w = size.width;
34808 var h = size.height;
34813 //var x = 0, y = 0;
34815 var rs = this.regions;
34816 var north = rs["north"];
34817 var south = rs["south"];
34818 var west = rs["west"];
34819 var east = rs["east"];
34820 var center = rs["center"];
34821 //if(this.hideOnLayout){ // not supported anymore
34822 //c.el.setStyle("display", "none");
34824 if(north && north.isVisible()){
34825 var b = north.getBox();
34826 var m = north.getMargins();
34827 b.width = w - (m.left+m.right);
34830 centerY = b.height + b.y + m.bottom;
34831 centerH -= centerY;
34832 north.updateBox(this.safeBox(b));
34834 if(south && south.isVisible()){
34835 var b = south.getBox();
34836 var m = south.getMargins();
34837 b.width = w - (m.left+m.right);
34839 var totalHeight = (b.height + m.top + m.bottom);
34840 b.y = h - totalHeight + m.top;
34841 centerH -= totalHeight;
34842 south.updateBox(this.safeBox(b));
34844 if(west && west.isVisible()){
34845 var b = west.getBox();
34846 var m = west.getMargins();
34847 b.height = centerH - (m.top+m.bottom);
34849 b.y = centerY + m.top;
34850 var totalWidth = (b.width + m.left + m.right);
34851 centerX += totalWidth;
34852 centerW -= totalWidth;
34853 west.updateBox(this.safeBox(b));
34855 if(east && east.isVisible()){
34856 var b = east.getBox();
34857 var m = east.getMargins();
34858 b.height = centerH - (m.top+m.bottom);
34859 var totalWidth = (b.width + m.left + m.right);
34860 b.x = w - totalWidth + m.left;
34861 b.y = centerY + m.top;
34862 centerW -= totalWidth;
34863 east.updateBox(this.safeBox(b));
34866 var m = center.getMargins();
34868 x: centerX + m.left,
34869 y: centerY + m.top,
34870 width: centerW - (m.left+m.right),
34871 height: centerH - (m.top+m.bottom)
34873 //if(this.hideOnLayout){
34874 //center.el.setStyle("display", "block");
34876 center.updateBox(this.safeBox(centerBox));
34879 this.fireEvent("layout", this);
34883 safeBox : function(box){
34884 box.width = Math.max(0, box.width);
34885 box.height = Math.max(0, box.height);
34890 * Adds a ContentPanel (or subclass) to this layout.
34891 * @param {String} target The target region key (north, south, east, west or center).
34892 * @param {Roo.ContentPanel} panel The panel to add
34893 * @return {Roo.ContentPanel} The added panel
34895 add : function(target, panel){
34897 target = target.toLowerCase();
34898 return this.regions[target].add(panel);
34902 * Remove a ContentPanel (or subclass) to this layout.
34903 * @param {String} target The target region key (north, south, east, west or center).
34904 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
34905 * @return {Roo.ContentPanel} The removed panel
34907 remove : function(target, panel){
34908 target = target.toLowerCase();
34909 return this.regions[target].remove(panel);
34913 * Searches all regions for a panel with the specified id
34914 * @param {String} panelId
34915 * @return {Roo.ContentPanel} The panel or null if it wasn't found
34917 findPanel : function(panelId){
34918 var rs = this.regions;
34919 for(var target in rs){
34920 if(typeof rs[target] != "function"){
34921 var p = rs[target].getPanel(panelId);
34931 * Searches all regions for a panel with the specified id and activates (shows) it.
34932 * @param {String/ContentPanel} panelId The panels id or the panel itself
34933 * @return {Roo.ContentPanel} The shown panel or null
34935 showPanel : function(panelId) {
34936 var rs = this.regions;
34937 for(var target in rs){
34938 var r = rs[target];
34939 if(typeof r != "function"){
34940 if(r.hasPanel(panelId)){
34941 return r.showPanel(panelId);
34949 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
34950 * @param {Roo.state.Provider} provider (optional) An alternate state provider
34953 restoreState : function(provider){
34955 provider = Roo.state.Manager;
34957 var sm = new Roo.LayoutStateManager();
34958 sm.init(this, provider);
34964 * Adds a xtype elements to the layout.
34968 xtype : 'ContentPanel',
34975 xtype : 'NestedLayoutPanel',
34981 items : [ ... list of content panels or nested layout panels.. ]
34985 * @param {Object} cfg Xtype definition of item to add.
34987 addxtype : function(cfg)
34989 // basically accepts a pannel...
34990 // can accept a layout region..!?!?
34991 //Roo.log('Roo.BorderLayout add ' + cfg.xtype)
34994 // theory? children can only be panels??
34996 //if (!cfg.xtype.match(/Panel$/)) {
35001 if (typeof(cfg.region) == 'undefined') {
35002 Roo.log("Failed to add Panel, region was not set");
35006 var region = cfg.region;
35012 xitems = cfg.items;
35019 case 'Content': // ContentPanel (el, cfg)
35020 case 'Scroll': // ContentPanel (el, cfg)
35022 cfg.autoCreate = true;
35023 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35025 // var el = this.el.createChild();
35026 // ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
35029 this.add(region, ret);
35033 case 'TreePanel': // our new panel!
35034 cfg.el = this.el.createChild();
35035 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35036 this.add(region, ret);
35041 // create a new Layout (which is a Border Layout...
35043 var clayout = cfg.layout;
35044 clayout.el = this.el.createChild();
35045 clayout.items = clayout.items || [];
35049 // replace this exitems with the clayout ones..
35050 xitems = clayout.items;
35052 // force background off if it's in center...
35053 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
35054 cfg.background = false;
35056 cfg.layout = new Roo.bootstrap.layout.Border(clayout);
35059 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35060 //console.log('adding nested layout panel ' + cfg.toSource());
35061 this.add(region, ret);
35062 nb = {}; /// find first...
35067 // needs grid and region
35069 //var el = this.getRegion(region).el.createChild();
35071 *var el = this.el.createChild();
35072 // create the grid first...
35073 cfg.grid.container = el;
35074 cfg.grid = new cfg.grid.xns[cfg.grid.xtype](cfg.grid);
35077 if (region == 'center' && this.active ) {
35078 cfg.background = false;
35081 ret = new cfg.xns[cfg.xtype](cfg); // new panel!!!!!
35083 this.add(region, ret);
35085 if (cfg.background) {
35086 // render grid on panel activation (if panel background)
35087 ret.on('activate', function(gp) {
35088 if (!gp.grid.rendered) {
35089 // gp.grid.render(el);
35093 // cfg.grid.render(el);
35099 case 'Border': // it can get called on it'self... - might need to check if this is fixed?
35100 // it was the old xcomponent building that caused this before.
35101 // espeically if border is the top element in the tree.
35111 if (typeof(Roo[cfg.xtype]) != 'undefined') {
35113 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
35114 this.add(region, ret);
35118 throw "Can not add '" + cfg.xtype + "' to Border";
35124 this.beginUpdate();
35128 Roo.each(xitems, function(i) {
35129 region = nb && i.region ? i.region : false;
35131 var add = ret.addxtype(i);
35134 nb[region] = nb[region] == undefined ? 0 : nb[region]+1;
35135 if (!i.background) {
35136 abn[region] = nb[region] ;
35143 // make the last non-background panel active..
35144 //if (nb) { Roo.log(abn); }
35147 for(var r in abn) {
35148 region = this.getRegion(r);
35150 // tried using nb[r], but it does not work..
35152 region.showPanel(abn[r]);
35163 factory : function(cfg)
35166 var validRegions = Roo.bootstrap.layout.Border.regions;
35168 var target = cfg.region;
35171 var r = Roo.bootstrap.layout;
35175 return new r.North(cfg);
35177 return new r.South(cfg);
35179 return new r.East(cfg);
35181 return new r.West(cfg);
35183 return new r.Center(cfg);
35185 throw 'Layout region "'+target+'" not supported.';
35192 * Ext JS Library 1.1.1
35193 * Copyright(c) 2006-2007, Ext JS, LLC.
35195 * Originally Released Under LGPL - original licence link has changed is not relivant.
35198 * <script type="text/javascript">
35202 * @class Roo.bootstrap.layout.Basic
35203 * @extends Roo.util.Observable
35204 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
35205 * and does not have a titlebar, tabs or any other features. All it does is size and position
35206 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
35207 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35208 * @cfg {string} region the region that it inhabits..
35209 * @cfg {bool} skipConfig skip config?
35213 Roo.bootstrap.layout.Basic = function(config){
35215 this.mgr = config.mgr;
35217 this.position = config.region;
35219 var skipConfig = config.skipConfig;
35223 * @scope Roo.BasicLayoutRegion
35227 * @event beforeremove
35228 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
35229 * @param {Roo.LayoutRegion} this
35230 * @param {Roo.ContentPanel} panel The panel
35231 * @param {Object} e The cancel event object
35233 "beforeremove" : true,
35235 * @event invalidated
35236 * Fires when the layout for this region is changed.
35237 * @param {Roo.LayoutRegion} this
35239 "invalidated" : true,
35241 * @event visibilitychange
35242 * Fires when this region is shown or hidden
35243 * @param {Roo.LayoutRegion} this
35244 * @param {Boolean} visibility true or false
35246 "visibilitychange" : true,
35248 * @event paneladded
35249 * Fires when a panel is added.
35250 * @param {Roo.LayoutRegion} this
35251 * @param {Roo.ContentPanel} panel The panel
35253 "paneladded" : true,
35255 * @event panelremoved
35256 * Fires when a panel is removed.
35257 * @param {Roo.LayoutRegion} this
35258 * @param {Roo.ContentPanel} panel The panel
35260 "panelremoved" : true,
35262 * @event beforecollapse
35263 * Fires when this region before collapse.
35264 * @param {Roo.LayoutRegion} this
35266 "beforecollapse" : true,
35269 * Fires when this region is collapsed.
35270 * @param {Roo.LayoutRegion} this
35272 "collapsed" : true,
35275 * Fires when this region is expanded.
35276 * @param {Roo.LayoutRegion} this
35281 * Fires when this region is slid into view.
35282 * @param {Roo.LayoutRegion} this
35284 "slideshow" : true,
35287 * Fires when this region slides out of view.
35288 * @param {Roo.LayoutRegion} this
35290 "slidehide" : true,
35292 * @event panelactivated
35293 * Fires when a panel is activated.
35294 * @param {Roo.LayoutRegion} this
35295 * @param {Roo.ContentPanel} panel The activated panel
35297 "panelactivated" : true,
35300 * Fires when the user resizes this region.
35301 * @param {Roo.LayoutRegion} this
35302 * @param {Number} newSize The new size (width for east/west, height for north/south)
35306 /** A collection of panels in this region. @type Roo.util.MixedCollection */
35307 this.panels = new Roo.util.MixedCollection();
35308 this.panels.getKey = this.getPanelId.createDelegate(this);
35310 this.activePanel = null;
35311 // ensure listeners are added...
35313 if (config.listeners || config.events) {
35314 Roo.bootstrap.layout.Basic.superclass.constructor.call(this, {
35315 listeners : config.listeners || {},
35316 events : config.events || {}
35320 if(skipConfig !== true){
35321 this.applyConfig(config);
35325 Roo.extend(Roo.bootstrap.layout.Basic, Roo.util.Observable,
35327 getPanelId : function(p){
35331 applyConfig : function(config){
35332 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35333 this.config = config;
35338 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
35339 * the width, for horizontal (north, south) the height.
35340 * @param {Number} newSize The new width or height
35342 resizeTo : function(newSize){
35343 var el = this.el ? this.el :
35344 (this.activePanel ? this.activePanel.getEl() : null);
35346 switch(this.position){
35349 el.setWidth(newSize);
35350 this.fireEvent("resized", this, newSize);
35354 el.setHeight(newSize);
35355 this.fireEvent("resized", this, newSize);
35361 getBox : function(){
35362 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
35365 getMargins : function(){
35366 return this.margins;
35369 updateBox : function(box){
35371 var el = this.activePanel.getEl();
35372 el.dom.style.left = box.x + "px";
35373 el.dom.style.top = box.y + "px";
35374 this.activePanel.setSize(box.width, box.height);
35378 * Returns the container element for this region.
35379 * @return {Roo.Element}
35381 getEl : function(){
35382 return this.activePanel;
35386 * Returns true if this region is currently visible.
35387 * @return {Boolean}
35389 isVisible : function(){
35390 return this.activePanel ? true : false;
35393 setActivePanel : function(panel){
35394 panel = this.getPanel(panel);
35395 if(this.activePanel && this.activePanel != panel){
35396 this.activePanel.setActiveState(false);
35397 this.activePanel.getEl().setLeftTop(-10000,-10000);
35399 this.activePanel = panel;
35400 panel.setActiveState(true);
35402 panel.setSize(this.box.width, this.box.height);
35404 this.fireEvent("panelactivated", this, panel);
35405 this.fireEvent("invalidated");
35409 * Show the specified panel.
35410 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
35411 * @return {Roo.ContentPanel} The shown panel or null
35413 showPanel : function(panel){
35414 panel = this.getPanel(panel);
35416 this.setActivePanel(panel);
35422 * Get the active panel for this region.
35423 * @return {Roo.ContentPanel} The active panel or null
35425 getActivePanel : function(){
35426 return this.activePanel;
35430 * Add the passed ContentPanel(s)
35431 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
35432 * @return {Roo.ContentPanel} The panel added (if only one was added)
35434 add : function(panel){
35435 if(arguments.length > 1){
35436 for(var i = 0, len = arguments.length; i < len; i++) {
35437 this.add(arguments[i]);
35441 if(this.hasPanel(panel)){
35442 this.showPanel(panel);
35445 var el = panel.getEl();
35446 if(el.dom.parentNode != this.mgr.el.dom){
35447 this.mgr.el.dom.appendChild(el.dom);
35449 if(panel.setRegion){
35450 panel.setRegion(this);
35452 this.panels.add(panel);
35453 el.setStyle("position", "absolute");
35454 if(!panel.background){
35455 this.setActivePanel(panel);
35456 if(this.config.initialSize && this.panels.getCount()==1){
35457 this.resizeTo(this.config.initialSize);
35460 this.fireEvent("paneladded", this, panel);
35465 * Returns true if the panel is in this region.
35466 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35467 * @return {Boolean}
35469 hasPanel : function(panel){
35470 if(typeof panel == "object"){ // must be panel obj
35471 panel = panel.getId();
35473 return this.getPanel(panel) ? true : false;
35477 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
35478 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35479 * @param {Boolean} preservePanel Overrides the config preservePanel option
35480 * @return {Roo.ContentPanel} The panel that was removed
35482 remove : function(panel, preservePanel){
35483 panel = this.getPanel(panel);
35488 this.fireEvent("beforeremove", this, panel, e);
35489 if(e.cancel === true){
35492 var panelId = panel.getId();
35493 this.panels.removeKey(panelId);
35498 * Returns the panel specified or null if it's not in this region.
35499 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
35500 * @return {Roo.ContentPanel}
35502 getPanel : function(id){
35503 if(typeof id == "object"){ // must be panel obj
35506 return this.panels.get(id);
35510 * Returns this regions position (north/south/east/west/center).
35513 getPosition: function(){
35514 return this.position;
35518 * Ext JS Library 1.1.1
35519 * Copyright(c) 2006-2007, Ext JS, LLC.
35521 * Originally Released Under LGPL - original licence link has changed is not relivant.
35524 * <script type="text/javascript">
35528 * @class Roo.bootstrap.layout.Region
35529 * @extends Roo.bootstrap.layout.Basic
35530 * This class represents a region in a layout manager.
35532 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
35533 * @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})
35534 * @cfg {String} tabPosition (top|bottom) "top" or "bottom" (defaults to "bottom")
35535 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
35536 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
35537 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
35538 * @cfg {String} title The title for the region (overrides panel titles)
35539 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
35540 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
35541 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
35542 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
35543 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
35544 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
35545 * the space available, similar to FireFox 1.5 tabs (defaults to false)
35546 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
35547 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
35548 * @cfg {String} overflow (hidden|visible) if you have menus in the region, then you need to set this to visible.
35550 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
35551 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
35552 * @cfg {Boolean} disableTabTips True to disable tab tooltips
35553 * @cfg {Number} width For East/West panels
35554 * @cfg {Number} height For North/South panels
35555 * @cfg {Boolean} split To show the splitter
35556 * @cfg {Boolean} toolbar xtype configuration for a toolbar - shows on right of tabbar
35558 * @cfg {string} cls Extra CSS classes to add to region
35560 * @cfg {Roo.bootstrap.layout.Manager} mgr The manager
35561 * @cfg {string} region the region that it inhabits..
35564 * @xxxcfg {Boolean} collapsible DISABLED False to disable collapsing (defaults to true)
35565 * @xxxcfg {Boolean} collapsed DISABLED True to set the initial display to collapsed (defaults to false)
35567 * @xxxcfg {String} collapsedTitle DISABLED Optional string message to display in the collapsed block of a north or south region
35568 * @xxxxcfg {Boolean} floatable DISABLED False to disable floating (defaults to true)
35569 * @xxxxcfg {Boolean} showPin True to show a pin button NOT SUPPORTED YET
35571 Roo.bootstrap.layout.Region = function(config)
35573 this.applyConfig(config);
35575 var mgr = config.mgr;
35576 var pos = config.region;
35577 config.skipConfig = true;
35578 Roo.bootstrap.layout.Region.superclass.constructor.call(this, config);
35581 this.onRender(mgr.el);
35584 this.visible = true;
35585 this.collapsed = false;
35586 this.unrendered_panels = [];
35589 Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
35591 position: '', // set by wrapper (eg. north/south etc..)
35592 unrendered_panels : null, // unrendered panels.
35593 createBody : function(){
35594 /** This region's body element
35595 * @type Roo.Element */
35596 this.bodyEl = this.el.createChild({
35598 cls: "roo-layout-panel-body tab-content" // bootstrap added...
35602 onRender: function(ctr, pos)
35604 var dh = Roo.DomHelper;
35605 /** This region's container element
35606 * @type Roo.Element */
35607 this.el = dh.append(ctr.dom, {
35609 cls: (this.config.cls || '') + " roo-layout-region roo-layout-panel roo-layout-panel-" + this.position
35611 /** This region's title element
35612 * @type Roo.Element */
35614 this.titleEl = dh.append(this.el.dom,
35617 unselectable: "on",
35618 cls: "roo-unselectable roo-layout-panel-hd breadcrumb roo-layout-title-" + this.position,
35620 {tag: "span", cls: "roo-unselectable roo-layout-panel-hd-text", unselectable: "on", html: " "},
35621 {tag: "div", cls: "roo-unselectable roo-layout-panel-hd-tools", unselectable: "on"}
35624 this.titleEl.enableDisplayMode();
35625 /** This region's title text element
35626 * @type HTMLElement */
35627 this.titleTextEl = this.titleEl.dom.firstChild;
35628 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
35630 this.closeBtn = this.createTool(this.tools.dom, "roo-layout-close");
35631 this.closeBtn.enableDisplayMode();
35632 this.closeBtn.on("click", this.closeClicked, this);
35633 this.closeBtn.hide();
35635 this.createBody(this.config);
35636 if(this.config.hideWhenEmpty){
35638 this.on("paneladded", this.validateVisibility, this);
35639 this.on("panelremoved", this.validateVisibility, this);
35641 if(this.autoScroll){
35642 this.bodyEl.setStyle("overflow", "auto");
35644 this.bodyEl.setStyle("overflow", this.config.overflow || 'hidden');
35646 //if(c.titlebar !== false){
35647 if((!this.config.titlebar && !this.config.title) || this.config.titlebar === false){
35648 this.titleEl.hide();
35650 this.titleEl.show();
35651 if(this.config.title){
35652 this.titleTextEl.innerHTML = this.config.title;
35656 if(this.config.collapsed){
35657 this.collapse(true);
35659 if(this.config.hidden){
35663 if (this.unrendered_panels && this.unrendered_panels.length) {
35664 for (var i =0;i< this.unrendered_panels.length; i++) {
35665 this.add(this.unrendered_panels[i]);
35667 this.unrendered_panels = null;
35673 applyConfig : function(c)
35676 *if(c.collapsible && this.position != "center" && !this.collapsedEl){
35677 var dh = Roo.DomHelper;
35678 if(c.titlebar !== false){
35679 this.collapseBtn = this.createTool(this.tools.dom, "roo-layout-collapse-"+this.position);
35680 this.collapseBtn.on("click", this.collapse, this);
35681 this.collapseBtn.enableDisplayMode();
35683 if(c.showPin === true || this.showPin){
35684 this.stickBtn = this.createTool(this.tools.dom, "roo-layout-stick");
35685 this.stickBtn.enableDisplayMode();
35686 this.stickBtn.on("click", this.expand, this);
35687 this.stickBtn.hide();
35692 /** This region's collapsed element
35693 * @type Roo.Element */
35696 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
35697 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
35700 if(c.floatable !== false){
35701 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
35702 this.collapsedEl.on("click", this.collapseClick, this);
35705 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
35706 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
35707 id: "message", unselectable: "on", style:{"float":"left"}});
35708 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
35710 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
35711 this.expandBtn.on("click", this.expand, this);
35715 if(this.collapseBtn){
35716 this.collapseBtn.setVisible(c.collapsible == true);
35719 this.cmargins = c.cmargins || this.cmargins ||
35720 (this.position == "west" || this.position == "east" ?
35721 {top: 0, left: 2, right:2, bottom: 0} :
35722 {top: 2, left: 0, right:0, bottom: 2});
35724 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
35727 this.bottomTabs = c.tabPosition != "top";
35729 this.autoScroll = c.autoScroll || false;
35734 this.duration = c.duration || .30;
35735 this.slideDuration = c.slideDuration || .45;
35740 * Returns true if this region is currently visible.
35741 * @return {Boolean}
35743 isVisible : function(){
35744 return this.visible;
35748 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
35749 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
35751 //setCollapsedTitle : function(title){
35752 // title = title || " ";
35753 // if(this.collapsedTitleTextEl){
35754 // this.collapsedTitleTextEl.innerHTML = title;
35758 getBox : function(){
35760 // if(!this.collapsed){
35761 b = this.el.getBox(false, true);
35763 // b = this.collapsedEl.getBox(false, true);
35768 getMargins : function(){
35769 return this.margins;
35770 //return this.collapsed ? this.cmargins : this.margins;
35773 highlight : function(){
35774 this.el.addClass("x-layout-panel-dragover");
35777 unhighlight : function(){
35778 this.el.removeClass("x-layout-panel-dragover");
35781 updateBox : function(box)
35783 if (!this.bodyEl) {
35784 return; // not rendered yet..
35788 if(!this.collapsed){
35789 this.el.dom.style.left = box.x + "px";
35790 this.el.dom.style.top = box.y + "px";
35791 this.updateBody(box.width, box.height);
35793 this.collapsedEl.dom.style.left = box.x + "px";
35794 this.collapsedEl.dom.style.top = box.y + "px";
35795 this.collapsedEl.setSize(box.width, box.height);
35798 this.tabs.autoSizeTabs();
35802 updateBody : function(w, h)
35805 this.el.setWidth(w);
35806 w -= this.el.getBorderWidth("rl");
35807 if(this.config.adjustments){
35808 w += this.config.adjustments[0];
35811 if(h !== null && h > 0){
35812 this.el.setHeight(h);
35813 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
35814 h -= this.el.getBorderWidth("tb");
35815 if(this.config.adjustments){
35816 h += this.config.adjustments[1];
35818 this.bodyEl.setHeight(h);
35820 h = this.tabs.syncHeight(h);
35823 if(this.panelSize){
35824 w = w !== null ? w : this.panelSize.width;
35825 h = h !== null ? h : this.panelSize.height;
35827 if(this.activePanel){
35828 var el = this.activePanel.getEl();
35829 w = w !== null ? w : el.getWidth();
35830 h = h !== null ? h : el.getHeight();
35831 this.panelSize = {width: w, height: h};
35832 this.activePanel.setSize(w, h);
35834 if(Roo.isIE && this.tabs){
35835 this.tabs.el.repaint();
35840 * Returns the container element for this region.
35841 * @return {Roo.Element}
35843 getEl : function(){
35848 * Hides this region.
35851 //if(!this.collapsed){
35852 this.el.dom.style.left = "-2000px";
35855 // this.collapsedEl.dom.style.left = "-2000px";
35856 // this.collapsedEl.hide();
35858 this.visible = false;
35859 this.fireEvent("visibilitychange", this, false);
35863 * Shows this region if it was previously hidden.
35866 //if(!this.collapsed){
35869 // this.collapsedEl.show();
35871 this.visible = true;
35872 this.fireEvent("visibilitychange", this, true);
35875 closeClicked : function(){
35876 if(this.activePanel){
35877 this.remove(this.activePanel);
35881 collapseClick : function(e){
35883 e.stopPropagation();
35886 e.stopPropagation();
35892 * Collapses this region.
35893 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
35896 collapse : function(skipAnim, skipCheck = false){
35897 if(this.collapsed) {
35901 if(skipCheck || this.fireEvent("beforecollapse", this) != false){
35903 this.collapsed = true;
35905 this.split.el.hide();
35907 if(this.config.animate && skipAnim !== true){
35908 this.fireEvent("invalidated", this);
35909 this.animateCollapse();
35911 this.el.setLocation(-20000,-20000);
35913 this.collapsedEl.show();
35914 this.fireEvent("collapsed", this);
35915 this.fireEvent("invalidated", this);
35921 animateCollapse : function(){
35926 * Expands this region if it was previously collapsed.
35927 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
35928 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
35931 expand : function(e, skipAnim){
35933 e.stopPropagation();
35935 if(!this.collapsed || this.el.hasActiveFx()) {
35939 this.afterSlideIn();
35942 this.collapsed = false;
35943 if(this.config.animate && skipAnim !== true){
35944 this.animateExpand();
35948 this.split.el.show();
35950 this.collapsedEl.setLocation(-2000,-2000);
35951 this.collapsedEl.hide();
35952 this.fireEvent("invalidated", this);
35953 this.fireEvent("expanded", this);
35957 animateExpand : function(){
35961 initTabs : function()
35963 //this.bodyEl.setStyle("overflow", "hidden"); -- this is set in render?
35965 var ts = new Roo.bootstrap.panel.Tabs({
35966 el: this.bodyEl.dom,
35967 tabPosition: this.bottomTabs ? 'bottom' : 'top',
35968 disableTooltips: this.config.disableTabTips,
35969 toolbar : this.config.toolbar
35972 if(this.config.hideTabs){
35973 ts.stripWrap.setDisplayed(false);
35976 ts.resizeTabs = this.config.resizeTabs === true;
35977 ts.minTabWidth = this.config.minTabWidth || 40;
35978 ts.maxTabWidth = this.config.maxTabWidth || 250;
35979 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
35980 ts.monitorResize = false;
35981 //ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden"); // this is set in render?
35982 ts.bodyEl.addClass('roo-layout-tabs-body');
35983 this.panels.each(this.initPanelAsTab, this);
35986 initPanelAsTab : function(panel){
35987 var ti = this.tabs.addTab(
35991 this.config.closeOnTab && panel.isClosable(),
35994 if(panel.tabTip !== undefined){
35995 ti.setTooltip(panel.tabTip);
35997 ti.on("activate", function(){
35998 this.setActivePanel(panel);
36001 if(this.config.closeOnTab){
36002 ti.on("beforeclose", function(t, e){
36004 this.remove(panel);
36008 panel.tabItem = ti;
36013 updatePanelTitle : function(panel, title)
36015 if(this.activePanel == panel){
36016 this.updateTitle(title);
36019 var ti = this.tabs.getTab(panel.getEl().id);
36021 if(panel.tabTip !== undefined){
36022 ti.setTooltip(panel.tabTip);
36027 updateTitle : function(title){
36028 if(this.titleTextEl && !this.config.title){
36029 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
36033 setActivePanel : function(panel)
36035 panel = this.getPanel(panel);
36036 if(this.activePanel && this.activePanel != panel){
36037 if(this.activePanel.setActiveState(false) === false){
36041 this.activePanel = panel;
36042 panel.setActiveState(true);
36043 if(this.panelSize){
36044 panel.setSize(this.panelSize.width, this.panelSize.height);
36047 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
36049 this.updateTitle(panel.getTitle());
36051 this.fireEvent("invalidated", this);
36053 this.fireEvent("panelactivated", this, panel);
36057 * Shows the specified panel.
36058 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
36059 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
36061 showPanel : function(panel)
36063 panel = this.getPanel(panel);
36066 var tab = this.tabs.getTab(panel.getEl().id);
36067 if(tab.isHidden()){
36068 this.tabs.unhideTab(tab.id);
36072 this.setActivePanel(panel);
36079 * Get the active panel for this region.
36080 * @return {Roo.ContentPanel} The active panel or null
36082 getActivePanel : function(){
36083 return this.activePanel;
36086 validateVisibility : function(){
36087 if(this.panels.getCount() < 1){
36088 this.updateTitle(" ");
36089 this.closeBtn.hide();
36092 if(!this.isVisible()){
36099 * Adds the passed ContentPanel(s) to this region.
36100 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
36101 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
36103 add : function(panel)
36105 if(arguments.length > 1){
36106 for(var i = 0, len = arguments.length; i < len; i++) {
36107 this.add(arguments[i]);
36112 // if we have not been rendered yet, then we can not really do much of this..
36113 if (!this.bodyEl) {
36114 this.unrendered_panels.push(panel);
36121 if(this.hasPanel(panel)){
36122 this.showPanel(panel);
36125 panel.setRegion(this);
36126 this.panels.add(panel);
36127 /* if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
36128 // sinle panel - no tab...?? would it not be better to render it with the tabs,
36129 // and hide them... ???
36130 this.bodyEl.dom.appendChild(panel.getEl().dom);
36131 if(panel.background !== true){
36132 this.setActivePanel(panel);
36134 this.fireEvent("paneladded", this, panel);
36141 this.initPanelAsTab(panel);
36145 if(panel.background !== true){
36146 this.tabs.activate(panel.getEl().id);
36148 this.fireEvent("paneladded", this, panel);
36153 * Hides the tab for the specified panel.
36154 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36156 hidePanel : function(panel){
36157 if(this.tabs && (panel = this.getPanel(panel))){
36158 this.tabs.hideTab(panel.getEl().id);
36163 * Unhides the tab for a previously hidden panel.
36164 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36166 unhidePanel : function(panel){
36167 if(this.tabs && (panel = this.getPanel(panel))){
36168 this.tabs.unhideTab(panel.getEl().id);
36172 clearPanels : function(){
36173 while(this.panels.getCount() > 0){
36174 this.remove(this.panels.first());
36179 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
36180 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
36181 * @param {Boolean} preservePanel Overrides the config preservePanel option
36182 * @return {Roo.ContentPanel} The panel that was removed
36184 remove : function(panel, preservePanel)
36186 panel = this.getPanel(panel);
36191 this.fireEvent("beforeremove", this, panel, e);
36192 if(e.cancel === true){
36195 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
36196 var panelId = panel.getId();
36197 this.panels.removeKey(panelId);
36199 document.body.appendChild(panel.getEl().dom);
36202 this.tabs.removeTab(panel.getEl().id);
36203 }else if (!preservePanel){
36204 this.bodyEl.dom.removeChild(panel.getEl().dom);
36206 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
36207 var p = this.panels.first();
36208 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
36209 tempEl.appendChild(p.getEl().dom);
36210 this.bodyEl.update("");
36211 this.bodyEl.dom.appendChild(p.getEl().dom);
36213 this.updateTitle(p.getTitle());
36215 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
36216 this.setActivePanel(p);
36218 panel.setRegion(null);
36219 if(this.activePanel == panel){
36220 this.activePanel = null;
36222 if(this.config.autoDestroy !== false && preservePanel !== true){
36223 try{panel.destroy();}catch(e){}
36225 this.fireEvent("panelremoved", this, panel);
36230 * Returns the TabPanel component used by this region
36231 * @return {Roo.TabPanel}
36233 getTabs : function(){
36237 createTool : function(parentEl, className){
36238 var btn = Roo.DomHelper.append(parentEl, {
36240 cls: "x-layout-tools-button",
36243 cls: "roo-layout-tools-button-inner " + className,
36247 btn.addClassOnOver("roo-layout-tools-button-over");
36252 * Ext JS Library 1.1.1
36253 * Copyright(c) 2006-2007, Ext JS, LLC.
36255 * Originally Released Under LGPL - original licence link has changed is not relivant.
36258 * <script type="text/javascript">
36264 * @class Roo.SplitLayoutRegion
36265 * @extends Roo.LayoutRegion
36266 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
36268 Roo.bootstrap.layout.Split = function(config){
36269 this.cursor = config.cursor;
36270 Roo.bootstrap.layout.Split.superclass.constructor.call(this, config);
36273 Roo.extend(Roo.bootstrap.layout.Split, Roo.bootstrap.layout.Region,
36275 splitTip : "Drag to resize.",
36276 collapsibleSplitTip : "Drag to resize. Double click to hide.",
36277 useSplitTips : false,
36279 applyConfig : function(config){
36280 Roo.bootstrap.layout.Split.superclass.applyConfig.call(this, config);
36283 onRender : function(ctr,pos) {
36285 Roo.bootstrap.layout.Split.superclass.onRender.call(this, ctr,pos);
36286 if(!this.config.split){
36291 var splitEl = Roo.DomHelper.append(ctr.dom, {
36293 id: this.el.id + "-split",
36294 cls: "roo-layout-split roo-layout-split-"+this.position,
36297 /** The SplitBar for this region
36298 * @type Roo.SplitBar */
36299 // does not exist yet...
36300 Roo.log([this.position, this.orientation]);
36302 this.split = new Roo.bootstrap.SplitBar({
36303 dragElement : splitEl,
36304 resizingElement: this.el,
36305 orientation : this.orientation
36308 this.split.on("moved", this.onSplitMove, this);
36309 this.split.useShim = this.config.useShim === true;
36310 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
36311 if(this.useSplitTips){
36312 this.split.el.dom.title = this.config.collapsible ? this.collapsibleSplitTip : this.splitTip;
36314 //if(config.collapsible){
36315 // this.split.el.on("dblclick", this.collapse, this);
36318 if(typeof this.config.minSize != "undefined"){
36319 this.split.minSize = this.config.minSize;
36321 if(typeof this.config.maxSize != "undefined"){
36322 this.split.maxSize = this.config.maxSize;
36324 if(this.config.hideWhenEmpty || this.config.hidden || this.config.collapsed){
36325 this.hideSplitter();
36330 getHMaxSize : function(){
36331 var cmax = this.config.maxSize || 10000;
36332 var center = this.mgr.getRegion("center");
36333 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
36336 getVMaxSize : function(){
36337 var cmax = this.config.maxSize || 10000;
36338 var center = this.mgr.getRegion("center");
36339 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
36342 onSplitMove : function(split, newSize){
36343 this.fireEvent("resized", this, newSize);
36347 * Returns the {@link Roo.SplitBar} for this region.
36348 * @return {Roo.SplitBar}
36350 getSplitBar : function(){
36355 this.hideSplitter();
36356 Roo.bootstrap.layout.Split.superclass.hide.call(this);
36359 hideSplitter : function(){
36361 this.split.el.setLocation(-2000,-2000);
36362 this.split.el.hide();
36368 this.split.el.show();
36370 Roo.bootstrap.layout.Split.superclass.show.call(this);
36373 beforeSlide: function(){
36374 if(Roo.isGecko){// firefox overflow auto bug workaround
36375 this.bodyEl.clip();
36377 this.tabs.bodyEl.clip();
36379 if(this.activePanel){
36380 this.activePanel.getEl().clip();
36382 if(this.activePanel.beforeSlide){
36383 this.activePanel.beforeSlide();
36389 afterSlide : function(){
36390 if(Roo.isGecko){// firefox overflow auto bug workaround
36391 this.bodyEl.unclip();
36393 this.tabs.bodyEl.unclip();
36395 if(this.activePanel){
36396 this.activePanel.getEl().unclip();
36397 if(this.activePanel.afterSlide){
36398 this.activePanel.afterSlide();
36404 initAutoHide : function(){
36405 if(this.autoHide !== false){
36406 if(!this.autoHideHd){
36407 var st = new Roo.util.DelayedTask(this.slideIn, this);
36408 this.autoHideHd = {
36409 "mouseout": function(e){
36410 if(!e.within(this.el, true)){
36414 "mouseover" : function(e){
36420 this.el.on(this.autoHideHd);
36424 clearAutoHide : function(){
36425 if(this.autoHide !== false){
36426 this.el.un("mouseout", this.autoHideHd.mouseout);
36427 this.el.un("mouseover", this.autoHideHd.mouseover);
36431 clearMonitor : function(){
36432 Roo.get(document).un("click", this.slideInIf, this);
36435 // these names are backwards but not changed for compat
36436 slideOut : function(){
36437 if(this.isSlid || this.el.hasActiveFx()){
36440 this.isSlid = true;
36441 if(this.collapseBtn){
36442 this.collapseBtn.hide();
36444 this.closeBtnState = this.closeBtn.getStyle('display');
36445 this.closeBtn.hide();
36447 this.stickBtn.show();
36450 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
36451 this.beforeSlide();
36452 this.el.setStyle("z-index", 10001);
36453 this.el.slideIn(this.getSlideAnchor(), {
36454 callback: function(){
36456 this.initAutoHide();
36457 Roo.get(document).on("click", this.slideInIf, this);
36458 this.fireEvent("slideshow", this);
36465 afterSlideIn : function(){
36466 this.clearAutoHide();
36467 this.isSlid = false;
36468 this.clearMonitor();
36469 this.el.setStyle("z-index", "");
36470 if(this.collapseBtn){
36471 this.collapseBtn.show();
36473 this.closeBtn.setStyle('display', this.closeBtnState);
36475 this.stickBtn.hide();
36477 this.fireEvent("slidehide", this);
36480 slideIn : function(cb){
36481 if(!this.isSlid || this.el.hasActiveFx()){
36485 this.isSlid = false;
36486 this.beforeSlide();
36487 this.el.slideOut(this.getSlideAnchor(), {
36488 callback: function(){
36489 this.el.setLeftTop(-10000, -10000);
36491 this.afterSlideIn();
36499 slideInIf : function(e){
36500 if(!e.within(this.el)){
36505 animateCollapse : function(){
36506 this.beforeSlide();
36507 this.el.setStyle("z-index", 20000);
36508 var anchor = this.getSlideAnchor();
36509 this.el.slideOut(anchor, {
36510 callback : function(){
36511 this.el.setStyle("z-index", "");
36512 this.collapsedEl.slideIn(anchor, {duration:.3});
36514 this.el.setLocation(-10000,-10000);
36516 this.fireEvent("collapsed", this);
36523 animateExpand : function(){
36524 this.beforeSlide();
36525 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
36526 this.el.setStyle("z-index", 20000);
36527 this.collapsedEl.hide({
36530 this.el.slideIn(this.getSlideAnchor(), {
36531 callback : function(){
36532 this.el.setStyle("z-index", "");
36535 this.split.el.show();
36537 this.fireEvent("invalidated", this);
36538 this.fireEvent("expanded", this);
36566 getAnchor : function(){
36567 return this.anchors[this.position];
36570 getCollapseAnchor : function(){
36571 return this.canchors[this.position];
36574 getSlideAnchor : function(){
36575 return this.sanchors[this.position];
36578 getAlignAdj : function(){
36579 var cm = this.cmargins;
36580 switch(this.position){
36596 getExpandAdj : function(){
36597 var c = this.collapsedEl, cm = this.cmargins;
36598 switch(this.position){
36600 return [-(cm.right+c.getWidth()+cm.left), 0];
36603 return [cm.right+c.getWidth()+cm.left, 0];
36606 return [0, -(cm.top+cm.bottom+c.getHeight())];
36609 return [0, cm.top+cm.bottom+c.getHeight()];
36615 * Ext JS Library 1.1.1
36616 * Copyright(c) 2006-2007, Ext JS, LLC.
36618 * Originally Released Under LGPL - original licence link has changed is not relivant.
36621 * <script type="text/javascript">
36624 * These classes are private internal classes
36626 Roo.bootstrap.layout.Center = function(config){
36627 config.region = "center";
36628 Roo.bootstrap.layout.Region.call(this, config);
36629 this.visible = true;
36630 this.minWidth = config.minWidth || 20;
36631 this.minHeight = config.minHeight || 20;
36634 Roo.extend(Roo.bootstrap.layout.Center, Roo.bootstrap.layout.Region, {
36636 // center panel can't be hidden
36640 // center panel can't be hidden
36643 getMinWidth: function(){
36644 return this.minWidth;
36647 getMinHeight: function(){
36648 return this.minHeight;
36661 Roo.bootstrap.layout.North = function(config)
36663 config.region = 'north';
36664 config.cursor = 'n-resize';
36666 Roo.bootstrap.layout.Split.call(this, config);
36670 this.split.placement = Roo.bootstrap.SplitBar.TOP;
36671 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36672 this.split.el.addClass("roo-layout-split-v");
36674 var size = config.initialSize || config.height;
36675 if(typeof size != "undefined"){
36676 this.el.setHeight(size);
36679 Roo.extend(Roo.bootstrap.layout.North, Roo.bootstrap.layout.Split,
36681 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36685 getBox : function(){
36686 if(this.collapsed){
36687 return this.collapsedEl.getBox();
36689 var box = this.el.getBox();
36691 box.height += this.split.el.getHeight();
36696 updateBox : function(box){
36697 if(this.split && !this.collapsed){
36698 box.height -= this.split.el.getHeight();
36699 this.split.el.setLeft(box.x);
36700 this.split.el.setTop(box.y+box.height);
36701 this.split.el.setWidth(box.width);
36703 if(this.collapsed){
36704 this.updateBody(box.width, null);
36706 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36714 Roo.bootstrap.layout.South = function(config){
36715 config.region = 'south';
36716 config.cursor = 's-resize';
36717 Roo.bootstrap.layout.Split.call(this, config);
36719 this.split.placement = Roo.bootstrap.SplitBar.BOTTOM;
36720 this.split.orientation = Roo.bootstrap.SplitBar.VERTICAL;
36721 this.split.el.addClass("roo-layout-split-v");
36723 var size = config.initialSize || config.height;
36724 if(typeof size != "undefined"){
36725 this.el.setHeight(size);
36729 Roo.extend(Roo.bootstrap.layout.South, Roo.bootstrap.layout.Split, {
36730 orientation: Roo.bootstrap.SplitBar.VERTICAL,
36731 getBox : function(){
36732 if(this.collapsed){
36733 return this.collapsedEl.getBox();
36735 var box = this.el.getBox();
36737 var sh = this.split.el.getHeight();
36744 updateBox : function(box){
36745 if(this.split && !this.collapsed){
36746 var sh = this.split.el.getHeight();
36749 this.split.el.setLeft(box.x);
36750 this.split.el.setTop(box.y-sh);
36751 this.split.el.setWidth(box.width);
36753 if(this.collapsed){
36754 this.updateBody(box.width, null);
36756 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36760 Roo.bootstrap.layout.East = function(config){
36761 config.region = "east";
36762 config.cursor = "e-resize";
36763 Roo.bootstrap.layout.Split.call(this, config);
36765 this.split.placement = Roo.bootstrap.SplitBar.RIGHT;
36766 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36767 this.split.el.addClass("roo-layout-split-h");
36769 var size = config.initialSize || config.width;
36770 if(typeof size != "undefined"){
36771 this.el.setWidth(size);
36774 Roo.extend(Roo.bootstrap.layout.East, Roo.bootstrap.layout.Split, {
36775 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36776 getBox : function(){
36777 if(this.collapsed){
36778 return this.collapsedEl.getBox();
36780 var box = this.el.getBox();
36782 var sw = this.split.el.getWidth();
36789 updateBox : function(box){
36790 if(this.split && !this.collapsed){
36791 var sw = this.split.el.getWidth();
36793 this.split.el.setLeft(box.x);
36794 this.split.el.setTop(box.y);
36795 this.split.el.setHeight(box.height);
36798 if(this.collapsed){
36799 this.updateBody(null, box.height);
36801 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36805 Roo.bootstrap.layout.West = function(config){
36806 config.region = "west";
36807 config.cursor = "w-resize";
36809 Roo.bootstrap.layout.Split.call(this, config);
36811 this.split.placement = Roo.bootstrap.SplitBar.LEFT;
36812 this.split.orientation = Roo.bootstrap.SplitBar.HORIZONTAL;
36813 this.split.el.addClass("roo-layout-split-h");
36817 Roo.extend(Roo.bootstrap.layout.West, Roo.bootstrap.layout.Split, {
36818 orientation: Roo.bootstrap.SplitBar.HORIZONTAL,
36820 onRender: function(ctr, pos)
36822 Roo.bootstrap.layout.West.superclass.onRender.call(this, ctr,pos);
36823 var size = this.config.initialSize || this.config.width;
36824 if(typeof size != "undefined"){
36825 this.el.setWidth(size);
36829 getBox : function(){
36830 if(this.collapsed){
36831 return this.collapsedEl.getBox();
36833 var box = this.el.getBox();
36835 box.width += this.split.el.getWidth();
36840 updateBox : function(box){
36841 if(this.split && !this.collapsed){
36842 var sw = this.split.el.getWidth();
36844 this.split.el.setLeft(box.x+box.width);
36845 this.split.el.setTop(box.y);
36846 this.split.el.setHeight(box.height);
36848 if(this.collapsed){
36849 this.updateBody(null, box.height);
36851 Roo.bootstrap.layout.Region.prototype.updateBox.call(this, box);
36854 Roo.namespace("Roo.bootstrap.panel");/*
36856 * Ext JS Library 1.1.1
36857 * Copyright(c) 2006-2007, Ext JS, LLC.
36859 * Originally Released Under LGPL - original licence link has changed is not relivant.
36862 * <script type="text/javascript">
36865 * @class Roo.ContentPanel
36866 * @extends Roo.util.Observable
36867 * A basic ContentPanel element.
36868 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
36869 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
36870 * @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
36871 * @cfg {Boolean} closable True if the panel can be closed/removed
36872 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
36873 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
36874 * @cfg {Toolbar} toolbar A toolbar for this panel
36875 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
36876 * @cfg {String} title The title for this panel
36877 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
36878 * @cfg {String} url Calls {@link #setUrl} with this value
36879 * @cfg {String} region (center|north|south|east|west) which region to put this panel on (when used with xtype constructors)
36880 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
36881 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
36882 * @cfg {String} content Raw content to fill content panel with (uses setContent on construction.)
36883 * @cfg {Boolean} badges render the badges
36886 * Create a new ContentPanel.
36887 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
36888 * @param {String/Object} config A string to set only the title or a config object
36889 * @param {String} content (optional) Set the HTML content for this panel
36890 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
36892 Roo.bootstrap.panel.Content = function( config){
36894 this.tpl = config.tpl || false;
36896 var el = config.el;
36897 var content = config.content;
36899 if(config.autoCreate){ // xtype is available if this is called from factory
36902 this.el = Roo.get(el);
36903 if(!this.el && config && config.autoCreate){
36904 if(typeof config.autoCreate == "object"){
36905 if(!config.autoCreate.id){
36906 config.autoCreate.id = config.id||el;
36908 this.el = Roo.DomHelper.append(document.body,
36909 config.autoCreate, true);
36911 var elcfg = { tag: "div",
36912 cls: "roo-layout-inactive-content",
36916 elcfg.html = config.html;
36920 this.el = Roo.DomHelper.append(document.body, elcfg , true);
36923 this.closable = false;
36924 this.loaded = false;
36925 this.active = false;
36928 if (config.toolbar && !config.toolbar.el && config.toolbar.xtype) {
36930 this.toolbar = new config.toolbar.xns[config.toolbar.xtype](config.toolbar);
36932 this.wrapEl = this.el; //this.el.wrap();
36934 if (config.toolbar.items) {
36935 ti = config.toolbar.items ;
36936 delete config.toolbar.items ;
36940 this.toolbar.render(this.wrapEl, 'before');
36941 for(var i =0;i < ti.length;i++) {
36942 // Roo.log(['add child', items[i]]);
36943 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
36945 this.toolbar.items = nitems;
36946 this.toolbar.el.insertBefore(this.wrapEl.dom.firstChild);
36947 delete config.toolbar;
36951 // xtype created footer. - not sure if will work as we normally have to render first..
36952 if (this.footer && !this.footer.el && this.footer.xtype) {
36953 if (!this.wrapEl) {
36954 this.wrapEl = this.el.wrap();
36957 this.footer.container = this.wrapEl.createChild();
36959 this.footer = Roo.factory(this.footer, Roo);
36964 if(typeof config == "string"){
36965 this.title = config;
36967 Roo.apply(this, config);
36971 this.resizeEl = Roo.get(this.resizeEl, true);
36973 this.resizeEl = this.el;
36975 // handle view.xtype
36983 * Fires when this panel is activated.
36984 * @param {Roo.ContentPanel} this
36988 * @event deactivate
36989 * Fires when this panel is activated.
36990 * @param {Roo.ContentPanel} this
36992 "deactivate" : true,
36996 * Fires when this panel is resized if fitToFrame is true.
36997 * @param {Roo.ContentPanel} this
36998 * @param {Number} width The width after any component adjustments
36999 * @param {Number} height The height after any component adjustments
37005 * Fires when this tab is created
37006 * @param {Roo.ContentPanel} this
37017 if(this.autoScroll){
37018 this.resizeEl.setStyle("overflow", "auto");
37020 // fix randome scrolling
37021 //this.el.on('scroll', function() {
37022 // Roo.log('fix random scolling');
37023 // this.scrollTo('top',0);
37026 content = content || this.content;
37028 this.setContent(content);
37030 if(config && config.url){
37031 this.setUrl(this.url, this.params, this.loadOnce);
37036 Roo.bootstrap.panel.Content.superclass.constructor.call(this);
37038 if (this.view && typeof(this.view.xtype) != 'undefined') {
37039 this.view.el = this.el.appendChild(document.createElement("div"));
37040 this.view = Roo.factory(this.view);
37041 this.view.render && this.view.render(false, '');
37045 this.fireEvent('render', this);
37048 Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
37052 setRegion : function(region){
37053 this.region = region;
37054 this.setActiveClass(region && !this.background);
37058 setActiveClass: function(state)
37061 this.el.replaceClass("roo-layout-inactive-content", "roo-layout-active-content");
37062 this.el.setStyle('position','relative');
37064 this.el.replaceClass("roo-layout-active-content", "roo-layout-inactive-content");
37065 this.el.setStyle('position', 'absolute');
37070 * Returns the toolbar for this Panel if one was configured.
37071 * @return {Roo.Toolbar}
37073 getToolbar : function(){
37074 return this.toolbar;
37077 setActiveState : function(active)
37079 this.active = active;
37080 this.setActiveClass(active);
37082 if(this.fireEvent("deactivate", this) === false){
37087 this.fireEvent("activate", this);
37091 * Updates this panel's element
37092 * @param {String} content The new content
37093 * @param {Boolean} loadScripts (optional) true to look for and process scripts
37095 setContent : function(content, loadScripts){
37096 this.el.update(content, loadScripts);
37099 ignoreResize : function(w, h){
37100 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
37103 this.lastSize = {width: w, height: h};
37108 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
37109 * @return {Roo.UpdateManager} The UpdateManager
37111 getUpdateManager : function(){
37112 return this.el.getUpdateManager();
37115 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
37116 * @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:
37119 url: "your-url.php",
37120 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
37121 callback: yourFunction,
37122 scope: yourObject, //(optional scope)
37125 text: "Loading...",
37130 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
37131 * 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.
37132 * @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}
37133 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
37134 * @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.
37135 * @return {Roo.ContentPanel} this
37138 var um = this.el.getUpdateManager();
37139 um.update.apply(um, arguments);
37145 * 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.
37146 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
37147 * @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)
37148 * @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)
37149 * @return {Roo.UpdateManager} The UpdateManager
37151 setUrl : function(url, params, loadOnce){
37152 if(this.refreshDelegate){
37153 this.removeListener("activate", this.refreshDelegate);
37155 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
37156 this.on("activate", this.refreshDelegate);
37157 return this.el.getUpdateManager();
37160 _handleRefresh : function(url, params, loadOnce){
37161 if(!loadOnce || !this.loaded){
37162 var updater = this.el.getUpdateManager();
37163 updater.update(url, params, this._setLoaded.createDelegate(this));
37167 _setLoaded : function(){
37168 this.loaded = true;
37172 * Returns this panel's id
37175 getId : function(){
37180 * Returns this panel's element - used by regiosn to add.
37181 * @return {Roo.Element}
37183 getEl : function(){
37184 return this.wrapEl || this.el;
37189 adjustForComponents : function(width, height)
37191 //Roo.log('adjustForComponents ');
37192 if(this.resizeEl != this.el){
37193 width -= this.el.getFrameWidth('lr');
37194 height -= this.el.getFrameWidth('tb');
37197 var te = this.toolbar.getEl();
37198 te.setWidth(width);
37199 height -= te.getHeight();
37202 var te = this.footer.getEl();
37203 te.setWidth(width);
37204 height -= te.getHeight();
37208 if(this.adjustments){
37209 width += this.adjustments[0];
37210 height += this.adjustments[1];
37212 return {"width": width, "height": height};
37215 setSize : function(width, height){
37216 if(this.fitToFrame && !this.ignoreResize(width, height)){
37217 if(this.fitContainer && this.resizeEl != this.el){
37218 this.el.setSize(width, height);
37220 var size = this.adjustForComponents(width, height);
37221 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
37222 this.fireEvent('resize', this, size.width, size.height);
37227 * Returns this panel's title
37230 getTitle : function(){
37232 if (typeof(this.title) != 'object') {
37237 for (var k in this.title) {
37238 if (!this.title.hasOwnProperty(k)) {
37242 if (k.indexOf('-') >= 0) {
37243 var s = k.split('-');
37244 for (var i = 0; i<s.length; i++) {
37245 t += "<span class='visible-"+s[i]+"'>"+this.title[k]+"</span>";
37248 t += "<span class='visible-"+k+"'>"+this.title[k]+"</span>";
37255 * Set this panel's title
37256 * @param {String} title
37258 setTitle : function(title){
37259 this.title = title;
37261 this.region.updatePanelTitle(this, title);
37266 * Returns true is this panel was configured to be closable
37267 * @return {Boolean}
37269 isClosable : function(){
37270 return this.closable;
37273 beforeSlide : function(){
37275 this.resizeEl.clip();
37278 afterSlide : function(){
37280 this.resizeEl.unclip();
37284 * Force a content refresh from the URL specified in the {@link #setUrl} method.
37285 * Will fail silently if the {@link #setUrl} method has not been called.
37286 * This does not activate the panel, just updates its content.
37288 refresh : function(){
37289 if(this.refreshDelegate){
37290 this.loaded = false;
37291 this.refreshDelegate();
37296 * Destroys this panel
37298 destroy : function(){
37299 this.el.removeAllListeners();
37300 var tempEl = document.createElement("span");
37301 tempEl.appendChild(this.el.dom);
37302 tempEl.innerHTML = "";
37308 * form - if the content panel contains a form - this is a reference to it.
37309 * @type {Roo.form.Form}
37313 * view - if the content panel contains a view (Roo.DatePicker / Roo.View / Roo.JsonView)
37314 * This contains a reference to it.
37320 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
37330 * @param {Object} cfg Xtype definition of item to add.
37334 getChildContainer: function () {
37335 return this.getEl();
37340 var ret = new Roo.factory(cfg);
37345 if (cfg.xtype.match(/^Form$/)) {
37348 //if (this.footer) {
37349 // el = this.footer.container.insertSibling(false, 'before');
37351 el = this.el.createChild();
37354 this.form = new Roo.form.Form(cfg);
37357 if ( this.form.allItems.length) {
37358 this.form.render(el.dom);
37362 // should only have one of theses..
37363 if ([ 'View', 'JsonView', 'DatePicker'].indexOf(cfg.xtype) > -1) {
37364 // views.. should not be just added - used named prop 'view''
37366 cfg.el = this.el.appendChild(document.createElement("div"));
37369 var ret = new Roo.factory(cfg);
37371 ret.render && ret.render(false, ''); // render blank..
37381 * @class Roo.bootstrap.panel.Grid
37382 * @extends Roo.bootstrap.panel.Content
37384 * Create a new GridPanel.
37385 * @cfg {Roo.bootstrap.Table} grid The grid for this panel
37386 * @param {Object} config A the config object
37392 Roo.bootstrap.panel.Grid = function(config)
37396 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
37397 {tag: "div", cls: "roo-layout-grid-wrapper roo-layout-inactive-content"}, true);
37399 config.el = this.wrapper;
37400 //this.el = this.wrapper;
37402 if (config.container) {
37403 // ctor'ed from a Border/panel.grid
37406 this.wrapper.setStyle("overflow", "hidden");
37407 this.wrapper.addClass('roo-grid-container');
37412 if(config.toolbar){
37413 var tool_el = this.wrapper.createChild();
37414 this.toolbar = Roo.factory(config.toolbar);
37416 if (config.toolbar.items) {
37417 ti = config.toolbar.items ;
37418 delete config.toolbar.items ;
37422 this.toolbar.render(tool_el);
37423 for(var i =0;i < ti.length;i++) {
37424 // Roo.log(['add child', items[i]]);
37425 nitems.push(this.toolbar.addxtype(Roo.apply({}, ti[i])));
37427 this.toolbar.items = nitems;
37429 delete config.toolbar;
37432 Roo.bootstrap.panel.Grid.superclass.constructor.call(this, config);
37433 config.grid.scrollBody = true;;
37434 config.grid.monitorWindowResize = false; // turn off autosizing
37435 config.grid.autoHeight = false;
37436 config.grid.autoWidth = false;
37438 this.grid = new config.grid.xns[config.grid.xtype](config.grid);
37440 if (config.background) {
37441 // render grid on panel activation (if panel background)
37442 this.on('activate', function(gp) {
37443 if (!gp.grid.rendered) {
37444 gp.grid.render(this.wrapper);
37445 gp.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37450 this.grid.render(this.wrapper);
37451 this.grid.getGridEl().replaceClass("roo-layout-inactive-content", "roo-layout-component-panel");
37454 //this.wrapper.dom.appendChild(config.grid.getGridEl().dom);
37455 // ??? needed ??? config.el = this.wrapper;
37460 // xtype created footer. - not sure if will work as we normally have to render first..
37461 if (this.footer && !this.footer.el && this.footer.xtype) {
37463 var ctr = this.grid.getView().getFooterPanel(true);
37464 this.footer.dataSource = this.grid.dataSource;
37465 this.footer = Roo.factory(this.footer, Roo);
37466 this.footer.render(ctr);
37476 Roo.extend(Roo.bootstrap.panel.Grid, Roo.bootstrap.panel.Content, {
37477 getId : function(){
37478 return this.grid.id;
37482 * Returns the grid for this panel
37483 * @return {Roo.bootstrap.Table}
37485 getGrid : function(){
37489 setSize : function(width, height){
37490 if(!this.ignoreResize(width, height)){
37491 var grid = this.grid;
37492 var size = this.adjustForComponents(width, height);
37493 var gridel = grid.getGridEl();
37494 gridel.setSize(size.width, size.height);
37496 var thd = grid.getGridEl().select('thead',true).first();
37497 var tbd = grid.getGridEl().select('tbody', true).first();
37499 tbd.setSize(width, height - thd.getHeight());
37508 beforeSlide : function(){
37509 this.grid.getView().scroller.clip();
37512 afterSlide : function(){
37513 this.grid.getView().scroller.unclip();
37516 destroy : function(){
37517 this.grid.destroy();
37519 Roo.bootstrap.panel.Grid.superclass.destroy.call(this);
37524 * @class Roo.bootstrap.panel.Nest
37525 * @extends Roo.bootstrap.panel.Content
37527 * Create a new Panel, that can contain a layout.Border.
37530 * @param {Roo.BorderLayout} layout The layout for this panel
37531 * @param {String/Object} config A string to set only the title or a config object
37533 Roo.bootstrap.panel.Nest = function(config)
37535 // construct with only one argument..
37536 /* FIXME - implement nicer consturctors
37537 if (layout.layout) {
37539 layout = config.layout;
37540 delete config.layout;
37542 if (layout.xtype && !layout.getEl) {
37543 // then layout needs constructing..
37544 layout = Roo.factory(layout, Roo);
37548 config.el = config.layout.getEl();
37550 Roo.bootstrap.panel.Nest.superclass.constructor.call(this, config);
37552 config.layout.monitorWindowResize = false; // turn off autosizing
37553 this.layout = config.layout;
37554 this.layout.getEl().addClass("roo-layout-nested-layout");
37561 Roo.extend(Roo.bootstrap.panel.Nest, Roo.bootstrap.panel.Content, {
37563 setSize : function(width, height){
37564 if(!this.ignoreResize(width, height)){
37565 var size = this.adjustForComponents(width, height);
37566 var el = this.layout.getEl();
37567 if (size.height < 1) {
37568 el.setWidth(size.width);
37570 el.setSize(size.width, size.height);
37572 var touch = el.dom.offsetWidth;
37573 this.layout.layout();
37574 // ie requires a double layout on the first pass
37575 if(Roo.isIE && !this.initialized){
37576 this.initialized = true;
37577 this.layout.layout();
37582 // activate all subpanels if not currently active..
37584 setActiveState : function(active){
37585 this.active = active;
37586 this.setActiveClass(active);
37589 this.fireEvent("deactivate", this);
37593 this.fireEvent("activate", this);
37594 // not sure if this should happen before or after..
37595 if (!this.layout) {
37596 return; // should not happen..
37599 for (var r in this.layout.regions) {
37600 reg = this.layout.getRegion(r);
37601 if (reg.getActivePanel()) {
37602 //reg.showPanel(reg.getActivePanel()); // force it to activate..
37603 reg.setActivePanel(reg.getActivePanel());
37606 if (!reg.panels.length) {
37609 reg.showPanel(reg.getPanel(0));
37618 * Returns the nested BorderLayout for this panel
37619 * @return {Roo.BorderLayout}
37621 getLayout : function(){
37622 return this.layout;
37626 * Adds a xtype elements to the layout of the nested panel
37630 xtype : 'ContentPanel',
37637 xtype : 'NestedLayoutPanel',
37643 items : [ ... list of content panels or nested layout panels.. ]
37647 * @param {Object} cfg Xtype definition of item to add.
37649 addxtype : function(cfg) {
37650 return this.layout.addxtype(cfg);
37655 * Ext JS Library 1.1.1
37656 * Copyright(c) 2006-2007, Ext JS, LLC.
37658 * Originally Released Under LGPL - original licence link has changed is not relivant.
37661 * <script type="text/javascript">
37664 * @class Roo.TabPanel
37665 * @extends Roo.util.Observable
37666 * A lightweight tab container.
37670 // basic tabs 1, built from existing content
37671 var tabs = new Roo.TabPanel("tabs1");
37672 tabs.addTab("script", "View Script");
37673 tabs.addTab("markup", "View Markup");
37674 tabs.activate("script");
37676 // more advanced tabs, built from javascript
37677 var jtabs = new Roo.TabPanel("jtabs");
37678 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
37680 // set up the UpdateManager
37681 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
37682 var updater = tab2.getUpdateManager();
37683 updater.setDefaultUrl("ajax1.htm");
37684 tab2.on('activate', updater.refresh, updater, true);
37686 // Use setUrl for Ajax loading
37687 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
37688 tab3.setUrl("ajax2.htm", null, true);
37691 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
37694 jtabs.activate("jtabs-1");
37697 * Create a new TabPanel.
37698 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
37699 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
37701 Roo.bootstrap.panel.Tabs = function(config){
37703 * The container element for this TabPanel.
37704 * @type Roo.Element
37706 this.el = Roo.get(config.el);
37709 if(typeof config == "boolean"){
37710 this.tabPosition = config ? "bottom" : "top";
37712 Roo.apply(this, config);
37716 if(this.tabPosition == "bottom"){
37717 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37718 this.el.addClass("roo-tabs-bottom");
37720 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
37721 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
37722 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
37724 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
37726 if(this.tabPosition != "bottom"){
37727 /** The body element that contains {@link Roo.TabPanelItem} bodies. +
37728 * @type Roo.Element
37730 this.bodyEl = Roo.get(this.createBody(this.el.dom));
37731 this.el.addClass("roo-tabs-top");
37735 this.bodyEl.setStyle("position", "relative");
37737 this.active = null;
37738 this.activateDelegate = this.activate.createDelegate(this);
37743 * Fires when the active tab changes
37744 * @param {Roo.TabPanel} this
37745 * @param {Roo.TabPanelItem} activePanel The new active tab
37749 * @event beforetabchange
37750 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
37751 * @param {Roo.TabPanel} this
37752 * @param {Object} e Set cancel to true on this object to cancel the tab change
37753 * @param {Roo.TabPanelItem} tab The tab being changed to
37755 "beforetabchange" : true
37758 Roo.EventManager.onWindowResize(this.onResize, this);
37759 this.cpad = this.el.getPadding("lr");
37760 this.hiddenCount = 0;
37763 // toolbar on the tabbar support...
37764 if (this.toolbar) {
37765 alert("no toolbar support yet");
37766 this.toolbar = false;
37768 var tcfg = this.toolbar;
37769 tcfg.container = this.stripEl.child('td.x-tab-strip-toolbar');
37770 this.toolbar = new Roo.Toolbar(tcfg);
37771 if (Roo.isSafari) {
37772 var tbl = tcfg.container.child('table', true);
37773 tbl.setAttribute('width', '100%');
37781 Roo.bootstrap.panel.Tabs.superclass.constructor.call(this);
37784 Roo.extend(Roo.bootstrap.panel.Tabs, Roo.util.Observable, {
37786 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
37788 tabPosition : "top",
37790 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
37792 currentTabWidth : 0,
37794 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
37798 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
37802 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
37804 preferredTabWidth : 175,
37806 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
37808 resizeTabs : false,
37810 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
37812 monitorResize : true,
37814 *@cfg {Object} toolbar xtype description of toolbar to show at the right of the tab bar.
37819 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
37820 * @param {String} id The id of the div to use <b>or create</b>
37821 * @param {String} text The text for the tab
37822 * @param {String} content (optional) Content to put in the TabPanelItem body
37823 * @param {Boolean} closable (optional) True to create a close icon on the tab
37824 * @return {Roo.TabPanelItem} The created TabPanelItem
37826 addTab : function(id, text, content, closable, tpl)
37828 var item = new Roo.bootstrap.panel.TabItem({
37832 closable : closable,
37835 this.addTabItem(item);
37837 item.setContent(content);
37843 * Returns the {@link Roo.TabPanelItem} with the specified id/index
37844 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
37845 * @return {Roo.TabPanelItem}
37847 getTab : function(id){
37848 return this.items[id];
37852 * Hides the {@link Roo.TabPanelItem} with the specified id/index
37853 * @param {String/Number} id The id or index of the TabPanelItem to hide.
37855 hideTab : function(id){
37856 var t = this.items[id];
37859 this.hiddenCount++;
37860 this.autoSizeTabs();
37865 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
37866 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
37868 unhideTab : function(id){
37869 var t = this.items[id];
37871 t.setHidden(false);
37872 this.hiddenCount--;
37873 this.autoSizeTabs();
37878 * Adds an existing {@link Roo.TabPanelItem}.
37879 * @param {Roo.TabPanelItem} item The TabPanelItem to add
37881 addTabItem : function(item){
37882 this.items[item.id] = item;
37883 this.items.push(item);
37884 // if(this.resizeTabs){
37885 // item.setWidth(this.currentTabWidth || this.preferredTabWidth);
37886 // this.autoSizeTabs();
37888 // item.autoSize();
37893 * Removes a {@link Roo.TabPanelItem}.
37894 * @param {String/Number} id The id or index of the TabPanelItem to remove.
37896 removeTab : function(id){
37897 var items = this.items;
37898 var tab = items[id];
37899 if(!tab) { return; }
37900 var index = items.indexOf(tab);
37901 if(this.active == tab && items.length > 1){
37902 var newTab = this.getNextAvailable(index);
37907 this.stripEl.dom.removeChild(tab.pnode.dom);
37908 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
37909 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
37911 items.splice(index, 1);
37912 delete this.items[tab.id];
37913 tab.fireEvent("close", tab);
37914 tab.purgeListeners();
37915 this.autoSizeTabs();
37918 getNextAvailable : function(start){
37919 var items = this.items;
37921 // look for a next tab that will slide over to
37922 // replace the one being removed
37923 while(index < items.length){
37924 var item = items[++index];
37925 if(item && !item.isHidden()){
37929 // if one isn't found select the previous tab (on the left)
37932 var item = items[--index];
37933 if(item && !item.isHidden()){
37941 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
37942 * @param {String/Number} id The id or index of the TabPanelItem to disable.
37944 disableTab : function(id){
37945 var tab = this.items[id];
37946 if(tab && this.active != tab){
37952 * Enables a {@link Roo.TabPanelItem} that is disabled.
37953 * @param {String/Number} id The id or index of the TabPanelItem to enable.
37955 enableTab : function(id){
37956 var tab = this.items[id];
37961 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
37962 * @param {String/Number} id The id or index of the TabPanelItem to activate.
37963 * @return {Roo.TabPanelItem} The TabPanelItem.
37965 activate : function(id){
37966 var tab = this.items[id];
37970 if(tab == this.active || tab.disabled){
37974 this.fireEvent("beforetabchange", this, e, tab);
37975 if(e.cancel !== true && !tab.disabled){
37977 this.active.hide();
37979 this.active = this.items[id];
37980 this.active.show();
37981 this.fireEvent("tabchange", this, this.active);
37987 * Gets the active {@link Roo.TabPanelItem}.
37988 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
37990 getActiveTab : function(){
37991 return this.active;
37995 * Updates the tab body element to fit the height of the container element
37996 * for overflow scrolling
37997 * @param {Number} targetHeight (optional) Override the starting height from the elements height
37999 syncHeight : function(targetHeight){
38000 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
38001 var bm = this.bodyEl.getMargins();
38002 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
38003 this.bodyEl.setHeight(newHeight);
38007 onResize : function(){
38008 if(this.monitorResize){
38009 this.autoSizeTabs();
38014 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
38016 beginUpdate : function(){
38017 this.updating = true;
38021 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
38023 endUpdate : function(){
38024 this.updating = false;
38025 this.autoSizeTabs();
38029 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
38031 autoSizeTabs : function(){
38032 var count = this.items.length;
38033 var vcount = count - this.hiddenCount;
38034 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) {
38037 var w = Math.max(this.el.getWidth() - this.cpad, 10);
38038 var availWidth = Math.floor(w / vcount);
38039 var b = this.stripBody;
38040 if(b.getWidth() > w){
38041 var tabs = this.items;
38042 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
38043 if(availWidth < this.minTabWidth){
38044 /*if(!this.sleft){ // incomplete scrolling code
38045 this.createScrollButtons();
38048 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
38051 if(this.currentTabWidth < this.preferredTabWidth){
38052 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
38058 * Returns the number of tabs in this TabPanel.
38061 getCount : function(){
38062 return this.items.length;
38066 * Resizes all the tabs to the passed width
38067 * @param {Number} The new width
38069 setTabWidth : function(width){
38070 this.currentTabWidth = width;
38071 for(var i = 0, len = this.items.length; i < len; i++) {
38072 if(!this.items[i].isHidden()) {
38073 this.items[i].setWidth(width);
38079 * Destroys this TabPanel
38080 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
38082 destroy : function(removeEl){
38083 Roo.EventManager.removeResizeListener(this.onResize, this);
38084 for(var i = 0, len = this.items.length; i < len; i++){
38085 this.items[i].purgeListeners();
38087 if(removeEl === true){
38088 this.el.update("");
38093 createStrip : function(container)
38095 var strip = document.createElement("nav");
38096 strip.className = "navbar navbar-default"; //"x-tabs-wrap";
38097 container.appendChild(strip);
38101 createStripList : function(strip)
38103 // div wrapper for retard IE
38104 // returns the "tr" element.
38105 strip.innerHTML = '<ul class="nav nav-tabs" role="tablist"></ul>';
38106 //'<div class="x-tabs-strip-wrap">'+
38107 // '<table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr>'+
38108 // '<td class="x-tab-strip-toolbar"></td></tr></tbody></table></div>';
38109 return strip.firstChild; //.firstChild.firstChild.firstChild;
38111 createBody : function(container)
38113 var body = document.createElement("div");
38114 Roo.id(body, "tab-body");
38115 //Roo.fly(body).addClass("x-tabs-body");
38116 Roo.fly(body).addClass("tab-content");
38117 container.appendChild(body);
38120 createItemBody :function(bodyEl, id){
38121 var body = Roo.getDom(id);
38123 body = document.createElement("div");
38126 //Roo.fly(body).addClass("x-tabs-item-body");
38127 Roo.fly(body).addClass("tab-pane");
38128 bodyEl.insertBefore(body, bodyEl.firstChild);
38132 createStripElements : function(stripEl, text, closable, tpl)
38134 var td = document.createElement("li"); // was td..
38137 //stripEl.insertBefore(td, stripEl.childNodes[stripEl.childNodes.length-1]);
38140 stripEl.appendChild(td);
38142 td.className = "x-tabs-closable";
38143 if(!this.closeTpl){
38144 this.closeTpl = new Roo.Template(
38145 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38146 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
38147 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
38150 var el = this.closeTpl.overwrite(td, {"text": text});
38151 var close = el.getElementsByTagName("div")[0];
38152 var inner = el.getElementsByTagName("em")[0];
38153 return {"el": el, "close": close, "inner": inner};
38156 // not sure what this is..
38157 // if(!this.tabTpl){
38158 //this.tabTpl = new Roo.Template(
38159 // '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
38160 // '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
38162 // this.tabTpl = new Roo.Template(
38163 // '<a href="#">' +
38164 // '<span unselectable="on"' +
38165 // (this.disableTooltips ? '' : ' title="{text}"') +
38166 // ' >{text}</span></a>'
38172 var template = tpl || this.tabTpl || false;
38176 template = new Roo.Template(
38178 '<span unselectable="on"' +
38179 (this.disableTooltips ? '' : ' title="{text}"') +
38180 ' >{text}</span></a>'
38184 switch (typeof(template)) {
38188 template = new Roo.Template(template);
38194 var el = template.overwrite(td, {"text": text});
38196 var inner = el.getElementsByTagName("span")[0];
38198 return {"el": el, "inner": inner};
38206 * @class Roo.TabPanelItem
38207 * @extends Roo.util.Observable
38208 * Represents an individual item (tab plus body) in a TabPanel.
38209 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
38210 * @param {String} id The id of this TabPanelItem
38211 * @param {String} text The text for the tab of this TabPanelItem
38212 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
38214 Roo.bootstrap.panel.TabItem = function(config){
38216 * The {@link Roo.TabPanel} this TabPanelItem belongs to
38217 * @type Roo.TabPanel
38219 this.tabPanel = config.panel;
38221 * The id for this TabPanelItem
38224 this.id = config.id;
38226 this.disabled = false;
38228 this.text = config.text;
38230 this.loaded = false;
38231 this.closable = config.closable;
38234 * The body element for this TabPanelItem.
38235 * @type Roo.Element
38237 this.bodyEl = Roo.get(this.tabPanel.createItemBody(this.tabPanel.bodyEl.dom, config.id));
38238 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
38239 this.bodyEl.setStyle("display", "block");
38240 this.bodyEl.setStyle("zoom", "1");
38241 //this.hideAction();
38243 var els = this.tabPanel.createStripElements(this.tabPanel.stripEl.dom, config.text, config.closable, config.tpl);
38245 this.el = Roo.get(els.el);
38246 this.inner = Roo.get(els.inner, true);
38247 this.textEl = Roo.get(this.el.dom.firstChild, true);
38248 this.pnode = Roo.get(els.el.parentNode, true);
38249 // this.el.on("mousedown", this.onTabMouseDown, this);
38250 this.el.on("click", this.onTabClick, this);
38252 if(config.closable){
38253 var c = Roo.get(els.close, true);
38254 c.dom.title = this.closeText;
38255 c.addClassOnOver("close-over");
38256 c.on("click", this.closeClick, this);
38262 * Fires when this tab becomes the active tab.
38263 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38264 * @param {Roo.TabPanelItem} this
38268 * @event beforeclose
38269 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
38270 * @param {Roo.TabPanelItem} this
38271 * @param {Object} e Set cancel to true on this object to cancel the close.
38273 "beforeclose": true,
38276 * Fires when this tab is closed.
38277 * @param {Roo.TabPanelItem} this
38281 * @event deactivate
38282 * Fires when this tab is no longer the active tab.
38283 * @param {Roo.TabPanel} tabPanel The parent TabPanel
38284 * @param {Roo.TabPanelItem} this
38286 "deactivate" : true
38288 this.hidden = false;
38290 Roo.bootstrap.panel.TabItem.superclass.constructor.call(this);
38293 Roo.extend(Roo.bootstrap.panel.TabItem, Roo.util.Observable,
38295 purgeListeners : function(){
38296 Roo.util.Observable.prototype.purgeListeners.call(this);
38297 this.el.removeAllListeners();
38300 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
38303 this.pnode.addClass("active");
38306 this.tabPanel.stripWrap.repaint();
38308 this.fireEvent("activate", this.tabPanel, this);
38312 * Returns true if this tab is the active tab.
38313 * @return {Boolean}
38315 isActive : function(){
38316 return this.tabPanel.getActiveTab() == this;
38320 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
38323 this.pnode.removeClass("active");
38325 this.fireEvent("deactivate", this.tabPanel, this);
38328 hideAction : function(){
38329 this.bodyEl.hide();
38330 this.bodyEl.setStyle("position", "absolute");
38331 this.bodyEl.setLeft("-20000px");
38332 this.bodyEl.setTop("-20000px");
38335 showAction : function(){
38336 this.bodyEl.setStyle("position", "relative");
38337 this.bodyEl.setTop("");
38338 this.bodyEl.setLeft("");
38339 this.bodyEl.show();
38343 * Set the tooltip for the tab.
38344 * @param {String} tooltip The tab's tooltip
38346 setTooltip : function(text){
38347 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
38348 this.textEl.dom.qtip = text;
38349 this.textEl.dom.removeAttribute('title');
38351 this.textEl.dom.title = text;
38355 onTabClick : function(e){
38356 e.preventDefault();
38357 this.tabPanel.activate(this.id);
38360 onTabMouseDown : function(e){
38361 e.preventDefault();
38362 this.tabPanel.activate(this.id);
38365 getWidth : function(){
38366 return this.inner.getWidth();
38369 setWidth : function(width){
38370 var iwidth = width - this.pnode.getPadding("lr");
38371 this.inner.setWidth(iwidth);
38372 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
38373 this.pnode.setWidth(width);
38377 * Show or hide the tab
38378 * @param {Boolean} hidden True to hide or false to show.
38380 setHidden : function(hidden){
38381 this.hidden = hidden;
38382 this.pnode.setStyle("display", hidden ? "none" : "");
38386 * Returns true if this tab is "hidden"
38387 * @return {Boolean}
38389 isHidden : function(){
38390 return this.hidden;
38394 * Returns the text for this tab
38397 getText : function(){
38401 autoSize : function(){
38402 //this.el.beginMeasure();
38403 this.textEl.setWidth(1);
38405 * #2804 [new] Tabs in Roojs
38406 * increase the width by 2-4 pixels to prevent the ellipssis showing in chrome
38408 //this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr") + 2);
38409 //this.el.endMeasure();
38413 * Sets the text for the tab (Note: this also sets the tooltip text)
38414 * @param {String} text The tab's text and tooltip
38416 setText : function(text){
38418 this.textEl.update(text);
38419 this.setTooltip(text);
38420 //if(!this.tabPanel.resizeTabs){
38421 // this.autoSize();
38425 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
38427 activate : function(){
38428 this.tabPanel.activate(this.id);
38432 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
38434 disable : function(){
38435 if(this.tabPanel.active != this){
38436 this.disabled = true;
38437 this.pnode.addClass("disabled");
38442 * Enables this TabPanelItem if it was previously disabled.
38444 enable : function(){
38445 this.disabled = false;
38446 this.pnode.removeClass("disabled");
38450 * Sets the content for this TabPanelItem.
38451 * @param {String} content The content
38452 * @param {Boolean} loadScripts true to look for and load scripts
38454 setContent : function(content, loadScripts){
38455 this.bodyEl.update(content, loadScripts);
38459 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
38460 * @return {Roo.UpdateManager} The UpdateManager
38462 getUpdateManager : function(){
38463 return this.bodyEl.getUpdateManager();
38467 * Set a URL to be used to load the content for this TabPanelItem.
38468 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
38469 * @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)
38470 * @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)
38471 * @return {Roo.UpdateManager} The UpdateManager
38473 setUrl : function(url, params, loadOnce){
38474 if(this.refreshDelegate){
38475 this.un('activate', this.refreshDelegate);
38477 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
38478 this.on("activate", this.refreshDelegate);
38479 return this.bodyEl.getUpdateManager();
38483 _handleRefresh : function(url, params, loadOnce){
38484 if(!loadOnce || !this.loaded){
38485 var updater = this.bodyEl.getUpdateManager();
38486 updater.update(url, params, this._setLoaded.createDelegate(this));
38491 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
38492 * Will fail silently if the setUrl method has not been called.
38493 * This does not activate the panel, just updates its content.
38495 refresh : function(){
38496 if(this.refreshDelegate){
38497 this.loaded = false;
38498 this.refreshDelegate();
38503 _setLoaded : function(){
38504 this.loaded = true;
38508 closeClick : function(e){
38511 this.fireEvent("beforeclose", this, o);
38512 if(o.cancel !== true){
38513 this.tabPanel.removeTab(this.id);
38517 * The text displayed in the tooltip for the close icon.
38520 closeText : "Close this tab"
38523 * This script refer to:
38524 * Title: International Telephone Input
38525 * Author: Jack O'Connor
38526 * Code version: v12.1.12
38527 * Availability: https://github.com/jackocnr/intl-tel-input.git
38530 Roo.bootstrap.PhoneInputData = function() {
38533 "Afghanistan (افغانستان)",
38538 "Albania (Shqipëri)",
38543 "Algeria (الجزائر)",
38568 "Antigua and Barbuda",
38578 "Armenia (Հայաստան)",
38594 "Austria (Österreich)",
38599 "Azerbaijan (Azərbaycan)",
38609 "Bahrain (البحرين)",
38614 "Bangladesh (বাংলাদেশ)",
38624 "Belarus (Беларусь)",
38629 "Belgium (België)",
38659 "Bosnia and Herzegovina (Босна и Херцеговина)",
38674 "British Indian Ocean Territory",
38679 "British Virgin Islands",
38689 "Bulgaria (България)",
38699 "Burundi (Uburundi)",
38704 "Cambodia (កម្ពុជា)",
38709 "Cameroon (Cameroun)",
38718 ["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"]
38721 "Cape Verde (Kabu Verdi)",
38726 "Caribbean Netherlands",
38737 "Central African Republic (République centrafricaine)",
38757 "Christmas Island",
38763 "Cocos (Keeling) Islands",
38774 "Comoros (جزر القمر)",
38779 "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)",
38784 "Congo (Republic) (Congo-Brazzaville)",
38804 "Croatia (Hrvatska)",
38825 "Czech Republic (Česká republika)",
38830 "Denmark (Danmark)",
38845 "Dominican Republic (República Dominicana)",
38849 ["809", "829", "849"]
38867 "Equatorial Guinea (Guinea Ecuatorial)",
38887 "Falkland Islands (Islas Malvinas)",
38892 "Faroe Islands (Føroyar)",
38913 "French Guiana (Guyane française)",
38918 "French Polynesia (Polynésie française)",
38933 "Georgia (საქართველო)",
38938 "Germany (Deutschland)",
38958 "Greenland (Kalaallit Nunaat)",
38995 "Guinea-Bissau (Guiné Bissau)",
39020 "Hungary (Magyarország)",
39025 "Iceland (Ísland)",
39045 "Iraq (العراق)",
39061 "Israel (ישראל)",
39088 "Jordan (الأردن)",
39093 "Kazakhstan (Казахстан)",
39114 "Kuwait (الكويت)",
39119 "Kyrgyzstan (Кыргызстан)",
39129 "Latvia (Latvija)",
39134 "Lebanon (لبنان)",
39149 "Libya (ليبيا)",
39159 "Lithuania (Lietuva)",
39174 "Macedonia (FYROM) (Македонија)",
39179 "Madagascar (Madagasikara)",
39209 "Marshall Islands",
39219 "Mauritania (موريتانيا)",
39224 "Mauritius (Moris)",
39245 "Moldova (Republica Moldova)",
39255 "Mongolia (Монгол)",
39260 "Montenegro (Crna Gora)",
39270 "Morocco (المغرب)",
39276 "Mozambique (Moçambique)",
39281 "Myanmar (Burma) (မြန်မာ)",
39286 "Namibia (Namibië)",
39301 "Netherlands (Nederland)",
39306 "New Caledonia (Nouvelle-Calédonie)",
39341 "North Korea (조선 민주주의 인민 공화국)",
39346 "Northern Mariana Islands",
39362 "Pakistan (پاکستان)",
39372 "Palestine (فلسطين)",
39382 "Papua New Guinea",
39424 "Réunion (La Réunion)",
39430 "Romania (România)",
39446 "Saint Barthélemy",
39457 "Saint Kitts and Nevis",
39467 "Saint Martin (Saint-Martin (partie française))",
39473 "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
39478 "Saint Vincent and the Grenadines",
39493 "São Tomé and Príncipe (São Tomé e Príncipe)",
39498 "Saudi Arabia (المملكة العربية السعودية)",
39503 "Senegal (Sénégal)",
39533 "Slovakia (Slovensko)",
39538 "Slovenia (Slovenija)",
39548 "Somalia (Soomaaliya)",
39558 "South Korea (대한민국)",
39563 "South Sudan (جنوب السودان)",
39573 "Sri Lanka (ශ්රී ලංකාව)",
39578 "Sudan (السودان)",
39588 "Svalbard and Jan Mayen",
39599 "Sweden (Sverige)",
39604 "Switzerland (Schweiz)",
39609 "Syria (سوريا)",
39654 "Trinidad and Tobago",
39659 "Tunisia (تونس)",
39664 "Turkey (Türkiye)",
39674 "Turks and Caicos Islands",
39684 "U.S. Virgin Islands",
39694 "Ukraine (Україна)",
39699 "United Arab Emirates (الإمارات العربية المتحدة)",
39721 "Uzbekistan (Oʻzbekiston)",
39731 "Vatican City (Città del Vaticano)",
39742 "Vietnam (Việt Nam)",
39747 "Wallis and Futuna (Wallis-et-Futuna)",
39752 "Western Sahara (الصحراء الغربية)",
39758 "Yemen (اليمن)",
39782 * This script refer to:
39783 * Title: International Telephone Input
39784 * Author: Jack O'Connor
39785 * Code version: v12.1.12
39786 * Availability: https://github.com/jackocnr/intl-tel-input.git
39790 * @class Roo.bootstrap.PhoneInput
39791 * @extends Roo.bootstrap.TriggerField
39792 * An input with International dial-code selection
39794 * @cfg {String} defaultDialCode default '+852'
39795 * @cfg {Array} preferedCountries default []
39798 * Create a new PhoneInput.
39799 * @param {Object} config Configuration options
39802 Roo.bootstrap.PhoneInput = function(config) {
39803 Roo.bootstrap.PhoneInput.superclass.constructor.call(this, config);
39806 Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
39808 listWidth: undefined,
39810 selectedClass: 'active',
39812 invalidClass : "has-warning",
39814 validClass: 'has-success',
39816 allowed: '0123456789',
39819 * @cfg {String} defaultDialCode The default dial code when initializing the input
39821 defaultDialCode: '+852',
39824 * @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
39826 preferedCountries: false,
39828 getAutoCreate : function()
39830 var data = Roo.bootstrap.PhoneInputData();
39831 var align = this.labelAlign || this.parentLabelAlign();
39834 this.allCountries = [];
39835 this.dialCodeMapping = [];
39837 for (var i = 0; i < data.length; i++) {
39839 this.allCountries[i] = {
39843 priority: c[3] || 0,
39844 areaCodes: c[4] || null
39846 this.dialCodeMapping[c[2]] = {
39849 priority: c[3] || 0,
39850 areaCodes: c[4] || null
39862 cls : 'form-control tel-input',
39863 autocomplete: 'new-password'
39866 var hiddenInput = {
39869 cls: 'hidden-tel-input'
39873 hiddenInput.name = this.name;
39876 if (this.disabled) {
39877 input.disabled = true;
39880 var flag_container = {
39897 cls: this.hasFeedback ? 'has-feedback' : '',
39903 cls: 'dial-code-holder',
39910 cls: 'roo-select2-container input-group',
39917 if (this.fieldLabel.length) {
39920 tooltip: 'This field is required'
39926 cls: 'control-label',
39932 html: this.fieldLabel
39935 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
39941 if(this.indicatorpos == 'right') {
39942 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
39949 if(align == 'left') {
39957 if(this.labelWidth > 12){
39958 label.style = "width: " + this.labelWidth + 'px';
39960 if(this.labelWidth < 13 && this.labelmd == 0){
39961 this.labelmd = this.labelWidth;
39963 if(this.labellg > 0){
39964 label.cls += ' col-lg-' + this.labellg;
39965 input.cls += ' col-lg-' + (12 - this.labellg);
39967 if(this.labelmd > 0){
39968 label.cls += ' col-md-' + this.labelmd;
39969 container.cls += ' col-md-' + (12 - this.labelmd);
39971 if(this.labelsm > 0){
39972 label.cls += ' col-sm-' + this.labelsm;
39973 container.cls += ' col-sm-' + (12 - this.labelsm);
39975 if(this.labelxs > 0){
39976 label.cls += ' col-xs-' + this.labelxs;
39977 container.cls += ' col-xs-' + (12 - this.labelxs);
39987 var settings = this;
39989 ['xs','sm','md','lg'].map(function(size){
39990 if (settings[size]) {
39991 cfg.cls += ' col-' + size + '-' + settings[size];
39995 this.store = new Roo.data.Store({
39996 proxy : new Roo.data.MemoryProxy({}),
39997 reader : new Roo.data.JsonReader({
40008 'name' : 'dialCode',
40012 'name' : 'priority',
40016 'name' : 'areaCodes',
40023 if(!this.preferedCountries) {
40024 this.preferedCountries = [
40031 var p = this.preferedCountries.reverse();
40034 for (var i = 0; i < p.length; i++) {
40035 for (var j = 0; j < this.allCountries.length; j++) {
40036 if(this.allCountries[j].iso2 == p[i]) {
40037 var t = this.allCountries[j];
40038 this.allCountries.splice(j,1);
40039 this.allCountries.unshift(t);
40045 this.store.proxy.data = {
40047 data: this.allCountries
40053 initEvents : function()
40056 Roo.bootstrap.PhoneInput.superclass.initEvents.call(this);
40058 this.indicator = this.indicatorEl();
40059 this.flag = this.flagEl();
40060 this.dialCodeHolder = this.dialCodeHolderEl();
40062 this.trigger = this.el.select('div.flag-box',true).first();
40063 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
40068 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40069 _this.list.setWidth(lw);
40072 this.list.on('mouseover', this.onViewOver, this);
40073 this.list.on('mousemove', this.onViewMove, this);
40074 this.inputEl().on("keyup", this.onKeyUp, this);
40076 this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
40078 this.view = new Roo.View(this.list, this.tpl, {
40079 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40082 this.view.on('click', this.onViewClick, this);
40083 this.setValue(this.defaultDialCode);
40086 onTriggerClick : function(e)
40088 Roo.log('trigger click');
40093 if(this.isExpanded()){
40095 this.hasFocus = false;
40097 this.store.load({});
40098 this.hasFocus = true;
40103 isExpanded : function()
40105 return this.list.isVisible();
40108 collapse : function()
40110 if(!this.isExpanded()){
40114 Roo.get(document).un('mousedown', this.collapseIf, this);
40115 Roo.get(document).un('mousewheel', this.collapseIf, this);
40116 this.fireEvent('collapse', this);
40120 expand : function()
40124 if(this.isExpanded() || !this.hasFocus){
40128 var lw = this.listWidth || Math.max(this.inputEl().getWidth(), this.minListWidth);
40129 this.list.setWidth(lw);
40132 this.restrictHeight();
40134 Roo.get(document).on('mousedown', this.collapseIf, this);
40135 Roo.get(document).on('mousewheel', this.collapseIf, this);
40137 this.fireEvent('expand', this);
40140 restrictHeight : function()
40142 this.list.alignTo(this.inputEl(), this.listAlign);
40143 this.list.alignTo(this.inputEl(), this.listAlign);
40146 onViewOver : function(e, t)
40148 if(this.inKeyMode){
40151 var item = this.view.findItemFromChild(t);
40154 var index = this.view.indexOf(item);
40155 this.select(index, false);
40160 onViewClick : function(view, doFocus, el, e)
40162 var index = this.view.getSelectedIndexes()[0];
40164 var r = this.store.getAt(index);
40167 this.onSelect(r, index);
40169 if(doFocus !== false && !this.blockFocus){
40170 this.inputEl().focus();
40174 onViewMove : function(e, t)
40176 this.inKeyMode = false;
40179 select : function(index, scrollIntoView)
40181 this.selectedIndex = index;
40182 this.view.select(index);
40183 if(scrollIntoView !== false){
40184 var el = this.view.getNode(index);
40186 this.list.scrollChildIntoView(el, false);
40191 createList : function()
40193 this.list = Roo.get(document.body).createChild({
40195 cls: 'typeahead typeahead-long dropdown-menu tel-list',
40196 style: 'display:none'
40199 this.list.setVisibilityMode(Roo.Element.DISPLAY).originalDisplay = 'block';
40202 collapseIf : function(e)
40204 var in_combo = e.within(this.el);
40205 var in_list = e.within(this.list);
40206 var is_list = (Roo.get(e.getTarget()).id == this.list.id) ? true : false;
40208 if (in_combo || in_list || is_list) {
40214 onSelect : function(record, index)
40216 if(this.fireEvent('beforeselect', this, record, index) !== false){
40218 this.setFlagClass(record.data.iso2);
40219 this.setDialCode(record.data.dialCode);
40220 this.hasFocus = false;
40222 this.fireEvent('select', this, record, index);
40226 flagEl : function()
40228 var flag = this.el.select('div.flag',true).first();
40235 dialCodeHolderEl : function()
40237 var d = this.el.select('input.dial-code-holder',true).first();
40244 setDialCode : function(v)
40246 this.dialCodeHolder.dom.value = '+'+v;
40249 setFlagClass : function(n)
40251 this.flag.dom.className = 'flag '+n;
40254 getValue : function()
40256 var v = this.inputEl().getValue();
40257 if(this.dialCodeHolder) {
40258 v = this.dialCodeHolder.dom.value+this.inputEl().getValue();
40263 setValue : function(v)
40265 var d = this.getDialCode(v);
40267 //invalid dial code
40268 if(v.length == 0 || !d || d.length == 0) {
40270 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
40271 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40277 this.setFlagClass(this.dialCodeMapping[d].iso2);
40278 this.setDialCode(d);
40279 this.inputEl().dom.value = v.replace('+'+d,'');
40280 this.hiddenEl().dom.value = this.getValue();
40285 getDialCode : function(v)
40289 if (v.length == 0) {
40290 return this.dialCodeHolder.dom.value;
40294 if (v.charAt(0) != "+") {
40297 var numericChars = "";
40298 for (var i = 1; i < v.length; i++) {
40299 var c = v.charAt(i);
40302 if (this.dialCodeMapping[numericChars]) {
40303 dialCode = v.substr(1, i);
40305 if (numericChars.length == 4) {
40315 this.setValue(this.defaultDialCode);
40319 hiddenEl : function()
40321 return this.el.select('input.hidden-tel-input',true).first();
40324 onKeyUp : function(e){
40326 var k = e.getKey();
40327 var c = e.getCharCode();
40330 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40331 this.allowed.indexOf(String.fromCharCode(c)) === -1
40336 // if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40339 if(this.allowed.indexOf(String.fromCharCode(c)) === -1){
40343 this.setValue(this.getValue());
40348 * @class Roo.bootstrap.MoneyField
40349 * @extends Roo.bootstrap.ComboBox
40350 * Bootstrap MoneyField class
40353 * Create a new MoneyField.
40354 * @param {Object} config Configuration options
40357 Roo.bootstrap.MoneyField = function(config) {
40359 Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
40363 Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
40366 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
40368 allowDecimals : true,
40370 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
40372 decimalSeparator : ".",
40374 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
40376 decimalPrecision : 0,
40378 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
40380 allowNegative : true,
40382 * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
40386 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
40388 minValue : Number.NEGATIVE_INFINITY,
40390 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
40392 maxValue : Number.MAX_VALUE,
40394 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
40396 minText : "The minimum value for this field is {0}",
40398 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
40400 maxText : "The maximum value for this field is {0}",
40402 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
40403 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
40405 nanText : "{0} is not a valid number",
40407 * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
40411 * @cfg {String} defaults currency of the MoneyField
40412 * value should be in lkey
40414 defaultCurrency : false,
40416 * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
40418 thousandsDelimiter : false,
40428 getAutoCreate : function()
40430 var align = this.labelAlign || this.parentLabelAlign();
40442 cls : 'form-control roo-money-amount-input',
40443 autocomplete: 'new-password'
40446 var hiddenInput = {
40450 cls: 'hidden-number-input'
40454 hiddenInput.name = this.name;
40457 if (this.disabled) {
40458 input.disabled = true;
40461 var clg = 12 - this.inputlg;
40462 var cmd = 12 - this.inputmd;
40463 var csm = 12 - this.inputsm;
40464 var cxs = 12 - this.inputxs;
40468 cls : 'row roo-money-field',
40472 cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
40476 cls: 'roo-select2-container input-group',
40480 cls : 'form-control roo-money-currency-input',
40481 autocomplete: 'new-password',
40483 name : this.currencyName
40487 cls : 'input-group-addon',
40501 cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
40505 cls: this.hasFeedback ? 'has-feedback' : '',
40516 if (this.fieldLabel.length) {
40519 tooltip: 'This field is required'
40525 cls: 'control-label',
40531 html: this.fieldLabel
40534 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
40540 if(this.indicatorpos == 'right') {
40541 indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
40548 if(align == 'left') {
40556 if(this.labelWidth > 12){
40557 label.style = "width: " + this.labelWidth + 'px';
40559 if(this.labelWidth < 13 && this.labelmd == 0){
40560 this.labelmd = this.labelWidth;
40562 if(this.labellg > 0){
40563 label.cls += ' col-lg-' + this.labellg;
40564 input.cls += ' col-lg-' + (12 - this.labellg);
40566 if(this.labelmd > 0){
40567 label.cls += ' col-md-' + this.labelmd;
40568 container.cls += ' col-md-' + (12 - this.labelmd);
40570 if(this.labelsm > 0){
40571 label.cls += ' col-sm-' + this.labelsm;
40572 container.cls += ' col-sm-' + (12 - this.labelsm);
40574 if(this.labelxs > 0){
40575 label.cls += ' col-xs-' + this.labelxs;
40576 container.cls += ' col-xs-' + (12 - this.labelxs);
40587 var settings = this;
40589 ['xs','sm','md','lg'].map(function(size){
40590 if (settings[size]) {
40591 cfg.cls += ' col-' + size + '-' + settings[size];
40598 initEvents : function()
40600 this.indicator = this.indicatorEl();
40602 this.initCurrencyEvent();
40604 this.initNumberEvent();
40607 initCurrencyEvent : function()
40610 throw "can not find store for combo";
40613 this.store = Roo.factory(this.store, Roo.data);
40614 this.store.parent = this;
40618 this.triggerEl = this.el.select('.input-group-addon', true).first();
40620 this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
40625 var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
40626 _this.list.setWidth(lw);
40629 this.list.on('mouseover', this.onViewOver, this);
40630 this.list.on('mousemove', this.onViewMove, this);
40631 this.list.on('scroll', this.onViewScroll, this);
40634 this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
40637 this.view = new Roo.View(this.list, this.tpl, {
40638 singleSelect:true, store: this.store, selectedClass: this.selectedClass
40641 this.view.on('click', this.onViewClick, this);
40643 this.store.on('beforeload', this.onBeforeLoad, this);
40644 this.store.on('load', this.onLoad, this);
40645 this.store.on('loadexception', this.onLoadException, this);
40647 this.keyNav = new Roo.KeyNav(this.currencyEl(), {
40648 "up" : function(e){
40649 this.inKeyMode = true;
40653 "down" : function(e){
40654 if(!this.isExpanded()){
40655 this.onTriggerClick();
40657 this.inKeyMode = true;
40662 "enter" : function(e){
40665 if(this.fireEvent("specialkey", this, e)){
40666 this.onViewClick(false);
40672 "esc" : function(e){
40676 "tab" : function(e){
40679 if(this.fireEvent("specialkey", this, e)){
40680 this.onViewClick(false);
40688 doRelay : function(foo, bar, hname){
40689 if(hname == 'down' || this.scope.isExpanded()){
40690 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
40698 this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
40702 initNumberEvent : function(e)
40704 this.inputEl().on("keydown" , this.fireKey, this);
40705 this.inputEl().on("focus", this.onFocus, this);
40706 this.inputEl().on("blur", this.onBlur, this);
40708 this.inputEl().relayEvent('keyup', this);
40710 if(this.indicator){
40711 this.indicator.addClass('invisible');
40714 this.originalValue = this.getValue();
40716 if(this.validationEvent == 'keyup'){
40717 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
40718 this.inputEl().on('keyup', this.filterValidation, this);
40720 else if(this.validationEvent !== false){
40721 this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
40724 if(this.selectOnFocus){
40725 this.on("focus", this.preFocus, this);
40728 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
40729 this.inputEl().on("keypress", this.filterKeys, this);
40731 this.inputEl().relayEvent('keypress', this);
40734 var allowed = "0123456789";
40736 if(this.allowDecimals){
40737 allowed += this.decimalSeparator;
40740 if(this.allowNegative){
40744 if(this.thousandsDelimiter) {
40748 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
40750 var keyPress = function(e){
40752 var k = e.getKey();
40754 var c = e.getCharCode();
40757 (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
40758 allowed.indexOf(String.fromCharCode(c)) === -1
40764 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
40768 if(allowed.indexOf(String.fromCharCode(c)) === -1){
40773 this.inputEl().on("keypress", keyPress, this);
40777 onTriggerClick : function(e)
40784 this.loadNext = false;
40786 if(this.isExpanded()){
40791 this.hasFocus = true;
40793 if(this.triggerAction == 'all') {
40794 this.doQuery(this.allQuery, true);
40798 this.doQuery(this.getRawValue());
40801 getCurrency : function()
40803 var v = this.currencyEl().getValue();
40808 restrictHeight : function()
40810 this.list.alignTo(this.currencyEl(), this.listAlign);
40811 this.list.alignTo(this.currencyEl(), this.listAlign);
40814 onViewClick : function(view, doFocus, el, e)
40816 var index = this.view.getSelectedIndexes()[0];
40818 var r = this.store.getAt(index);
40821 this.onSelect(r, index);
40825 onSelect : function(record, index){
40827 if(this.fireEvent('beforeselect', this, record, index) !== false){
40829 this.setFromCurrencyData(index > -1 ? record.data : false);
40833 this.fireEvent('select', this, record, index);
40837 setFromCurrencyData : function(o)
40841 this.lastCurrency = o;
40843 if (this.currencyField) {
40844 currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
40846 Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
40849 this.lastSelectionText = currency;
40851 //setting default currency
40852 if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
40853 this.setCurrency(this.defaultCurrency);
40857 this.setCurrency(currency);
40860 setFromData : function(o)
40864 c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
40866 this.setFromCurrencyData(c);
40871 value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
40873 Roo.log('no value set for '+ (this.name ? this.name : this.id));
40876 this.setValue(value);
40880 setCurrency : function(v)
40882 this.currencyValue = v;
40885 this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
40890 setValue : function(v)
40892 v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
40898 this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
40900 this.inputEl().dom.value = (v == '') ? '' :
40901 Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
40903 if(!this.allowZero && v === '0') {
40904 this.hiddenEl().dom.value = '';
40905 this.inputEl().dom.value = '';
40912 getRawValue : function()
40914 var v = this.inputEl().getValue();
40919 getValue : function()
40921 return this.fixPrecision(this.parseValue(this.getRawValue()));
40924 parseValue : function(value)
40926 if(this.thousandsDelimiter) {
40928 r = new RegExp(",", "g");
40929 value = value.replace(r, "");
40932 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
40933 return isNaN(value) ? '' : value;
40937 fixPrecision : function(value)
40939 if(this.thousandsDelimiter) {
40941 r = new RegExp(",", "g");
40942 value = value.replace(r, "");
40945 var nan = isNaN(value);
40947 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
40948 return nan ? '' : value;
40950 return parseFloat(value).toFixed(this.decimalPrecision);
40953 decimalPrecisionFcn : function(v)
40955 return Math.floor(v);
40958 validateValue : function(value)
40960 if(!Roo.bootstrap.MoneyField.superclass.validateValue.call(this, value)){
40964 var num = this.parseValue(value);
40967 this.markInvalid(String.format(this.nanText, value));
40971 if(num < this.minValue){
40972 this.markInvalid(String.format(this.minText, this.minValue));
40976 if(num > this.maxValue){
40977 this.markInvalid(String.format(this.maxText, this.maxValue));
40984 validate : function()
40986 if(this.disabled || this.allowBlank){
40991 var currency = this.getCurrency();
40993 if(this.validateValue(this.getRawValue()) && currency.length){
40998 this.markInvalid();
41002 getName: function()
41007 beforeBlur : function()
41013 var v = this.parseValue(this.getRawValue());
41020 onBlur : function()
41024 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
41025 //this.el.removeClass(this.focusClass);
41028 this.hasFocus = false;
41030 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
41034 var v = this.getValue();
41036 if(String(v) !== String(this.startValue)){
41037 this.fireEvent('change', this, v, this.startValue);
41040 this.fireEvent("blur", this);
41043 inputEl : function()
41045 return this.el.select('.roo-money-amount-input', true).first();
41048 currencyEl : function()
41050 return this.el.select('.roo-money-currency-input', true).first();
41053 hiddenEl : function()
41055 return this.el.select('input.hidden-number-input',true).first();