2012-02-14 06:14:13 +00:00
/ *
* lib / js / lib / jquery . min . js
* //*!
* jQuery JavaScript Library v1 . 6.2
* http : //jquery.com/
*
* Copyright 2011 , John Resig
* Dual licensed under the MIT or GPL Version 2 licenses .
* http : //jquery.org/license
*
* Includes Sizzle . js
* http : //sizzlejs.com/
* Copyright 2011 , The Dojo Foundation
* Released under the MIT , BSD , and GPL Licenses .
*
* Date : Thu Jun 30 14 : 16 : 56 2011 - 0400
* /
( function ( a , b ) { function cv ( a ) { return f . isWindow ( a ) ? a : a . nodeType === 9 ? a . defaultView || a . parentWindow : ! 1 } function cs ( a ) { if ( ! cg [ a ] ) { var b = c . body , d = f ( "<" + a + ">" ) . appendTo ( b ) , e = d . css ( "display" ) ; d . remove ( ) ; if ( e === "none" || e === "" ) { ch || ( ch = c . createElement ( "iframe" ) , ch . frameBorder = ch . width = ch . height = 0 ) , b . appendChild ( ch ) ; if ( ! ci || ! ch . createElement ) ci = ( ch . contentWindow || ch . contentDocument ) . document , ci . write ( ( c . compatMode === "CSS1Compat" ? "<!doctype html>" : "" ) + "<html><body>" ) , ci . close ( ) ; d = ci . createElement ( a ) , ci . body . appendChild ( d ) , e = f . css ( d , "display" ) , b . removeChild ( ch ) } cg [ a ] = e } return cg [ a ] } function cr ( a , b ) { var c = { } ; f . each ( cm . concat . apply ( [ ] , cm . slice ( 0 , b ) ) , function ( ) { c [ this ] = a } ) ; return c } function cq ( ) { cn = b } function cp ( ) { setTimeout ( cq , 0 ) ; return cn = f . now ( ) } function cf ( ) { try { return new a . ActiveXObject ( "Microsoft.XMLHTTP" ) } catch ( b ) { } } function ce ( ) { try { return new a . XMLHttpRequest } catch ( b ) { } } function b$ ( a , c ) { a . dataFilter && ( c = a . dataFilter ( c , a . dataType ) ) ; var d = a . dataTypes , e = { } , g , h , i = d . length , j , k = d [ 0 ] , l , m , n , o , p ; for ( g = 1 ; g < i ; g ++ ) { if ( g === 1 ) for ( h in a . converters ) typeof h == "string" && ( e [ h . toLowerCase ( ) ] = a . converters [ h ] ) ; l = k , k = d [ g ] ; if ( k === "*" ) k = l ; else if ( l !== "*" && l !== k ) { m = l + " " + k , n = e [ m ] || e [ "* " + k ] ; if ( ! n ) { p = b ; for ( o in e ) { j = o . split ( " " ) ; if ( j [ 0 ] === l || j [ 0 ] === "*" ) { p = e [ j [ 1 ] + " " + k ] ; if ( p ) { o = e [ o ] , o === ! 0 ? n = p : p === ! 0 && ( n = o ) ; break } } } } ! n && ! p && f . error ( "No conversion from " + m . replace ( " " , " to " ) ) , n !== ! 0 && ( c = n ? n ( c ) : p ( o ( c ) ) ) } } return c } function bZ ( a , c , d ) { var e = a . contents , f = a . dataTypes , g = a . responseFields , h , i , j , k ; for ( i in g ) i in d && ( c [ g [ i ] ] = d [ i ] ) ; while ( f [ 0 ] === "*" ) f . shift ( ) , h === b && ( h = a . mimeType || c . getResponseHeader ( "content-type" ) ) ; if ( h ) for ( i in e ) if ( e [ i ] && e [ i ] . test ( h ) ) { f . unshift ( i ) ; break } if ( f [ 0 ] in d ) j = f [ 0 ] ; else { for ( i in d ) { if ( ! f [ 0 ] || a . converters [ i + " " + f [ 0 ] ] ) { j = i ; break } k || ( k = i ) } j = j || k } if ( j ) { j !== f [ 0 ] && f . unshift ( j ) ; return d [ j ] } } function bY ( a , b , c , d ) { if ( f . isArray ( b ) ) f . each ( b , function ( b , e ) { c || bC . test ( a ) ? d ( a , e ) : bY ( a + "[" + ( typeof e == "object" || f . isArray ( e ) ? b : "" ) + "]" , e , c , d ) } ) ; else if ( ! c && b != null && typeof b == "object" ) for ( var e in b ) bY ( a + "[" + e + "]" , b [ e ] , c , d ) ; else d ( a , b ) } function bX ( a , c , d , e , f , g ) { f = f || c . dataTypes [ 0 ] , g = g || { } , g [ f ] = ! 0 ; var h = a [ f ] , i = 0 , j = h ? h . length : 0 , k = a === bR , l ; for ( ; i < j && ( k || ! l ) ; i ++ ) l = h [ i ] ( c , d , e ) , typeof l == "string" && ( ! k || g [ l ] ? l = b : ( c . dataTypes . unshift ( l ) , l = bX ( a , c , d , e , l , g ) ) ) ; ( k || ! l ) && ! g [ "*" ] && ( l = bX ( a , c , d , e , "*" , g ) ) ; return l } function bW ( a ) { return function ( b , c ) { typeof b != "string" && ( c = b , b = "*" ) ; if ( f . isFunction ( c ) ) { var d = b . toLowerCase ( ) . split ( bN ) , e = 0 , g = d . length , h , i , j ; for ( ; e < g ; e ++ ) h = d [ e ] , j = /^\+/ . test ( h ) , j && ( h = h . substr ( 1 ) || "*" ) , i = a [ h ] = a [ h ] || [ ] , i [ j ? "unshift" : "push" ] ( c ) } } } function bA ( a , b , c ) { var d = b === "width" ? a . offsetWidth : a . offsetHeight , e = b === "width" ? bv : bw ; if ( d > 0 ) { c !== "border" && f . each ( e , function ( ) { c || ( d -= parseFloat ( f . css ( a , "padding" + this ) ) || 0 ) , c === "margin" ? d += parseFloat ( f . css ( a , c + this ) ) || 0 : d -= parseFloat ( f . css ( a , "border" + this + "Width" ) ) || 0 } ) ; return d + "px" } d = bx ( a , b , b ) ; if ( d < 0 || d == null ) d = a . style [ b ] || 0 ; d = parseFloat ( d ) || 0 , c && f . each ( e , function ( ) { d += parseFloat ( f . css ( a , "padding" + this ) ) || 0 , c !== "padding" && ( d += parseFloat ( f . css ( a , "border" + this + "Width" ) ) || 0 ) , c === "margin" && ( d += parseFloat ( f . css ( a , c + this ) ) || 0 ) } ) ; return d + "px" } function bm ( a , b ) { b . src ? f . ajax ( { url : b . src , async : ! 1 , dataType : "script" } ) : f . globalEval ( ( b . text || b . textContent || b . innerHTML || "" ) . replace ( be , "/*$0*/" ) ) , b . parentNode && b . parentNode . removeChild ( b ) } function bl ( a ) { f . nodeName ( a , "input" ) ? bk ( a ) : "getElementsByTagName" in a && f . grep ( a . getElementsByTagName ( "input" ) , bk ) } function bk ( a ) { if ( a . type === "checkbox" || a . type === "radio" ) a . defaultChecked = a . checked } function bj ( a ) { return "getElementsByTagName" in a ? a . getElementsByTagName ( "*" ) : "querySelectorAll" in a ? a . querySelectorAll ( "*" ) : [ ] } function bi ( a , b ) { var c ; if ( b . nodeType === 1 ) { b . clearAttributes && b . clearAttributes ( ) , b . mergeAttributes && b . mergeAttributes ( a ) , c = b . nodeName . toLowerCase ( ) ; if ( c === "object" ) b . outerHTML = a . outerHTML ; else if ( c !== "input" || a . type !== "checkbox" && a . type !== "radio" ) { if ( c === "option" ) b . selected = a . defaultSelected ; else if ( c === "input" || c === "textarea" ) b . defaultValue = a . defaultValue } else a . checked && ( b . defaultChecked = b . checked = a . checked ) , b . value !== a . value && ( b . value = a . value ) ; b . removeAttribute ( f . expando ) } } function bh (
shift ( ) , i . sort ( ) ) ; if ( ! ! e && ! f . event . customEvent [ h ] || ! ! f . event . global [ h ] ) { c = typeof c == "object" ? c [ f . expando ] ? c : new f . Event ( h , c ) : new f . Event ( h ) , c . type = h , c . exclusive = j , c . namespace = i . join ( "." ) , c . namespace _re = new RegExp ( "(^|\\.)" + i . join ( "\\.(?:.*\\.)?" ) + "(\\.|$)" ) ; if ( g || ! e ) c . preventDefault ( ) , c . stopPropagation ( ) ; if ( ! e ) { f . each ( f . cache , function ( ) { var a = f . expando , b = this [ a ] ; b && b . events && b . events [ h ] && f . event . trigger ( c , d , b . handle . elem ) } ) ; return } if ( e . nodeType === 3 || e . nodeType === 8 ) return ; c . result = b , c . target = e , d = d != null ? f . makeArray ( d ) : [ ] , d . unshift ( c ) ; var k = e , l = h . indexOf ( ":" ) < 0 ? "on" + h : "" ; do { var m = f . _data ( k , "handle" ) ; c . currentTarget = k , m && m . apply ( k , d ) , l && f . acceptData ( k ) && k [ l ] && k [ l ] . apply ( k , d ) === ! 1 && ( c . result = ! 1 , c . preventDefault ( ) ) , k = k . parentNode || k . ownerDocument || k === c . target . ownerDocument && a } while ( k && ! c . isPropagationStopped ( ) ) ; if ( ! c . isDefaultPrevented ( ) ) { var n , o = f . event . special [ h ] || { } ; if ( ( ! o . _default || o . _default . call ( e . ownerDocument , c ) === ! 1 ) && ( h !== "click" || ! f . nodeName ( e , "a" ) ) && f . acceptData ( e ) ) { try { l && e [ h ] && ( n = e [ l ] , n && ( e [ l ] = null ) , f . event . triggered = h , e [ h ] ( ) ) } catch ( p ) { } n && ( e [ l ] = n ) , f . event . triggered = b } } return c . result } } , handle : function ( c ) { c = f . event . fix ( c || a . event ) ; var d = ( ( f . _data ( this , "events" ) || { } ) [ c . type ] || [ ] ) . slice ( 0 ) , e = ! c . exclusive && ! c . namespace , g = Array . prototype . slice . call ( arguments , 0 ) ; g [ 0 ] = c , c . currentTarget = this ; for ( var h = 0 , i = d . length ; h < i ; h ++ ) { var j = d [ h ] ; if ( e || c . namespace _re . test ( j . namespace ) ) { c . handler = j . handler , c . data = j . data , c . handleObj = j ; var k = j . handler . apply ( this , g ) ; k !== b && ( c . result = k , k === ! 1 && ( c . preventDefault ( ) , c . stopPropagation ( ) ) ) ; if ( c . isImmediatePropagationStopped ( ) ) break } } return c . result } , props : "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which" . split ( " " ) , fix : function ( a ) { if ( a [ f . expando ] ) return a ; var d = a ; a = f . Event ( d ) ; for ( var e = this . props . length , g ; e ; ) g = this . props [ -- e ] , a [ g ] = d [ g ] ; a . target || ( a . target = a . srcElement || c ) , a . target . nodeType === 3 && ( a . target = a . target . parentNode ) , ! a . relatedTarget && a . fromElement && ( a . relatedTarget = a . fromElement === a . target ? a . toElement : a . fromElement ) ; if ( a . pageX == null && a . clientX != null ) { var h = a . target . ownerDocument || c , i = h . documentElement , j = h . body ; a . pageX = a . clientX + ( i && i . scrollLeft || j && j . scrollLeft || 0 ) - ( i && i . clientLeft || j && j . clientLeft || 0 ) , a . pageY = a . clientY + ( i && i . scrollTop || j && j . scrollTop || 0 ) - ( i && i . clientTop || j && j . clientTop || 0 ) } a . which == null && ( a . charCode != null || a . keyCode != null ) && ( a . which = a . charCode != null ? a . charCode : a . keyCode ) , ! a . metaKey && a . ctrlKey && ( a . metaKey = a . ctrlKey ) , ! a . which && a . button !== b && ( a . which = a . button & 1 ? 1 : a . button & 2 ? 3 : a . button & 4 ? 2 : 0 ) ; return a } , guid : 1e8 , proxy : f . proxy , special : { ready : { setup : f . bindReady , teardown : f . noop } , live : { add : function ( a ) { f . event . add ( this , N ( a . origType , a . selector ) , f . extend ( { } , a , { handler : M , guid : a . handler . guid } ) ) } , remove : function ( a ) { f . event . remove ( this , N ( a . origType , a . selector ) , a ) } } , beforeunload : { setup : function ( a , b , c ) { f . isWindow ( this ) && ( this . onbeforeunload = c ) } , teardown : function ( a , b ) { this . onbeforeunload === b && ( this . onbeforeunload = null ) } } } } , f . removeEvent = c . removeEventListener ? function ( a , b , c ) { a . removeEventListener && a . removeEventListener ( b , c , ! 1 ) } : function ( a , b , c ) { a . detachEvent && a . detachEvent ( "on" + b , c ) } , f . Event = function ( a , b ) { if ( ! this . preventDefault ) return new f . Event ( a , b ) ; a && a . type ? ( this . originalEvent = a , this . type = a . type , this . isDefaultPrevented = a . defaultPrevented || a . returnValue === ! 1 || a . getPreventDefault && a . getPreventDefault ( ) ? E : D ) : this . type = a , b && f . extend ( this , b ) , this . timeStamp = f . now ( ) , this [ f . expando ] = ! 0 } , f . Event . prototype = { preventDefault : function ( ) { this . isDefaultPrevented = E ; var a = this . originalEvent ; ! a || ( a . preventDefault ? a . preventDefault ( ) : a . returnValue = ! 1 ) } , stopPropagation : function ( ) { this . isPropagationStopped = E ; var a = this . originalEvent ; ! a || ( a . stopPropagation && a . stopPropagation ( ) , a . cancelBubble = ! 0 ) } , stopImmediatePropagation : function ( ) { this . isImmediatePropagationStopped = E , this . stopPropagation ( ) } , isDefaultPrevented : D , isPropagationStopped : D
) } return this . pushStack ( d , a , e . selector ) } } ) , f . extend ( { clone : function ( a , b , c ) { var d = a . cloneNode ( ! 0 ) , e , g , h ; if ( ( ! f . support . noCloneEvent || ! f . support . noCloneChecked ) && ( a . nodeType === 1 || a . nodeType === 11 ) && ! f . isXMLDoc ( a ) ) { bi ( a , d ) , e = bj ( a ) , g = bj ( d ) ; for ( h = 0 ; e [ h ] ; ++ h ) bi ( e [ h ] , g [ h ] ) } if ( b ) { bh ( a , d ) ; if ( c ) { e = bj ( a ) , g = bj ( d ) ; for ( h = 0 ; e [ h ] ; ++ h ) bh ( e [ h ] , g [ h ] ) } } e = g = null ; return d } , clean : function ( a , b , d , e ) { var g ; b = b || c , typeof b . createElement == "undefined" && ( b = b . ownerDocument || b [ 0 ] && b [ 0 ] . ownerDocument || c ) ; var h = [ ] , i ; for ( var j = 0 , k ; ( k = a [ j ] ) != null ; j ++ ) { typeof k == "number" && ( k += "" ) ; if ( ! k ) continue ; if ( typeof k == "string" ) if ( ! ba . test ( k ) ) k = b . createTextNode ( k ) ; else { k = k . replace ( Z , "<$1></$2>" ) ; var l = ( $ . exec ( k ) || [ "" , "" ] ) [ 1 ] . toLowerCase ( ) , m = bf [ l ] || bf . _default , n = m [ 0 ] , o = b . createElement ( "div" ) ; o . innerHTML = m [ 1 ] + k + m [ 2 ] ; while ( n -- ) o = o . lastChild ; if ( ! f . support . tbody ) { var p = _ . test ( k ) , q = l === "table" && ! p ? o . firstChild && o . firstChild . childNodes : m [ 1 ] === "<table>" && ! p ? o . childNodes : [ ] ; for ( i = q . length - 1 ; i >= 0 ; -- i ) f . nodeName ( q [ i ] , "tbody" ) && ! q [ i ] . childNodes . length && q [ i ] . parentNode . removeChild ( q [ i ] ) } ! f . support . leadingWhitespace && Y . test ( k ) && o . insertBefore ( b . createTextNode ( Y . exec ( k ) [ 0 ] ) , o . firstChild ) , k = o . childNodes } var r ; if ( ! f . support . appendChecked ) if ( k [ 0 ] && typeof ( r = k . length ) == "number" ) for ( i = 0 ; i < r ; i ++ ) bl ( k [ i ] ) ; else bl ( k ) ; k . nodeType ? h . push ( k ) : h = f . merge ( h , k ) } if ( d ) { g = function ( a ) { return ! a . type || bd . test ( a . type ) } ; for ( j = 0 ; h [ j ] ; j ++ ) if ( e && f . nodeName ( h [ j ] , "script" ) && ( ! h [ j ] . type || h [ j ] . type . toLowerCase ( ) === "text/javascript" ) ) e . push ( h [ j ] . parentNode ? h [ j ] . parentNode . removeChild ( h [ j ] ) : h [ j ] ) ; else { if ( h [ j ] . nodeType === 1 ) { var s = f . grep ( h [ j ] . getElementsByTagName ( "script" ) , g ) ; h . splice . apply ( h , [ j + 1 , 0 ] . concat ( s ) ) } d . appendChild ( h [ j ] ) } } return h } , cleanData : function ( a ) { var b , c , d = f . cache , e = f . expando , g = f . event . special , h = f . support . deleteExpando ; for ( var i = 0 , j ; ( j = a [ i ] ) != null ; i ++ ) { if ( j . nodeName && f . noData [ j . nodeName . toLowerCase ( ) ] ) continue ; c = j [ f . expando ] ; if ( c ) { b = d [ c ] && d [ c ] [ e ] ; if ( b && b . events ) { for ( var k in b . events ) g [ k ] ? f . event . remove ( j , k ) : f . removeEvent ( j , k , b . handle ) ; b . handle && ( b . handle . elem = null ) } h ? delete j [ f . expando ] : j . removeAttribute && j . removeAttribute ( f . expando ) , delete d [ c ] } } } } ) ; var bn = /alpha\([^)]*\)/i , bo = /opacity=([^)]*)/ , bp = /([A-Z]|^ms)/g , bq = /^-?\d+(?:px)?$/i , br = /^-?\d/ , bs = /^[+\-]=/ , bt = /[^+\-\.\de]+/g , bu = { position : "absolute" , visibility : "hidden" , display : "block" } , bv = [ "Left" , "Right" ] , bw = [ "Top" , "Bottom" ] , bx , by , bz ; f . fn . css = function ( a , c ) { if ( arguments . length === 2 && c === b ) return this ; return f . access ( this , a , c , ! 0 , function ( a , c , d ) { return d !== b ? f . style ( a , c , d ) : f . css ( a , c ) } ) } , f . extend ( { cssHooks : { opacity : { get : function ( a , b ) { if ( b ) { var c = bx ( a , "opacity" , "opacity" ) ; return c === "" ? "1" : c } return a . style . opacity } } } , cssNumber : { fillOpacity : ! 0 , fontWeight : ! 0 , lineHeight : ! 0 , opacity : ! 0 , orphans : ! 0 , widows : ! 0 , zIndex : ! 0 , zoom : ! 0 } , cssProps : { "float" : f . support . cssFloat ? "cssFloat" : "styleFloat" } , style : function ( a , c , d , e ) { if ( ! ! a && a . nodeType !== 3 && a . nodeType !== 8 && ! ! a . style ) { var g , h , i = f . camelCase ( c ) , j = a . style , k = f . cssHooks [ i ] ; c = f . cssProps [ i ] || i ; if ( d === b ) { if ( k && "get" in k && ( g = k . get ( a , ! 1 , e ) ) !== b ) return g ; return j [ c ] } h = typeof d ; if ( h === "number" && isNaN ( d ) || d == null ) return ; h === "string" && bs . test ( d ) && ( d = + d . replace ( bt , "" ) + parseFloat ( f . css ( a , c ) ) , h = "number" ) , h === "number" && ! f . cssNumber [ i ] && ( d += "px" ) ; if ( ! k || ! ( "set" in k ) || ( d = k . set ( a , d ) ) !== b ) try { j [ c ] = d } catch ( l ) { } } } , css : function ( a , c , d ) { var e , g ; c = f . camelCase ( c ) , g = f . cssHooks [ c ] , c = f . cssProps [ c ] || c , c === "cssFloat" && ( c = "float" ) ; if ( g && "get" in g && ( e = g . get ( a , ! 0 , d ) ) !== b ) return e ; if ( bx ) return bx ( a , c ) } , swap : function ( a , b , c ) { var d = { } ; for ( var e in b ) d [ e ] = a . style [ e ] , a . style [ e ] = b [ e ] ; c . call ( a ) ; for ( e in b ) a . style [ e ] = d [ e ] } } ) , f . curCSS = f . css , f . each ( [ "height" , "width" ] , function ( a , b ) { f . cssHooks [ b ] = { get : function ( a , c , d ) { var e ; if ( c ) { if ( a . offsetWidth !== 0 ) return bA ( a , b , d ) ; f . swap ( a , bu , function ( ) { e = bA ( a , b , d ) } ) ; return e } } , set : function ( a , b ) { if ( ! bq . test ( b ) ) return b ; b = parseFloat ( b ) ; if ( b >= 0 ) return b + "px" } } } ) , f . support . opacity || ( f . cssHooks . opacity = { get : function ( a , b ) { return bo . test ( ( b && a . currentStyle ? a . currentStyle . filter : a . style . filter ) || "" ) ? parseFloat ( RegExp . $1 ) / 100 + "" : b ? "1" : "" } , set : function ( a , b ) { var c = a . style , d = a . currentStyle ; c . zoom = 1 ; var e = f . isNaN ( b ) ? "" : "alpha(opacity=" + b * 100 + ")" ,
/ *
* lib / js / lib / history / history . min . js
* //*
* jQuery hashchange event - v1 . 3 - 7 / 21 / 2010
* http : //benalman.com/projects/jquery-hashchange-plugin/
*
* Copyright ( c ) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses .
* http : //benalman.com/about/license/
* /
( function ( $ , e , b ) { var c = "hashchange" , h = document , f , g = $ . event . special , i = h . documentMode , d = "on" + c in e && ( i === b || i > 7 ) ; function a ( j ) { j = j || location . href ; return "#" + j . replace ( /^[^#]*#?(.*)$/ , "$1" ) } $ . fn [ c ] = function ( j ) { return j ? this . bind ( c , j ) : this . trigger ( c ) } ; $ . fn [ c ] . delay = 50 ; g [ c ] = $ . extend ( g [ c ] , { setup : function ( ) { if ( d ) { return false } $ ( f . start ) } , teardown : function ( ) { if ( d ) { return false } $ ( f . stop ) } } ) ; f = ( function ( ) { var j = { } , p , m = a ( ) , k = function ( q ) { return q } , l = k , o = k ; j . start = function ( ) { p || n ( ) } ; j . stop = function ( ) { p && clearTimeout ( p ) ; p = b } ; function n ( ) { var r = a ( ) , q = o ( m ) ; if ( r !== m ) { l ( m = r , q ) ; $ ( e ) . trigger ( c ) } else { if ( q !== m ) { location . href = location . href . replace ( /#.*/ , "" ) + q } } p = setTimeout ( n , $ . fn [ c ] . delay ) } $ . browser . msie && ! d && ( function ( ) { var q , r ; j . start = function ( ) { if ( ! q ) { r = $ . fn [ c ] . src ; r = r && r + a ( ) ; q = $ ( '<iframe tabindex="-1" title="empty"/>' ) . hide ( ) . one ( "load" , function ( ) { r || l ( a ( ) ) ; n ( ) } ) . attr ( "src" , r || "javascript:0" ) . insertAfter ( "body" ) [ 0 ] . contentWindow ; h . onpropertychange = function ( ) { try { if ( event . propertyName === "title" ) { q . document . title = h . title } } catch ( s ) { } } } } ; j . stop = k ; o = function ( ) { return a ( q . location . href ) } ; l = function ( v , s ) { var u = q . document , t = $ . fn [ c ] . domain ; if ( v !== s ) { u . title = h . title ; u . open ( ) ; t && u . write ( '<script>document.domain="' + t + '"<\/script>' ) ; u . close ( ) ; q . location . hash = v } } } ) ( ) ; return j } ) ( ) } ) ( jQuery , this ) ;
// manage history
// load pages via ajax
// setup the history adapter
// if settings no_history is set, no history will be bound
// this can be used to make it work with legacy
$ ( document ) . bind ( 'ready' , function ( ) {
// standard page openener
$ ( window ) . bind ( 'hashchange' , function ( ) {
if ( wn . settings . no _history )
return ;
// load the state on the browser
wn . page . set ( location . hash ) ;
} ) ;
} )
/ *
* lib / js / core . min . js
* /
/ *
* lib / js / wn / class . js
* / ; ( f u n c t i o n ( ) { v a r i n i t i a l i z i n g = f a l s e , f n T e s t = / x y z / . t e s t ( f u n c t i o n ( ) { x y z ; } ) ? / \ b _ s u p e r \ b / : / . * / ; t h i s . C l a s s = f u n c t i o n ( ) { } ; C l a s s . e x t e n d = f u n c t i o n ( p r o p ) { v a r _ s u p e r = t h i s . p r o t o t y p e ; i n i t i a l i z i n g = t r u e ; v a r p r o t o t y p e = n e w t h i s ( ) ; i n i t i a l i z i n g = f a l s e ; f o r ( v a r n a m e i n p r o p ) { p r o t o t y p e [ n a m e ] = t y p e o f p r o p [ n a m e ] = = " f u n c t i o n " & & t y p e o f _ s u p e r [ n a m e ] = = " f u n c t i o n " & & f n T e s t . t e s t ( p r o p [ n a m e ] ) ? ( f u n c t i o n ( n a m e , f n ) { r e t u r n f u n c t i o n ( ) { v a r t m p = t h i s . _ s u p e r ; t h i s . _ s u p e r = _ s u p e r [ n a m e ] ; v a r r e t = f n . a p p l y ( t h i s , a r g u m e n t s ) ; t h i s . _ s u p e r = t m p ; r e t u r n r e t ; } ; } ) ( n a m e , p r o p [ n a m e ] ) : p r o p [ n a m e ] ; }
function Class ( ) { if ( ! initializing && this . init )
this . init . apply ( this , arguments ) ; }
Class . prototype = prototype ; Class . prototype . constructor = Class ; Class . extend = arguments . callee ; return Class ; } ; } ) ( ) ;
/ *
* lib / js / wn / provide . js
* /
if ( ! window . wn ) wn = { }
wn . provide = function ( namespace ) { var nsl = namespace . split ( '.' ) ; var l = nsl . length ; var parent = window ; for ( var i = 0 ; i < l ; i ++ ) { var n = nsl [ i ] ; if ( ! parent [ n ] ) { parent [ n ] = { } }
parent = parent [ n ] ; } }
wn . provide ( 'wn.settings' ) ; wn . provide ( 'wn.ui' ) ;
/ *
* lib / js / wn / xmlhttp . js
* /
wn . xmlhttp = { request : function ( ) { if ( window . XMLHttpRequest )
return new XMLHttpRequest ( ) ; else if ( window . ActiveXObject )
return new ActiveXObject ( "MsXml2.XmlHttp" ) ; } , complete : function ( req , callback , url ) { if ( req . status == 200 || req . status == 304 ) { callback ( req . responseText ) ; } else { alert ( url + ' request error: ' + req . statusText + ' (' + req . status + ')' ) ; } } , get : function ( url , callback , args , async ) { if ( async === null ) async = true ; var req = wn . xmlhttp . request ( ) ; req . onreadystatechange = function ( ) { if ( req . readyState == 4 ) { wn . xmlhttp . complete ( req , callback , url ) } }
var sep = ( ( args && args . indexOf ( '?' ) ) == - 1 ) ? '?' : '&' ; var u = args ? ( url + sep + args ) : url ; req . open ( 'GET' , u , async ) ; req . send ( null ) ; if ( ! async ) { wn . xmlhttp . complete ( req , callback , url ) } } }
/ *
* lib / js / wn / versions . js
* /
wn . versions = { check : function ( ) { if ( localStorage ) { if ( window . _version _number == - 1 || parseInt ( localStorage . _version _number ) != parseInt ( window . _version _number ) ) { var localversion = localStorage . _version _number ; localStorage . clear ( ) ; console . log ( "Cache cleared - version: " + localversion
+ ' to ' + _version _number ) }
localStorage . setItem ( '_version_number' , window . _version _number ) ; } } }
/ *
* lib / js / wn / assets . js
* /
wn . assets = { executed _ : { } , exists : function ( src ) { if ( 'localStorage' in window && localStorage . getItem ( src ) )
return true } , add : function ( src , txt ) { if ( 'localStorage' in window ) { localStorage . setItem ( src , txt ) ; } } , get : function ( src ) { return localStorage . getItem ( src ) ; } , extn : function ( src ) { if ( src . indexOf ( '?' ) != - 1 ) { src = src . split ( '?' ) . slice ( - 1 ) [ 0 ] ; }
return src . split ( '.' ) . slice ( - 1 ) [ 0 ] ; } , load : function ( src ) { var t = src ; wn . xmlhttp . get ( t , function ( txt ) { wn . assets . add ( src , txt ) ; } , 'q=' + Math . floor ( Math . random ( ) * 1000 ) , false ) } , execute : function ( src ) { if ( ! wn . assets . exists ( src ) ) { wn . assets . load ( src ) ; }
var type = wn . assets . extn ( src ) ; if ( wn . assets . handler [ type ] ) { wn . assets . handler [ type ] ( wn . assets . get ( src ) , src ) ; wn . assets . executed _ [ src ] = 1 ; } } , handler : { js : function ( txt , src ) { wn . dom . eval ( txt ) ; } , css : function ( txt , src ) { var se = document . createElement ( 'style' ) ; se . type = "text/css" ; if ( se . styleSheet ) { se . styleSheet . cssText = txt ; } else { se . appendChild ( document . createTextNode ( txt ) ) ; }
document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( se ) ; } , cgi : function ( txt , src ) { wn . dom . eval ( txt ) } } }
/ *
* lib / js / wn / require . js
* /
wn . require = function ( items ) { if ( typeof items === "string" ) { items = [ items ] ; }
var l = items . length ; for ( var i = 0 ; i < l ; i ++ ) { var src = items [ i ] ; if ( ! ( src in wn . assets . executed _ ) ) { wn . assets . execute ( src ) ; } } }
/ *
* lib / js / wn / dom . js
* /
wn . provide ( 'wn.dom' ) ; wn . dom . by _id = function ( id ) { return document . getElementById ( id ) ; }
wn . dom . eval = function ( txt ) { var el = document . createElement ( 'script' ) ; el . appendChild ( document . createTextNode ( txt ) ) ; document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( el ) ; }
wn . dom . add = function ( parent , newtag , className , cs , innerHTML , onclick ) { if ( parent && parent . substr ) parent = wn . dom . by _id ( parent ) ; var c = document . createElement ( newtag ) ; if ( parent )
parent . appendChild ( c ) ; if ( className ) { if ( newtag . toLowerCase ( ) == 'img' )
c . src = className
else
c . className = className ; }
if ( cs ) wn . dom . css ( c , cs ) ; if ( innerHTML ) c . innerHTML = innerHTML ; if ( onclick ) c . onclick = onclick ; return c ; }
wn . dom . css = function ( ele , s ) { if ( ele && s ) { for ( var i in s ) ele . style [ i ] = s [ i ] ; } ; return ele ; }
wn . dom . hide = function ( ele ) { ele . style . display = 'none' ; }
wn . dom . show = function ( ele , value ) { if ( ! value ) value = 'block' ; ele . style . display = value ; }
/ *
* lib / js / wn / page . js
* /
wn . page = { set : function ( src ) { var new _selection = $ ( '.inner div.content[_src="' + src + '"]' ) ; if ( ! new _selection . length ) { wn . assets . execute ( src ) ; new _selection = $ ( '.inner div.content[_src="' + src + '"]' ) ; }
$ ( '.inner .current_page' ) . removeClass ( 'current_page' ) ; new _selection . addClass ( 'current_page' ) ; var title = $ ( 'nav ul li a[href*="' + src + '"]' ) . attr ( 'title' ) || 'No Title'
state = window . location . hash ; if ( state != src ) { window . location . hash = state ; }
else { document . title = title ; } } }
/ *
* lib / js / lib / json2 . js
* /
var JSON ; if ( ! JSON ) { JSON = { } ; }
( function ( ) { "use strict" ; function f ( n ) { return n < 10 ? '0' + n : n ; }
if ( typeof Date . prototype . toJSON !== 'function' ) { Date . prototype . toJSON = function ( key ) { return isFinite ( this . valueOf ( ) ) ? this . getUTCFullYear ( ) + '-' +
f ( this . getUTCMonth ( ) + 1 ) + '-' +
f ( this . getUTCDate ( ) ) + 'T' +
f ( this . getUTCHours ( ) ) + ':' +
f ( this . getUTCMinutes ( ) ) + ':' +
f ( this . getUTCSeconds ( ) ) + 'Z' : null ; } ; String . prototype . toJSON = Number . prototype . toJSON = Boolean . prototype . toJSON = function ( key ) { return this . valueOf ( ) ; } ; }
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g , escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g , gap , indent , meta = { '\b' : '\\b' , '\t' : '\\t' , '\n' : '\\n' , '\f' : '\\f' , '\r' : '\\r' , '"' : '\\"' , '\\' : '\\\\' } , rep ; function quote ( string ) { escapable . lastIndex = 0 ; return escapable . test ( string ) ? '"' + string . replace ( escapable , function ( a ) { var c = meta [ a ] ; return typeof c === 'string' ? c : '\\u' + ( '0000' + a . charCodeAt ( 0 ) . toString ( 16 ) ) . slice ( - 4 ) ; } ) + '"' : '"' + string + '"' ; }
function str ( key , holder ) { var i , k , v , length , mind = gap , partial , value = holder [ key ] ; if ( value && typeof value === 'object' && typeof value . toJSON === 'function' ) { value = value . toJSON ( key ) ; }
if ( typeof rep === 'function' ) { value = rep . call ( holder , key , value ) ; }
switch ( typeof value ) { case 'string' : return quote ( value ) ; case 'number' : return isFinite ( value ) ? String ( value ) : 'null' ; case 'boolean' : case 'null' : return String ( value ) ; case 'object' : if ( ! value ) { return 'null' ; }
gap += indent ; partial = [ ] ; if ( Object . prototype . toString . apply ( value ) === '[object Array]' ) { length = value . length ; for ( i = 0 ; i < length ; i += 1 ) { partial [ i ] = str ( i , value ) || 'null' ; }
v = partial . length === 0 ? '[]' : gap ? '[\n' + gap + partial . join ( ',\n' + gap ) + '\n' + mind + ']' : '[' + partial . join ( ',' ) + ']' ; gap = mind ; return v ; }
if ( rep && typeof rep === 'object' ) { length = rep . length ; for ( i = 0 ; i < length ; i += 1 ) { if ( typeof rep [ i ] === 'string' ) { k = rep [ i ] ; v = str ( k , value ) ; if ( v ) { partial . push ( quote ( k ) + ( gap ? ': ' : ':' ) + v ) ; } } } } else { for ( k in value ) { if ( Object . prototype . hasOwnProperty . call ( value , k ) ) { v = str ( k , value ) ; if ( v ) { partial . push ( quote ( k ) + ( gap ? ': ' : ':' ) + v ) ; } } } }
v = partial . length === 0 ? '{}' : gap ? '{\n' + gap + partial . join ( ',\n' + gap ) + '\n' + mind + '}' : '{' + partial . join ( ',' ) + '}' ; gap = mind ; return v ; } }
if ( typeof JSON . stringify !== 'function' ) { JSON . stringify = function ( value , replacer , space ) { var i ; gap = '' ; indent = '' ; if ( typeof space === 'number' ) { for ( i = 0 ; i < space ; i += 1 ) { indent += ' ' ; } } else if ( typeof space === 'string' ) { indent = space ; }
rep = replacer ; if ( replacer && typeof replacer !== 'function' && ( typeof replacer !== 'object' || typeof replacer . length !== 'number' ) ) { throw new Error ( 'JSON.stringify' ) ; }
return str ( '' , { '' : value } ) ; } ; }
if ( typeof JSON . parse !== 'function' ) { JSON . parse = function ( text , reviver ) { var j ; function walk ( holder , key ) { var k , v , value = holder [ key ] ; if ( value && typeof value === 'object' ) { for ( k in value ) { if ( Object . prototype . hasOwnProperty . call ( value , k ) ) { v = walk ( value , k ) ; if ( v !== undefined ) { value [ k ] = v ; } else { delete value [ k ] ; } } } }
return reviver . call ( holder , key , value ) ; }
text = String ( text ) ; cx . lastIndex = 0 ; if ( cx . test ( text ) ) { text = text . replace ( cx , function ( a ) { return '\\u' +
( '0000' + a . charCodeAt ( 0 ) . toString ( 16 ) ) . slice ( - 4 ) ; } ) ; }
if ( /^[\],:{}\s]*$/ . test ( text . replace ( /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g , '@' ) . replace ( /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g , ']' ) . replace ( /(?:^|:|,)(?:\s*\[)+/g , '' ) ) ) { j = eval ( '(' + text + ')' ) ; return typeof reviver === 'function' ? walk ( { '' : j } , '' ) : j ; }
throw new SyntaxError ( 'JSON.parse' ) ; } ; } } ( ) ) ;
/ *
* lib / js / core . js
* /
2012-02-20 07:05:23 +00:00
if ( ! console ) { var console = { log : function ( txt ) { errprint ( txt ) ; } } }
2012-02-14 06:14:13 +00:00
wn . versions . check ( ) ; $ ( document ) . bind ( 'ready' , function ( ) { var base = window . location . href . split ( '#' ) [ 0 ] ; $ . each ( $ ( 'a[softlink!="false"]' ) , function ( i , v ) { if ( v . href . substr ( 0 , base . length ) == base ) { var path = ( v . href . substr ( base . length ) ) ; if ( path . substr ( 0 , 1 ) != '#' ) { v . href = base + '#' + path ; } } } ) ; if ( ! wn . settings . no _history && window . location . hash ) { wn . page . set ( window . location . hash . substr ( 1 ) ) ; } } ) ;
/ *
* lib / js / legacy / globals . js
* /
wn . provide ( 'wn.widgets.form' ) ; wn . provide ( 'wn.widgets.report' ) ; wn . provide ( 'wn.utils' ) ; wn . provide ( 'wn.model' ) ; wn . provide ( 'wn.profile' ) ; wn . provide ( 'wn.session' ) ; wn . provide ( '_f' ) ; wn . provide ( '_p' ) ; wn . provide ( '_r' ) ; wn . provide ( '_c' ) ; wn . provide ( '_e' ) ; wn . provide ( '_startup_data' )
2012-02-17 08:34:55 +00:00
wn . settings . no _history = 1 ; var NEWLINE = '\n' ; var login _file = '' ; var version = 'v170' ; var profile = null ; var session = { } ; var is _testing = false ; var user = null ; var user _defaults = null ; var user _roles = null ; var user _fullname = null ; var user _email = null ; var user _img = { } ; var home _page = null ; var hide _autosuggest = null ; var page _body = null ; var pscript = { } ; var selector = null ; var top _index = 91 ; var _f = { } ; var _p = { } ; var _e = { } ; var _r = { } ; var FILTER _SEP = '\1' ; var _c = { } ; var widget _files = { '_f.FrmContainer' : 'form.compressed.js' , '_c.CalendarPopup' : 'widgets/form/date_picker.js' , '_r.ReportContainer' : 'report.compressed.js' , '_p.PrintQuery' : 'widgets/print_query.js' , 'Calendar' : 'widgets/calendar.js' , 'Recommendation' : 'widgets/recommend.js' , 'RatingWidget' : 'widgets/rating.js' }
2012-02-20 07:05:23 +00:00
var frms = { } ; var cur _frm = null ; var pscript = { } ; var validated = true ; var validation _message = '' ; var tinymce _loaded = null ; var cur _autosug = null ;
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / utils / datatype . js
* /
var startup _list = [ ] ; wn . utils . full _name = function ( fn , ln ) { return fn + ( ln ? ' ' : '' ) + ( ln ? ln : '' ) }
function fmt _money ( v ) { if ( v == null || v == '' ) return '0.00' ; v = ( v + '' ) . replace ( /,/g , '' ) ; v = parseFloat ( v ) ; if ( isNaN ( v ) ) { return '' ; } else { var cp = wn . control _panel ; var val = 2 ; if ( cp . currency _format == 'Millions' ) val = 3 ; v = v . toFixed ( 2 ) ; var delimiter = "," ; amount = v + '' ; var a = amount . split ( '.' , 2 )
var d = a [ 1 ] ; var i = parseInt ( a [ 0 ] ) ; if ( isNaN ( i ) ) { return '' ; }
var minus = '' ; if ( v < 0 ) { minus = '-' ; }
i = Math . abs ( i ) ; var n = new String ( i ) ; var a = [ ] ; if ( n . length > 3 )
{ var nn = n . substr ( n . length - 3 ) ; a . unshift ( nn ) ; n = n . substr ( 0 , n . length - 3 ) ; while ( n . length > val )
{ var nn = n . substr ( n . length - val ) ; a . unshift ( nn ) ; n = n . substr ( 0 , n . length - val ) ; } }
if ( n . length > 0 ) { a . unshift ( n ) ; }
n = a . join ( delimiter ) ; if ( d . length < 1 ) { amount = n ; }
else { amount = n + '.' + d ; }
amount = minus + amount ; return amount ; } }
function toTitle ( str ) { var word _in = str . split ( " " ) ; var word _out = [ ] ; for ( w in word _in ) { word _out [ w ] = word _in [ w ] . charAt ( 0 ) . toUpperCase ( ) + word _in [ w ] . slice ( 1 ) ; }
return word _out . join ( " " ) ; }
function is _null ( v ) { if ( v == null ) { return 1 } else if ( v == 0 ) { if ( ( v + '' ) . length >= 1 ) return 0 ; else return 1 ; } else { return 0 } }
function $s ( ele , v , ftype , fopt ) { if ( v == null ) v = '' ; if ( ftype == 'Text' || ftype == 'Small Text' ) { ele . innerHTML = v ? v . replace ( /\n/g , '<br>' ) : '' ; } else if ( ftype == 'Date' ) { v = dateutil . str _to _user ( v ) ; if ( v == null ) v = ''
ele . innerHTML = v ; } else if ( ftype == 'Link' && fopt ) { ele . innerHTML = '' ; doc _link ( ele , fopt , v ) ; } else if ( ftype == 'Currency' ) { ele . style . textAlign = 'right' ; if ( is _null ( v ) )
ele . innerHTML = '' ; else
ele . innerHTML = fmt _money ( v ) ; } else if ( ftype == 'Int' ) { ele . style . textAlign = 'right' ; ele . innerHTML = v ; } else if ( ftype == 'Check' ) { if ( v ) ele . innerHTML = '<img src="lib/images/ui/tick.gif">' ; else ele . innerHTML = '' ; } else { ele . innerHTML = v ; } }
function clean _smart _quotes ( s ) { if ( s ) { s = s . replace ( /\u2018/g , "'" ) ; s = s . replace ( /\u2019/g , "'" ) ; s = s . replace ( /\u201c/g , '"' ) ; s = s . replace ( /\u201d/g , '"' ) ; s = s . replace ( /\u2013/g , '-' ) ; s = s . replace ( /\u2014/g , '--' ) ; }
return s ; }
function copy _dict ( d ) { var n = { } ; for ( var k in d ) n [ k ] = d [ k ] ; return n ; }
function $p ( ele , top , left ) { ele . style . position = 'absolute' ; ele . style . top = top + 'px' ; ele . style . left = left + 'px' ; }
function replace _newlines ( t ) { return t ? t . replace ( /\n/g , '<br>' ) : '' ; }
function cstr ( s ) { if ( s == null ) return '' ; return s + '' ; }
function flt ( v , decimals ) { if ( v == null || v == '' ) return 0 ; v = ( v + '' ) . replace ( /,/g , '' ) ; v = parseFloat ( v ) ; if ( isNaN ( v ) )
v = 0 ; if ( decimals != null )
return v . toFixed ( decimals ) ; return v ; }
function esc _quotes ( s ) { if ( s == null ) s = '' ; return s . replace ( /'/ , "\'" ) ; }
var crop = function ( s , len ) { if ( s . length > len )
return s . substr ( 0 , len - 3 ) + '...' ; else
return s ; }
var strip = function ( s , chars ) { var s = lstrip ( s , chars )
s = rstrip ( s , chars ) ; return s ; }
var lstrip = function ( s , chars ) { if ( ! chars ) chars = [ '\n' , '\t' , ' ' ] ; var first _char = s . substr ( 0 , 1 ) ; while ( in _list ( chars , first _char ) ) { var s = s . substr ( 1 ) ; first _char = s . substr ( 0 , 1 ) ; }
return s ; }
var rstrip = function ( s , chars ) { if ( ! chars ) chars = [ '\n' , '\t' , ' ' ] ; var last _char = s . substr ( s . length - 1 ) ; while ( in _list ( chars , last _char ) ) { var s = s . substr ( 0 , this . length - 1 ) ; last _char = s . substr ( this . length - 1 ) ; }
return s ; }
function repl _all ( s , s1 , s2 ) { var idx = s . indexOf ( s1 ) ; while ( idx != - 1 ) { s = s . replace ( s1 , s2 ) ; idx = s . indexOf ( s1 ) ; }
return s ; }
function repl ( s , dict ) { if ( s == null ) return '' ; for ( key in dict ) s = repl _all ( s , '%(' + key + ')s' , dict [ key ] ) ; return s ; }
function keys ( obj ) { var mykeys = [ ] ; for ( key in obj ) mykeys [ mykeys . length ] = key ; return mykeys ; }
function values ( obj ) { var myvalues = [ ] ; for ( key in obj ) myvalues [ myvalues . length ] = obj [ key ] ; return myvalues ; }
function in _list ( list , item ) { for ( var i = 0 ; i < list . length ; i ++ )
if ( list [ i ] == item ) return true ; return false ; }
function has _common ( list1 , list2 ) { if ( ! list1 || ! list2 ) return false ; for ( var i = 0 ; i < list1 . length ; i ++ ) { if ( in _list ( list2 , list1 [ i ] ) ) return true ; }
return false ; }
var inList = in _list ; function add _lists ( l1 , l2 ) { var l = [ ] ; for ( var k in l1 ) l . push ( l1 [ k ] ) ; for ( var k in l2 ) l . push ( l2 [ k ] ) ; return l ; }
function docstring ( obj ) { var l = [ ] ; for ( key in obj ) { var v = obj [ key ] ; if ( v != null ) { if ( typeof ( v ) == typeof ( 1 ) ) { l [ l . length ] = "'" + key + "':" + ( v + '' ) ; } else { v = v + '' ; l [ l . length ] = "'" + key + "':'" + v . replace ( /'/g , "\\'" ) . replace ( /\n/g , "\\n" ) + "'" ; } } }
return "{" + l . join ( ',' ) + '}' ; }
function DocLink ( p , doctype , name , onload ) { var a = $a ( p , 'span' , 'link_type' ) ; a . innerHTML = a . dn = name ; a . dt = doctype ; a . onclick = function ( ) { loaddoc ( this . dt , this . dn , onload ) } ; return a ; }
var doc _link = DocLink ; var known _numbers = { 0 : 'zero' , 1 : 'one' , 2 : 'two' , 3 : 'three' , 4 : 'four' , 5 : 'five' , 6 : 'six' , 7 : 'seven' , 8 : 'eight' , 9 : 'nine' , 10 : 'ten' , 11 : 'eleven' , 12 : 'twelve' , 13 : 'thirteen' , 14 : 'fourteen' , 15 : 'fifteen' , 16 : 'sixteen' , 17 : 'seventeen' , 18 : 'eighteen' , 19 : 'nineteen' , 20 : 'twenty' , 30 : 'thirty' , 40 : 'forty' , 50 : 'fifty' , 60 : 'sixty' , 70 : 'seventy' , 80 : 'eighty' , 90 : 'ninety' }
function in _words ( n ) { var is _million = wn . control _panel . currency _format == 'Millions' ? 1 : 0 ; n = cint ( n )
if ( known _numbers [ n ] ) return known _numbers [ n ] ; var bestguess = n + '' ; var remainder = 0
if ( n <= 20 )
alert ( 'Error while converting to words' ) ; else if ( n < 100 ) { return in _words ( Math . floor ( n / 10 ) * 10 ) + '-' + in _words ( n % 10 ) ; } else if ( n < 1000 ) { bestguess = in _words ( Math . floor ( n / 100 ) ) + ' ' + 'hundred' ; remainder = n % 100 ; } else if ( ! is _million ) { if ( n < 100000 ) { bestguess = in _words ( Math . floor ( n / 1000 ) ) + ' ' + 'thousand' ; remainder = n % 1000 ; } else if ( n < 10000000 ) { bestguess = in _words ( Math . floor ( n / 100000 ) ) + ' ' + 'lakh' ; remainder = n % 100000 ; } else { bestguess = in _words ( Math . floor ( n / 10000000 ) ) + ' ' + 'crore'
remainder = n % 10000000 } } else { if ( n < 1000000 ) { bestguess = in _words ( Math . floor ( n / 1000 ) ) + ' ' + 'thousand' ; remainder = n % 1000 ; } else if ( n < 1000000000 ) { bestguess = in _words ( Math . floor ( n / 1000000 ) ) + ' ' + 'million' ; remainder = n % 1000000 ; } else { bestguess = in _words ( Math . floor ( n / 1000000000 ) ) + ' ' + 'billion'
remainder = n % 1000000000 } }
if ( remainder ) { if ( remainder >= 100 ) comma = ','
else comma = ''
return bestguess + comma + ' ' + in _words ( remainder ) ; } else { return bestguess ; } }
function roundNumber ( num , dec ) { var result = Math . round ( num * Math . pow ( 10 , dec ) ) / Math . pow ( 10 , dec ) ; return result ; }
/ *
* lib / js / legacy / utils / browser _detect . js
* /
var appVer = navigator . appVersion . toLowerCase ( ) ; var is _minor = parseFloat ( appVer ) ; var is _major = parseInt ( is _minor ) ; var iePos = appVer . indexOf ( 'msie' ) ; if ( iePos != - 1 ) { is _minor = parseFloat ( appVer . substring ( iePos + 5 , appVer . indexOf ( ';' , iePos ) ) )
is _major = parseInt ( is _minor ) ; }
var isIE = ( iePos != - 1 ) ; var isIE6 = ( isIE && is _major <= 6 ) ; var isIE7 = ( isIE && is _major >= 7 ) ; if ( /Firefox[\/\s](\d+\.\d+)/ . test ( navigator . userAgent ) ) { var isFF = 1 ; var ffversion = new Number ( RegExp . $1 )
if ( ffversion >= 3 ) var isFF3 = 1 ; else if ( ffversion >= 2 ) var isFF2 = 1 ; else if ( ffversion >= 1 ) var isFF1 = 1 ; }
var isSafari = navigator . userAgent . indexOf ( 'Safari' ) != - 1 ? 1 : 0 ; var isChrome = navigator . userAgent . indexOf ( 'Chrome' ) != - 1 ? 1 : 0 ;
/ *
* lib / js / legacy / utils / datetime . js
* /
function same _day ( d1 , d2 ) { if ( d1 . getFullYear ( ) == d2 . getFullYear ( ) && d1 . getMonth ( ) == d2 . getMonth ( ) && d1 . getDate ( ) == d2 . getDate ( ) ) return true ; else return false ; }
var month _list = [ 'Jan' , 'Feb' , 'Mar' , 'Apr' , 'May' , 'Jun' , 'Jul' , 'Aug' , 'Sep' , 'Oct' , 'Nov' , 'Dec' ] ; var month _last = { 1 : 31 , 2 : 28 , 3 : 31 , 4 : 30 , 5 : 31 , 6 : 30 , 7 : 31 , 8 : 31 , 9 : 30 , 10 : 31 , 11 : 30 , 12 : 31 }
var month _list _full = [ 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' , 'October' , 'November' , 'December' ] ; var week _list = [ 'Sun' , 'Mon' , 'Tue' , 'Wed' , 'Thu' , 'Fri' , 'Sat' ] ; var week _list _full = [ 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' ] ; function int _to _str ( i , len ) { i = '' + i ; if ( i . length < len ) for ( c = 0 ; c < ( len - i . length ) ; c ++ ) i = '0' + i ; return i }
wn . datetime = { str _to _obj : function ( d ) { if ( ! d ) return new Date ( ) ; var tm = [ null , null ] ; if ( d . search ( ' ' ) != - 1 ) { var tm = d . split ( ' ' ) [ 1 ] . split ( ':' ) ; var d = d . split ( ' ' ) [ 0 ] ; }
if ( d . search ( '-' ) != - 1 ) { var t = d . split ( '-' ) ; return new Date ( t [ 0 ] , t [ 1 ] - 1 , t [ 2 ] , tm [ 0 ] , tm [ 1 ] ) ; } else if ( d . search ( '/' ) != - 1 ) { var t = d . split ( '/' ) ; return new Date ( t [ 0 ] , t [ 1 ] - 1 , t [ 2 ] , tm [ 0 ] , tm [ 1 ] ) ; } else { return new Date ( ) ; } } , obj _to _str : function ( d ) { return d . getFullYear ( ) + '-' + int _to _str ( d . getMonth ( ) + 1 , 2 ) + '-' + int _to _str ( d . getDate ( ) , 2 ) ; } , obj _to _user : function ( d ) { return dateutil . str _to _user ( dateutil . obj _to _str ( d ) ) ; } , get _diff : function ( d1 , d2 ) { return ( ( d1 - d2 ) / 86400000 ) ; } , add _days : function ( d , days ) { d . setTime ( d . getTime ( ) + ( days * 24 * 60 * 60 * 1000 ) ) ; return d } , add _months : function ( d , months ) { dt = dateutil . str _to _obj ( d )
new _dt = new Date ( dt . getFullYear ( ) , dt . getMonth ( ) + months , dt . getDate ( ) )
if ( new _dt . getDate ( ) != dt . getDate ( ) ) { return dateutil . month _end ( new Date ( dt . getFullYear ( ) , dt . getMonth ( ) + months , 1 ) ) }
return dateutil . obj _to _str ( new _dt ) ; } , month _start : function ( ) { var d = new Date ( ) ; return d . getFullYear ( ) + '-' + int _to _str ( d . getMonth ( ) + 1 , 2 ) + '-01' ; } , month _end : function ( d ) { if ( ! d ) var d = new Date ( ) ; var m = d . getMonth ( ) + 1 ; var y = d . getFullYear ( ) ; last _date = month _last [ m ] ; if ( m == 2 && ( y % 4 ) == 0 && ( ( y % 100 ) != 0 || ( y % 400 ) == 0 ) )
last _date = 29 ; return y + '-' + int _to _str ( m , 2 ) + '-' + last _date ; } , get _user _fmt : function ( ) { var t = wn . control _panel . date _format ; if ( ! t ) t = 'dd-mm-yyyy' ; return t ; } , str _to _user : function ( val , no _time _str ) { var user _fmt = dateutil . get _user _fmt ( ) ; var time _str = '' ; if ( val == null || val == '' ) return null ; if ( val . search ( ':' ) != - 1 ) { var tmp = val . split ( ' ' ) ; if ( tmp [ 1 ] )
time _str = ' ' + tmp [ 1 ] ; var d = tmp [ 0 ] ; } else { var d = val ; }
if ( no _time _str ) time _str = '' ; d = d . split ( '-' ) ; if ( d . length == 3 ) { if ( user _fmt == 'dd-mm-yyyy' )
val = d [ 2 ] + '-' + d [ 1 ] + '-' + d [ 0 ] + time _str ; else if ( user _fmt == 'dd/mm/yyyy' )
val = d [ 2 ] + '/' + d [ 1 ] + '/' + d [ 0 ] + time _str ; else if ( user _fmt == 'yyyy-mm-dd' )
val = d [ 0 ] + '-' + d [ 1 ] + '-' + d [ 2 ] + time _str ; else if ( user _fmt == 'mm/dd/yyyy' )
val = d [ 1 ] + '/' + d [ 2 ] + '/' + d [ 0 ] + time _str ; else if ( user _fmt == 'mm-dd-yyyy' )
val = d [ 1 ] + '-' + d [ 2 ] + '-' + d [ 0 ] + time _str ; }
return val ; } , full _str : function ( ) { var d = new Date ( ) ; return d . getFullYear ( ) + '-' + ( d . getMonth ( ) + 1 ) + '-' + d . getDate ( ) + ' '
+ d . getHours ( ) + ':' + d . getMinutes ( ) + ':' + d . getSeconds ( ) ; } , user _to _str : function ( d ) { var user _fmt = this . get _user _fmt ( ) ; if ( user _fmt == 'dd-mm-yyyy' ) { var d = d . split ( '-' ) ; return d [ 2 ] + '-' + d [ 1 ] + '-' + d [ 0 ] ; }
else if ( user _fmt == 'dd/mm/yyyy' ) { var d = d . split ( '/' ) ; return d [ 2 ] + '-' + d [ 1 ] + '-' + d [ 0 ] ; }
else if ( user _fmt == 'yyyy-mm-dd' ) { return d ; }
else if ( user _fmt == 'mm/dd/yyyy' ) { var d = d . split ( '/' ) ; return d [ 2 ] + '-' + d [ 0 ] + '-' + d [ 1 ] ; }
else if ( user _fmt == 'mm-dd-yyyy' ) { var d = d . split ( '-' ) ; return d [ 2 ] + '-' + d [ 0 ] + '-' + d [ 1 ] ; } } , global _date _format : function ( d ) { if ( d . substr ) d = this . str _to _obj ( d ) ; return d . getDate ( ) + ' ' + month _list _full [ d . getMonth ( ) ] + ' ' + d . getFullYear ( ) ; } , get _today : function ( ) { var today = new Date ( ) ; var m = ( today . getMonth ( ) + 1 ) + '' ; if ( m . length == 1 ) m = '0' + m ; var d = today . getDate ( ) + '' ; if ( d . length == 1 ) d = '0' + d ; return today . getFullYear ( ) + '-' + m + '-' + d ; } , get _cur _time : function ( ) { var d = new Date ( ) ; var hh = d . getHours ( ) + ''
var mm = cint ( d . getMinutes ( ) / 5 ) * 5 + ''
return ( hh . length == 1 ? '0' + hh : hh ) + ':' + ( mm . length == 1 ? '0' + mm : mm ) ; } }
wn . datetime . only _date = function ( val ) { if ( val == null || val == '' ) return null ; if ( val . search ( ':' ) != - 1 ) { var tmp = val . split ( ' ' ) ; var d = tmp [ 0 ] . split ( '-' ) ; } else { var d = val . split ( '-' ) ; }
if ( d . length == 3 )
val = d [ 2 ] + '-' + d [ 1 ] + '-' + d [ 0 ] ; return val ; }
wn . datetime . time _to _ampm = function ( v ) { if ( ! v ) { var d = new Date ( ) ; var t = [ d . getHours ( ) , cint ( d . getMinutes ( ) / 5 ) * 5 ] } else { var t = v . split ( ':' ) ; }
if ( t . length != 2 ) { show _alert ( '[set_time] Incorect time format' ) ; return ; }
if ( cint ( t [ 0 ] ) == 0 ) var ret = [ '12' , t [ 1 ] , 'AM' ] ; else if ( cint ( t [ 0 ] ) < 12 ) var ret = [ cint ( t [ 0 ] ) + '' , t [ 1 ] , 'AM' ] ; else if ( cint ( t [ 0 ] ) == 12 ) var ret = [ '12' , t [ 1 ] , 'PM' ] ; else var ret = [ ( cint ( t [ 0 ] ) - 12 ) + '' , t [ 1 ] , 'PM' ] ; return ret ; }
wn . datetime . time _to _hhmm = function ( hh , mm , am ) { if ( am == 'AM' && hh == '12' ) { hh = '00' ; } else if ( am == 'PM' && hh != '12' ) { hh = cint ( hh ) + 12 ; }
return hh + ':' + mm ; }
function prettyDate ( time ) { if ( ! time ) return ''
var date = new Date ( ( time || "" ) . replace ( /-/g , "/" ) . replace ( /[TZ]/g , " " ) . replace ( /\.[0-9]*/ , "" ) ) , diff = ( ( ( new Date ( ) ) . getTime ( ) - date . getTime ( ) ) / 1000 ) , day _diff = Math . floor ( diff / 86400 ) ; if ( isNaN ( day _diff ) || day _diff < 0 )
return '' ; return day _diff == 0 && ( diff < 60 && "just now" || diff < 120 && "1 minute ago" || diff < 3600 && Math . floor ( diff / 60 ) + " minutes ago" || diff < 7200 && "1 hour ago" || diff < 86400 && Math . floor ( diff / 3600 ) + " hours ago" ) || day _diff == 1 && "Yesterday" || day _diff < 7 && day _diff + " days ago" || day _diff < 31 && Math . ceil ( day _diff / 7 ) + " weeks ago" || day _diff < 365 && Math . ceil ( day _diff / 30 ) + " months ago" || "more than " + Math . floor ( day _diff / 365 ) + " year(s) ago" ; }
if ( typeof jQuery != "undefined" )
jQuery . fn . prettyDate = function ( ) { return this . each ( function ( ) { var date = prettyDate ( this . title ) ; if ( date )
jQuery ( this ) . text ( date ) ; } ) ; } ; var comment _when = prettyDate ; wn . datetime . comment _when = prettyDate ; var date = dateutil = wn . datetime ; var get _today = wn . datetime . get _today
var time _to _ampm = wn . datetime . time _to _ampm ; var time _to _hhmm = wn . datetime . time _to _hhmm ; var only _date = wn . datetime . only _date ;
/ *
* lib / js / legacy / utils / dom . js
* /
wn . dom . set _unique _id = function ( ele ) { var id = 'unique-' + wn . dom . id _count ; ele . setAttribute ( 'id' , id ) ; wn . dom . id _count ++ ; return id ; }
wn . tinymce = { add _simple : function ( ele , height ) { if ( ele . myid ) { tinyMCE . execCommand ( 'mceAddControl' , true , ele . myid ) ; return ; }
ele . myid = wn . dom . set _unique _id ( ele ) ; $ ( ele ) . tinymce ( { script _url : 'lib/js/legacy/tiny_mce_33/tiny_mce.js' , height : height ? height : '200px' , theme : "advanced" , theme _advanced _buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,outdent,indent,link,unlink,forecolor,backcolor,code," , theme _advanced _buttons2 : "" , theme _advanced _buttons3 : "" , theme _advanced _toolbar _location : "top" , theme _advanced _toolbar _align : "left" , theme _advanced _path : false , theme _advanced _resizing : false } ) ; } , remove : function ( ele ) { tinyMCE . execCommand ( 'mceRemoveControl' , true , ele . myid ) ; } , get _value : function ( ele ) { return tinymce . get ( ele . myid ) . getContent ( ) ; } }
wn . ele = { link : function ( args ) { var span = $a ( args . parent , 'span' , 'link_type' , args . style ) ; span . loading _img = $a ( args . parent , 'img' , '' , { margin : '0px 4px -2px 4px' , display : 'none' } ) ; span . loading _img . src = 'lib/images/ui/button-load.gif' ; span . innerHTML = args . label ; span . user _onclick = args . onclick ; span . onclick = function ( ) { if ( ! this . disabled ) this . user _onclick ( this ) ; }
span . set _working = function ( ) { this . disabled = 1 ; $di ( this . loading _img ) ; }
span . done _working = function ( ) { this . disabled = 0 ; $dh ( this . loading _img ) ; }
return span ; } }
function $ln ( parent , label , onclick , style ) { return wn . ele . link ( { parent : parent , label : label , onclick : onclick , style : style } ) }
function $btn ( parent , label , onclick , style , css _class , is _ajax ) { wn . require ( 'lib/js/wn/ui/button.js' ) ; if ( css _class === 'green' ) css _class = 'primary' ; return new wn . ui . Button ( { parent : parent , label : label , onclick : onclick , style : style , is _ajax : is _ajax , css _class : css _class } ) . btn ; }
$item _normal = function ( ele ) { $y ( ele , { padding : '6px 8px' , cursor : 'pointer' , marginRight : '8px' , whiteSpace : 'nowrap' , overflow : 'hidden' , borderBottom : '1px solid #DDD' } ) ; $bg ( ele , '#FFF' ) ; $fg ( ele , '#000' ) ; }
$item _active = function ( ele ) { $bg ( ele , '#FE8' ) ; $fg ( ele , '#000' ) ; }
$item _selected = function ( ele ) { $bg ( ele , '#777' ) ; $fg ( ele , '#FFF' ) ; }
$item _pressed = function ( ele ) { $bg ( ele , '#F90' ) ; $fg ( ele , '#FFF' ) ; } ; ( function ( $ ) { $ . fn . set _working = function ( ) { var ele = this . get ( 0 ) ; if ( ele . loading _img ) { $di ( ele . loading _img ) } else { ele . disabled = 1 ; ele . loading _img = $a ( ele . parentNode , 'img' , '' , { marginLeft : '4px' , marginBottom : '-2px' , display : 'inline' } ) ; ele . loading _img . src = 'lib/images/ui/button-load.gif' ; } }
$ . fn . done _working = function ( ) { var ele = this . get ( 0 ) ; ele . disabled = 0 ; if ( ele . loading _img ) { $dh ( ele . loading _img ) } ; } } ) ( jQuery ) ; function set _opacity ( ele , ieop ) { var op = ieop / 100 ; if ( ele . filters ) { try { ele . filters . item ( "DXImageTransform.Microsoft.Alpha" ) . opacity = ieop ; } catch ( e ) { ele . style . filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + ieop + ')' ; } } else { ele . style . opacity = op ; } }
$br = function ( ele , r , corners ) { if ( corners ) { var cl = [ 'top-left' , 'top-right' , 'bottom-right' , 'bottom-left' ] ; for ( var i = 0 ; i < 4 ; i ++ ) { if ( corners [ i ] ) { $ ( ele ) . css ( '-moz-border-radius-' + cl [ i ] . replace ( '-' , '' ) , r ) . css ( '-webkit-' + cl [ i ] + '-border-radius' , r ) ; } } } else { $ ( ele ) . css ( '-moz-border-radius' , r ) . css ( '-webkit-border-radius' , r ) . css ( 'border-radius' , r ) ; } }
$bs = function ( ele , r ) { $ ( ele ) . css ( '-moz-box-shadow' , r ) . css ( '-webkit-box-shadow' , r ) . css ( 'box-shadow' , r ) ; }
function empty _select ( s ) { if ( s . custom _select ) { s . empty ( ) ; return ; }
if ( s . inp ) s = s . inp ; if ( s ) { var tmplen = s . length ; for ( var i = 0 ; i < tmplen ; i ++ ) s . options [ 0 ] = null ; } }
function sel _val ( s ) { if ( s . custom _select ) { return s . inp . value ? s . inp . value : '' ; }
if ( s . inp ) s = s . inp ; try { if ( s . selectedIndex < s . options . length ) return s . options [ s . selectedIndex ] . value ; else return '' ; } catch ( err ) { return '' ; } }
function add _sel _options ( s , list , sel _val , o _style ) { if ( s . custom _select ) { s . set _options ( list )
if ( sel _val ) s . inp . value = sel _val ; return ; }
if ( s . inp ) s = s . inp ; for ( var i = 0 , len = list . length ; i < len ; i ++ ) { var o = new Option ( list [ i ] , list [ i ] , false , ( list [ i ] == sel _val ? true : false ) ) ; if ( o _style ) $y ( o , o _style ) ; s . options [ s . options . length ] = o ; } }
function cint ( v , def ) { v = v + '' ; v = lstrip ( v , [ '0' ] ) ; v = parseInt ( v ) ; if ( isNaN ( v ) ) v = def ? def : 0 ; return v ; }
function validate _email ( id ) { if ( strip ( id ) . search ( "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" ) == - 1 ) return 0 ; else return 1 ; }
function validate _spl _chars ( txt ) { if ( txt . search ( /^[a-zA-Z0-9_\- ]*$/ ) == - 1 ) return 1 ; else return 0 ; }
function d2h ( d ) { return cint ( d ) . toString ( 16 ) ; }
function h2d ( h ) { return parseInt ( h , 16 ) ; }
var $n = '\n' ; function set _title ( t ) { document . title = ( wn . title _prefix ? ( wn . title _prefix + ' - ' ) : '' ) + t ; }
function $a ( parent , newtag , className , cs , innerHTML , onclick ) { if ( parent && parent . substr ) parent = $i ( parent ) ; var c = document . createElement ( newtag ) ; if ( parent )
parent . appendChild ( c ) ; if ( className ) { if ( newtag . toLowerCase ( ) == 'img' )
c . src = className
else
c . className = className ; }
if ( cs ) $y ( c , cs ) ; if ( innerHTML ) c . innerHTML = innerHTML ; if ( onclick ) c . onclick = onclick ; return c ; }
2012-02-17 08:34:55 +00:00
function $a _input ( p , in _type , attributes , cs ) { if ( ! attributes ) attributes = { } ; var $input = $ ( p ) . append ( '<input type="' + in _type + '">' ) . find ( 'input:last' ) ; for ( key in attributes )
$input . attr ( key , attributes [ key ] ) ; var input = $input . get ( 0 ) ; if ( cs )
$y ( input , cs ) ; return input ; }
2012-02-14 06:14:13 +00:00
function $dh ( d ) { if ( d && d . substr ) d = $i ( d ) ; if ( d && d . style . display . toLowerCase ( ) != 'none' ) d . style . display = 'none' ; }
function $ds ( d ) { if ( d && d . substr ) d = $i ( d ) ; var t = 'block' ; if ( d && in _list ( [ 'span' , 'img' , 'button' ] , d . tagName . toLowerCase ( ) ) )
t = 'inline'
if ( d && d . style . display . toLowerCase ( ) != t )
d . style . display = t ; }
function $di ( d ) { if ( d && d . substr ) d = $i ( d ) ; if ( d ) d . style . display = 'inline' ; }
function $i ( id ) { if ( ! id ) return null ; if ( id && id . appendChild ) return id ; return document . getElementById ( id ) ; }
function $t ( parent , txt ) { if ( parent . substr ) parent = $i ( parent ) ; return parent . appendChild ( document . createTextNode ( txt ) ) ; }
function $w ( e , w ) { if ( e && e . style && w ) e . style . width = w ; }
function $h ( e , h ) { if ( e && e . style && h ) e . style . height = h ; }
function $bg ( e , w ) { if ( e && e . style && w ) e . style . backgroundColor = w ; }
function $fg ( e , w ) { if ( e && e . style && w ) e . style . color = w ; }
function $op ( e , w ) { if ( e && e . style && w ) { set _opacity ( e , w ) ; } }
function $y ( ele , s ) { if ( ele && s ) { for ( var i in s ) ele . style [ i ] = s [ i ] ; } ; return ele ; }
function $yt ( tab , r , c , s ) { var rmin = r ; var rmax = r ; if ( r == '*' ) { rmin = 0 ; rmax = tab . rows . length - 1 ; }
if ( r . search && r . search ( '-' ) != - 1 ) { r = r . split ( '-' ) ; rmin = cint ( r [ 0 ] ) ; rmax = cint ( r [ 1 ] ) ; }
var cmin = c ; var cmax = c ; if ( c == '*' ) { cmin = 0 ; cmax = tab . rows [ 0 ] . cells . length - 1 ; }
if ( c . search && c . search ( '-' ) != - 1 ) { c = c . split ( '-' ) ; rmin = cint ( c [ 0 ] ) ; rmax = cint ( c [ 1 ] ) ; }
for ( var ri = rmin ; ri <= rmax ; ri ++ ) { for ( var ci = cmin ; ci <= cmax ; ci ++ )
$y ( $td ( tab , ri , ci ) , s ) ; } }
function set _style ( txt ) { var se = document . createElement ( 'style' ) ; se . type = "text/css" ; if ( se . styleSheet ) { se . styleSheet . cssText = txt ; } else { se . appendChild ( document . createTextNode ( txt ) ) ; }
document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( se ) ; }
function make _table ( parent , nr , nc , table _width , widths , cell _style , table _style ) { var t = $a ( parent , 'table' ) ; t . style . borderCollapse = 'collapse' ; if ( table _width ) t . style . width = table _width ; if ( cell _style ) t . cell _style = cell _style ; for ( var ri = 0 ; ri < nr ; ri ++ ) { var r = t . insertRow ( ri ) ; for ( var ci = 0 ; ci < nc ; ci ++ ) { var c = r . insertCell ( ci ) ; if ( ri == 0 && widths && widths [ ci ] ) { c . style . width = widths [ ci ] ; }
if ( cell _style ) { for ( var s in cell _style ) c . style [ s ] = cell _style [ s ] ; } } }
t . append _row = function ( ) { return append _row ( this ) ; }
if ( table _style ) $y ( t , table _style ) ; return t ; }
function append _row ( t , at , style ) { var r = t . insertRow ( at ? at : t . rows . length ) ; if ( t . rows . length > 1 ) { for ( var i = 0 ; i < t . rows [ 0 ] . cells . length ; i ++ ) { var c = r . insertCell ( i ) ; if ( style ) $y ( c , style ) ; } }
return r }
function $td ( t , r , c ) { if ( r < 0 ) r = t . rows . length + r ; if ( c < 0 ) c = t . rows [ 0 ] . cells . length + c ; return t . rows [ r ] . cells [ c ] ; }
function $sum ( t , cidx ) { var s = 0 ; if ( cidx < 1 ) cidx = t . rows [ 0 ] . cells . length + cidx ; for ( var ri = 0 ; ri < t . rows . length ; ri ++ ) { var c = t . rows [ ri ] . cells [ cidx ] ; if ( c . div ) s += flt ( c . div . innerHTML ) ; else if ( c . value ) s += flt ( c . value ) ; else s += flt ( c . innerHTML ) ; }
return s ; }
function objpos ( obj ) { if ( obj . substr ) obj = $i ( obj ) ; var p = $ ( obj ) . offset ( ) ; return { x : cint ( p . left ) , y : cint ( p . top ) } }
function get _screen _dims ( ) { var d = { } ; d . w = 0 ; d . h = 0 ; if ( typeof ( window . innerWidth ) == 'number' ) { d . w = window . innerWidth ; d . h = window . innerHeight ; } else if ( document . documentElement && ( document . documentElement . clientWidth || document . documentElement . clientHeight ) ) { d . w = document . documentElement . clientWidth ; d . h = document . documentElement . clientHeight ; } else if ( document . body && ( document . body . clientWidth || document . body . clientHeight ) ) { d . w = document . body . clientWidth ; d . h = document . body . clientHeight ; }
return d }
function get _page _size ( ) { return [ $ ( document ) . height ( ) , $ ( document ) . width ( ) ] ; }
function get _scroll _top ( ) { var st = 0 ; if ( document . documentElement && document . documentElement . scrollTop )
st = document . documentElement . scrollTop ; else if ( document . body && document . body . scrollTop )
st = document . body . scrollTop ; return st ; }
function get _cookie ( c ) { var t = "" + document . cookie ; var ind = t . indexOf ( c ) ; if ( ind == - 1 || c == "" ) return "" ; var ind1 = t . indexOf ( ';' , ind ) ; if ( ind1 == - 1 ) ind1 = t . length ; return unescape ( t . substring ( ind + c . length + 1 , ind1 ) ) ; }
wn . urllib = { get _arg : function ( name ) { name = name . replace ( /[\[]/ , "\\\[" ) . replace ( /[\]]/ , "\\\]" ) ; var regexS = "[\\?&]" + name + "=([^&#]*)" ; var regex = new RegExp ( regexS ) ; var results = regex . exec ( window . location . href ) ; if ( results == null )
return "" ; else
return decodeURIComponent ( results [ 1 ] ) ; } , get _dict : function ( ) { var d = { }
var t = window . location . href . split ( '?' ) [ 1 ] ; if ( ! t ) return d ; if ( t . indexOf ( '#' ) != - 1 ) t = t . split ( '#' ) [ 0 ] ; if ( ! t ) return d ; t = t . split ( '&' ) ; for ( var i = 0 ; i < t . length ; i ++ ) { var a = t [ i ] . split ( '=' ) ; d [ decodeURIComponent ( a [ 0 ] ) ] = decodeURIComponent ( a [ 1 ] ) ; }
return d ; } , get _base _url : function ( ) { var url = window . location . href . split ( '#' ) [ 0 ] . split ( '?' ) [ 0 ] . split ( 'index.html' ) [ 0 ] ; if ( url . substr ( url . length - 1 , 1 ) == '/' ) url = url . substr ( 0 , url . length - 1 )
2012-02-17 05:08:49 +00:00
return url } , get _file _url : function ( file _id ) { return repl ( 'files/%(fn)s' , { fn : file _id } ) } }
2012-02-14 06:14:13 +00:00
get _url _arg = wn . urllib . get _arg ; get _url _dict = wn . urllib . get _dict ; var user _img = { }
var user _img _queue = { } ; var user _img _loading = [ ] ; set _user _img = function ( img , username , get _latest , img _id ) { function set _it ( i ) { if ( user _img [ username ] == 'no_img_m' )
i . src = 'lib/images/ui/no_img_m.gif' ; else if ( user _img [ username ] == 'no_img_f' )
i . src = 'lib/images/ui/no_img_f.gif' ; else { ac _id = wn . control _panel . account _id ; i . src = repl ( 'cgi-bin/getfile.cgi?ac=%(ac)s&name=%(fn)s' , { fn : user _img [ username ] , ac : ac _id } ) ; } }
if ( img _id ) { user _img [ username ] = img _id ; set _it ( img ) ; return ; }
if ( user _img [ username ] && ! get _latest ) { set _it ( img ) ; } else { if ( in _list ( user _img _loading , username ) ) { if ( ! user _img _queue [ username ] )
user _img _queue [ username ] = [ ] ; user _img _queue [ username ] . push ( img ) ; return ; }
$c ( 'webnotes.profile.get_user_img' , { username : username } , function ( r , rt ) { delete user _img _loading [ user _img _loading . indexOf ( username ) ] ; user _img [ username ] = r . message ; if ( user _img _queue [ username ] ) { var q = user _img _queue [ username ] ; for ( var i in q ) { set _it ( q [ i ] ) ; } }
set _it ( img ) ; } , null , 1 ) ; user _img _loading . push ( username ) ; } }
/ *
* lib / js / legacy / utils / handler . js
* /
var outUrl = "index.cgi" ; var NULL _CHAR = '^\5*' ; function checkResponse ( r , on _timeout , no _spinner , freeze _msg ) { try { if ( r . readyState == 4 && r . status == 200 ) return true ; else return false ; } catch ( e ) { msgprint ( "error:Request timed out, try again" ) ; if ( on _timeout )
on _timeout ( ) ; hide _loading ( ) ; if ( freeze _msg )
unfreeze ( ) ; return false ; } }
var pending _req = 0 ; function newHttpReq ( ) { if ( ! isIE )
var r = new XMLHttpRequest ( ) ; else if ( window . ActiveXObject )
var r = new ActiveXObject ( "Microsoft.XMLHTTP" ) ; return r ; }
function $c ( command , args , fn , on _timeout , no _spinner , freeze _msg , btn ) { var req = newHttpReq ( ) ; ret _fn = function ( ) { if ( checkResponse ( req , on _timeout , no _spinner , freeze _msg ) ) { if ( btn ) $ ( btn ) . done _working ( ) ; if ( ! no _spinner )
hide _loading ( ) ; var rtxt = req . responseText ; try { var r = JSON . parse ( rtxt ) ; } catch ( e ) { msgprint ( 'Handler Exception:' + rtxt ) ; return ; }
if ( freeze _msg ) unfreeze ( ) ; if ( ! validate _session ( r , rtxt ) ) return ; if ( r . exc ) { errprint ( r . exc ) ; console . log ( r . exc ) ; } ; if ( r . server _messages ) { msgprint ( r . server _messages ) ; } ; if ( r . docs ) { LocalDB . sync ( r . docs ) ; }
saveAllowed = true ; if ( fn ) fn ( r , rtxt ) ; } }
if ( btn ) $ ( btn ) . set _working ( ) ; req . onreadystatechange = ret _fn ; req . open ( "POST" , outUrl , true ) ; req . setRequestHeader ( "ENCTYPE" , "multipart/form-data" ) ; req . setRequestHeader ( "Content-Type" , "application/x-www-form-urlencoded; charset=UTF-8" ) ; args [ 'cmd' ] = command ; req . send ( makeArgString ( args ) ) ; if ( ! no _spinner ) set _loading ( ) ; if ( freeze _msg ) freeze ( freeze _msg , 1 ) ; }
function validate _session ( r , rt ) { if ( r . message == 'Logged In' ) { start _sid = get _cookie ( 'sid' ) ; return true ; }
if ( start _sid && start _sid != get _cookie ( 'sid' ) && user && user != 'Guest' ) { page _body . set _session _changed ( ) ; return ; }
if ( r . exc && r . session _status == 'Session Expired' ) { resume _session ( ) ; return ; }
if ( r . exc && r . session _status == 'Logged Out' ) { msgprint ( 'You have been logged out' ) ; setTimeout ( 'redirect_to_login()' , 3000 ) ; return ; }
if ( r . exc && r . exc _type && r . exc _type == 'PermissionError' ) { loadpage ( '_home' ) ; }
return true ; }
function $c _obj ( doclist , method , arg , call _back , no _spinner , freeze _msg , btn ) { var args = { 'method' : method , 'arg' : ( typeof arg == 'string' ? arg : JSON . stringify ( arg ) ) }
if ( typeof doclist == 'string' ) args . doctype = doclist ; else args . docs = compress _doclist ( doclist )
$c ( 'runserverobj' , args , call _back , null , no _spinner , freeze _msg , btn ) ; }
function $c _page ( module , page , method , arg , call _back , no _spinner , freeze _msg , btn ) { if ( arg && ! arg . substr ) arg = JSON . stringify ( arg ) ; $c ( module + '.page.' + page + '.' + page + '.' + method , { 'arg' : arg } , call _back , null , no _spinner , freeze _msg , btn ) ; }
wn . call = function ( args ) { if ( args . module && args . page ) { $c _page ( args . module , args . page , args . method , args . args , args . callback , args . no _spinner , false , args . btn ) ; } else if ( args . docs ) { $c _obj ( args . doc , args . method , args . args , args . callback , args . no _spinner , false , args . btn ) ; } else { $c ( args . method , args . args , args . callback , false , args . no _spinner , false , args . btn ) ; } }
function $c _obj _csv ( doclist , method , arg ) { var args = { }
args . cmd = 'runserverobj' ; args . as _csv = 1 ; args . method = method ; args . arg = arg ; if ( doclist . substr )
args . doctype = doclist ; else
args . docs = compress _doclist ( doclist ) ; open _url _post ( outUrl , args ) ; }
function my _eval ( co ) { var w = window ; if ( ! w . execScript ) { if ( /Gecko/ . test ( navigator . userAgent ) ) { eval ( co , w ) ; } else { eval . call ( w , co ) ; } } else { w . execScript ( co ) ; } }
function makeArgString ( dict ) { var varList = [ ] ; for ( key in dict ) { varList [ varList . length ] = key + '=' + encodeURIComponent ( dict [ key ] ) ; }
return varList . join ( '&' ) ; }
function open _url _post ( URL , PARAMS , new _window ) { var temp = document . createElement ( "form" ) ; temp . action = URL ; temp . method = "POST" ; temp . style . display = "none" ; if ( new _window ) { temp . target = '_blank' ; }
for ( var x in PARAMS ) { var opt = document . createElement ( "textarea" ) ; opt . name = x ; opt . value = PARAMS [ x ] ; temp . appendChild ( opt ) ; }
document . body . appendChild ( temp ) ; temp . submit ( ) ; return temp ; }
/ *
* lib / js / legacy / utils / msgprint . js
* /
var msg _dialog ; function msgprint ( msg , issmall , callback ) { if ( ! msg ) return ; if ( typeof ( msg ) != 'string' )
msg = JSON . stringify ( msg ) ; if ( issmall ) { show _alert ( msg ) ; return ; }
if ( msg . substr ( 0 , 8 ) == '__small:' ) { show _alert ( msg . substr ( 8 ) ) ; return ; }
if ( ! msg _dialog ) { msg _dialog = new Dialog ( 500 , 200 , "Message" ) ; msg _dialog . make _body ( [ [ 'HTML' , 'Msg' ] ] )
msg _dialog . onhide = function ( ) { msg _dialog . msg _area . innerHTML = '' ; $dh ( msg _dialog . msg _icon ) ; if ( msg _dialog . custom _onhide ) msg _dialog . custom _onhide ( ) ; }
$y ( msg _dialog . rows [ 'Msg' ] , { fontSize : '14px' , lineHeight : '1.5em' , padding : '16px' } )
var t = make _table ( msg _dialog . rows [ 'Msg' ] , 1 , 2 , '100%' , [ '20px' , '250px' ] , { padding : '2px' , verticalAlign : 'Top' } ) ; msg _dialog . msg _area = $td ( t , 0 , 1 ) ; msg _dialog . msg _icon = $a ( $td ( t , 0 , 0 ) , 'img' ) ; }
if ( ! msg _dialog . display ) msg _dialog . show ( ) ; var has _msg = msg _dialog . msg _area . innerHTML ? 1 : 0 ; var m = $a ( msg _dialog . msg _area , 'div' , '' ) ; if ( has _msg ) $y ( m , { marginTop : '4px' } ) ; $dh ( msg _dialog . msg _icon ) ; if ( msg . substr ( 0 , 6 ) . toLowerCase ( ) == 'error:' ) { msg _dialog . msg _icon . src = 'lib/images/icons/error.gif' ; $di ( msg _dialog . msg _icon ) ; msg = msg . substr ( 6 ) ; } else if ( msg . substr ( 0 , 8 ) . toLowerCase ( ) == 'message:' ) { msg _dialog . msg _icon . src = 'lib/images/icons/application.gif' ; $di ( msg _dialog . msg _icon ) ; msg = msg . substr ( 8 ) ; } else if ( msg . substr ( 0 , 3 ) . toLowerCase ( ) == 'ok:' ) { msg _dialog . msg _icon . src = 'lib/images/icons/accept.gif' ; $di ( msg _dialog . msg _icon ) ; msg = msg . substr ( 3 ) ; }
m . innerHTML = replace _newlines ( msg ) ; if ( m . offsetHeight > 200 ) { $y ( m , { height : '200px' , width : '400px' , overflow : 'auto' } ) }
msg _dialog . custom _onhide = callback ; }
2012-02-20 11:01:55 +00:00
var growl _area ; function show _alert ( txt , id ) { if ( ! growl _area ) { growl _area = $a ( popup _cont , 'div' , '' , { position : 'fixed' , bottom : '8px' , right : '8px' , width : '320px' , zIndex : 10 } ) ; }
var wrapper = $a ( growl _area , 'div' , '' , { position : 'relative' } ) ; var body = $a ( wrapper , 'div' , 'notice' ) ; var c = $a ( body , 'div' , 'wn-icon ic-round_delete' , { cssFloat : 'right' } ) ; $ ( c ) . click ( function ( ) { $dh ( this . wrapper ) } ) ; c . wrapper = wrapper ; var t = $a ( body , 'div' , '' , { color : '#FFF' } ) ; $ ( t ) . html ( txt ) ; if ( id ) { $ ( t ) . attr ( 'id' , id ) ; }
$ ( wrapper ) . hide ( ) . fadeIn ( 1000 ) ; }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / utils / shortcut . js
* /
( function ( jQuery ) { jQuery . hotkeys = { version : "0.8" , specialKeys : { 8 : "backspace" , 9 : "tab" , 13 : "return" , 16 : "shift" , 17 : "ctrl" , 18 : "alt" , 19 : "pause" , 20 : "capslock" , 27 : "esc" , 32 : "space" , 33 : "pageup" , 34 : "pagedown" , 35 : "end" , 36 : "home" , 37 : "left" , 38 : "up" , 39 : "right" , 40 : "down" , 45 : "insert" , 46 : "del" , 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9" , 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/" , 112 : "f1" , 113 : "f2" , 114 : "f3" , 115 : "f4" , 116 : "f5" , 117 : "f6" , 118 : "f7" , 119 : "f8" , 120 : "f9" , 121 : "f10" , 122 : "f11" , 123 : "f12" , 144 : "numlock" , 145 : "scroll" , 191 : "/" , 224 : "meta" } , shiftNums : { "`" : "~" , "1" : "!" , "2" : "@" , "3" : "#" , "4" : "$" , "5" : "%" , "6" : "^" , "7" : "&" , "8" : "*" , "9" : "(" , "0" : ")" , "-" : "_" , "=" : "+" , ";" : ": " , "'" : "\"" , "," : "<" , "." : ">" , "/" : "?" , "\\" : "|" } } ; function keyHandler ( handleObj ) { if ( typeof handleObj . data !== "string" ) { return ; }
var origHandler = handleObj . handler , keys = handleObj . data . toLowerCase ( ) . split ( " " ) ; handleObj . handler = function ( event ) { if ( this !== event . target && ( /textarea|select/i . test ( event . target . nodeName ) || event . target . type === "text" ) ) { return ; }
var special = event . type !== "keypress" && jQuery . hotkeys . specialKeys [ event . which ] , character = String . fromCharCode ( event . which ) . toLowerCase ( ) , key , modif = "" , possible = { } ; if ( event . altKey && special !== "alt" ) { modif += "alt+" ; }
if ( event . ctrlKey && special !== "ctrl" ) { modif += "ctrl+" ; }
if ( event . metaKey && ! event . ctrlKey && special !== "meta" ) { modif += "meta+" ; }
if ( event . shiftKey && special !== "shift" ) { modif += "shift+" ; }
if ( special ) { possible [ modif + special ] = true ; } else { possible [ modif + character ] = true ; possible [ modif + jQuery . hotkeys . shiftNums [ character ] ] = true ; if ( modif === "shift+" ) { possible [ jQuery . hotkeys . shiftNums [ character ] ] = true ; } }
for ( var i = 0 , l = keys . length ; i < l ; i ++ ) { if ( possible [ keys [ i ] ] ) { return origHandler . apply ( this , arguments ) ; } } } ; }
jQuery . each ( [ "keydown" , "keyup" , "keypress" ] , function ( ) { jQuery . event . special [ this ] = { add : keyHandler } ; } ) ; } ) ( jQuery ) ;
/ *
* 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 , 'div' ) ; else
this . wrapper = document . createElement ( 'div' ) ; this . label _area = $a ( this . wrapper , 'div' , '' , { margin : '8px 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' , 'field_label' )
this . label _icon = $a ( this . label _area , 'img' , '' , { margin : '-3px 4px -3px 4px' } ) ; $dh ( this . label _icon ) ; this . label _icon . src = 'lib/images/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 = 'lib/images/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 , 'div' ) ; this . disp _area = $a ( this . wrapper , 'div' ) ; }
if ( this . in _grid ) { if ( this . label _area ) $dh ( this . label _area ) ; } else { this . input _area . className = 'input_area' ; $y ( this . wrapper , { marginBottom : '4px' } ) ; 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' , 'field_description' , '' , this . df . description )
if ( in _list ( [ 'Text Editor' , 'Code' ] , this . df . fieldtype ) )
$ ( this . desc _area ) . addClass ( 'field_description_top' ) ; } }
Field . prototype . get _status = function ( ) { if ( this . in _filter ) this . not _in _form = this . in _filter ; if ( this . not _in _form ) { return 'Write' ; }
var fn = this . df . fieldname ? this . df . fieldname : this . df . label ; this . df = get _field ( this . doctype , fn , this . docname ) ; 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 . set _status || this . set _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 . set _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 ; }
2012-02-17 06:36:33 +00:00
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 )
2012-02-14 06:14:13 +00:00
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 ( ) ; }
if ( in _list ( [ 'Data' , 'Text' , 'Small Text' , 'Code' ] , this . df . fieldtype ) )
val = clean _smart _quotes ( val ) ; 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' } ) ; } }
2012-02-17 08:34:55 +00:00
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 )
2012-02-14 06:14:13 +00:00
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 ) { }
2012-02-17 08:34:55 +00:00
this . txt . field _object = this ; } }
2012-02-17 10:20:07 +00:00
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 ; }
2012-02-14 06:14:13 +00:00
this . input . name = this . df . fieldname ; this . input . onchange = function ( ) { if ( ! me . last _value ) me . last _value = '' ; if ( me . validate )
me . input . value = me . validate ( me . input . value ) ; me . set ( me . input . value ) ; if ( me . format _input )
me . format _input ( ) ; if ( in _list ( [ 'Currency' , 'Float' , 'Int' ] , me . df . fieldtype ) ) { if ( flt ( me . last _value ) == flt ( me . input . value ) ) { me . last _value = me . input . value ; return ; } }
me . last _value = me . input . value ; 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' ) { wn . require ( 'lib/js/legacy/widgets/autosuggest.js' ) ; if ( this . suggest _icon ) $di ( this . suggest _icon ) ; this . set _get _query = function ( ) { }
this . get _query = function ( doc , dt , dn ) { return repl ( 'SELECT DISTINCT `%(fieldname)s` FROM `tab%(dt)s` WHERE `%(fieldname)s` LIKE "%s" LIMIT 50' , { fieldname : me . df . fieldname , dt : me . df . parent } ) }
var opts = { script : '' , json : true , maxresults : 10 , link _field : this } ; this . as = new AutoSuggest ( this . input , opts ) ; } }
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' ) ; wn . require ( 'lib/css/legacy/jquery-ui.css' ) ; $ ( 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 ; } ; var _link _onchange _flag = null ; 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 , 'ic-zoom' , 'ic-sq_next' , 'ic-sq_plus' ) ; me . setup _buttons ( ) ; me . onrefresh = function ( ) { if ( me . can _create && cur _frm . doc . docstatus == 0 ) $ds ( me . btn2 ) ; else $dh ( me . btn2 ) ; } }
me . txt . field _object = this ; me . set _onchange ( ) ; me . input . set _input = function ( val ) { if ( val == undefined ) val = '' ; me . txt . value = val ; }
me . get _value = function ( ) { return me . txt . value ; }
wn . require ( 'lib/js/legacy/widgets/autosuggest.js' ) ; var opts = { script : '' , json : true , maxresults : 10 , link _field : me } ; this . as = new AutoSuggest ( me . txt , opts ) ; }
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 _onchange = function ( ) { var me = this ; me . txt . onchange = function ( e ) { if ( cur _autosug ) return ; if ( _link _onchange _flag ) { return ; }
_link _onchange _flag = 1 ; me . refresh _label _icon ( ) ; if ( me . not _in _form ) { _link _onchange _flag = 0 ; return ; }
if ( cur _frm ) { if ( me . txt . value == locals [ me . doctype ] [ me . docname ] [ me . df . fieldname ] ) { me . set ( me . txt . value ) ; me . run _trigger ( ) ; setTimeout ( '_link_onchange_flag = 0' , 500 ) ; return ; } }
me . set ( me . txt . value ) ; if ( _f . cur _grid _cell )
_f . cur _grid _cell . grid . cell _deselect ( ) ; if ( ! me . txt . value ) { me . run _trigger ( ) ; setTimeout ( '_link_onchange_flag = 0' , 500 ) ; 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' : me . txt . value , 'options' : me . df . options , 'fetch' : fetch } , function ( r , rt ) { setTimeout ( '_link_onchange_flag = 0' , 500 ) ; if ( selector && selector . display ) return ; if ( r . message == 'Ok' ) { 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 = 'lib/images/ui/tick.gif' ; $dh ( this . checkimg ) ; }
2012-02-17 08:34:55 +00:00
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 ( ) ; } )
2012-02-14 06:14:13 +00:00
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' , 'field_description' , '' , 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 )
2012-02-17 08:34:55 +00:00
me . validate ( ) ; me . set ( sel _val ( this ) ) ; me . run _trigger ( ) ; }
2012-02-14 06:14:13 +00:00
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 ( v . split ( "," ) , 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 ( ) { }
2012-02-17 08:34:55 +00:00
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 ( ) ; }
2012-02-14 06:14:13 +00:00
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 ) { 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 , 'div' , 'wn-icon ' + iconsrc , { width : '16px' } ) ; 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 , 'div' , 'wn-icon ' + iconsrc1 , { width : '16px' } ) ; me . btn1 . setAttribute ( 'title' , 'Open Link' ) ; }
if ( iconsrc2 ) { var c3 = tab . rows [ 0 ] . insertCell ( 3 ) ; $y ( c3 , { width : '20px' } ) ; me . btn2 = $a ( c3 , 'div' , 'wn-icon ' + iconsrc2 , { width : '16px' } ) ; 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 . substr ( 0 , 20 ) + ( ( me . df . label . length > 20 ) ? '..' : '' ) , null , { maxWidth : '170px' , fontWeight : 'bold' } , null , 1 )
this . input . onclick = function ( ) { if ( me . not _in _form ) return ; this . disabled = 'disabled' ; if ( cur _frm . cscript [ me . df . label ] && ( ! me . in _filter ) ) { cur _frm . runclientscript ( me . df . label , me . doctype , me . docname ) ; this . disabled = false ; } else { cur _frm . runscript ( me . df . options , me ) ; this . disabled = false ; } } }
_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 ; }
/ *
* lib / js / wn / ui / dialog . js
* /
wn . widgets . FieldGroup = function ( ) { this . first _button = false ; this . make _fields = function ( body , fl ) { $y ( this . body , { padding : '11px' } ) ; this . fields _dict = { } ; for ( var i = 0 ; i < fl . length ; i ++ ) { var df = fl [ i ] ; var div = $a ( body , 'div' , '' , { margin : '6px 0px' } )
f = make _field ( df , null , div , null ) ; f . not _in _form = 1 ; this . fields _dict [ df . fieldname ] = f
f . refresh ( ) ; if ( df . fieldtype == 'Button' && ! this . first _button ) { $ ( f . input ) . addClass ( 'primary' ) ; this . first _button = true ; } } }
this . get _values = function ( ) { var ret = { } ; var errors = [ ] ; for ( var key in this . fields _dict ) { var f = this . fields _dict [ key ] ; var v = f . get _value ? f . get _value ( ) : null ; if ( f . df . reqd && ! v )
errors . push ( f . df . label + ' is mandatory' ) ; if ( v ) ret [ f . df . fieldname ] = v ; }
if ( errors . length ) { msgprint ( '<b>Please check the following Errors</b>\n' + errors . join ( '\n' ) ) ; return null ; }
return ret ; }
this . set _value = function ( key , val ) { var f = this . fields _dict [ key ] ; if ( f ) { f . set _input ( val ) ; f . refresh _mandatory ( ) ; } }
this . set _values = function ( dict ) { for ( var key in dict ) { if ( this . fields _dict [ key ] ) { this . set _value ( key , dict [ key ] ) ; } } }
this . clear = function ( ) { for ( key in this . fields _dict ) { var f = this . fields _dict [ key ] ; if ( f ) { f . set _input ( f . df [ 'default' ] || '' ) ; } } } }
wn . widgets . Dialog = function ( opts ) { this . opts = opts ; this . display = false ; this . make = function ( opts ) { if ( opts )
this . opts = opts ; if ( ! this . opts . width ) this . opts . width = 480 ; this . wrapper = $a ( popup _cont , 'div' , 'dialog_wrapper' ) ; if ( this . opts . width )
this . wrapper . style . width = this . opts . width + 'px' ; this . make _head ( ) ; this . body = $a ( this . wrapper , 'div' , 'dialog_body' ) ; if ( this . opts . fields )
this . make _fields ( this . body , this . opts . fields ) ; }
this . make _head = function ( ) { var me = this ; this . head = $a ( this . wrapper , 'div' , 'dialog_head' ) ; var t = make _table ( this . head , 1 , 2 , '100%' , [ '100%' , '16px' ] , { padding : '2px' } ) ; $y ( $td ( t , 0 , 0 ) , { paddingLeft : '16px' , fontWeight : 'bold' , fontSize : '14px' , textAlign : 'center' } ) ; $y ( $td ( t , 0 , 1 ) , { textAlign : 'right' } ) ; var img = $a ( $td ( t , 0 , 01 ) , 'img' , '' , { cursor : 'pointer' } ) ; img . src = 'lib/images/icons/close.gif' ; this . title _text = $td ( t , 0 , 0 ) ; this . set _title ( this . opts . title ) ; img . onclick = function ( ) { if ( me . oncancel ) me . oncancel ( ) ; me . hide ( ) ; }
this . cancel _img = img ; }
this . set _title = function ( t ) { this . title _text . innerHTML = t ? t : '' ; }
this . set _postion = function ( ) { var d = get _screen _dims ( ) ; this . wrapper . style . left = ( ( d . w - cint ( this . wrapper . style . width ) ) / 2 ) + 'px' ; this . wrapper . style . top = ( get _scroll _top ( ) + 60 ) + 'px' ; top _index ++ ; $y ( this . wrapper , { zIndex : top _index } ) ; }
this . show = function ( ) { if ( this . display ) return ; this . set _postion ( )
$ds ( this . wrapper ) ; freeze ( ) ; this . display = true ; cur _dialog = this ; if ( this . onshow ) this . onshow ( ) ; }
this . hide = function ( ) { if ( this . onhide ) this . onhide ( ) ; unfreeze ( ) ; $dh ( this . wrapper ) ; if ( cur _autosug ) cur _autosug . clearSuggestions ( ) ; this . display = false ; cur _dialog = null ; }
this . no _cancel = function ( ) { $dh ( this . cancel _img ) ; }
if ( opts ) this . make ( ) ; }
2012-02-17 08:34:55 +00:00
wn . widgets . Dialog . prototype = new wn . widgets . FieldGroup ( ) ; $ ( document ) . bind ( 'keydown' , function ( e ) { if ( cur _dialog && ! cur _dialog . no _cancel _flag && e . which == 27 ) { cur _dialog . hide ( ) ; } } ) ;
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / widgets / dialog . js
* /
var cur _dialog ; var top _index = 91 ; function Dialog ( w , h , title , content ) { this . make ( { width : w , title : title } ) ; if ( content ) this . make _body ( content ) ; this . onshow = '' ; this . oncancel = '' ; this . no _cancel _flag = 0 ; this . display = false ; this . first _button = false ; }
Dialog . prototype = new wn . widgets . Dialog ( )
Dialog . prototype . make _body = function ( content ) { this . rows = { } ; this . widgets = { } ; for ( var i in content ) this . make _row ( content [ i ] ) ; }
Dialog . prototype . clear _inputs = function ( d ) { for ( var wid in this . widgets ) { var w = this . widgets [ wid ] ; var tn = w . tagName ? w . tagName . toLowerCase ( ) : '' ; if ( tn == 'input' || tn == 'textarea' ) { w . value = '' ; } else if ( tn == 'select' ) { sel _val ( w . options [ 0 ] . value ) ; } else if ( w . txt ) { w . txt . value = '' ; } else if ( w . input ) { w . input . value = '' ; } } }
Dialog . prototype . make _row = function ( d ) { var me = this ; this . rows [ d [ 1 ] ] = $a ( this . body , 'div' , 'dialog_row' ) ; var row = this . rows [ d [ 1 ] ] ; if ( d [ 0 ] != 'HTML' ) { var t = make _table ( row , 1 , 2 , '100%' , [ '30%' , '70%' ] ) ; row . tab = t ; var c1 = $td ( t , 0 , 0 ) ; var c2 = $td ( t , 0 , 1 ) ; if ( d [ 0 ] != 'Check' && d [ 0 ] != 'Button' )
$t ( c1 , d [ 1 ] ) ; }
if ( d [ 0 ] == 'HTML' ) { if ( d [ 2 ] ) row . innerHTML = d [ 2 ] ; this . widgets [ d [ 1 ] ] = row ; }
else if ( d [ 0 ] == 'Check' ) { var i = $a _input ( c2 , 'checkbox' , '' , { width : '20px' } ) ; c1 . innerHTML = d [ 1 ] ; this . widgets [ d [ 1 ] ] = i ; }
else if ( d [ 0 ] == 'Data' ) { c1 . innerHTML = d [ 1 ] ; c2 . style . overflow = 'auto' ; this . widgets [ d [ 1 ] ] = $a _input ( c2 , 'text' ) ; if ( d [ 2 ] ) $a ( c2 , 'div' , 'field_description' ) . innerHTML = d [ 2 ] ; }
else if ( d [ 0 ] == 'Link' ) { c1 . innerHTML = d [ 1 ] ; var f = make _field ( { fieldtype : 'Link' , 'label' : d [ 1 ] , 'options' : d [ 2 ] } , '' , c2 , this , 0 , 1 ) ; f . not _in _form = 1 ; f . dialog = this ; f . refresh ( ) ; this . widgets [ d [ 1 ] ] = f . input ; }
else if ( d [ 0 ] == 'Date' ) { c1 . innerHTML = d [ 1 ] ; var f = make _field ( { fieldtype : 'Date' , 'label' : d [ 1 ] , 'options' : d [ 2 ] } , '' , c2 , this , 0 , 1 ) ; f . not _in _form = 1 ; f . refresh ( ) ; f . dialog = this ; this . widgets [ d [ 1 ] ] = f . input ; }
else if ( d [ 0 ] == 'Password' ) { c1 . innerHTML = d [ 1 ] ; c2 . style . overflow = 'auto' ; this . widgets [ d [ 1 ] ] = $a _input ( c2 , 'password' ) ; if ( d [ 3 ] ) $a ( c2 , 'div' , 'field_description' ) . innerHTML = d [ 3 ] ; }
else if ( d [ 0 ] == 'Select' ) { c1 . innerHTML = d [ 1 ] ; this . widgets [ d [ 1 ] ] = $a ( c2 , 'select' , '' , { width : '160px' } )
if ( d [ 2 ] ) $a ( c2 , 'div' , 'field_description' ) . innerHTML = d [ 2 ] ; if ( d [ 3 ] ) add _sel _options ( this . widgets [ d [ 1 ] ] , d [ 3 ] , d [ 3 ] [ 0 ] ) ; }
else if ( d [ 0 ] == 'Text' ) { c1 . innerHTML = d [ 1 ] ; c2 . style . overflow = 'auto' ; this . widgets [ d [ 1 ] ] = $a ( c2 , 'textarea' ) ; if ( d [ 2 ] ) $a ( c2 , 'div' , 'field_description' ) . innerHTML = d [ 2 ] ; }
else if ( d [ 0 ] == 'Button' ) { c2 . style . height = '32px' ; var b = $btn ( c2 , d [ 1 ] , function ( btn ) { if ( btn . _onclick ) btn . _onclick ( me ) } , null , null , 1 ) ; b . dialog = me ; if ( ! this . first _button ) { $ ( b ) . addClass ( 'primary' ) ; this . first _button = true ; }
if ( d [ 2 ] ) { b . _onclick = d [ 2 ] ; }
this . widgets [ d [ 1 ] ] = b ; } }
/ *
* lib / js / wn / ui / listing . js
* /
wn . widgets . Listing = function ( opts ) { this . opts = opts ; this . page _length = 20 ; this . btns = { } ; this . start = 0 ; var me = this ; this . make = function ( opts ) { this . wrapper = $a ( this . opts . parent , 'div' ) ; this . filters _area = $a ( this . wrapper , 'div' , 'listing-filters' ) ; this . toolbar _area = $a ( this . wrapper , 'div' , 'listing-toolbar' ) ; this . results _area = $a ( this . wrapper , 'div' , 'listing-results' ) ; this . more _button _area = $a ( this . wrapper , 'div' , 'listing-more' ) ; this . no _results _area = $a ( this . wrapper , 'div' , 'help_box' , { display : 'none' } , ( this . opts . no _result _message ? this . opts . no _result _message : 'No results' ) ) ; if ( opts ) this . opts = opts ; this . page _length = this . opts . page _length ? this . opts . page _length : this . page _length ; this . make _toolbar ( ) ; this . make _filters ( ) ; this . make _more _button ( ) ; }
this . make _filters = function ( ) { if ( this . opts . filters ) { $ds ( this . filters _area ) ; this . filters = new wn . widgets . FieldGroup ( this . filters _area , this . opts . fields ) ; } }
this . make _toolbar = function ( ) { if ( ! this . opts . hide _refresh ) { this . ref _img = $a ( this . toolbar _area , 'span' , 'link_type' , { color : '#888' } , '[refresh]' ) ; this . ref _img . onclick = function ( ) { me . run ( ) ; }
this . loading _img = $a ( this . toolbar _area , 'img' , 'lib/images/ui/button-load.gif' , { display : 'none' , marginLeft : '3px' , marginBottom : '-2px' } ) ; }
if ( this . opts . new _doctype ) { this . new _btn = $btn ( this . toolbar _area , 'New ' + get _doctype _label ( this . opts . new _doctype ) , function ( ) { newdoc ( me . opts . new _doctype , me . opts . new _doc _onload , me . opts . new _doc _indialog , me . opts . new _doc _onsave ) ; } , { marginLeft : '7px' } ) ; } }
this . make _more _button = function ( ) { this . more _btn = $btn ( this . more _button _area , 'More...' , function ( ) { me . more _btn . set _working ( ) ; me . run ( function ( ) { me . more _btn . done _working ( ) ; } , 1 ) ; } , '' , 0 , 1 ) ; $y ( this . more _btn . loading _img , { marginBottom : '0px' } ) ; }
this . clear = function ( ) { this . results _area . innerHTML = '' ; this . table = null ; $ds ( this . results _area ) ; $dh ( this . no _results _area ) ; }
this . make _results = function ( r , rt ) { if ( this . start == 0 ) this . clear ( ) ; $dh ( this . more _button _area ) ; if ( this . loading _img ) $dh ( this . loading _img )
if ( r . values && r . values . length ) { this . values = r . values ; var m = Math . min ( r . values . length , this . page _length ) ; for ( var i = 0 ; i < m ; i ++ ) { var row = this . add _row ( ) ; this . opts . render _row ( row , r . values [ i ] , this , i ) ; }
this . start += m ; if ( r . values . length > this . page _length ) $ds ( this . more _button _area ) ; } else { if ( this . start == 0 ) { $dh ( this . results _area ) ; $ds ( this . no _results _area ) ; } }
if ( this . onrun ) this . onrun ( ) ; if ( this . opts . onrun ) this . opts . onrun ( ) ; }
this . add _row = function ( ) { return $a ( this . results _area , 'div' , '' , ( opts . cell _style ? opts . cell _style : { padding : '3px 0px' } ) ) ; }
this . run = function ( callback , append ) { if ( callback )
this . onrun = callback ; if ( ! append )
this . start = 0 ; this . query = this . opts . get _query ? this . opts . get _query ( ) : this . opts . query ; this . add _limits ( ) ; args = { query _max : this . query _max || this . opts . query _max || '' }
args . simple _query = this . query ; args . as _dict = 1 ; if ( this . loading _img ) $di ( this . loading _img ) ; wn . call ( { method : 'webnotes.widgets.query_builder.runquery' , args : args , callback : function ( r , rt ) { me . make _results ( r , rt ) } , no _spinner : this . opts . no _loading , btn : this . opts . run _btn } ) ; }
this . refresh = this . run ; this . add _limits = function ( ) { this . query += ' LIMIT ' + this . start + ',' + ( this . page _length + 1 ) ; }
if ( opts ) this . make ( ) ; }
/ *
* lib / js / legacy / widgets / layout . js
* /
function Layout ( parent , width ) { if ( parent && parent . substr ) { parent = $i ( parent ) ; }
this . wrapper = $a ( parent , 'div' , '' , { display : 'none' } ) ; if ( width ) { this . width = this . wrapper . style . width ; }
this . myrows = [ ] ; }
Layout . prototype . addrow = function ( ) { this . cur _row = new LayoutRow ( this , this . wrapper ) ; this . myrows [ this . myrows . length ] = this . cur _row ; return this . cur _row }
Layout . prototype . addsubrow = function ( ) { this . cur _row = new LayoutRow ( this , this . cur _row . main _body ) ; this . myrows [ this . myrows . length ] = this . cur _row ; return this . cur _row }
Layout . prototype . addcell = function ( width ) { return this . cur _row . addCell ( width ) ; }
Layout . prototype . setcolour = function ( col ) { $bg ( cc , col ) ; }
Layout . prototype . show = function ( ) { $ds ( this . wrapper ) ; }
Layout . prototype . hide = function ( ) { $dh ( this . wrapper ) ; }
Layout . prototype . close _borders = function ( ) { if ( this . with _border ) { this . myrows [ this . myrows . length - 1 ] . wrapper . style . borderBottom = '1px solid #000' ; } }
function LayoutRow ( layout , parent ) { this . layout = layout ; this . wrapper = $a ( parent , 'div' ) ; this . main _head = $a ( this . wrapper , 'div' ) ; this . main _body = $a ( this . wrapper , 'div' ) ; if ( layout . with _border ) { this . wrapper . style . border = '1px solid #000' ; this . wrapper . style . borderBottom = '0px' ; }
this . header = $a ( this . main _body , 'div' , '' , { padding : ( layout . with _border ? '0px 8px' : '0px' ) } ) ; this . body = $a ( this . main _body , 'div' ) ; this . table = $a ( this . body , 'table' , '' , { width : '100%' , borderCollapse : 'collapse' } ) ; this . row = this . table . insertRow ( 0 ) ; this . mycells = [ ] ; }
LayoutRow . prototype . hide = function ( ) { $dh ( this . wrapper ) ; }
LayoutRow . prototype . show = function ( ) { $ds ( this . wrapper ) ; }
LayoutRow . prototype . addCell = function ( wid ) { var lc = new LayoutCell ( this . layout , this , wid ) ; this . mycells [ this . mycells . length ] = lc ; return lc ; }
function LayoutCell ( layout , layoutRow , width ) { if ( width ) { var w = width + '' ; if ( w . substr ( w . length - 2 , 2 ) != 'px' ) { if ( w . substr ( w . length - 1 , 1 ) != "%" ) { width = width + '%' } ; } }
this . width = width ; this . layout = layout ; var cidx = layoutRow . row . cells . length ; this . cell = layoutRow . row . insertCell ( cidx ) ; this . cell . style . verticalAlign = 'top' ; this . set _width ( layoutRow . row , width ) ; var h = $a ( this . cell , 'div' , '' , { padding : ( layout . with _border ? '0px 8px' : '0px' ) } ) ; this . wrapper = $a ( this . cell , 'div' , '' , { padding : ( layout . with _border ? '8px' : '8px 0px' ) } ) ; layout . cur _cell = this . wrapper ; layout . cur _cell . header = h ; }
LayoutCell . prototype . set _width = function ( row , width ) { var w = 100 ; var n _cells = row . cells . length ; var cells _with _no _width = n _cells ; if ( width ) { $y ( row . cells [ n _cells - 1 ] , { width : cint ( width ) + '%' } ) } else { row . cells [ n _cells - 1 ] . estimated _width = 1 ; }
for ( var i = 0 ; i < n _cells ; i ++ ) { if ( ! row . cells [ i ] . estimated _width ) { w = w - cint ( row . cells [ i ] . style . width ) ; cells _with _no _width -- ; } }
for ( var i = 0 ; i < n _cells ; i ++ ) { if ( row . cells [ i ] . estimated _width )
$y ( row . cells [ i ] , { width : cint ( w / cells _with _no _width ) + '%' } ) } }
LayoutCell . prototype . show = function ( ) { $ds ( this . wrapper ) ; }
LayoutCell . prototype . hide = function ( ) { $dh ( this . wrapper ) ; }
/ *
* lib / js / legacy / webpage / page _header . js
* /
2012-02-20 07:05:23 +00:00
var def _ph _style = { wrapper : { marginBottom : '16px' , backgroundColor : '#EEE' } , main _heading : { } , sub _heading : { marginBottom : '8px' , color : '#555' , display : 'none' } , separator : { borderTop : '3px solid #777' } , toolbar _area : { padding : '3px 0px' , display : 'none' , borderBottom : '1px solid #AAA' } }
2012-02-14 06:14:13 +00:00
function PageHeader ( parent , main _text , sub _text ) { this . wrapper = $a ( parent , 'div' , 'page_header' ) ; this . t1 = make _table ( $a ( this . wrapper , 'div' , '' , def _ph _style . wrapper . backgroundColor ) , 1 , 2 , '100%' , [ null , '100px' ] , { padding : '2px' } ) ; $y ( this . t1 , { borderCollapse : 'collapse' } )
2012-02-20 07:05:23 +00:00
this . lhs = $td ( this . t1 , 0 , 0 ) ; this . main _head = $a ( this . lhs , 'h1' , '' , def _ph _style . main _heading ) ; this . sub _head = $a ( this . lhs , 'h4' , '' , def _ph _style . sub _heading ) ; this . separator = $a ( this . wrapper , 'div' , '' , def _ph _style . separator ) ; this . toolbar _area = $a ( this . wrapper , 'div' , '' , def _ph _style . toolbar _area ) ; this . padding _area = $a ( this . wrapper , 'div' , '' , { padding : '3px' } ) ; $y ( $td ( this . t1 , 0 , 1 ) , { textAlign : 'right' , padding : '3px' } ) ; this . close _btn = $a ( $td ( this . t1 , 0 , 1 ) , 'span' , 'close' , { } , '×' ) ; this . close _btn . onclick = function ( ) { nav _obj . show _last _open ( ) ; } ; if ( main _text ) this . main _head . innerHTML = main _text ; if ( sub _text ) this . sub _head . innerHTML = sub _text ; this . buttons = { } ; this . buttons2 = { } ; }
2012-02-14 06:14:13 +00:00
PageHeader . prototype . add _button = function ( label , fn , bold , icon , green ) { var tb = this . toolbar _area ; if ( this . buttons [ label ] ) return ; var btn = $btn ( tb , label , fn , { marginRight : '4px' } , ( green ? 'primary' : '' ) ) ; if ( bold ) $y ( btn , { fontWeight : 'bold' } ) ; this . buttons [ label ] = btn ; $ds ( this . toolbar _area ) ; return btn ; }
PageHeader . prototype . clear _toolbar = function ( ) { this . toolbar _area . innerHTML = '' ; this . buttons = { } ; }
PageHeader . prototype . make _buttonset = function ( ) { $ ( this . toolbar _area ) . buttonset ( ) ; }
/ *
* lib / js / legacy / widgets / select . js
* /
function SelectWidget ( parent , options , width , editable , bg _color ) { var me = this ; this . inp = $a ( parent , 'select' ) ; if ( options ) add _sel _options ( this . inp , options ) ; if ( width ) $y ( this . inp , { width : width } ) ; this . set _width = function ( w ) { $y ( this . inp , { width : w } ) } ; this . set _options = function ( o ) { add _sel _options ( this . inp , o ) ; }
this . inp . onchange = function ( ) { if ( me . onchange ) me . onchange ( this ) ; }
return ; }
/ *
* lib / js / legacy / webpage / history . js
* /
var nav _obj = { }
nav _obj . observers = [ ] ; nav _obj . add _observer = function ( o ) { nav _obj . observers . push ( o ) ; }
nav _obj . ol = [ ] ; nav _obj . open _notify = function ( t , dt , dn , no _history ) { if ( nav _obj . ol . length ) { var tmp = nav _obj . ol [ nav _obj . ol . length - 1 ] ; if ( tmp && tmp [ 0 ] == t && tmp [ 1 ] == dt && tmp [ 2 ] == dn ) return ; }
if ( ! no _history ) { var tmp = [ ] ; for ( var i in nav _obj . ol )
if ( ! ( nav _obj . ol [ i ] [ 0 ] == t && nav _obj . ol [ i ] [ 1 ] == dt && nav _obj . ol [ i ] [ 2 ] == dn ) ) tmp . push ( nav _obj . ol [ i ] ) ; nav _obj . ol = tmp ; nav _obj . ol . push ( [ t , dt , dn ] )
en _t = encodeURIComponent ( t ) ; en _dt = encodeURIComponent ( dt ) ; en _dn = dn ? encodeURIComponent ( dn ) : '' ; if ( en _t == 'Page' ) { var id = en _dt + ( dn ? ( '/' + en _dn ) : '' ) } else { var id = en _t + '/' + en _dt + ( dn ? ( '/' + en _dn ) : '' ) }
if ( nav _obj . on _open )
nav _obj . on _open ( id ) ; if ( window . location . hash != '!' + id ) { window . location . hash = '!' + id ; } }
2012-02-14 11:55:31 +00:00
nav _obj . notify _observers ( t , dt , dn ) ; if ( wn . boot . analytics _code ) { try { eval ( wn . boot . analytics _code ) ; } catch ( e ) { console . log ( e ) ; } } }
2012-02-14 06:14:13 +00:00
nav _obj . notify _observers = function ( t , dt , dn ) { for ( var i = 0 ; i < nav _obj . observers . length ; i ++ ) { var o = nav _obj . observers [ i ] ; if ( o && o . notify ) o . notify ( t , dt , dn ) ; } }
nav _obj . rename _notify = function ( dt , oldn , newn ) { for ( var i = 0 ; i < nav _obj . ol . length ; i ++ ) { var o = nav _obj . ol [ i ] ; if ( o [ 1 ] == dt && o [ 2 ] == oldn ) o [ 2 ] = newn ; } }
nav _obj . show _last _open = function ( ) { var l = nav _obj . ol [ nav _obj . ol . length - 2 ] ; delete nav _obj . ol [ nav _obj . ol . length - 1 ] ; if ( ! l ) loadpage ( '_home' ) ; else if ( l [ 0 ] == 'Page' ) { loadpage ( l [ 1 ] ) ; } else if ( l [ 0 ] == 'Report' ) { loadreport ( l [ 1 ] , l [ 2 ] ) ; } else if ( l [ 0 ] == 'Form' ) { loaddoc ( l [ 1 ] , l [ 2 ] ) ; } else if ( l [ 0 ] == 'DocBrowser' || l [ 0 ] == 'List' ) { loaddocbrowser ( l [ 1 ] ) ; } }
var _history _current ; function history _get _name ( t ) { var parts = [ ] ; if ( t . length >= 3 ) { for ( var i = 2 ; i < t . length ; i ++ ) { parts . push ( t [ i ] ) ; } }
return parts . join ( '/' ) }
nav _obj . get _page = function ( loc ) { if ( ! loc ) loc = window . location . hash ; if ( loc . substr ( 0 , 1 ) == '#' ) { loc = loc . substr ( 1 ) ; }
if ( loc . substr ( 0 , 1 ) == '!' ) { loc = loc . substr ( 1 ) ; }
if ( ! in _list ( [ 'Page/' , 'Form/' , 'Repor' , 'DocBr' , 'List/' ] , loc . substr ( 0 , 5 ) ) ) { loc = 'Page/' + loc ; }
return loc . split ( '/' ) ; }
function historyChange ( newLocation ) { var t = nav _obj . get _page ( newLocation )
for ( var i = 0 ; i < t . length ; i ++ )
t [ i ] = decodeURIComponent ( t [ i ] ) ; if ( nav _obj . ol . length ) { var c = nav _obj . ol [ nav _obj . ol . length - 1 ] ; if ( t . length == 2 ) { if ( c [ 0 ] == t [ 0 ] && c [ 1 ] == t [ 1 ] ) return ; } else { if ( c [ 0 ] == t [ 0 ] && c [ 1 ] == t [ 1 ] && c [ 2 ] == t [ 2 ] ) return ; } }
if ( t [ 2 ] )
var docname = history _get _name ( t ) ; if ( t [ 0 ] == 'Form' ) { _history _current = newLocation ; if ( docname . substr ( 0 , 3 ) == 'New' && ! ( locals [ t [ 1 ] ] && locals [ t [ 1 ] ] [ docname ] ) ) { newdoc ( t [ 1 ] ) ; } else { loaddoc ( t [ 1 ] , docname ) ; } } else if ( t [ 0 ] == 'Report' ) { _history _current = newLocation ; loadreport ( t [ 1 ] , docname ) ; } else if ( t [ 0 ] == 'Page' ) { _history _current = newLocation ; loadpage ( t [ 1 ] ) ; } else if ( t [ 0 ] == 'Application' ) { _history _current = newLocation ; loadapp ( t [ 1 ] ) ; } else if ( t [ 0 ] == 'DocBrowser' || t [ 0 ] == 'List' ) { _history _current = newLocation ; loaddocbrowser ( t [ 1 ] ) ; } } ; $ ( window ) . bind ( 'hashchange' , function ( ) { historyChange ( location . hash ) ; } ) ;
/ *
* lib / js / legacy / webpage / search . js
* /
search _fields = { } ; function setlinkvalue ( name ) { selector . input . set _input ( name ) ; selector . hide ( ) ; }
function makeselector ( ) { var d = new Dialog ( 540 , 440 , 'Search' ) ; d . make _body ( [ [ 'Data' , 'Beginning With' , 'Tip: You can use wildcard "%"' ] , [ 'Select' , 'Search By' ] , [ 'Button' , 'Search' ] , [ 'HTML' , 'Help' ] , [ 'HTML' , 'Result' ] ] ) ; var inp = d . widgets [ 'Beginning With' ] ; var field _sel = d . widgets [ 'Search By' ] ; var btn = d . widgets [ 'Search' ] ; d . sel _type = '' ; d . values _len = 0 ; d . set = function ( input , type , label ) { d . sel _type = type ; d . input = input ; if ( d . style != 'Link' ) { d . rows [ 'Result' ] . innerHTML = '' ; d . values _len = 0 ; }
d . style = 'Link' ; d . set _query _description ( )
if ( ! d . sel _type ) d . sel _type = 'Value' ; d . set _title ( 'Select a "' + d . sel _type + '" for field "' + label + '"' ) ; }
d . set _search = function ( dt ) { if ( d . style != 'Search' ) { d . rows [ 'Result' ] . innerHTML = '' ; d . values _len = 0 ; }
d . style = 'Search' ; if ( d . input ) { d . input = null ; sel _type = null ; }
d . sel _type = get _label _doctype ( dt ) ; d . set _title ( 'Quick Search for ' + dt ) ; }
2012-02-17 08:34:55 +00:00
$ ( inp ) . keydown ( function ( e ) { if ( e . which == 13 ) { if ( ! btn . disabled ) btn . onclick ( ) ; } } )
2012-02-14 06:14:13 +00:00
d . set _query _description = function ( ) { if ( d . input && d . input . query _description ) { d . rows [ 'Help' ] . innerHTML = '<div class="help_box">' + d . input . query _description + '</div>' ; } else { d . rows [ 'Help' ] . innerHTML = '' } }
d . onshow = function ( ) { if ( d . set _doctype != d . sel _type ) { d . rows [ 'Result' ] . innerHTML = '' ; d . values _len = 0 ; }
inp . value = '' ; if ( d . input && d . input . txt . value ) { inp . value = d . input . txt . value ; }
try { inp . focus ( ) ; } catch ( e ) { }
if ( d . input ) d . input . set _get _query ( ) ; var get _sf _list = function ( dt ) { var l = [ ] ; var lf = search _fields [ dt ] ; for ( var i = 0 ; i < lf . length ; i ++ ) l . push ( lf [ i ] [ 1 ] ) ; return l ; }
$ds ( d . rows [ 'Search By' ] ) ; if ( search _fields [ d . sel _type ] ) { empty _select ( field _sel ) ; add _sel _options ( field _sel , get _sf _list ( d . sel _type ) , 'ID' ) ; } else { empty _select ( field _sel ) ; add _sel _options ( field _sel , [ 'ID' ] , 'ID' ) ; $c ( 'webnotes.widgets.search.getsearchfields' , { 'doctype' : d . sel _type } , function ( r , rt ) { search _fields [ d . sel _type ] = r . searchfields ; empty _select ( field _sel ) ; add _sel _options ( field _sel , get _sf _list ( d . sel _type ) ) ; field _sel . selectedIndex = 0 ; } ) ; } }
d . onhide = function ( ) { if ( d . input && d . input . txt )
d . input . txt . onchange ( ) }
btn . onclick = function ( ) { if ( this . disabled ) return ; this . args . is _ajax = true ; this . set _working ( ) ; d . set _doctype = d . sel _type ; var q = '' ; args = { } ; if ( d . input && d . input . get _query ) { var doc = { } ; args . is _simple = 1 ; if ( cur _frm ) doc = locals [ cur _frm . doctype ] [ cur _frm . docname ] ; var q = d . input . get _query ( doc , d . input . doctype , d . input . docname ) ; if ( ! q ) { return '' ; } }
var get _sf _fieldname = function ( v ) { var lf = search _fields [ d . sel _type ] ; if ( ! lf )
return 'name'
for ( var i = 0 ; i < lf . length ; i ++ ) if ( lf [ i ] [ 1 ] == v ) return lf [ i ] [ 0 ] ; }
$ . extend ( args , { 'txt' : strip ( inp . value ) , 'doctype' : d . sel _type , 'query' : q , 'searchfield' : get _sf _fieldname ( sel _val ( field _sel ) ) } ) ; $c ( 'webnotes.widgets.search.search_widget' , args , function ( r , rtxt ) { btn . done _working ( ) ; if ( r . coltypes ) r . coltypes [ 0 ] = 'Link' ; d . values _len = r . values . length ; d . set _result ( r ) ; } , function ( ) { btn . done _working ( ) ; } ) ; }
d . set _result = function ( r ) { d . rows [ 'Result' ] . innerHTML = '' ; var c = $a ( d . rows [ 'Result' ] , 'div' , 'comment' , { paddingBottom : '4px' , marginBottom : '4px' , borderBottom : '1px solid #CCC' , marginLeft : '4px' } ) ; if ( r . values . length == 50 )
c . innerHTML = 'Showing max 50 results. Use filters to narrow down your search' ; else
c . innerHTML = 'Showing ' + r . values . length + ' resuts.' ; var w = $a ( d . rows [ 'Result' ] , 'div' , '' , { height : '240px' , overflow : 'auto' , margin : '4px' } ) ; for ( var i = 0 ; i < r . values . length ; i ++ ) { var div = $a ( w , 'div' , '' , { marginBottom : '4px' , paddingBottom : '4px' , borderBottom : '1px dashed #CCC' } ) ; var l = $a ( $a ( div , 'div' ) , 'span' , 'link_type' ) ; l . innerHTML = r . values [ i ] [ 0 ] ; l . link _name = r . values [ i ] [ 0 ] ; l . dt = r . coloptions [ 0 ] ; if ( d . input )
l . onclick = function ( ) { setlinkvalue ( this . link _name ) ; }
else
l . onclick = function ( ) { loaddoc ( this . dt , this . link _name ) ; d . hide ( ) ; }
var cl = [ ]
for ( var j = 1 ; j < r . values [ i ] . length ; j ++ ) cl . push ( r . values [ i ] [ j ] ) ; var c = $a ( div , 'div' , 'comment' , { marginTop : '2px' } ) ; c . innerHTML = cl . join ( ', ' ) ; } }
selector = d ; }
/ *
* lib / js / legacy / webpage / spinner . js
* /
function set _loading ( ) { pending _req ++ ; $ ( '#spinner' ) . css ( 'visibility' , 'visible' ) ; $ ( 'body' ) . css ( 'cursor' , 'progress' ) ; }
function hide _loading ( ) { pending _req -- ; if ( ! pending _req ) { $ ( 'body' ) . css ( 'cursor' , 'default' ) ; $ ( '#spinner' ) . css ( 'visibility' , 'hidden' ) ; } }
/ *
* lib / js / legacy / webpage / freeze _page . js
* /
var fcount = 0 ; var frozen = 0 ; var dialog _message ; var dialog _back ; function freeze ( msg , do _freeze ) { if ( ! dialog _back ) { dialog _back = $a ( $i ( 'body_div' ) , 'div' , 'dialog_back' ) ; if ( isIE ) dialog _back . style [ 'filter' ] = 'alpha(opacity=60)' ; }
$ds ( dialog _back ) ; fcount ++ ; frozen = 1 ; }
function unfreeze ( ) { if ( dialog _message )
$dh ( dialog _message ) ; if ( ! fcount ) return ; fcount -- ; if ( ! fcount ) { $dh ( dialog _back ) ; frozen = 0 ; } }
/ *
* lib / js / legacy / webpage / error _console . js
* /
var err _console ; var err _list = [ ] ; function errprint ( t ) { err _list [ err _list . length ] = ( '<pre style="font-family: Courier, Fixed; font-size: 11px; border-bottom: 1px solid #AAA; overflow: auto; width: 90%;">' + t + '</pre>' ) ; }
function setup _err _console ( ) { err _console = new Dialog ( 640 , 480 , 'Error Console' )
err _console . make _body ( [ [ 'HTML' , 'Error List' ] , [ 'Button' , 'Clear' ] , [ 'HTML' , 'Error Report' ] ] ) ; var span = $a ( err _console . widgets [ 'Error Report' ] , 'span' , 'link_type' ) ; span . innerHTML = 'Send Error Report' ; span . onclick = function ( ) { msg = prompt ( 'How / where did you get the error [optional]' )
var call _back = function ( r , rt ) { err _console . hide ( ) ; msgprint ( "Error Report Sent" ) }
$c ( 'webnotes.utils.send_error_report' , { 'err_msg' : err _console . rows [ 'Error List' ] . innerHTML , 'msg' : msg } , call _back ) ; }
err _console . widgets [ 'Clear' ] . onclick = function ( ) { err _list = [ ] ; err _console . rows [ 'Error List' ] . innerHTML = '' ; err _console . hide ( ) ; }
err _console . onshow = function ( ) { err _console . rows [ 'Error List' ] . innerHTML = '<div style="padding: 16px; height: 360px; width: 90%; overflow: auto;">'
+ err _list . join ( '<div style="height: 10px; margin-bottom: 10px; border-bottom: 1px solid #AAA"></div>' ) + '</div>' ; } }
startup _list . push ( setup _err _console ) ;
/ *
* lib / js / legacy / webpage / loaders . js
* /
function loadreport ( dt , rep _name , onload , menuitem , reset _report ) { wn . require ( 'lib/js/legacy/report.compressed.js' ) ; dt = get _label _doctype ( dt ) ; var show _report _builder = function ( ) { if ( ! _r . rb _con ) { _r . rb _con = new _r . ReportContainer ( ) ; }
_r . rb _con . set _dt ( dt , function ( rb ) { if ( rep _name ) { var t = rb . current _loaded ; rb . load _criteria ( rep _name ) ; if ( onload )
onload ( rb ) ; if ( ( rb . dt ) && ( ! rb . dt . has _data ( ) || rb . current _loaded != t ) )
rb . dt . run ( ) ; } else { if ( reset _report ) { rb . reset _report ( ) ; } }
if ( ! rb . forbidden ) { page _body . change _to ( 'Report Builder' ) ; nav _obj . open _notify ( 'Report' , dt , rep _name ) ; } } ) ; }
show _report _builder ( ) ; }
var load _doc = loaddoc ; function loaddoc ( doctype , name , onload , menuitem , from _archive ) { doctype = get _label _doctype ( doctype ) ; if ( frms [ 'DocType' ] && frms [ 'DocType' ] . opendocs [ doctype ] ) { msgprint ( "Cannot open an instance of \"" + doctype + "\" when the DocType is open." ) ; return ; }
if ( doctype == 'DocType' && frms [ name ] ) { msgprint ( "Cannot open DocType \"" + name + "\" when its instance is open." ) ; return ; }
var show _form = function ( f ) { if ( ! _f . frm _con ) { _f . frm _con = new _f . FrmContainer ( ) ; }
if ( ! frms [ doctype ] ) { _f . add _frm ( doctype , show _doc , name , from _archive ) ; } else if ( LocalDB . is _doc _loaded ( doctype , name ) ) { show _doc ( ) ; } else { $c ( 'webnotes.widgets.form.load.getdoc' , { 'name' : name , 'doctype' : doctype , 'user' : user , 'from_archive' : ( from _archive ? 1 : 0 ) } , show _doc , null , null ) ; } }
var show _doc = function ( r , rt ) { if ( locals [ doctype ] && locals [ doctype ] [ name ] ) { page _body . set _status ( 'Done' ) ; var frm = frms [ doctype ] ; frm . refresh ( name ) ; if ( ! frm . in _dialog )
nav _obj . open _notify ( 'Form' , doctype , name ) ; if ( onload ) onload ( ) ; } else { if ( r . exc ) { msgprint ( 'There were errors while loading ' + doctype + ' ' + name ) ; }
loadpage ( '_home' ) ; } }
show _form ( ) ; }
function new _doc ( doctype , onload , in _dialog , on _save _callback , cdt , cdn , cnic ) { doctype = get _label _doctype ( doctype ) ; if ( ! doctype ) { if ( cur _frm ) doctype = cur _frm . doctype ; else return ; }
var show _doc = function ( ) { frm = frms [ doctype ] ; if ( frm . perm [ 0 ] [ CREATE ] == 1 ) { if ( frm . meta . issingle ) { var dn = doctype ; LocalDB . set _default _values ( locals [ doctype ] [ doctype ] ) ; } else
var dn = LocalDB . create ( doctype ) ; if ( onload ) onload ( dn ) ; if ( frm . in _dialog ) { var fd = _f . frm _dialog ; fd . cdt = cdt ; fd . cdn = cdn ; fd . cnic = cnic ; fd . on _save _callback = on _save _callback ; } else { nav _obj . open _notify ( 'Form' , doctype , dn ) ; }
frm . refresh ( dn ) ; } else { msgprint ( 'error:Not Allowed To Create ' + doctype + '\nContact your Admin for help' ) ; } }
var show _form = function ( ) { if ( ! _f . frm _con ) { _f . frm _con = new _f . FrmContainer ( ) ; }
if ( ! frms [ doctype ] )
_f . add _frm ( doctype , show _doc ) ; else
show _doc ( frms [ doctype ] ) ; }
show _form ( ) ; }
var newdoc = new _doc ; var pscript = { } ; var cur _page ; function loadpage ( page _name , call _back , no _history ) { if ( ! page _name ) return ; if ( page _name == '_home' )
page _name = home _page ; var fn = function ( r , rt ) { page _body . set _status ( 'Done' ) ; if ( page _body . pages [ page _name ] ) { var p = page _body . pages [ page _name ]
page _body . change _to ( page _name ) ; } else { var p = render _page ( page _name ) ; if ( ! p ) return ; }
cur _page = page _name ; if ( call _back ) call _back ( ) ; scroll ( 0 , 0 ) ; pscript . update _page _history ( page _name , no _history )
try { if ( pscript [ 'refresh_' + page _name ] ) pscript [ 'refresh_' + page _name ] ( ) ; } catch ( e ) { console . log ( e ) ; } }
if ( get _local ( 'Page' , page _name ) || page _body . pages [ page _name ] )
fn ( ) ; else { args = get _url _dict ( ) ; args . name = page _name ; $c ( 'webnotes.widgets.page.getpage' , args , fn ) ; } }
pscript . update _page _history = function ( page _name , no _history ) { var arg = null ; var t = null ; if ( window . location . hash ) { var t = nav _obj . get _page ( window . location . hash ) } else if ( get _url _arg ( 'page' ) ) { var t = nav _obj . get _page ( get _url _arg ( 'page' ) ) }
if ( t && t [ 1 ] == page _name ) arg = t [ 2 ] ; nav _obj . open _notify ( 'Page' , page _name , arg , no _history ) ; }
function loadscript ( src , call _back ) { set _loading ( ) ; var script = $a ( 'head' , 'script' ) ; script . type = 'text/javascript' ; script . src = src ; script . onload = function ( ) { if ( call _back ) call _back ( ) ; hide _loading ( ) ; }
script . onreadystatechange = function ( ) { if ( this . readyState == 'complete' || this . readyState == 'loaded' ) { hide _loading ( ) ; call _back ( ) ; } } }
var doc _browser _page ; function loaddocbrowser ( dt , label , fields ) { wn . require ( 'lib/js/legacy/webpage/docbrowser.js' ) ; dt = get _label _doctype ( dt ) ; if ( ! doc _browser _page )
doc _browser _page = new ItemBrowserPage ( ) ; doc _browser _page . show ( dt , label , fields ) ; nav _obj . open _notify ( 'List' , dt , '' ) ; }
/ *
* lib / js / legacy / webpage / uploader . js
* /
var uploaders = { } ; var upload _frame _count = 0 ; Uploader = function ( parent , args , callback ) { var id = 'frame' + upload _frame _count ; upload _frame _count ++ ; this . callback = callback ; var div = $a ( parent , 'div' ) ; div . innerHTML = '<iframe id="' + id + '" name="' + id + ' " src=" blank . html " \
style = "width:0px; height:0px; border:0px" > < / i f r a m e > ' ; v a r d i v = $ a ( p a r e n t , ' d i v ' ) ; d i v . i n n e r H T M L = ' < f o r m m e t h o d = " P O S T " e n c t y p e = " m u l t i p a r t / f o r m - d a t a " a c t i o n = " ' + o u t U r l + ' " t a r g e t = " ' + i d + ' " > < / f o r m > ' ; v a r u l _ f o r m = d i v . c h i l d N o d e s [ 0 ] ; v a r f _ l i s t = [ ] ; v a r i n p _ f d a t a = $ a _ i n p u t ( $ a ( u l _ f o r m , ' s p a n ' ) , ' f i l e ' , { n a m e : ' f i l e d a t a ' } , { m a r g i n L e f t : ' 7 p x ' } ) ; i f ( ! ( ' c m d ' i n a r g s ) ) { v a r i n p = $ a _ i n p u t ( $ a ( u l _ f o r m , ' s p a n ' ) , ' h i d d e n ' , { n a m e : ' c m d ' } ) ; i n p . v a l u e = ' u p l o a d f i l e ' ; }
var inp = $a _input ( $a ( ul _form , 'span' ) , 'hidden' , { name : 'uploader_id' } ) ; inp . value = id ; var inp = $a _input ( $a ( ul _form , 'span' ) , 'submit' , null , { marginLeft : '7px' } ) ; inp . value = 'Upload' ; $y ( inp , { width : '80px' } ) ; for ( var key in args ) { var inp = $a _input ( $a ( ul _form , 'span' ) , 'hidden' , { name : key } ) ; inp . value = args [ key ] ; }
uploaders [ id ] = this ; }
function upload _callback ( id , fid ) { uploaders [ id ] . callback ( fid ) ; }
/ *
* lib / js / legacy / webpage / page . js
* /
var pages = [ ] ; var stylesheets = [ ] ; function Page ( page _name , content ) { var me = this ; this . name = page _name ; this . trigger = function ( event ) { try { if ( pscript [ event + '_' + this . name ] )
pscript [ event + '_' + this . name ] ( this . wrapper ) ; } catch ( e ) { console . log ( e ) ; } }
this . onshow = function ( ) { set _title ( me . doc . title ? me . doc . title : me . name ) ; if ( ! me . onload _complete ) { me . trigger ( 'onload' ) ; me . onload _complete = true ; }
me . trigger ( 'onshow' ) ; cur _frm = null ; }
this . wrapper = page _body . add _page ( page _name , this . onshow ) ; this . cont = this . wrapper
if ( content )
this . wrapper . innerHTML = content ; if ( page _name == home _page )
pages [ '_home' ] = this ; return this ; }
function render _page ( page _name , menuitem ) { if ( ! page _name ) return ; if ( ( ! locals [ 'Page' ] ) || ( ! locals [ 'Page' ] [ page _name ] ) ) { loadpage ( '_home' ) ; return ; }
var pdoc = locals [ 'Page' ] [ page _name ] ; if ( pdoc . style ) set _style ( pdoc . style )
if ( pdoc . stylesheet ) { set _style ( locals . Stylesheet [ pdoc . stylesheet ] . stylesheet ) ; stylesheets . push ( pdoc . stylesheet ) ; }
var p = new Page ( page _name , pdoc . _Page _ _content ? pdoc . _Page _ _content : pdoc . content ) ; var script = pdoc . _ _script ? pdoc . _ _script : pdoc . script ; p . doc = pdoc ; if ( script ) { eval ( script ) ; }
page _body . change _to ( page _name ) ; return p ; }
function refresh _page ( page _name ) { var fn = function ( r , rt ) { render _page ( page _name ) }
$c ( 'webnotes.widgets.page.getpage' , { 'name' : page _name , stylesheets : JSON . stringify ( stylesheets ) } , fn ) ; }
/ *
* lib / js / legacy / wn / page _layout . js
* /
wn . PageLayout = function ( args ) { $ . extend ( this , args )
this . wrapper = $a ( this . parent , 'div' ) ; this . wtab = make _table ( this . wrapper , 1 , 2 , '100%' , [ this . main _width , this . sidebar _width ] ) ; this . main = $a ( $td ( this . wtab , 0 , 0 ) , 'div' , 'layout_wrapper' ) ; this . sidebar _area = $a ( $td ( this . wtab , 0 , 1 ) , 'div' ) ; this . head = $a ( this . main , 'div' ) ; this . toolbar _area = $a ( this . main , 'div' ) ; this . body = $a ( this . main , 'div' ) ; this . footer = $a ( this . main , 'div' ) ; if ( this . heading ) { this . page _head = new PageHeader ( this . head , this . heading ) ; } }
/ *
* lib / js / legacy / wn / widgets / footer . js
* /
wn . widgets . Footer = function ( args ) { $ . extend ( this , args ) ; this . make = function ( ) { this . wrapper = $a ( this . parent , 'div' , 'std-footer' ) ; this . table = make _table ( this . wrapper , 1 , this . columns , [ ] , { width : 100 / this . columns + '%' } ) ; this . render _items ( ) ; }
this . render _items = function ( ) { for ( var i = 0 ; i < this . items . length ; i ++ ) { var item = this . items [ i ] ; var div = $a ( $td ( this . table , 0 , item . column ) , 'div' , 'std-footer-item' ) ; div . label = $a ( $a ( div , 'div' ) , 'span' , 'link_type' , '' , item . label ) ; div . label . onclick = item . onclick ; if ( item . description ) { div . description = $a ( div , 'div' , 'field_description' , '' , item . description ) ; } } }
if ( this . items )
this . make ( ) ; }
/ *
* lib / js / legacy / model / local _data . js
* /
var locals = { 'DocType' : { } } ; var fields = { } ; var fields _list = { } ; var LocalDB = { } ; var READ = 0 ; var WRITE = 1 ; var CREATE = 2 ; var SUBMIT = 3 ; var CANCEL = 4 ; var AMEND = 5 ; LocalDB . getchildren = function ( child _dt , parent , parentfield , parenttype ) { var l = [ ] ; for ( var key in locals [ child _dt ] ) { var d = locals [ child _dt ] [ key ] ; if ( ( d . parent == parent ) && ( d . parentfield == parentfield ) ) { if ( parenttype ) { if ( d . parenttype == parenttype ) l . push ( d ) ; } else { l . push ( d ) ; } } }
l . sort ( function ( a , b ) { return ( cint ( a . idx ) - cint ( b . idx ) ) } ) ; return l ; }
LocalDB . add = function ( dt , dn ) { if ( ! locals [ dt ] ) locals [ dt ] = { } ; if ( locals [ dt ] [ dn ] ) delete locals [ dt ] [ dn ] ; locals [ dt ] [ dn ] = { 'name' : dn , 'doctype' : dt , 'docstatus' : 0 } ; return locals [ dt ] [ dn ] ; }
LocalDB . delete _doc = function ( dt , dn ) { var doc = get _local ( dt , dn ) ; for ( var ndt in locals ) { if ( locals [ ndt ] ) { for ( var ndn in locals [ ndt ] ) { var doc = locals [ ndt ] [ ndn ] ; if ( doc && doc . parenttype == dt && ( doc . parent == dn || doc . _ _oldparent == dn ) ) { delete locals [ ndt ] [ ndn ] ; } } } }
delete locals [ dt ] [ dn ] ; }
function get _local ( dt , dn ) { return locals [ dt ] ? locals [ dt ] [ dn ] : null ; }
LocalDB . sync = function ( list ) { if ( list . _kl ) list = expand _doclist ( list ) ; for ( var i = 0 ; i < list . length ; i ++ ) { var d = list [ i ] ; if ( ! d . name )
d . name = LocalDB . get _localname ( d . doctype ) ; LocalDB . add ( d . doctype , d . name ) ; locals [ d . doctype ] [ d . name ] = d ; if ( d . doctype == 'DocType' ) { fields _list [ d . name ] = [ ] ; } else if ( d . doctype == 'DocField' ) { if ( ! d . parent ) { alert ( 'Error: No parent specified for field "' + d . label + '"' ) ; }
if ( ! fields _list [ d . parent ] ) fields _list [ d . parent ] = [ ] ; fields _list [ d . parent ] [ fields _list [ d . parent ] . length ] = d ; if ( ! fields [ d . parent ] )
fields [ d . parent ] = { } ; if ( d . fieldname ) { fields [ d . parent ] [ d . fieldname ] = d ; } else if ( d . label ) { fields [ d . parent ] [ d . label ] = d ; } } else if ( d . doctype == 'Event' ) { if ( ( ! d . localname ) && _c . calendar && ( ! _c . calendar . has _event [ d . name ] ) )
_c . calendar . set _event ( d ) ; }
if ( d . localname )
notify _rename _observers ( d . doctype , d . localname , d . name ) ; } }
local _name _idx = { } ; LocalDB . get _localname = function ( doctype ) { if ( ! local _name _idx [ doctype ] ) local _name _idx [ doctype ] = 1 ; var n = 'New ' + get _doctype _label ( doctype ) + ' ' + local _name _idx [ doctype ] ; local _name _idx [ doctype ] ++ ; return n ; }
LocalDB . set _default _values = function ( doc ) { var doctype = doc . doctype ; var docfields = fields _list [ doctype ] ; if ( ! docfields ) { return ; }
var fields _to _refresh = [ ] ; for ( var fid = 0 ; fid < docfields . length ; fid ++ ) { var f = docfields [ fid ] ; if ( ! in _list ( no _value _fields , f . fieldtype ) && doc [ f . fieldname ] == null ) { var v = LocalDB . get _default _value ( f . fieldname , f . fieldtype , f [ 'default' ] ) ; if ( v ) { doc [ f . fieldname ] = v ; fields _to _refresh . push ( f . fieldname ) ; } } }
return fields _to _refresh ; }
LocalDB . is _doc _loaded = function ( dt , dn ) { var exists = false ; if ( locals [ dt ] && locals [ dt ] [ dn ] ) exists = true ; if ( exists && dt == 'DocType' && ! locals [ dt ] [ dn ] . _ _islocal && ! frms [ dt ] )
exists = false ; return exists ; }
function check _perm _match ( p , dt , dn ) { if ( ! dn ) return true ; var out = false ; if ( p . match ) { if ( user _defaults [ p . match ] ) { for ( var i = 0 ; i < user _defaults [ p . match ] . length ; i ++ ) { if ( user _defaults [ p . match ] [ i ] == locals [ dt ] [ dn ] [ p . match ] ) { return true ; } }
return false ; } else if ( ! locals [ dt ] [ dn ] [ p . match ] ) { return true ; } else { return false ; } } else { return true ; } }
function get _perm ( doctype , dn , ignore _submit ) { var perm = [ [ 0 , 0 ] , ] ; if ( in _list ( user _roles , 'Administrator' ) ) perm [ 0 ] [ READ ] = 1 ; var plist = getchildren ( 'DocPerm' , doctype , 'permissions' , 'DocType' ) ; for ( var pidx in plist ) { var p = plist [ pidx ] ; var pl = cint ( p . permlevel ? p . permlevel : 0 ) ; if ( in _list ( user _roles , p . role ) ) { if ( check _perm _match ( p , doctype , dn ) ) { if ( ! perm [ pl ] ) perm [ pl ] = [ ] ; if ( ! perm [ pl ] [ READ ] ) { if ( cint ( p . read ) ) perm [ pl ] [ READ ] = 1 ; else perm [ pl ] [ READ ] = 0 ; }
if ( ! perm [ pl ] [ WRITE ] ) { if ( cint ( p . write ) ) { perm [ pl ] [ WRITE ] = 1 ; perm [ pl ] [ READ ] = 1 ; } else perm [ pl ] [ WRITE ] = 0 ; }
if ( ! perm [ pl ] [ CREATE ] ) { if ( cint ( p . create ) ) perm [ pl ] [ CREATE ] = 1 ; else perm [ pl ] [ CREATE ] = 0 ; }
if ( ! perm [ pl ] [ SUBMIT ] ) { if ( cint ( p . submit ) ) perm [ pl ] [ SUBMIT ] = 1 ; else perm [ pl ] [ SUBMIT ] = 0 ; }
if ( ! perm [ pl ] [ CANCEL ] ) { if ( cint ( p . cancel ) ) perm [ pl ] [ CANCEL ] = 1 ; else perm [ pl ] [ CANCEL ] = 0 ; }
if ( ! perm [ pl ] [ AMEND ] ) { if ( cint ( p . amend ) ) perm [ pl ] [ AMEND ] = 1 ; else perm [ pl ] [ AMEND ] = 0 ; } } } }
if ( ( ! ignore _submit ) && dn && locals [ doctype ] [ dn ] . docstatus > 0 ) { for ( pl in perm )
perm [ pl ] [ WRITE ] = 0 ; }
return perm ; }
LocalDB . create = function ( doctype , n ) { if ( ! n ) n = LocalDB . get _localname ( doctype ) ; var doc = LocalDB . add ( doctype , n )
doc . _ _islocal = 1 ; doc . owner = user ; LocalDB . set _default _values ( doc ) ; return n ; }
LocalDB . delete _record = function ( dt , dn ) { var d = locals [ dt ] [ dn ] ; if ( ! d . _ _islocal )
d . _ _oldparent = d . parent ; d . parent = 'old_parent:' + d . parent ; d . docstatus = 2 ; d . _ _deleted = 1 ; }
LocalDB . get _default _value = function ( fn , ft , df ) { if ( df == '_Login' || df == '__user' )
return user ; else if ( df == '_Full Name' )
return user _fullname ; else if ( ft == 'Date' && ( df == 'Today' || df == '__today' ) ) { return get _today ( ) ; }
else if ( df )
return df ; else if ( user _defaults [ fn ] )
return user _defaults [ fn ] [ 0 ] ; else if ( sys _defaults [ fn ] )
return sys _defaults [ fn ] ; }
LocalDB . add _child = function ( doc , childtype , parentfield ) { var n = LocalDB . create ( childtype ) ; var d = locals [ childtype ] [ n ] ; d . parent = doc . name ; d . parentfield = parentfield ; d . parenttype = doc . doctype ; return d ; }
LocalDB . no _copy _list = [ 'amended_from' , 'amendment_date' , 'cancel_reason' ] ; LocalDB . copy = function ( dt , dn , from _amend ) { var newdoc = LocalDB . create ( dt ) ; for ( var key in locals [ dt ] [ dn ] ) { if ( key !== 'name' && key . substr ( 0 , 2 ) != '__' ) { locals [ dt ] [ newdoc ] [ key ] = locals [ dt ] [ dn ] [ key ] ; }
var df = get _field ( dt , key ) ; if ( df && ( ( ! from _amend && cint ( df . no _copy ) == 1 ) || in _list ( LocalDB . no _copy _list , df . fieldname ) ) ) { locals [ dt ] [ newdoc ] [ key ] = '' ; } }
return locals [ dt ] [ newdoc ] ; }
function make _doclist ( dt , dn , deleted ) { var dl = [ ] ; dl [ 0 ] = locals [ dt ] [ dn ] ; for ( var ndt in locals ) { if ( locals [ ndt ] ) { for ( var ndn in locals [ ndt ] ) { var doc = locals [ ndt ] [ ndn ] ; if ( doc && doc . parenttype == dt && ( doc . parent == dn || ( deleted && doc . _ _oldparent == dn ) ) ) { dl [ dl . length ] = doc ; } } } }
return dl ; }
var rename _observers = [ ] ; function notify _rename _observers ( dt , old _name , new _name ) { try { var old = locals [ dt ] [ old _name ] ; old . parent = null ; old . _ _deleted = 1 ; } catch ( e ) { alert ( "[rename_from_local] No Document for: " + old _name ) ; }
for ( var i = 0 ; i < rename _observers . length ; i ++ ) { if ( rename _observers [ i ] )
rename _observers [ i ] . rename _notify ( dt , old _name , new _name ) ; } }
var Meta = { } ; var local _dt = { } ; Meta . make _local _dt = function ( dt , dn ) { var dl = make _doclist ( 'DocType' , dt ) ; if ( ! local _dt [ dt ] ) local _dt [ dt ] = { } ; if ( ! local _dt [ dt ] [ dn ] ) local _dt [ dt ] [ dn ] = { } ; for ( var i = 0 ; i < dl . length ; i ++ ) { var d = dl [ i ] ; if ( d . doctype == 'DocField' ) { var key = d . fieldname ? d . fieldname : d . label ; local _dt [ dt ] [ dn ] [ key ] = copy _dict ( d ) ; } } }
Meta . get _field = function ( dt , fn , dn ) { if ( dn && local _dt [ dt ] && local _dt [ dt ] [ dn ] ) { return local _dt [ dt ] [ dn ] [ fn ] ; } else { if ( fields [ dt ] ) var d = fields [ dt ] [ fn ] ; if ( d ) return d ; }
return { } ; }
Meta . set _field _property = function ( fn , key , val , doc ) { if ( ! doc && ( cur _frm . doc ) ) doc = cur _frm . doc ; try { local _dt [ doc . doctype ] [ doc . name ] [ fn ] [ key ] = val ; refresh _field ( fn ) ; } catch ( e ) { alert ( "Client Script Error: Unknown values for " + doc . name + ',' + fn + '.' + key + '=' + val ) ; } }
function get _doctype _label ( dt ) { if ( session . dt _labels && session . dt _labels [ dt ] )
return session . dt _labels [ dt ]
else
return dt }
function get _label _doctype ( label ) { if ( session . rev _dt _labels && session . rev _dt _labels [ label ] )
return session . rev _dt _labels [ label ]
else
return label }
var getchildren = LocalDB . getchildren ; var get _field = Meta . get _field ; var createLocal = LocalDB . create ;
/ *
* lib / js / legacy / model / doclist . js
* /
function compress _doclist ( list ) { var kl = { } ; var vl = [ ] ; var flx = { } ; for ( var i = 0 ; i < list . length ; i ++ ) { var o = list [ i ] ; var fl = [ ] ; if ( ! kl [ o . doctype ] ) { var tfl = [ 'doctype' , 'name' , 'docstatus' , 'owner' , 'parent' , 'parentfield' , 'parenttype' , 'idx' , 'creation' , 'modified' , 'modified_by' , '__islocal' , '__deleted' , '__newname' , '__modified' , '_user_tags' ] ; var fl = [ 'doctype' , 'name' , 'docstatus' , 'owner' , 'parent' , 'parentfield' , 'parenttype' , 'idx' , 'creation' , 'modified' , 'modified_by' , '__islocal' , '__deleted' , '__newname' , '__modified' , '_user_tags' ] ; for ( key in fields [ o . doctype ] ) { if ( ! in _list ( fl , key ) && ! in _list ( no _value _fields , fields [ o . doctype ] [ key ] . fieldtype ) && ! fields [ o . doctype ] [ key ] . no _column ) { fl [ fl . length ] = key ; tfl [ tfl . length ] = key } }
flx [ o . doctype ] = fl ; kl [ o . doctype ] = tfl }
var nl = [ ] ; var fl = flx [ o . doctype ] ; for ( var j = 0 ; j < fl . length ; j ++ ) { var v = o [ fl [ j ] ] ; nl . push ( v ) ; }
vl . push ( nl ) ; }
return JSON . stringify ( { '_vl' : vl , '_kl' : kl } ) ; }
function expand _doclist ( docs ) { var l = [ ] ; for ( var i = 0 ; i < docs . _vl . length ; i ++ )
l [ l . length ] = zip ( docs . _kl [ docs . _vl [ i ] [ 0 ] ] , docs . _vl [ i ] ) ; return l ; }
function zip ( k , v ) { var obj = { } ; for ( var i = 0 ; i < k . length ; i ++ ) { obj [ k [ i ] ] = v [ i ] ; }
return obj ; }
function save _doclist ( dt , dn , save _action , onsave , onerr ) { var doc = locals [ dt ] [ dn ] ; var doctype = locals [ 'DocType' ] [ dt ] ; var tmplist = [ ] ; var doclist = make _doclist ( dt , dn , 1 ) ; var all _clear = true ; if ( save _action != 'Cancel' ) { for ( var n in doclist ) { var tmp = check _required ( doclist [ n ] . doctype , doclist [ n ] . name , doclist [ 0 ] . doctype ) ; if ( doclist [ n ] . docstatus + '' != '2' && all _clear )
all _clear = tmp ; } }
var f = frms [ dt ] ; if ( f && ! all _clear ) { if ( f ) f . savingflag = false ; return 'Error' ; }
var _save = function ( ) { page _body . set _status ( 'Saving...' )
$c ( 'webnotes.widgets.form.save.savedocs' , { 'docs' : compress _doclist ( doclist ) , 'docname' : dn , 'action' : save _action , 'user' : user } , function ( r , rtxt ) { if ( f ) { f . savingflag = false ; }
if ( r . saved ) { if ( onsave ) onsave ( r ) ; } else { if ( onerr ) onerr ( r ) ; } } , function ( ) { if ( f ) { f . savingflag = false ; } } , 0 , ( f ? 'Saving...' : '' ) ) ; }
if ( doc . _ _islocal && ( doctype && doctype . autoname && doctype . autoname . toLowerCase ( ) == 'prompt' ) ) { var newname = prompt ( 'Enter the name of the new ' + dt , '' ) ; if ( newname ) { doc . _ _newname = strip ( newname ) ; _save ( ) ; } else { msgprint ( 'Not Saved' ) ; onerr ( ) ; } } else { _save ( ) ; } }
function check _required ( dt , dn , parent _dt ) { var doc = locals [ dt ] [ dn ] ; if ( doc . docstatus > 1 ) return true ; var fl = fields _list [ dt ] ; if ( ! fl ) return true ; var all _clear = true ; var errfld = [ ] ; for ( var i = 0 ; i < fl . length ; i ++ ) { var key = fl [ i ] . fieldname ; var v = doc [ key ] ; if ( fl [ i ] . reqd && is _null ( v ) && fl [ i ] . fieldname ) { errfld [ errfld . length ] = fl [ i ] . label ; if ( cur _frm ) { var f = cur _frm . fields _dict [ fl [ i ] . fieldname ] ; if ( f ) { if ( f . set _as _error ) f . set _as _error ( 1 ) ; if ( ! cur _frm . error _in _section && f . parent _section ) { cur _frm . set _section ( f . parent _section . sec _id ) ; cur _frm . error _in _section = 1 ; } } }
if ( all _clear ) all _clear = false ; } }
if ( errfld . length ) msgprint ( '<b>Mandatory fields required in ' +
( doc . parenttype ? ( fields [ doc . parenttype ] [ doc . parentfield ] . label + ' (Table)' ) : get _doctype _label ( doc . doctype ) ) + ':</b>\n' + errfld . join ( '\n' ) ) ; return all _clear ; }
/ *
* lib / js / legacy / webpage / body . js
* /
function Body ( ) { this . left _sidebar = null ; this . right _sidebar = null ; this . status _area = null ; var me = this ; page _body = this ; this . no _of _columns = function ( ) { var n = 2 ; if ( cint ( me && me . cp && me . cp . right _sidebar _width ) )
n = n + 1 ; return n ; }
this . ready = function ( ) { $dh ( 'startup_div' ) ; $ds ( 'body_div' ) ; }
this . setup _page _areas = function ( ) { var n = this . no _of _columns ( ) ; this . body _table = make _table ( this . body , 1 , n , '100%' ) ; $y ( this . body _table , { tableLayout : 'fixed' } ) ; var c = 0 ; this . left _sidebar = $td ( this . body _table , 0 , c ) ; $y ( this . left _sidebar , { width : cint ( this . cp . left _sidebar _width ) + 'px' } ) ; c ++ ; this . center = $a ( $td ( this . body _table , 0 , c ) , 'div' ) ; c ++ ; if ( cint ( this . cp . right _sidebar _width ) ) { this . right _sidebar = $td ( this . body _table , 0 , c ) ; $y ( this . right _sidebar , { width : cint ( this . cp . right _sidebar _width ) + 'px' } )
c ++ ; }
this . center . header = $a ( this . center , 'div' ) ; this . center . body = $a ( this . center , 'div' ) ; this . center . loading = $a ( this . center , 'div' , '' , { margin : '200px 0px' , fontSize : '14px' , color : '#999' , textAlign : 'center' } ) ; this . center . loading . innerHTML = 'Loading...' }
this . setup _sidebar _menu = function ( ) { if ( this . left _sidebar && this . cp . show _sidebar _menu ) { sidebar _menu = new SidebarMenu ( ) ; sidebar _menu . make _menu ( '' ) ; } }
this . run _startup _code = function ( ) { $ ( document ) . trigger ( 'startup' ) ; try { if ( this . cp . custom _startup _code )
eval ( this . cp . custom _startup _code ) ; } catch ( e ) { errprint ( e ) ; } }
2012-02-15 08:32:20 +00:00
this . setup = function ( ) { this . cp = wn . control _panel ; this . wrapper = $a ( $i ( 'body_div' ) , 'div' ) ; this . body = $a ( this . wrapper , 'div' ) ; this . setup _page _areas ( ) ; if ( user == 'Guest' ) user _defaults . hide _webnotes _toolbar = 1 ; if ( ! cint ( user _defaults . hide _webnotes _toolbar ) || user == 'Administrator' ) { this . wntoolbar = new wn . ui . toolbar . Toolbar ( ) ; }
2012-02-14 06:14:13 +00:00
if ( this . cp . page _width ) $y ( this . wrapper , { width : cint ( this . cp . page _width ) + 'px' } ) ; }
this . pages = { } ; this . cur _page = null ; this . add _page = function ( label , onshow , onhide ) { var c = $a ( this . center . body , 'div' ) ; if ( onshow )
c . onshow = onshow ; if ( onhide )
c . onhide = onhide ; this . pages [ label ] = c ; $dh ( c ) ; return c ; }
this . change _to = function ( label ) { $dh ( this . center . loading ) ; if ( me . cur _page && me . pages [ label ] != me . cur _page ) { if ( me . cur _page . onhide )
me . cur _page . onhide ( ) ; $dh ( me . cur _page ) ; }
me . cur _page = me . pages [ label ] ; me . cur _page _label = label ; $ ( me . cur _page ) . fadeIn ( ) ; if ( me . cur _page . onshow )
me . cur _page . onshow ( me . cur _page ) ; }
this . set _status = function ( txt ) { if ( this . status _area )
this . status _area . innerHTML = txt ; }
this . set _session _changed = function ( ) { if ( this . session _message _set ) return ; var div = $a ( $i ( 'body_div' ) . parentNode , 'div' , '' , { textAlign : 'center' , fontSize : '14px' , margin : '150px auto' } ) ; $dh ( 'body_div' ) ; div . innerHTML = 'This session has been changed. Please <span class="link_type" onclick="window.location.reload()">refresh</span> to continue' ; this . session _message _set = 1 ; }
this . setup ( ) ; }
/ *
* lib / js / legacy / app . js
* /
var popup _cont ; var session = { } ; var start _sid = null ; if ( ! wn ) var wn = { } ; function startup ( ) { start _sid = get _cookie ( 'sid' ) ; popup _cont = $a ( document . getElementsByTagName ( 'body' ) [ 0 ] , 'div' ) ; var setup _globals = function ( r ) { wn . boot = r ; profile = r . profile ; user = r . profile . name ; user _fullname = profile . first _name + ( r . profile . last _name ? ( ' ' + r . profile . last _name ) : '' ) ; user _defaults = profile . defaults ; user _roles = profile . roles ; user _email = profile . email ; profile . start _items = r . start _items ; home _page = r . home _page ; _p . letter _heads = r . letter _heads ; sys _defaults = r . sysdefaults ; session . rt = profile . can _read ; if ( r . ipinfo ) session . ipinfo = r . ipinfo ; session . dt _labels = r . dt _labels ; session . rev _dt _labels = { }
if ( r . dt _labels ) { for ( key in r . dt _labels ) session . rev _dt _labels [ r . dt _labels [ key ] ] = key ; }
wn . control _panel = r . control _panel ; }
var setup _history = function ( r ) { rename _observers . push ( nav _obj ) ; }
2012-02-17 08:34:55 +00:00
var callback = function ( r , rt ) { if ( r . exc ) console . log ( r . exc ) ; setup _globals ( r ) ; setup _history ( ) ; var a = new Body ( ) ; page _body . run _startup _code ( ) ; page _body . setup _sidebar _menu ( ) ; for ( var i = 0 ; i < startup _list . length ; i ++ ) { startup _list [ i ] ( ) ; }
2012-02-14 06:14:13 +00:00
if ( get _url _arg ( 'embed' ) ) { newdoc ( get _url _arg ( 'embed' ) ) ; return ; }
var t = to _open ( ) ; if ( t ) { historyChange ( t ) ; } else if ( home _page ) { loadpage ( home _page ) ; }
page _body . ready ( ) ; }
if ( wn . boot ) { LocalDB . sync ( wn . boot . docs ) ; callback ( wn . boot , '' ) ; if ( wn . boot . error _messages )
console . log ( wn . boot . error _messages )
if ( wn . boot . server _messages )
msgprint ( wn . boot . server _messages ) ; } else { if ( $i ( 'startup_div' ) )
$c ( 'startup' , { } , callback , null , 1 ) ; } }
function to _open ( ) { if ( get _url _arg ( 'page' ) )
return get _url _arg ( 'page' ) ; var h = location . hash ; if ( h ) { return h . substr ( 1 ) ; } }
function logout ( ) { $c ( 'logout' , args = { } , function ( r , rt ) { if ( r . exc ) { msgprint ( r . exc ) ; return ; }
redirect _to _login ( ) ; } ) ; }
function redirect _to _login ( ) { if ( login _file )
window . location . href = login _file ; else { window . location . reload ( ) ; } }
_p . def _print _style _body = "html, body, div, span, td { font-family: Arial, Helvetica; font-size: 12px; }" + "\npre { margin:0; padding:0;}"
_p . def _print _style _other = "\n.simpletable, .noborder { border-collapse: collapse; margin-bottom: 10px;}"
+ "\n.simpletable td {border: 1pt solid #000; vertical-align: top; padding: 2px; }"
+ "\n.noborder td { vertical-align: top; }"
_p . go = function ( html ) { var d = document . createElement ( 'div' )
d . innerHTML = html
$ ( d ) . printElement ( ) ; }
_p . preview = function ( html ) { var w = window . open ( '' ) ; w . document . write ( html )
w . document . close ( ) ; }
function setup _calendar ( ) { var p = new Page ( '_calendar' ) ; p . wrapper . style . height = '100%' ; p . wrapper . onshow = function ( ) { wn . require ( 'lib/js/legacy/widgets/calendar.js' ) ; if ( ! _c . calendar ) { _c . calendar = new Calendar ( ) ; _c . calendar . init ( p . cont ) ; rename _observers . push ( _c . calendar ) ; } } }
startup _list . push ( setup _calendar ) ; var resize _observers = [ ]
function set _resize _observer ( fn ) { if ( resize _observers . indexOf ( fn ) == - 1 ) resize _observers . push ( fn ) ; }
window . onresize = function ( ) { return ; var ht = get _window _height ( ) ; for ( var i = 0 ; i < resize _observers . length ; i ++ ) { resize _observers [ i ] ( ht ) ; } }
get _window _height = function ( ) { var ht = window . innerHeight ? window . innerHeight : document . documentElement . offsetHeight ? document . documentElement . offsetHeight : document . body . offsetHeight ; return ht ; }
/ *
* js / app . js
* /
wn . app = { name : 'ERPNext' , license : 'GNU/GPL - Usage Condition: All "erpnext" branding must be kept as it is' , source : 'https://github.com/webnotes/erpnext' , publisher : 'Web Notes Technologies Pvt Ltd, Mumbai' , copyright : '© Web Notes Technologies Pvt Ltd' , version : '2.' + window . _version _number }
wn . modules _path = 'erpnext' ; wn . settings . no _history = true ; $ ( document ) . bind ( 'ready' , function ( ) { startup ( ) ; } ) ; $ ( document ) . bind ( 'toolbar_setup' , function ( ) { $ ( '.brand' ) . html ( '<b>erp</b>next' ) ; } )
/ *
* lib / js / bootstrap / bootstrap - dropdown . js
* //* ============================================================
* bootstrap - dropdown . js v1 . 4.0
* http : //twitter.github.com/bootstrap/javascript.html#dropdown
* === === === === === === === === === === === === === === === === === === === ===
* Copyright 2011 Twitter , Inc .
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
* === === === === === === === === === === === === === === === === === === === === * /
! function ( $ ) {
"use strict"
/ * D R O P D O W N P L U G I N D E F I N I T I O N
* === === === === === === === === == * /
$ . fn . dropdown = function ( selector ) {
return this . each ( function ( ) {
$ ( this ) . delegate ( selector || d , 'click' , function ( e ) {
var li = $ ( this ) . parent ( 'li' )
, isActive = li . hasClass ( 'open' )
clearMenus ( )
! isActive && li . toggleClass ( 'open' )
return false
} )
} )
}
/ * A P P L Y T O S T A N D A R D D R O P D O W N E L E M E N T S
* === === === === === === === === === === === == * /
var d = 'a.menu, .dropdown-toggle'
function clearMenus ( ) {
$ ( d ) . parent ( 'li' ) . removeClass ( 'open' )
}
$ ( function ( ) {
$ ( 'html' ) . bind ( "click" , clearMenus )
$ ( 'body' ) . dropdown ( '[data-dropdown] a.menu, [data-dropdown] .dropdown-toggle' )
} )
} ( window . jQuery || window . ender ) ;
/ *
* erpnext / startup / startup . js
* /
var current _module ; var is _system _manager = 0 ; var module _content _dict = { } ; var user _full _nm = { } ; wn . provide ( 'erpnext.startup' ) ; erpnext . startup . set _globals = function ( ) { pscript . is _erpnext _saas = cint ( wn . control _panel . sync _with _gateway )
if ( inList ( user _roles , 'System Manager' ) ) is _system _manager = 1 ; }
erpnext . startup . start = function ( ) { $ ( '#startup_div' ) . html ( 'Starting up...' ) . toggle ( true ) ; erpnext . startup . set _globals ( ) ; if ( user == 'Guest' ) { $dh ( page _body . left _sidebar ) ; if ( wn . boot . custom _css ) { set _style ( wn . boot . custom _css ) ; }
2012-02-20 11:01:55 +00:00
if ( wn . boot . website _settings . title _prefix ) { wn . title _prefix = wn . boot . website _settings . title _prefix ; } } else { pscript . startup _make _sidebar ( ) ; erpnext . toolbar . setup ( ) ; erpnext . startup . set _periodic _updates ( ) ; $ ( 'footer' ) . html ( ' < div class = "erpnext-footer" > \
2012-02-14 06:14:13 +00:00
Powered by < a href = "https://erpnext.com" > ERPNext < / a > < / d i v > ' ) ; }
$ ( '#startup_div' ) . toggle ( false ) ; }
show _chart _browser = function ( nm , chart _type ) { var call _back = function ( ) { if ( nm == 'Sales Browser' ) { var sb _obj = new SalesBrowser ( ) ; sb _obj . set _val ( chart _type ) ; }
else if ( nm == 'Accounts Browser' )
pscript . make _chart ( chart _type ) ; }
loadpage ( nm , call _back ) ; }
ModulePage = function ( parent , module _name , module _label , help _page , callback ) { this . parent = parent ; page _body . cur _page . module _page = this ; this . wrapper = $a ( parent , 'div' ) ; this . module _name = module _name ; this . transactions = [ ] ; this . page _head = new PageHeader ( this . wrapper , module _label ) ; if ( help _page ) { var btn = this . page _head . add _button ( 'Help' , function ( ) { loadpage ( this . help _page ) } , 1 , 'ui-icon-help' )
btn . help _page = help _page ; }
if ( callback ) this . callback = function ( ) { callback ( ) ; } }
2012-02-20 11:01:55 +00:00
var update _messages = function ( ) { if ( inList ( [ 'Guest' , 'Administrator' ] , user ) ) { return ; }
$c _page ( 'home' , 'event_updates' , 'get_unread_messages' , null , function ( r , rt ) { if ( ! r . exc ) { page _body . wntoolbar . set _new _comments ( r . message ) ; } } ) ; }
erpnext . startup . set _periodic _updates = function ( ) { wn . updates = { } ; if ( wn . updates . id ) { clearInterval ( wn . updates . id ) ; }
wn . updates . id = setInterval ( update _messages , 180000 ) ; }
2012-02-14 06:14:13 +00:00
$ ( document ) . bind ( 'startup' , function ( ) { erpnext . startup . start ( ) ; } ) ;
/ *
* erpnext / website / js / topbar . js
* /
2012-02-17 06:36:33 +00:00
wn . provide ( 'erpnext.topbar' ) ; erpnext . topbar . TopBar = Class . extend ( { init : function ( ) { this . make ( ) ; $ ( '.brand' ) . html ( wn . boot . website _settings . brand _html ) ; this . make _items ( ) ; $ ( '.topbar' ) . dropdown ( ) ; } , make : function ( ) { $ ( 'header' ) . append ( ' < div class = "topbar" > \
2012-02-14 06:14:13 +00:00
< div class = "topbar-inner" > \
< div class = "container" > \
< a class = "brand" > [ brand ] < / a > \
< ul class = "nav" > \
< / u l > \
< img src = "lib/images/ui/spinner.gif" id = "spinner" / > \
< ul class = "nav secondary-nav" > \
< li > < a href = "#!Login Page" > Login < / a > < / l i > \
< / u l > \
< / d i v > \
< / d i v > \
2012-02-17 06:36:33 +00:00
< / d i v > ' ) ; $ ( ' . b r a n d ' ) . a t t r ( ' h r e f ' , ' # ! ' + ( w n . b o o t . w e b s i t e _ s e t t i n g s . h o m e _ p a g e | | ' L o g i n P a g e ' ) ) } , m a k e _ i t e m s : f u n c t i o n ( ) { v a r i t e m s = w n . b o o t . w e b s i t e _ m e n u s ; f o r ( v a r i = 0 ; i < i t e m s . l e n g t h ; i + + ) { v a r i t e m = i t e m s [ i ] ; i f ( ! i t e m . p a r e n t _ l a b e l & & i t e m . p a r e n t f i e l d = = ' t o p _ b a r _ i t e m s ' ) { i t e m . r o u t e = i t e m . u r l | | i t e m . c u s t o m _ p a g e ; $ ( ' h e a d e r . n a v : f i r s t ' ) . a p p e n d ( r e p l ( ' < l i d a t a - l a b e l = " % ( l a b e l ) s " > \
< a href = "#!%(route)s" > % ( label ) s < / a > < / l i > ' , i t e m ) ) } }
for ( var i = 0 ; i < items . length ; i ++ ) { var item = items [ i ] ; if ( item . parent _label && item . parentfield == 'top_bar_items' ) { $parent _li = $ ( repl ( 'header li[data-label="%(parent_label)s"]' , item ) ) ; if ( ! $parent _li . hasClass ( 'dropdown' ) ) { $parent _li . addClass ( 'dropdown' ) ; $parent _li . find ( 'a:first' ) . addClass ( 'dropdown-toggle' ) ; $parent _li . append ( '<ul class="dropdown-menu"></ul>' ) ; }
item . route = item . url || item . custom _page ; $parent _li . find ( '.dropdown-menu' ) . append ( repl ( ' < li data - label = "%(label)s" > \
< a href = "#!%(route)s" > % ( label ) s < / a > < / l i > ' , i t e m ) ) } } } } ) ; e r p n e x t . F o o t e r = C l a s s . e x t e n d ( { i n i t : f u n c t i o n ( ) { $ ( ' f o o t e r ' ) . h t m l ( r e p l ( ' < d i v c l a s s = " w e b - f o o t e r " > \
2012-02-14 06:14:13 +00:00
< div class = "web-footer-menu" > < ul > < / u l > < / d i v > \
< div class = "web-footer-address" > % ( address ) s < / d i v > \
< div class = "web-footer-copyright" > & copy ; % ( copyright ) s < / d i v > \
< div class = "web-footer-powered" > Powered by \
< a href = "https://erpnext.com" > erpnext . com < / a > < / d i v > \
< / d i v > ' , w n . b o o t . w e b s i t e _ s e t t i n g s ) ) ; t h i s . m a k e _ i t e m s ( ) ; } , m a k e _ i t e m s : f u n c t i o n ( ) { v a r i t e m s = w n . b o o t . w e b s i t e _ m e n u s
for ( var i = 0 ; i < items . length ; i ++ ) { var item = items [ i ] ; if ( ! item . parent _label && item . parentfield == 'footer_items' ) { item . route = item . url || item . custom _page ; $ ( '.web-footer-menu ul' ) . append ( repl ( ' < li > < a href = "#!%(route)s" \
data - label = "%(label)s" > % ( label ) s < / a > < / l i > ' , i t e m ) ) } } } } ) ; $ ( d o c u m e n t ) . b i n d ( ' s t a r t u p ' , f u n c t i o n ( ) { e r p n e x t . f o o t e r = n e w e r p n e x t . F o o t e r ( ) ; e r p n e x t . t o p b a r . t o p b a r = n e w e r p n e x t . t o p b a r . T o p B a r ( ) ; } )