2009-07-03 12:38:21 +00:00
// Adminer specific functions
2009-12-17 14:53:26 +00:00
/ * * L o a d s y n t a x h i g h l i g h t i n g
2010-04-21 12:01:32 +00:00
* @ param string first three characters of database system version
2009-12-17 14:53:26 +00:00
* /
2011-02-15 17:11:24 +00:00
function bodyLoad ( version ) {
2013-12-19 20:34:15 +00:00
if ( window . jush ) {
jush . create _links = ' target="_blank" rel="noreferrer"' ;
2014-01-30 17:06:58 +00:00
if ( version ) {
for ( var key in jush . urls ) {
var obj = jush . urls ;
if ( typeof obj [ key ] != 'string' ) {
obj = obj [ key ] ;
key = 0 ;
}
obj [ key ] = obj [ key ]
. replace ( /\/doc\/mysql/ , '/doc/refman/' + version ) // MySQL
. replace ( /\/docs\/current/ , '/docs/' + version ) // PostgreSQL
;
2010-05-02 21:37:05 +00:00
}
2013-12-19 20:34:15 +00:00
}
if ( window . jushLinks ) {
jush . custom _links = jushLinks ;
}
jush . highlight _tag ( 'code' , 0 ) ;
2018-01-11 12:42:45 +00:00
var tags = qsa ( 'textarea' , document ) ;
2013-12-19 20:34:15 +00:00
for ( var i = 0 ; i < tags . length ; i ++ ) {
if ( /(^|\s)jush-/ . test ( tags [ i ] . className ) ) {
var pre = jush . textarea ( tags [ i ] ) ;
if ( pre ) {
setupSubmitHighlightInput ( pre ) ;
}
2011-03-28 10:41:02 +00:00
}
2013-12-19 20:34:15 +00:00
}
2011-03-28 10:41:02 +00:00
}
2009-07-11 19:45:57 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * G e t v a l u e o f d y n a m i c a l l y c r e a t e d f o r m f i e l d
* @ param HTMLFormElement
* @ param string
* @ return HTMLElement
* /
2009-12-17 13:22:28 +00:00
function formField ( form , name ) {
2010-10-19 11:28:43 +00:00
// required in IE < 8, form.elements[name] doesn't work
2009-09-11 17:08:18 +00:00
for ( var i = 0 ; i < form . length ; i ++ ) {
if ( form [ i ] . name == name ) {
return form [ i ] ;
}
}
}
2009-12-17 14:53:26 +00:00
/ * * T r y t o c h a n g e i n p u t t y p e t o p a s s w o r d o r t o t e x t
* @ param HTMLInputElement
* @ param boolean
* /
2009-12-17 13:22:28 +00:00
function typePassword ( el , disable ) {
2009-09-11 17:08:18 +00:00
try {
el . type = ( disable ? 'text' : 'password' ) ;
} catch ( e ) {
}
}
2013-04-04 17:35:15 +00:00
var dbCtrl ;
2013-06-25 16:58:08 +00:00
var dbPrevious = { } ;
2013-04-04 17:35:15 +00:00
/ * * C h e c k i f d a t a b a s e s h o u l d b e o p e n e d t o a n e w w i n d o w
* @ param MouseEvent
2018-01-11 16:00:39 +00:00
* @ this HTMLSelectElement
2013-04-04 17:35:15 +00:00
* /
2018-01-11 16:00:39 +00:00
function dbMouseDown ( event ) {
2013-04-04 17:35:15 +00:00
dbCtrl = isCtrl ( event ) ;
2018-01-11 16:00:39 +00:00
if ( dbPrevious [ this . name ] == undefined ) {
dbPrevious [ this . name ] = this . value ;
2013-04-04 17:35:15 +00:00
}
}
/ * * L o a d d a t a b a s e a f t e r s e l e c t i n g i t
2018-01-11 16:00:39 +00:00
* @ this HTMLSelectElement
2013-04-04 17:35:15 +00:00
* /
2018-01-11 16:00:39 +00:00
function dbChange ( ) {
2013-04-04 17:35:15 +00:00
if ( dbCtrl ) {
2018-01-11 16:00:39 +00:00
this . form . target = '_blank' ;
2013-04-04 17:35:15 +00:00
}
2018-01-11 16:00:39 +00:00
this . form . submit ( ) ;
this . form . target = '' ;
if ( dbCtrl && dbPrevious [ this . name ] != undefined ) {
this . value = dbPrevious [ this . name ] ;
dbPrevious [ this . name ] = undefined ;
2013-04-04 17:35:15 +00:00
}
}
2012-08-05 05:52:50 +00:00
/ * * C h e c k w h e t h e r t h e q u e r y w i l l b e e x e c u t e d w i t h i n d e x
2018-01-12 11:50:09 +00:00
* @ this HTMLElement
2012-08-05 05:52:50 +00:00
* /
2018-01-12 11:50:09 +00:00
function selectFieldChange ( ) {
var form = this . form ;
2012-08-05 05:52:50 +00:00
var ok = ( function ( ) {
2018-01-11 12:42:45 +00:00
var inputs = qsa ( 'input' , form ) ;
2012-08-05 05:52:50 +00:00
for ( var i = 0 ; i < inputs . length ; i ++ ) {
if ( inputs [ i ] . value && /^fulltext/ . test ( inputs [ i ] . name ) ) {
return true ;
}
}
var ok = form . limit . value ;
2018-01-11 12:42:45 +00:00
var selects = qsa ( 'select' , form ) ;
2012-08-05 05:52:50 +00:00
var group = false ;
var columns = { } ;
for ( var i = 0 ; i < selects . length ; i ++ ) {
var select = selects [ i ] ;
var col = selectValue ( select ) ;
var match = /^(where.+)col\]/ . exec ( select . name ) ;
if ( match ) {
var op = selectValue ( form [ match [ 1 ] + 'op]' ] ) ;
var val = form [ match [ 1 ] + 'val]' ] . value ;
if ( col in indexColumns && ( ! /LIKE|REGEXP/ . test ( op ) || ( op == 'LIKE' && val . charAt ( 0 ) != '%' ) ) ) {
return true ;
} else if ( col || val ) {
ok = false ;
}
}
if ( ( match = /^(columns.+)fun\]/ . exec ( select . name ) ) ) {
if ( /^(avg|count|count distinct|group_concat|max|min|sum)$/ . test ( col ) ) {
group = true ;
}
var val = selectValue ( form [ match [ 1 ] + 'col]' ] ) ;
if ( val ) {
columns [ col && col != 'count' ? '' : val ] = 1 ;
}
}
if ( col && /^order/ . test ( select . name ) ) {
if ( ! ( col in indexColumns ) ) {
2013-07-13 18:23:43 +00:00
ok = false ;
2012-08-05 05:52:50 +00:00
}
break ;
}
}
if ( group ) {
for ( var col in columns ) {
if ( ! ( col in indexColumns ) ) {
ok = false ;
}
}
}
return ok ;
} ) ( ) ;
setHtml ( 'noindex' , ( ok ? '' : '!' ) ) ;
}
2009-12-17 13:22:28 +00:00
var added = '.' , rowCount ;
2009-07-03 12:38:21 +00:00
2011-03-14 13:17:28 +00:00
/ * * C h e c k i f v a l i s e q u a l t o a - d e l i m i t e r - b w h e r e d e l i m i t e r i s ' _ ' , ' ' o r b i g l e t t e r
2009-12-17 14:53:26 +00:00
* @ param string
2011-03-14 13:17:28 +00:00
* @ param string
* @ param string
* @ return boolean
2009-12-17 14:53:26 +00:00
* /
2011-03-14 13:17:28 +00:00
function delimiterEqual ( val , a , b ) {
return ( val == a + '_' + b || val == a + b || val == a + b . charAt ( 0 ) . toUpperCase ( ) + b . substr ( 1 ) ) ;
2009-07-03 12:38:21 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * E s c a p e s t r i n g t o u s e a s i d e n t i f i e r
* @ param string
* @ return string
* /
2009-12-17 13:22:28 +00:00
function idfEscape ( s ) {
2010-05-20 20:06:34 +00:00
return s . replace ( /`/ , '``' ) ;
2009-07-03 12:38:21 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * D e t e c t f o r e i g n k e y
2018-01-11 16:00:39 +00:00
* @ this HTMLInputElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function editingNameChange ( ) {
var name = this . name . substr ( 0 , this . name . length - 7 ) ;
var type = formField ( this . form , name + '[type]' ) ;
2009-07-03 12:38:21 +00:00
var opts = type . options ;
var candidate ; // don't select anything with ambiguous match (like column `id`)
2018-01-11 16:00:39 +00:00
var val = this . value ;
2009-07-03 12:38:21 +00:00
for ( var i = opts . length ; i -- ; ) {
2011-03-14 13:17:28 +00:00
var match = /(.+)`(.+)/ . exec ( opts [ i ] . value ) ;
if ( ! match ) { // common type
if ( candidate && i == opts . length - 2 && val == opts [ candidate ] . value . replace ( /.+`/ , '' ) && name == 'fields[1]' ) { // single target table, link to column, first field - probably `id`
return ;
2009-07-03 12:38:21 +00:00
}
break ;
}
2011-03-14 13:17:28 +00:00
var table = match [ 1 ] ;
var column = match [ 2 ] ;
var tables = [ table , table . replace ( /s$/ , '' ) , table . replace ( /es$/ , '' ) ] ;
for ( var j = 0 ; j < tables . length ; j ++ ) {
table = tables [ j ] ;
if ( val == column || val == table || delimiterEqual ( val , table , column ) || delimiterEqual ( val , column , table ) ) {
if ( candidate ) {
return ;
}
candidate = i ;
break ;
2009-07-03 12:38:21 +00:00
}
}
}
if ( candidate ) {
2009-09-11 17:08:18 +00:00
type . selectedIndex = candidate ;
2009-07-03 12:38:21 +00:00
type . onchange ( ) ;
}
}
2009-12-17 14:53:26 +00:00
/ * * A d d t a b l e r o w f o r n e x t f i e l d
* @ param boolean
* @ return boolean
2018-01-11 16:00:39 +00:00
* @ this HTMLInputElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function editingAddRow ( focus ) {
var match = /(\d+)(\.\d+)?/ . exec ( this . name ) ;
2009-07-03 12:38:21 +00:00
var x = match [ 0 ] + ( match [ 2 ] ? added . substr ( match [ 2 ] . length ) : added ) + '1' ;
2018-01-11 16:00:39 +00:00
var row = parentTag ( this , 'tr' ) ;
2013-05-05 00:02:59 +00:00
var row2 = cloneNode ( row ) ;
2018-01-11 12:42:45 +00:00
var tags = qsa ( 'select' , row ) ;
var tags2 = qsa ( 'select' , row2 ) ;
2009-07-03 12:38:21 +00:00
for ( var i = 0 ; i < tags . length ; i ++ ) {
2013-06-03 15:56:18 +00:00
tags2 [ i ] . name = tags [ i ] . name . replace ( /[0-9.]+/ , x ) ;
2009-07-03 12:38:21 +00:00
tags2 [ i ] . selectedIndex = tags [ i ] . selectedIndex ;
}
2018-01-11 12:42:45 +00:00
tags = qsa ( 'input' , row ) ;
tags2 = qsa ( 'input' , row2 ) ;
2009-09-25 09:52:24 +00:00
var input = tags2 [ 0 ] ; // IE loose tags2 after insertBefore()
2009-07-03 12:38:21 +00:00
for ( var i = 0 ; i < tags . length ; i ++ ) {
if ( tags [ i ] . name == 'auto_increment_col' ) {
tags2 [ i ] . value = x ;
tags2 [ i ] . checked = false ;
}
tags2 [ i ] . name = tags [ i ] . name . replace ( /([0-9.]+)/ , x ) ;
2009-09-10 11:45:14 +00:00
if ( /\[(orig|field|comment|default)/ . test ( tags [ i ] . name ) ) {
2009-07-03 12:38:21 +00:00
tags2 [ i ] . value = '' ;
}
2009-09-10 11:45:14 +00:00
if ( /\[(has_default)/ . test ( tags [ i ] . name ) ) {
tags2 [ i ] . checked = false ;
}
2009-07-03 12:38:21 +00:00
}
2018-01-11 16:00:39 +00:00
tags [ 0 ] . onchange = editingNameChange ;
2013-07-10 16:02:31 +00:00
tags [ 0 ] . onkeyup = function ( ) {
2013-07-07 05:49:39 +00:00
} ;
2009-07-03 12:38:21 +00:00
row . parentNode . insertBefore ( row2 , row . nextSibling ) ;
2009-09-25 09:52:24 +00:00
if ( focus ) {
2018-01-11 16:00:39 +00:00
input . onchange = editingNameChange ;
2013-07-10 16:02:31 +00:00
input . onkeyup = function ( ) {
2013-07-07 05:49:39 +00:00
} ;
2009-09-25 09:52:24 +00:00
input . focus ( ) ;
}
2009-07-03 12:38:21 +00:00
added += '0' ;
2009-12-17 13:22:28 +00:00
rowCount ++ ;
2009-09-25 09:52:24 +00:00
return true ;
2009-07-03 12:38:21 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * R e m o v e t a b l e r o w f o r f i e l d
2013-07-07 06:35:26 +00:00
* @ param string
2018-01-12 15:06:00 +00:00
* @ return boolean false
2018-01-11 16:00:39 +00:00
* @ this HTMLInputElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function editingRemoveRow ( name ) {
var field = formField ( this . form , this . name . replace ( /[^\[]+(.+)/ , name ) ) ;
2009-07-03 12:38:21 +00:00
field . parentNode . removeChild ( field ) ;
2018-01-11 16:00:39 +00:00
parentTag ( this , 'tr' ) . style . display = 'none' ;
2018-01-12 15:06:00 +00:00
return false ;
2016-05-31 18:36:00 +00:00
}
/ * * M o v e t a b l e r o w f o r f i e l d
* @ param boolean direction to move row , true for up or false for down
* @ return boolean
2018-01-11 16:00:39 +00:00
* @ this HTMLInputElement
2016-05-31 18:36:00 +00:00
* /
2018-01-11 16:00:39 +00:00
function editingMoveRow ( dir ) {
var row = parentTag ( this , 'tr' ) ;
2016-05-31 18:36:00 +00:00
if ( ! ( 'nextElementSibling' in row ) ) {
return false ;
}
row . parentNode . insertBefore ( row , dir
? row . previousElementSibling
: row . nextElementSibling ? row . nextElementSibling . nextElementSibling : row . parentNode . firstChild ) ;
return true ;
2009-07-03 12:38:21 +00:00
}
2009-12-17 13:22:28 +00:00
var lastType = '' ;
2009-12-17 14:53:26 +00:00
/ * * C l e a r l e n g t h a n d h i d e c o l l a t i o n o r u n s i g n e d
* @ param HTMLSelectElement
* /
2009-12-17 13:22:28 +00:00
function editingTypeChange ( type ) {
2009-07-03 12:38:21 +00:00
var name = type . name . substr ( 0 , type . name . length - 6 ) ;
2009-12-17 13:22:28 +00:00
var text = selectValue ( type ) ;
2009-07-03 12:38:21 +00:00
for ( var i = 0 ; i < type . form . elements . length ; i ++ ) {
var el = type . form . elements [ i ] ;
2013-07-08 16:59:43 +00:00
if ( el . name == name + '[length]' ) {
if ( ! (
( /(char|binary)$/ . test ( lastType ) && /(char|binary)$/ . test ( text ) )
|| ( /(enum|set)$/ . test ( lastType ) && /(enum|set)$/ . test ( text ) )
) ) {
el . value = '' ;
}
2013-07-10 20:13:36 +00:00
el . onchange . apply ( el ) ;
2009-12-17 12:54:17 +00:00
}
2010-04-02 13:44:23 +00:00
if ( lastType == 'timestamp' && el . name == name + '[has_default]' && /timestamp/i . test ( formField ( type . form , name + '[default]' ) . value ) ) {
el . checked = false ;
}
2009-07-03 12:38:21 +00:00
if ( el . name == name + '[collation]' ) {
2013-07-11 01:24:36 +00:00
alterClass ( el , 'hidden' , ! /(char|text|enum|set)$/ . test ( text ) ) ;
2009-07-03 12:38:21 +00:00
}
if ( el . name == name + '[unsigned]' ) {
2013-07-11 01:24:36 +00:00
alterClass ( el , 'hidden' , ! /((^|[^o])int|float|double|decimal)$/ . test ( text ) ) ;
2009-07-03 12:38:21 +00:00
}
2013-04-17 16:41:58 +00:00
if ( el . name == name + '[on_update]' ) {
2014-03-15 21:08:34 +00:00
alterClass ( el , 'hidden' , ! /timestamp|datetime/ . test ( text ) ) ; // MySQL supports datetime since 5.6.5
2013-04-17 16:41:58 +00:00
}
2010-05-20 20:06:34 +00:00
if ( el . name == name + '[on_delete]' ) {
2013-07-11 01:24:36 +00:00
alterClass ( el , 'hidden' , ! /`/ . test ( text ) ) ;
2010-05-20 20:06:34 +00:00
}
2009-07-03 12:38:21 +00:00
}
2013-07-23 01:03:30 +00:00
helpClose ( ) ;
2009-07-03 12:38:21 +00:00
}
2013-07-10 20:13:36 +00:00
/ * * M a r k l e n g t h a s r e q u i r e d
2018-01-11 16:00:39 +00:00
* @ this HTMLInputElement
2013-07-10 20:13:36 +00:00
* /
2018-01-11 16:00:39 +00:00
function editingLengthChange ( ) {
alterClass ( this , 'required' , ! this . value . length && /var(char|binary)$/ . test ( selectValue ( this . parentNode . previousSibling . firstChild ) ) ) ;
2013-07-10 20:13:36 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * E d i t e n u m o r s e t
2018-01-11 16:00:39 +00:00
* @ this HTMLInputElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function editingLengthFocus ( ) {
var td = this . parentNode ;
2009-12-17 13:30:23 +00:00
if ( /(enum|set)$/ . test ( selectValue ( td . previousSibling . firstChild ) ) ) {
2018-01-11 10:55:17 +00:00
var edit = qs ( '#enum-edit' ) ;
2018-01-11 16:00:39 +00:00
var val = this . value ;
2013-12-21 02:02:56 +00:00
edit . value = ( /^'.+'$/ . test ( val ) ? val . substr ( 1 , val . length - 2 ) . replace ( /','/g , "\n" ) . replace ( /''/g , "'" ) : val ) ; //! doesn't handle 'a'',''b' correctly
2009-10-19 05:11:45 +00:00
td . appendChild ( edit ) ;
2018-01-11 16:00:39 +00:00
this . style . display = 'none' ;
2009-10-19 05:11:45 +00:00
edit . style . display = 'inline' ;
edit . focus ( ) ;
}
}
2009-12-17 14:53:26 +00:00
/ * * F i n i s h e d i t i n g o f e n u m o r s e t
2018-01-11 16:00:39 +00:00
* @ this HTMLTextAreaElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function editingLengthBlur ( ) {
var field = this . parentNode . firstChild ;
var val = this . value ;
2013-12-21 02:02:56 +00:00
field . value = ( /^'[^\n]+'$/ . test ( val ) ? val : "'" + val . replace ( /\n+$/ , '' ) . replace ( /'/g , "''" ) . replace ( /\n/g , "','" ) + "'" ) ;
2009-10-19 05:11:45 +00:00
field . style . display = 'inline' ;
2018-01-11 16:00:39 +00:00
this . style . display = 'none' ;
2009-10-19 05:11:45 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * S h o w o r h i d e s e l e c t e d t a b l e c o l u m n
* @ param boolean
* @ param number
* /
2009-12-17 13:22:28 +00:00
function columnShow ( checked , column ) {
2018-01-11 12:42:45 +00:00
var trs = qsa ( 'tr' , qs ( '#edit-fields' ) ) ;
2009-07-03 12:38:21 +00:00
for ( var i = 0 ; i < trs . length ; i ++ ) {
2018-01-11 12:42:45 +00:00
alterClass ( qsa ( 'td' , trs [ i ] ) [ column ] , 'hidden' , ! checked ) ;
2009-07-03 12:38:21 +00:00
}
}
2012-09-22 19:24:16 +00:00
/ * * H i d e c o l u m n w i t h d e f a u l t v a l u e s i n n a r r o w w i n d o w
* /
function editingHideDefaults ( ) {
if ( innerWidth < document . documentElement . scrollWidth ) {
2018-01-11 10:55:17 +00:00
qs ( '#form' ) [ 'defaults' ] . checked = false ;
2012-09-22 19:24:16 +00:00
columnShow ( false , 5 ) ;
}
}
2009-12-17 14:53:26 +00:00
/ * * D i s p l a y p a r t i t i o n o p t i o n s
2018-01-11 16:00:39 +00:00
* @ this HTMLSelectElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function partitionByChange ( ) {
var partitionTable = /RANGE|LIST/ . test ( selectValue ( this ) ) ;
alterClass ( this . form [ 'partitions' ] , 'hidden' , partitionTable || ! this . selectedIndex ) ;
2018-01-11 10:55:17 +00:00
alterClass ( qs ( '#partition-table' ) , 'hidden' , ! partitionTable ) ;
2013-07-19 19:37:12 +00:00
helpClose ( ) ;
2009-07-03 12:38:21 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * A d d n e x t p a r t i t i o n r o w
2018-01-11 16:00:39 +00:00
* @ this HTMLInputElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function partitionNameChange ( ) {
var row = cloneNode ( parentTag ( this , 'tr' ) ) ;
2009-07-03 12:38:21 +00:00
row . firstChild . firstChild . value = '' ;
2018-01-11 16:00:39 +00:00
parentTag ( this , 'table' ) . appendChild ( row ) ;
this . onchange = function ( ) { } ;
2009-07-03 12:38:21 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * A d d r o w f o r f o r e i g n k e y
2018-01-11 16:00:39 +00:00
* @ this HTMLSelectElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function foreignAddRow ( ) {
this . onchange = function ( ) { } ;
var row = cloneNode ( parentTag ( this , 'tr' ) ) ;
2018-01-11 12:42:45 +00:00
var selects = qsa ( 'select' , row ) ;
2009-07-03 12:38:21 +00:00
for ( var i = 0 ; i < selects . length ; i ++ ) {
selects [ i ] . name = selects [ i ] . name . replace ( /\]/ , '1$&' ) ;
selects [ i ] . selectedIndex = 0 ;
}
2018-01-11 16:00:39 +00:00
parentTag ( this , 'table' ) . appendChild ( row ) ;
2009-07-03 12:38:21 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * A d d r o w f o r i n d e x e s
2018-01-11 16:00:39 +00:00
* @ this HTMLSelectElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function indexesAddRow ( ) {
this . onchange = function ( ) { } ;
var row = cloneNode ( parentTag ( this , 'tr' ) ) ;
2018-01-11 12:42:45 +00:00
var selects = qsa ( 'select' , row ) ;
2009-07-03 12:38:21 +00:00
for ( var i = 0 ; i < selects . length ; i ++ ) {
2010-10-22 22:02:24 +00:00
selects [ i ] . name = selects [ i ] . name . replace ( /indexes\[\d+/ , '$&1' ) ;
2009-07-03 12:38:21 +00:00
selects [ i ] . selectedIndex = 0 ;
}
2018-01-11 12:42:45 +00:00
var inputs = qsa ( 'input' , row ) ;
2011-07-13 13:13:00 +00:00
for ( var i = 0 ; i < inputs . length ; i ++ ) {
inputs [ i ] . name = inputs [ i ] . name . replace ( /indexes\[\d+/ , '$&1' ) ;
inputs [ i ] . value = '' ;
}
2018-01-11 16:00:39 +00:00
parentTag ( this , 'table' ) . appendChild ( row ) ;
2009-07-03 12:38:21 +00:00
}
2011-07-13 13:13:00 +00:00
/ * * C h a n g e c o l u m n i n i n d e x
* @ param string name prefix
2018-01-11 16:00:39 +00:00
* @ this HTMLSelectElement
2011-07-13 13:13:00 +00:00
* /
2018-01-11 16:00:39 +00:00
function indexesChangeColumn ( prefix ) {
2011-07-13 13:13:00 +00:00
var names = [ ] ;
2014-01-12 03:06:25 +00:00
for ( var tag in { 'select' : 1 , 'input' : 1 } ) {
2018-01-11 16:00:39 +00:00
var columns = qsa ( tag , parentTag ( this , 'td' ) ) ;
2014-01-12 03:06:25 +00:00
for ( var i = 0 ; i < columns . length ; i ++ ) {
if ( /\[columns\]/ . test ( columns [ i ] . name ) ) {
var value = selectValue ( columns [ i ] ) ;
if ( value ) {
names . push ( value ) ;
}
}
2011-07-13 13:13:00 +00:00
}
}
2018-01-11 16:00:39 +00:00
this . form [ this . name . replace ( /\].*/ , '][name]' ) ] . value = prefix + names . join ( '_' ) ;
2011-07-13 13:13:00 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * A d d c o l u m n f o r i n d e x
2011-07-13 13:13:00 +00:00
* @ param string name prefix
2018-01-11 16:00:39 +00:00
* @ this HTMLSelectElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function indexesAddColumn ( prefix ) {
var field = this ;
2011-04-09 14:36:22 +00:00
var select = field . form [ field . name . replace ( /\].*/ , '][type]' ) ] ;
if ( ! select . selectedIndex ) {
2013-07-07 06:59:02 +00:00
while ( selectValue ( select ) != "INDEX" && select . selectedIndex < select . options . length ) {
select . selectedIndex ++ ;
}
2011-04-09 14:36:22 +00:00
select . onchange ( ) ;
}
2013-05-05 00:02:59 +00:00
var column = cloneNode ( field . parentNode ) ;
2018-01-11 12:42:45 +00:00
var selects = qsa ( 'select' , column ) ;
2014-01-12 03:06:25 +00:00
for ( var i = 0 ; i < selects . length ; i ++ ) {
select = selects [ i ] ;
select . name = select . name . replace ( /\]\[\d+/ , '$&1' ) ;
select . selectedIndex = 0 ;
}
2018-01-12 11:42:30 +00:00
field . onchange = partial ( indexesChangeColumn , prefix ) ;
2018-01-11 12:42:45 +00:00
var inputs = qsa ( 'input' , column ) ;
2014-01-12 03:06:25 +00:00
for ( var i = 0 ; i < inputs . length ; i ++ ) {
var input = inputs [ i ] ;
input . name = input . name . replace ( /\]\[\d+/ , '$&1' ) ;
if ( input . type != 'checkbox' ) {
input . value = '' ;
}
}
2012-08-08 16:22:23 +00:00
parentTag ( field , 'td' ) . appendChild ( column ) ;
2011-07-13 13:13:00 +00:00
field . onchange ( ) ;
2009-07-03 12:38:21 +00:00
}
2014-03-15 17:58:24 +00:00
/ * * H a n d l e c h a n g i n g t r i g g e r t i m e o r e v e n t
* @ param RegExp
* @ param string
* @ param HTMLFormElement
* /
function triggerChange ( tableRe , table , form ) {
var formEvent = selectValue ( form [ 'Event' ] ) ;
if ( tableRe . test ( form [ 'Trigger' ] . value ) ) {
form [ 'Trigger' ] . value = table + '_' + ( selectValue ( form [ 'Timing' ] ) . charAt ( 0 ) + formEvent . charAt ( 0 ) ) . toLowerCase ( ) ;
}
alterClass ( form [ 'Of' ] , 'hidden' , formEvent != 'UPDATE OF' ) ;
}
2012-03-06 08:47:33 +00:00
var that , x , y ; // em and tablePos defined in schema.inc.php
2009-07-03 12:38:21 +00:00
2009-12-17 14:53:26 +00:00
/ * * G e t m o u s e p o s i t i o n
* @ param MouseEvent
2018-01-11 16:00:39 +00:00
* @ this HTMLElement
2009-12-17 14:53:26 +00:00
* /
2018-01-11 16:00:39 +00:00
function schemaMousedown ( event ) {
2012-03-06 16:24:33 +00:00
if ( ( event . which ? event . which : event . button ) == 1 ) {
2018-01-11 16:00:39 +00:00
that = this ;
x = event . clientX - this . offsetLeft ;
y = event . clientY - this . offsetTop ;
2012-03-06 16:24:33 +00:00
}
2009-07-03 12:38:21 +00:00
}
2009-12-17 14:53:26 +00:00
/ * * M o v e o b j e c t
* @ param MouseEvent
* /
2018-01-12 15:33:20 +00:00
function schemaMousemove ( event ) {
2009-07-03 12:38:21 +00:00
if ( that !== undefined ) {
2018-01-12 15:33:20 +00:00
var left = ( event . clientX - x ) / em ;
var top = ( event . clientY - y ) / em ;
2018-01-11 12:42:45 +00:00
var divs = qsa ( 'div' , that ) ;
2009-12-17 13:22:28 +00:00
var lineSet = { } ;
2009-07-03 12:38:21 +00:00
for ( var i = 0 ; i < divs . length ; i ++ ) {
if ( divs [ i ] . className == 'references' ) {
2018-01-12 15:38:40 +00:00
var div2 = qs ( '[id="' + ( /^refs/ . test ( divs [ i ] . id ) ? 'refd' : 'refs' ) + divs [ i ] . id . substr ( 4 ) + '"]' ) ;
2009-12-17 13:22:28 +00:00
var ref = ( tablePos [ divs [ i ] . title ] ? tablePos [ divs [ i ] . title ] : [ div2 . parentNode . offsetTop / em , 0 ] ) ;
2009-07-03 12:38:21 +00:00
var left1 = - 1 ;
var id = divs [ i ] . id . replace ( /^ref.(.+)-.+/ , '$1' ) ;
if ( divs [ i ] . parentNode != div2 . parentNode ) {
left1 = Math . min ( 0 , ref [ 1 ] - left ) - 1 ;
divs [ i ] . style . left = left1 + 'em' ;
2018-01-11 11:07:33 +00:00
divs [ i ] . querySelector ( 'div' ) . style . width = - left1 + 'em' ;
2009-07-03 12:38:21 +00:00
var left2 = Math . min ( 0 , left - ref [ 1 ] ) - 1 ;
div2 . style . left = left2 + 'em' ;
2018-01-11 11:07:33 +00:00
div2 . querySelector ( 'div' ) . style . width = - left2 + 'em' ;
2009-07-03 12:38:21 +00:00
}
2009-12-17 13:22:28 +00:00
if ( ! lineSet [ id ] ) {
2018-01-12 15:38:40 +00:00
var line = qs ( '[id="' + divs [ i ] . id . replace ( /^....(.+)-.+$/ , 'refl$1' ) + '"]' ) ;
2012-03-06 08:48:28 +00:00
var top1 = top + divs [ i ] . offsetTop / em ;
var top2 = top + div2 . offsetTop / em ;
2009-07-03 12:38:21 +00:00
if ( divs [ i ] . parentNode != div2 . parentNode ) {
2012-03-06 08:48:28 +00:00
top2 += ref [ 0 ] - top ;
2018-01-11 11:07:33 +00:00
line . querySelector ( 'div' ) . style . height = Math . abs ( top1 - top2 ) + 'em' ;
2009-07-03 12:38:21 +00:00
}
2012-03-06 08:48:28 +00:00
line . style . left = ( left + left1 ) + 'em' ;
line . style . top = Math . min ( top1 , top2 ) + 'em' ;
2009-12-17 13:22:28 +00:00
lineSet [ id ] = true ;
2009-07-03 12:38:21 +00:00
}
}
}
that . style . left = left + 'em' ;
that . style . top = top + 'em' ;
}
}
2009-12-17 14:53:26 +00:00
/ * * F i n i s h m o v e
* @ param MouseEvent
2011-02-08 19:58:31 +00:00
* @ param string
2009-12-17 14:53:26 +00:00
* /
2018-01-12 15:33:20 +00:00
function schemaMouseup ( event , db ) {
2009-07-03 12:38:21 +00:00
if ( that !== undefined ) {
2018-01-12 15:33:20 +00:00
tablePos [ that . firstChild . firstChild . firstChild . data ] = [ ( event . clientY - y ) / em , ( event . clientX - x ) / em ] ;
2009-07-03 12:38:21 +00:00
that = undefined ;
var s = '' ;
2009-12-17 13:22:28 +00:00
for ( var key in tablePos ) {
s += '_' + key + ':' + Math . round ( tablePos [ key ] [ 0 ] * 10000 ) / 10000 + 'x' + Math . round ( tablePos [ key ] [ 1 ] * 10000 ) / 10000 ;
2009-07-03 12:38:21 +00:00
}
2010-12-29 17:08:34 +00:00
s = encodeURIComponent ( s . substr ( 1 ) ) ;
2018-01-11 10:55:17 +00:00
var link = qs ( '#schema-link' ) ;
2010-12-29 17:08:34 +00:00
link . href = link . href . replace ( /[^=]+$/ , '' ) + s ;
2011-02-08 19:58:31 +00:00
cookie ( 'adminer_schema-' + db + '=' + s , 30 ) ; //! special chars in db
2009-07-03 12:38:21 +00:00
}
}
2013-07-19 17:35:31 +00:00
2014-03-15 17:58:24 +00:00
2013-07-19 20:04:14 +00:00
var helpOpen , helpIgnore ; // when mouse outs <option> then it mouse overs border of <select> - ignore it
2013-07-19 17:35:31 +00:00
2013-07-19 18:55:49 +00:00
/ * * D i s p l a y h e l p
2013-07-19 20:04:14 +00:00
* @ param MouseEvent
2013-07-19 18:55:49 +00:00
* @ param string
* @ param bool display on left side ( otherwise on top )
2018-01-11 16:00:39 +00:00
* @ this HTMLElement
2013-07-19 18:55:49 +00:00
* /
2018-01-11 16:00:39 +00:00
function helpMouseover ( event , text , side ) {
2013-07-19 20:04:14 +00:00
var target = getTarget ( event ) ;
2013-07-19 18:55:49 +00:00
if ( ! text ) {
helpClose ( ) ;
2018-01-11 16:00:39 +00:00
} else if ( window . jush && ( ! helpIgnore || this != target ) ) {
2013-07-19 17:35:31 +00:00
helpOpen = 1 ;
2018-01-11 10:55:17 +00:00
var help = qs ( '#help' ) ;
2013-07-19 17:35:31 +00:00
help . innerHTML = text ;
jush . highlight _tag ( [ help ] ) ;
alterClass ( help , 'hidden' ) ;
2013-07-19 23:24:59 +00:00
var rect = target . getBoundingClientRect ( ) ;
2014-02-21 17:54:04 +00:00
var body = document . documentElement ;
help . style . top = ( body . scrollTop + rect . top - ( side ? ( help . offsetHeight - target . offsetHeight ) / 2 : help . offsetHeight ) ) + 'px' ;
help . style . left = ( body . scrollLeft + rect . left - ( side ? help . offsetWidth : ( help . offsetWidth - target . offsetWidth ) / 2 ) ) + 'px' ;
2013-07-19 17:35:31 +00:00
}
}
2013-07-19 18:55:49 +00:00
/ * * C l o s e h e l p a f t e r t i m e o u t
2013-07-19 20:04:14 +00:00
* @ param MouseEvent
2018-01-11 16:00:39 +00:00
* @ this HTMLElement
2013-07-19 18:55:49 +00:00
* /
2018-01-11 16:00:39 +00:00
function helpMouseout ( event ) {
2013-07-19 17:35:31 +00:00
helpOpen = 0 ;
2018-01-11 16:00:39 +00:00
helpIgnore = ( this != getTarget ( event ) ) ;
2013-07-19 17:35:31 +00:00
setTimeout ( function ( ) {
if ( ! helpOpen ) {
helpClose ( ) ;
}
} , 200 ) ;
}
2013-07-19 18:55:49 +00:00
/ * * C l o s e h e l p
* /
2013-07-19 17:35:31 +00:00
function helpClose ( ) {
2018-01-11 10:55:17 +00:00
alterClass ( qs ( '#help' ) , 'hidden' , true ) ;
2013-07-19 17:35:31 +00:00
}