2012-05-07 12:30:57 +00:00
/ *
* lib / js / legacy / widgets / form / fields . js
* /
var no _value _fields = [ 'Section Break' , 'Column Break' , 'HTML' , 'Table' , 'FlexTable' , 'Button' , 'Image' ] ; var codeid = 0 ; var code _editors = { } ; function Field ( ) { this . with _label = 1 ; }
Field . prototype . make _body = function ( ) { var ischk = ( this . df . fieldtype == 'Check' ? 1 : 0 ) ; if ( this . parent )
this . wrapper = $a ( this . parent , ( this . with _label ? 'div' : 'span' ) ) ; else
this . wrapper = document . createElement ( ( this . with _label ? 'div' : 'span' ) ) ; this . label _area = $a ( this . wrapper , 'div' , '' , { margin : '0px 0px 2px 0px' } ) ; if ( ischk && ! this . in _grid ) { this . input _area = $a ( this . label _area , 'span' , '' , { marginRight : '4px' } ) ; this . disp _area = $a ( this . label _area , 'span' , '' , { marginRight : '4px' } ) ; }
if ( this . with _label ) { this . label _span = $a ( this . label _area , 'span' , 'small' )
this . label _icon = $a ( this . label _area , 'img' , '' , { margin : '-3px 4px -3px 4px' } ) ; $dh ( this . label _icon ) ; this . label _icon . src = 'images/lib/icons/error.gif' ; this . label _icon . title = 'Mandatory value needs to be entered' ; this . suggest _icon = $a ( this . label _area , 'img' , '' , { margin : '-3px 4px -3px 0px' } ) ; $dh ( this . suggest _icon ) ; this . suggest _icon . src = 'images/lib/icons/bullet_arrow_down.png' ; this . suggest _icon . title = 'With suggestions' ; } else { this . label _span = $a ( this . label _area , 'span' , '' , { marginRight : '4px' } )
$dh ( this . label _area ) ; }
if ( ! this . input _area ) { this . input _area = $a ( this . wrapper , ( this . with _label ? 'div' : 'span' ) ) ; this . disp _area = $a ( this . wrapper , ( this . with _label ? 'div' : 'span' ) ) ; }
if ( this . in _grid ) { if ( this . label _area ) $dh ( this . label _area ) ; } else { this . input _area . className = 'input_area' ; $y ( this . wrapper , { marginBottom : '9px' } ) ; this . set _description ( ) ; }
if ( this . onmake ) this . onmake ( ) ; }
Field . prototype . set _max _width = function ( ) { var no _max = [ 'Code' , 'Text Editor' , 'Text' , 'Table' , 'HTML' ]
if ( this . wrapper && this . layout _cell && this . layout _cell . parentNode . cells && this . layout _cell . parentNode . cells . length == 1 && ! in _list ( no _max , this . df . fieldtype ) ) { $y ( this . wrapper , { paddingRight : '50%' } ) ; } }
Field . prototype . set _label = function ( ) { if ( this . with _label && this . label _area && this . label != this . df . label ) { this . label _span . innerHTML = this . df . label ; this . label = this . df . label ; } }
Field . prototype . set _description = function ( ) { if ( this . df . description ) { var p = in _list ( [ 'Text Editor' , 'Code' , 'Check' ] , this . df . fieldtype ) ? this . label _area : this . wrapper ; this . desc _area = $a ( p , 'div' , 'help small' , '' , this . df . description )
if ( in _list ( [ 'Text Editor' , 'Code' ] , this . df . fieldtype ) )
$ ( this . desc _area ) . addClass ( 'help small' ) ; } }
Field . prototype . get _status = function ( ) { if ( this . in _filter ) this . not _in _form = this . in _filter ; if ( this . not _in _form ) { return 'Write' ; }
if ( ! this . df . permlevel ) this . df . permlevel = 0 ; var p = this . perm [ this . df . permlevel ] ; var ret ; if ( cur _frm . editable && p && p [ WRITE ] ) ret = 'Write' ; else if ( p && p [ READ ] ) ret = 'Read' ; else ret = 'None' ; if ( this . df . fieldtype == 'Binary' )
ret = 'None' ; if ( cint ( this . df . hidden ) )
ret = 'None' ; if ( ret == 'Write' && cint ( cur _frm . doc . docstatus ) > 0 ) ret = 'Read' ; var a _o _s = cint ( this . df . allow _on _submit ) ; if ( a _o _s && ( this . in _grid || ( this . frm && this . frm . not _in _container ) ) ) { a _o _s = null ; if ( this . in _grid ) a _o _s = this . grid . field . df . allow _on _submit ; if ( this . frm && this . frm . not _in _container ) { a _o _s = cur _grid . field . df . allow _on _submit ; } }
if ( cur _frm . editable && a _o _s && cint ( cur _frm . doc . docstatus ) > 0 && ! this . df . hidden ) { tmp _perm = get _perm ( cur _frm . doctype , cur _frm . docname , 1 ) ; if ( tmp _perm [ this . df . permlevel ] && tmp _perm [ this . df . permlevel ] [ WRITE ] ) ret = 'Write' ; }
return ret ; }
Field . prototype . set _style _mandatory = function ( add ) { if ( add ) { $ ( this . txt ? this . txt : this . input ) . addClass ( 'input-mandatory' ) ; if ( this . disp _area ) $ ( this . disp _area ) . addClass ( 'input-mandatory' ) ; } else { $ ( this . txt ? this . txt : this . input ) . removeClass ( 'input-mandatory' ) ; if ( this . disp _area ) $ ( this . disp _area ) . removeClass ( 'input-mandatory' ) ; } }
Field . prototype . refresh _mandatory = function ( ) { if ( this . in _filter ) return ; if ( this . df . reqd ) { if ( this . label _area ) this . label _area . style . color = "#d22" ; this . set _style _mandatory ( 1 ) ; } else { if ( this . label _area ) this . label _area . style . color = "#222" ; this . set _style _mandatory ( 0 ) ; }
this . refresh _label _icon ( )
this . set _reqd = this . df . reqd ; }
Field . prototype . refresh _display = function ( ) { if ( ! this . current _status || this . current _status != this . disp _status ) { if ( this . disp _status == 'Write' ) { if ( this . make _input && ( ! this . input ) ) { this . make _input ( ) ; if ( this . onmake _input ) this . onmake _input ( ) ; }
if ( this . show ) this . show ( )
else { $ds ( this . wrapper ) ; }
if ( this . input ) { $ds ( this . input _area ) ; $dh ( this . disp _area ) ; if ( this . input . refresh ) this . input . refresh ( ) ; } else { $dh ( this . input _area ) ; $ds ( this . disp _area ) ; } } else if ( this . disp _status == 'Read' ) { if ( this . show ) this . show ( )
else { $ds ( this . wrapper ) ; }
$dh ( this . input _area ) ; $ds ( this . disp _area ) ; } else { if ( this . hide ) this . hide ( ) ; else $dh ( this . wrapper ) ; }
this . current _status = this . disp _status ; } }
Field . prototype . refresh = function ( ) { this . disp _status = this . get _status ( ) ; if ( this . in _grid && this . table _refresh && this . disp _status == 'Write' )
{ this . table _refresh ( ) ; return ; }
this . set _label ( ) ; this . refresh _display ( ) ; if ( this . onrefresh )
this . onrefresh ( ) ; if ( this . input ) { if ( this . input . refresh ) this . input . refresh ( this . df ) ; }
if ( this . wrapper ) { this . wrapper . fieldobj = this ; $ ( this . wrapper ) . trigger ( 'refresh' ) ; }
if ( ! this . not _in _form )
this . set _input ( _f . get _value ( this . doctype , this . docname , this . df . fieldname ) ) ; this . refresh _mandatory ( ) ; this . set _max _width ( ) ; }
Field . prototype . refresh _label _icon = function ( ) { if ( this . df . reqd ) { if ( this . get _value && is _null ( this . get _value ( ) ) ) { if ( this . label _icon ) $ds ( this . label _icon ) ; $ ( this . txt ? this . txt : this . input ) . addClass ( 'field-to-update' ) } else { if ( this . label _icon ) $dh ( this . label _icon ) ; $ ( this . txt ? this . txt : this . input ) . removeClass ( 'field-to-update' ) } } }
Field . prototype . set = function ( val ) { if ( this . not _in _form )
return ; if ( ( ! this . docname ) && this . grid ) { this . docname = this . grid . add _newrow ( ) ; }
var set _val = val ; if ( this . validate ) set _val = this . validate ( val ) ; _f . set _value ( this . doctype , this . docname , this . df . fieldname , set _val ) ; this . value = val ; }
Field . prototype . set _input = function ( val ) { this . value = val ; if ( this . input && this . input . set _input ) { if ( val == null ) this . input . set _input ( '' ) ; else this . input . set _input ( val ) ; }
var disp _val = val ; if ( val == null ) disp _val = '' ; this . set _disp ( disp _val ) ; }
Field . prototype . run _trigger = function ( ) { this . refresh _label _icon ( ) ; if ( this . df . reqd && this . get _value && ! is _null ( this . get _value ( ) ) && this . set _as _error )
this . set _as _error ( 0 ) ; if ( this . not _in _form ) { return ; }
if ( cur _frm . cscript [ this . df . fieldname ] )
cur _frm . runclientscript ( this . df . fieldname , this . doctype , this . docname ) ; cur _frm . refresh _dependency ( ) ; }
Field . prototype . set _disp _html = function ( t ) { if ( this . disp _area ) { $ ( this . disp _area ) . addClass ( 'disp_area' ) ; this . disp _area . innerHTML = ( t == null ? '' : t ) ; if ( ! t ) $ ( this . disp _area ) . addClass ( 'disp_area_no_val' ) ; } }
Field . prototype . set _disp = function ( val ) { this . set _disp _html ( val ) ; }
Field . prototype . set _as _error = function ( set ) { if ( this . in _grid || this . in _filter ) return ; var w = this . txt ? this . txt : this . input ; if ( set ) { $y ( w , { border : '2px solid RED' } ) ; } else { $y ( w , { border : '1px solid #888' } ) ; } }
Field . prototype . activate = function ( docname ) { this . docname = docname ; this . refresh ( ) ; if ( this . input ) { var v = _f . get _value ( this . doctype , this . docname , this . df . fieldname ) ; this . last _value = v ; if ( this . input . onchange && this . input . get _value && this . input . get _value ( ) != v ) { if ( this . validate )
this . input . set _value ( this . validate ( v ) ) ; else
this . input . set _value ( ( v == null ) ? '' : v ) ; if ( this . format _input )
this . format _input ( ) ; }
if ( this . input . focus ) { try { this . input . focus ( ) ; } catch ( e ) { } } }
if ( this . txt ) { try { this . txt . focus ( ) ; } catch ( e ) { }
this . txt . field _object = this ; } }
function DataField ( ) { } DataField . prototype = new Field ( ) ; DataField . prototype . make _input = function ( ) { var me = this ; this . input = $a _input ( this . input _area , this . df . fieldtype == 'Password' ? 'password' : 'text' ) ; this . get _value = function ( ) { var v = this . input . value ; if ( this . validate )
v = this . validate ( v ) ; return v ; }
this . input . name = this . df . fieldname ; $ ( this . input ) . change ( function ( ) { me . set _value ( me . get _value && me . get _value ( ) || $ ( this . input ) . val ( ) ) ; } ) ; this . set _value = function ( val ) { if ( ! me . last _value ) me . last _value = '' ; if ( me . validate ) { val = me . validate ( val ) ; me . input . value = val == undefined ? '' : val ; }
me . set ( val ) ; if ( me . format _input )
me . format _input ( ) ; if ( in _list ( [ 'Currency' , 'Float' , 'Int' ] , me . df . fieldtype ) ) { if ( flt ( me . last _value ) == flt ( val ) ) { me . last _value = val ; return ; } }
me . last _value = val ; me . run _trigger ( ) ; }
this . input . set _input = function ( val ) { if ( val == null ) val = '' ; me . input . value = val ; if ( me . format _input ) me . format _input ( ) ; }
if ( this . df . options == 'Suggest' ) { if ( this . suggest _icon ) $di ( this . suggest _icon ) ; $ ( me . input ) . autocomplete ( { source : function ( request , response ) { wn . call ( { method : 'webnotes.widgets.search.search_link' , args : { 'txt' : request . term , 'dt' : me . df . options , 'query' : repl ( ' SELECT DISTINCT ` %(fieldname)s ` FROM \
` tab%(dt)s ` WHERE ` %(fieldname)s ` LIKE "%s" LIMIT 50 ' , { fieldname : me . df . fieldname , dt : me . df . parent } ) } , callback : function ( r ) { response ( r . results ) ; } } ) ; } } ) ; } }
DataField . prototype . validate = function ( v ) { if ( this . df . options == 'Phone' ) { if ( v + '' == '' ) return '' ; v1 = ''
v = v . replace ( / /g , '' ) . replace ( /-/g , '' ) . replace ( /\(/g , '' ) . replace ( /\)/g , '' ) ; if ( v && v . substr ( 0 , 1 ) == '+' ) { v1 = '+' ; v = v . substr ( 1 ) ; }
if ( v && v . substr ( 0 , 2 ) == '00' ) { v1 += '00' ; v = v . substr ( 2 ) ; }
if ( v && v . substr ( 0 , 1 ) == '0' ) { v1 += '0' ; v = v . substr ( 1 ) ; }
v1 += cint ( v ) + '' ; return v1 ; } else if ( this . df . options == 'Email' ) { if ( v + '' == '' ) return '' ; if ( ! validate _email ( v ) ) { msgprint ( this . df . label + ': ' + v + ' is not a valid email id' ) ; return '' ; } else
return v ; } else { return v ; } }
DataField . prototype . onrefresh = function ( ) { if ( this . input && this . df . colour ) { var col = '#' + this . df . colour . split ( ':' ) [ 1 ] ; $bg ( this . input , col ) ; } }
function ReadOnlyField ( ) { }
ReadOnlyField . prototype = new Field ( ) ; function HTMLField ( ) { }
HTMLField . prototype = new Field ( ) ; HTMLField . prototype . with _label = 0 ; HTMLField . prototype . set _disp = function ( val ) { this . disp _area . innerHTML = val ; }
HTMLField . prototype . set _input = function ( val ) { if ( val ) this . set _disp ( val ) ; }
HTMLField . prototype . onrefresh = function ( ) { this . set _disp ( this . df . options ? this . df . options : '' ) ; }
var datepicker _active = 0 ; function DateField ( ) { } DateField . prototype = new Field ( ) ; DateField . prototype . make _input = function ( ) { var me = this ; this . user _fmt = wn . control _panel . date _format ; if ( ! this . user _fmt ) this . user _fmt = 'dd-mm-yy' ; this . input = $a ( this . input _area , 'input' ) ; $ ( this . input ) . datepicker ( { dateFormat : me . user _fmt . replace ( 'yyyy' , 'yy' ) , altFormat : 'yy-mm-dd' , changeYear : true , beforeShow : function ( input , inst ) { datepicker _active = 1 } , onClose : function ( dateText , inst ) { datepicker _active = 0 ; if ( _f . cur _grid _cell )
_f . cur _grid _cell . grid . cell _deselect ( ) ; } } ) ; var me = this ; me . input . onchange = function ( ) { if ( this . value == null ) this . value = '' ; if ( ! this . not _in _form )
me . set ( dateutil . user _to _str ( me . input . value ) ) ; me . run _trigger ( ) ; }
me . input . set _input = function ( val ) { if ( val == null ) val = '' ; else val = dateutil . str _to _user ( val ) ; me . input . value = val ; }
me . get _value = function ( ) { if ( me . input . value )
return dateutil . user _to _str ( me . input . value ) ; } }
DateField . prototype . set _disp = function ( val ) { var v = dateutil . str _to _user ( val ) ; if ( v == null ) v = '' ; this . set _disp _html ( v ) ; }
DateField . prototype . validate = function ( v ) { if ( ! v ) return ; var me = this ; this . clear = function ( ) { msgprint ( "Date must be in format " + this . user _fmt ) ; me . input . set _input ( '' ) ; return '' ; }
var t = v . split ( '-' ) ; if ( t . length != 3 ) { return this . clear ( ) ; }
else if ( cint ( t [ 1 ] ) > 12 || cint ( t [ 1 ] ) < 1 ) { return this . clear ( ) ; }
else if ( cint ( t [ 2 ] ) > 31 || cint ( t [ 2 ] ) < 1 ) { return this . clear ( ) ; }
return v ; } ; function LinkField ( ) { } LinkField . prototype = new Field ( ) ; LinkField . prototype . make _input = function ( ) { var me = this ; if ( me . df . no _buttons ) { this . txt = $a ( this . input _area , 'input' ) ; this . input = this . txt ; } else { makeinput _popup ( this , 'icon-search' , 'icon-play' , 'icon-plus' ) ; me . setup _buttons ( ) ; me . onrefresh = function ( ) { if ( me . can _create && cur _frm . doc . docstatus == 0 )
$ ( me . btn2 ) . css ( 'display' , 'inline-block' ) ; else $dh ( me . btn2 ) ; } }
me . txt . field _object = this ; me . input . set _input = function ( val ) { if ( val == undefined ) val = '' ; me . txt . value = val ; }
me . get _value = function ( ) { return me . txt . value ; }
$ ( me . txt ) . autocomplete ( { source : function ( request , response ) { wn . call ( { method : 'webnotes.widgets.search.search_link' , args : { 'txt' : request . term , 'dt' : me . df . options , 'query' : me . get _custom _query ( ) } , callback : function ( r ) { response ( r . results ) ; } , } ) ; } , select : function ( event , ui ) { me . set _input _value ( ui . item . value ) ; } } ) . data ( 'autocomplete' ) . _renderItem = function ( ul , item ) { return $ ( '<li></li>' ) . data ( 'item.autocomplete' , item ) . append ( repl ( '<a>%(label)s<br><span style="font-size:10px">%(info)s</span></a>' , item ) ) . appendTo ( ul ) ; } ; $ ( this . txt ) . change ( function ( ) { if ( ! $ ( this ) . val ( ) ) { if ( selector && selector . display )
return ; me . set _input _value ( '' ) ; } } ) }
LinkField . prototype . get _custom _query = function ( ) { this . set _get _query ( ) ; if ( this . get _query ) { if ( cur _frm )
var doc = locals [ cur _frm . doctype ] [ cur _frm . docname ] ; return this . get _query ( doc , this . doctype , this . docname ) ; } }
LinkField . prototype . setup _buttons = function ( ) { var me = this ; me . btn . onclick = function ( ) { selector . set ( me , me . df . options , me . df . label ) ; selector . show ( me . txt ) ; }
if ( me . btn1 ) me . btn1 . onclick = function ( ) { if ( me . txt . value && me . df . options ) { loaddoc ( me . df . options , me . txt . value ) ; } }
me . can _create = 0 ; if ( ( ! me . not _in _form ) && in _list ( profile . can _create , me . df . options ) ) { me . can _create = 1 ; me . btn2 . onclick = function ( ) { var on _save _callback = function ( new _rec ) { if ( new _rec ) { var d = _f . calling _doc _stack . pop ( ) ; locals [ d [ 0 ] ] [ d [ 1 ] ] [ me . df . fieldname ] = new _rec ; me . refresh ( ) ; if ( me . grid ) me . grid . refresh ( ) ; me . run _trigger ( ) ; } }
_f . calling _doc _stack . push ( [ me . doctype , me . docname ] ) ; new _doc ( me . df . options , me . on _new , 1 , on _save _callback , me . doctype , me . docname , me . frm . not _in _container ) ; } } else { $dh ( me . btn2 ) ; $y ( $td ( me . tab , 0 , 2 ) , { width : '0px' } ) ; } }
LinkField . prototype . set _input _value = function ( val ) { var me = this ; var from _selector = false ; if ( selector && selector . display ) from _selector = true ; me . refresh _label _icon ( ) ; if ( me . not _in _form ) { $ ( this . txt ) . val ( val ) ; return ; }
if ( cur _frm ) { if ( val == locals [ me . doctype ] [ me . docname ] [ me . df . fieldname ] ) { me . run _trigger ( ) ; return ; } }
me . set ( val ) ; if ( _f . cur _grid _cell )
_f . cur _grid _cell . grid . cell _deselect ( ) ; if ( locals [ me . doctype ] [ me . docname ] [ me . df . fieldname ] && ! val ) { me . run _trigger ( ) ; return ; }
var fetch = '' ; if ( cur _frm . fetch _dict [ me . df . fieldname ] )
fetch = cur _frm . fetch _dict [ me . df . fieldname ] . columns . join ( ', ' ) ; $c ( 'webnotes.widgets.form.utils.validate_link' , { 'value' : val , 'options' : me . df . options , 'fetch' : fetch } , function ( r , rt ) { if ( r . message == 'Ok' ) { if ( $ ( me . txt ) . val ( ) != val ) { if ( ( me . grid && ! from _selector ) || ( ! me . grid ) ) { $ ( me . txt ) . val ( val ) ; } }
if ( r . fetch _values )
me . set _fetch _values ( r . fetch _values ) ; me . run _trigger ( ) ; } else { var astr = '' ; if ( in _list ( profile . can _create , me . df . options ) ) astr = repl ( '<br><br><span class="link_type" onclick="newdoc(\'%(dt)s\')">Click here</span> to create a new %(dtl)s' , { dt : me . df . options , dtl : get _doctype _label ( me . df . options ) } )
msgprint ( repl ( 'error:<b>%(val)s</b> is not a valid %(dt)s.<br><br>You must first create a new %(dt)s <b>%(val)s</b> and then select its value. To find an existing %(dt)s, click on the magnifying glass next to the field.%(add)s' , { val : me . txt . value , dt : get _doctype _label ( me . df . options ) , add : astr } ) ) ; me . txt . value = '' ; me . set ( '' ) ; } } ) ; }
LinkField . prototype . set _fetch _values = function ( fetch _values ) { var fl = cur _frm . fetch _dict [ this . df . fieldname ] . fields ; var changed _fields = [ ] ; for ( var i = 0 ; i < fl . length ; i ++ ) { if ( locals [ this . doctype ] [ this . docname ] [ fl [ i ] ] != fetch _values [ i ] ) { locals [ this . doctype ] [ this . docname ] [ fl [ i ] ] = fetch _values [ i ] ; if ( ! this . grid ) { refresh _field ( fl [ i ] ) ; changed _fields . push ( fl [ i ] ) ; } } }
for ( i = 0 ; i < changed _fields . length ; i ++ ) { if ( cur _frm . fields _dict [ changed _fields [ i ] ] )
cur _frm . fields _dict [ changed _fields [ i ] ] . run _trigger ( ) ; }
if ( this . grid ) this . grid . refresh ( ) ; }
LinkField . prototype . set _get _query = function ( ) { if ( this . get _query ) return ; if ( this . grid ) { var f = this . grid . get _field ( this . df . fieldname ) ; if ( f . get _query ) this . get _query = f . get _query ; } }
LinkField . prototype . set _disp = function ( val ) { var t = null ; if ( val ) t = "<a href=\'javascript:loaddoc(\"" + this . df . options + "\", \"" + val + "\")\'>" + val + "</a>" ; this . set _disp _html ( t ) ; }
function IntField ( ) { } IntField . prototype = new DataField ( ) ; IntField . prototype . validate = function ( v ) { if ( isNaN ( parseInt ( v ) ) ) return null ; return cint ( v ) ; } ; IntField . prototype . format _input = function ( ) { if ( this . input . value == null ) this . input . value = '' ; }
function FloatField ( ) { } FloatField . prototype = new DataField ( ) ; FloatField . prototype . validate = function ( v ) { var v = parseFloat ( v ) ; if ( isNaN ( v ) )
return null ; return v ; } ; FloatField . prototype . format _input = function ( ) { if ( this . input . value == null ) this . input . value = '' ; }
function CurrencyField ( ) { } CurrencyField . prototype = new DataField ( ) ; CurrencyField . prototype . format _input = function ( ) { var v = fmt _money ( this . input . value ) ; if ( this . not _in _form ) { if ( ! flt ( this . input . value ) ) v = '' ; }
this . input . value = v ; }
CurrencyField . prototype . validate = function ( v ) { if ( v == null || v == '' )
return 0 ; return flt ( v , 2 ) ; }
CurrencyField . prototype . set _disp = function ( val ) { var v = fmt _money ( val ) ; this . set _disp _html ( v ) ; }
CurrencyField . prototype . onmake _input = function ( ) { if ( ! this . input ) return ; this . input . onfocus = function ( ) { if ( flt ( this . value ) == 0 ) this . select ( ) ; } }
function CheckField ( ) { } CheckField . prototype = new Field ( ) ; CheckField . prototype . validate = function ( v ) { var v = parseInt ( v ) ; if ( isNaN ( v ) ) return 0 ; return v ; } ; CheckField . prototype . onmake = function ( ) { this . checkimg = $a ( this . disp _area , 'div' ) ; var img = $a ( this . checkimg , 'img' ) ; img . src = 'images/lib/ui/tick.gif' ; $dh ( this . checkimg ) ; }
CheckField . prototype . make _input = function ( ) { var me = this ; this . input = $a _input ( this . input _area , 'checkbox' ) ; $y ( this . input , { width : "16px" , border : '0px' , margin : '2px' } ) ; $ ( this . input ) . click ( function ( ) { me . set ( this . checked ? 1 : 0 ) ; me . run _trigger ( ) ; } )
this . input . set _input = function ( v ) { v = parseInt ( v ) ; if ( isNaN ( v ) ) v = 0 ; if ( v ) me . input . checked = true ; else me . input . checked = false ; }
this . get _value = function ( ) { return this . input . checked ? 1 : 0 ; } }
CheckField . prototype . set _disp = function ( val ) { if ( val ) { $ds ( this . checkimg ) ; }
else { $dh ( this . checkimg ) ; } }
function TextField ( ) { } TextField . prototype = new Field ( ) ; TextField . prototype . set _disp = function ( val ) { this . disp _area . innerHTML = replace _newlines ( val ) ; }
TextField . prototype . make _input = function ( ) { var me = this ; if ( this . in _grid )
return ; this . input = $a ( this . input _area , 'textarea' ) ; if ( this . df . fieldtype == 'Small Text' )
this . input . style . height = "80px" ; this . input . set _input = function ( v ) { me . input . value = v ; }
this . input . onchange = function ( ) { me . set ( me . input . value ) ; me . run _trigger ( ) ; }
this . get _value = function ( ) { return this . input . value ; } }
var text _dialog ; function make _text _dialog ( ) { var d = new Dialog ( 520 , 410 , 'Edit Text' ) ; d . make _body ( [ [ 'Text' , 'Enter Text' ] , [ 'HTML' , 'Description' ] , [ 'Button' , 'Update' ] ] ) ; d . widgets [ 'Update' ] . onclick = function ( ) { var t = this . dialog ; t . field . set ( t . widgets [ 'Enter Text' ] . value ) ; t . hide ( ) ; }
d . onshow = function ( ) { this . widgets [ 'Enter Text' ] . style . height = '300px' ; var v = _f . get _value ( this . field . doctype , this . field . docname , this . field . df . fieldname ) ; this . widgets [ 'Enter Text' ] . value = v == null ? '' : v ; this . widgets [ 'Enter Text' ] . focus ( ) ; this . widgets [ 'Description' ] . innerHTML = ''
if ( this . field . df . description )
$a ( this . widgets [ 'Description' ] , 'div' , 'help small' , '' , this . field . df . description ) ; }
d . onhide = function ( ) { if ( _f . cur _grid _cell )
_f . cur _grid _cell . grid . cell _deselect ( ) ; }
text _dialog = d ; }
TextField . prototype . table _refresh = function ( ) { if ( ! this . text _dialog )
make _text _dialog ( ) ; text _dialog . set _title ( 'Enter text for "' + this . df . label + '"' ) ; text _dialog . field = this ; text _dialog . show ( ) ; }
function SelectField ( ) { } SelectField . prototype = new Field ( ) ; SelectField . prototype . make _input = function ( ) { var me = this ; var opt = [ ] ; if ( this . in _filter && ( ! this . df . single _select ) ) { this . input = $a ( this . input _area , 'select' ) ; this . input . multiple = true ; this . input . style . height = '4em' ; this . input . lab = $a ( this . input _area , 'div' , { fontSize : '9px' , color : '#999' } ) ; this . input . lab . innerHTML = '(Use Ctrl+Click to select multiple or de-select)' } else { this . input = $a ( this . input _area , 'select' ) ; this . input . onchange = function ( ) { if ( me . validate )
me . validate ( ) ; me . set ( sel _val ( this ) ) ; me . run _trigger ( ) ; }
if ( this . df . options == 'attach_files:' ) { this . file _attach = true ; } }
this . set _as _single = function ( ) { var i = this . input ; i . multiple = false ; i . style . height = null ; if ( i . lab ) $dh ( i . lab ) }
this . refresh _options = function ( options ) { if ( options )
me . df . options = options ; if ( this . file _attach )
this . set _attach _options ( ) ; me . options _list = me . df . options ? me . df . options . split ( '\n' ) : [ '' ] ; empty _select ( this . input ) ; if ( me . in _filter && me . options _list [ 0 ] != '' ) { me . options _list = add _lists ( [ '' ] , me . options _list ) ; }
add _sel _options ( this . input , me . options _list ) ; }
this . onrefresh = function ( ) { this . refresh _options ( ) ; if ( this . not _in _form ) { this . input . value = '' ; return ; }
if ( _f . get _value )
var v = _f . get _value ( this . doctype , this . docname , this . df . fieldname ) ; else { if ( this . options _list && this . options _list . length )
var v = this . options _list [ 0 ] ; else
var v = null ; }
this . input . set _input ( v ) ; }
this . input . set _input = function ( v ) { if ( ! v ) { if ( ! me . input . multiple ) { if ( me . docname ) { if ( me . options _list && me . options _list . length ) { me . set ( me . options _list [ 0 ] ) ; me . input . value = me . options _list [ 0 ] ; } else { me . input . value = '' ; } } } } else { if ( me . options _list ) { if ( me . input . multiple ) { for ( var i = 0 ; i < me . input . options . length ; i ++ ) { me . input . options [ i ] . selected = 0 ; if ( me . input . options [ i ] . value && inList ( typeof ( v ) == 'string' ? v . split ( "," ) : v , me . input . options [ i ] . value ) )
me . input . options [ i ] . selected = 1 ; } } else if ( in _list ( me . options _list , v ) ) { me . input . value = v ; } } } }
this . get _value = function ( ) { if ( me . input . multiple ) { var l = [ ] ; for ( var i = 0 ; i < me . input . options . length ; i ++ ) { if ( me . input . options [ i ] . selected ) l [ l . length ] = me . input . options [ i ] . value ; }
return l ; } else { if ( me . input . options ) { var val = sel _val ( me . input ) ; if ( ! val && ! me . input . selectedIndex )
val = me . input . options [ 0 ] . value ; return val ; }
return me . input . value ; } }
this . set _attach _options = function ( ) { if ( ! cur _frm ) return ; var fl = cur _frm . doc . file _list ; if ( fl ) { this . df . options = '' ; var fl = fl . split ( '\n' ) ; for ( var i in fl ) { this . df . options += '\n' + fl [ i ] . split ( ',' ) [ 1 ] ; } } else { this . df . options = '' } }
this . refresh ( ) ; }
function TimeField ( ) { } TimeField . prototype = new Field ( ) ; TimeField . prototype . get _time = function ( ) { return time _to _hhmm ( sel _val ( this . input _hr ) , sel _val ( this . input _mn ) , sel _val ( this . input _am ) ) ; }
TimeField . prototype . set _time = function ( v ) { ret = time _to _ampm ( v ) ; this . input _hr . inp . value = ret [ 0 ] ; this . input _mn . inp . value = ret [ 1 ] ; this . input _am . inp . value = ret [ 2 ] ; }
TimeField . prototype . set _style _mandatory = function ( ) { }
TimeField . prototype . set _as _error = function ( ) { }
TimeField . prototype . make _input = function ( ) { var me = this ; this . input = $a ( this . input _area , 'div' , 'time_field' ) ; var t = make _table ( this . input , 1 , 3 , '200px' ) ; var opt _hr = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' , '12' ] ; var opt _mn = [ '00' , '05' , '10' , '15' , '20' , '25' , '30' , '35' , '40' , '45' , '50' , '55' ] ; var opt _am = [ 'AM' , 'PM' ] ; this . input _hr = new SelectWidget ( $td ( t , 0 , 0 ) , opt _hr , '50px' ) ; this . input _mn = new SelectWidget ( $td ( t , 0 , 1 ) , opt _mn , '50px' ) ; this . input _am = new SelectWidget ( $td ( t , 0 , 2 ) , opt _am , '50px' ) ; var onchange _fn = function ( ) { me . set ( me . get _time ( ) ) ; me . run _trigger ( ) ; }
this . input _hr . inp . onchange = onchange _fn ; this . input _mn . inp . onchange = onchange _fn ; this . input _am . inp . onchange = onchange _fn ; this . onrefresh = function ( ) { var v = _f . get _value ? _f . get _value ( me . doctype , me . docname , me . df . fieldname ) : null ; me . set _time ( v ) ; if ( ! v )
me . set ( me . get _time ( ) ) ; }
this . input . set _input = function ( v ) { if ( v == null ) v = '' ; me . set _time ( v ) ; }
this . get _value = function ( ) { return this . get _time ( ) ; }
this . refresh ( ) ; }
TimeField . prototype . set _disp = function ( v ) { var t = time _to _ampm ( v ) ; var t = t [ 0 ] + ':' + t [ 1 ] + ' ' + t [ 2 ] ; this . set _disp _html ( t ) ; }
function makeinput _popup ( me , iconsrc , iconsrc1 , iconsrc2 ) { var icon _style = { cursor : 'pointer' , width : '16px' , verticalAlign : 'middle' , marginBottom : '-3px' } ; me . input = $a ( me . input _area , 'div' ) ; if ( ! me . not _in _form )
$y ( me . input , { width : '80%' } ) ; me . input . set _width = function ( w ) { $y ( me . input , { width : ( w - 2 ) + 'px' } ) ; }
var tab = $a ( me . input , 'table' ) ; me . tab = tab ; $y ( tab , { width : '100%' , borderCollapse : 'collapse' , tableLayout : 'fixed' } ) ; var c0 = tab . insertRow ( 0 ) . insertCell ( 0 ) ; var c1 = tab . rows [ 0 ] . insertCell ( 1 ) ; $y ( c1 , { width : '20px' } ) ; me . txt = $a ( $a ( $a ( c0 , 'div' , '' , { paddingRight : '8px' } ) , 'div' ) , 'input' , '' , { width : '100%' } ) ; me . btn = $a ( c1 , 'i' , iconsrc , icon _style )
if ( iconsrc1 )
me . btn . setAttribute ( 'title' , 'Search' ) ; else
me . btn . setAttribute ( 'title' , 'Select Date' ) ; if ( iconsrc1 ) { var c2 = tab . rows [ 0 ] . insertCell ( 2 ) ; $y ( c2 , { width : '20px' } ) ; me . btn1 = $a ( c2 , 'i' , iconsrc1 , icon _style )
me . btn1 . setAttribute ( 'title' , 'Open Link' ) ; }
if ( iconsrc2 ) { var c3 = tab . rows [ 0 ] . insertCell ( 3 ) ; $y ( c3 , { width : '20px' } ) ; me . btn2 = $a ( c3 , 'i' , iconsrc2 , icon _style )
me . btn2 . setAttribute ( 'title' , 'Create New' ) ; $dh ( me . btn2 ) ; }
if ( me . df . colour )
me . txt . style . background = '#' + me . df . colour . split ( ':' ) [ 1 ] ; me . txt . name = me . df . fieldname ; me . setdisabled = function ( tf ) { me . txt . disabled = tf ; } }
var tmpid = 0 ; _f . ButtonField = function ( ) { } ; _f . ButtonField . prototype = new Field ( ) ; _f . ButtonField . prototype . with _label = 0 ; _f . ButtonField . prototype . init = function ( ) { this . prev _button = null ; if ( ! this . frm ) return ; if ( cur _frm && cur _frm . fields [ cur _frm . fields . length - 1 ] && cur _frm . fields [ cur _frm . fields . length - 1 ] . df . fieldtype == 'Button' ) { this . make _body = function ( ) { this . prev _button = cur _frm . fields [ cur _frm . fields . length - 1 ] ; if ( ! this . prev _button . prev _button ) { this . prev _button . button _area = $a ( this . prev _button . input _area , 'span' ) ; }
this . wrapper = this . prev _button . wrapper ; this . input _area = this . prev _button . input _area ; this . disp _area = this . prev _button . disp _area ; this . button _area = $a ( this . prev _button . input _area , 'span' ) ; } } }
_f . ButtonField . prototype . make _input = function ( ) { var me = this ; if ( ! this . prev _button ) { $y ( this . input _area , { marginTop : '4px' , marginBottom : '4px' } ) ; }
if ( ! this . button _area )
this . button _area = $a ( this . input _area , 'span' , '' , { marginRight : '4px' } ) ; this . input = $btn ( this . button _area , me . df . label , null , { fontWeight : 'bold' } , null , 1 )
2012-05-11 10:53:41 +00:00
$ ( this . input ) . click ( function ( ) { if ( me . not _in _form ) return ; if ( cur _frm . cscript [ me . df . fieldname ] && ( ! me . in _filter ) ) { cur _frm . runclientscript ( me . df . fieldname , me . doctype , me . docname ) ; } else { cur _frm . runscript ( me . df . options , me ) ; } } ) ; }
2012-05-07 12:30:57 +00:00
_f . ButtonField . prototype . hide = function ( ) { $dh ( this . button _area ) ; } ; _f . ButtonField . prototype . show = function ( ) { $ds ( this . button _area ) ; } ; _f . ButtonField . prototype . set = function ( v ) { } ; _f . ButtonField . prototype . set _disp = function ( val ) { }
function make _field ( docfield , doctype , parent , frm , in _grid , hide _label ) { switch ( docfield . fieldtype . toLowerCase ( ) ) { case 'data' : var f = new DataField ( ) ; break ; case 'password' : var f = new DataField ( ) ; break ; case 'int' : var f = new IntField ( ) ; break ; case 'float' : var f = new FloatField ( ) ; break ; case 'currency' : var f = new CurrencyField ( ) ; break ; case 'read only' : var f = new ReadOnlyField ( ) ; break ; case 'link' : var f = new LinkField ( ) ; break ; case 'date' : var f = new DateField ( ) ; break ; case 'time' : var f = new TimeField ( ) ; break ; case 'html' : var f = new HTMLField ( ) ; break ; case 'check' : var f = new CheckField ( ) ; break ; case 'text' : var f = new TextField ( ) ; break ; case 'small text' : var f = new TextField ( ) ; break ; case 'select' : var f = new SelectField ( ) ; break ; case 'button' : var f = new _f . ButtonField ( ) ; break ; case 'code' : var f = new _f . CodeField ( ) ; break ; case 'text editor' : var f = new _f . CodeField ( ) ; break ; case 'table' : var f = new _f . TableField ( ) ; break ; case 'section break' : var f = new _f . SectionBreak ( ) ; break ; case 'column break' : var f = new _f . ColumnBreak ( ) ; break ; case 'image' : var f = new _f . ImageField ( ) ; break ; }
f . parent = parent ; f . doctype = doctype ; f . df = docfield ; f . perm = frm ? frm . perm : [ [ 1 , 1 , 1 ] ] ; if ( _f )
f . col _break _width = _f . cur _col _break _width ; if ( in _grid ) { f . in _grid = true ; f . with _label = 0 ; }
if ( hide _label ) { f . with _label = 0 ; }
if ( frm ) { f . frm = frm ; if ( parent )
f . layout _cell = parent . parentNode ; }
if ( f . init ) f . init ( ) ; f . make _body ( ) ; return f ; }