2012-02-14 06:14:13 +00:00
2012-02-21 05:00:43 +00:00
/ *
* lib / js / lib / bootstrap . min . js
2012-03-09 11:14:21 +00:00
* /
! function ( a ) { a ( function ( ) { "use strict" , a . support . transition = function ( ) { var b = document . body || document . documentElement , c = b . style , d = c . transition !== undefined || c . WebkitTransition !== undefined || c . MozTransition !== undefined || c . MsTransition !== undefined || c . OTransition !== undefined ; return d && { end : function ( ) { var b = "TransitionEnd" ; return a . browser . webkit ? b = "webkitTransitionEnd" : a . browser . mozilla ? b = "transitionend" : a . browser . opera && ( b = "oTransitionEnd" ) , b } ( ) } } ( ) } ) } ( window . jQuery ) , ! function ( a ) { "use strict" ; var b = '[data-dismiss="alert"]' , c = function ( c ) { a ( c ) . on ( "click" , b , this . close ) } ; c . prototype = { constructor : c , close : function ( b ) { function f ( ) { e . remove ( ) , e . trigger ( "closed" ) } var c = a ( this ) , d = c . attr ( "data-target" ) , e ; d || ( d = c . attr ( "href" ) , d = d && d . replace ( /.*(?=#[^\s]*$)/ , "" ) ) , e = a ( d ) , e . trigger ( "close" ) , b && b . preventDefault ( ) , e . length || ( e = c . hasClass ( "alert" ) ? c : c . parent ( ) ) , e . removeClass ( "in" ) , a . support . transition && e . hasClass ( "fade" ) ? e . on ( a . support . transition . end , f ) : f ( ) } } , a . fn . alert = function ( b ) { return this . each ( function ( ) { var d = a ( this ) , e = d . data ( "alert" ) ; e || d . data ( "alert" , e = new c ( this ) ) , typeof b == "string" && e [ b ] . call ( d ) } ) } , a . fn . alert . Constructor = c , a ( function ( ) { a ( "body" ) . on ( "click.alert.data-api" , b , c . prototype . close ) } ) } ( window . jQuery ) , ! function ( a ) { "use strict" ; var b = function ( b , c ) { this . $element = a ( b ) , this . options = a . extend ( { } , a . fn . button . defaults , c ) } ; b . prototype = { constructor : b , setState : function ( a ) { var b = "disabled" , c = this . $element , d = c . data ( ) , e = c . is ( "input" ) ? "val" : "html" ; a += "Text" , d . resetText || c . data ( "resetText" , c [ e ] ( ) ) , c [ e ] ( d [ a ] || this . options [ a ] ) , setTimeout ( function ( ) { a == "loadingText" ? c . addClass ( b ) . attr ( b , b ) : c . removeClass ( b ) . removeAttr ( b ) } , 0 ) } , toggle : function ( ) { var a = this . $element . parent ( '[data-toggle="buttons-radio"]' ) ; a && a . find ( ".active" ) . removeClass ( "active" ) , this . $element . toggleClass ( "active" ) } } , a . fn . button = function ( c ) { return this . each ( function ( ) { var d = a ( this ) , e = d . data ( "button" ) , f = typeof c == "object" && c ; e || d . data ( "button" , e = new b ( this , f ) ) , c == "toggle" ? e . toggle ( ) : c && e . setState ( c ) } ) } , a . fn . button . defaults = { loadingText : "loading..." } , a . fn . button . Constructor = b , a ( function ( ) { a ( "body" ) . on ( "click.button.data-api" , "[data-toggle^=button]" , function ( b ) { a ( b . target ) . button ( "toggle" ) } ) } ) } ( window . jQuery ) , ! function ( a ) { "use strict" ; var b = function ( b , c ) { this . $element = a ( b ) , this . options = a . extend ( { } , a . fn . carousel . defaults , c ) , this . options . slide && this . slide ( this . options . slide ) } ; b . prototype = { cycle : function ( ) { return this . interval = setInterval ( a . proxy ( this . next , this ) , this . options . interval ) , this } , to : function ( b ) { var c = this . $element . find ( ".active" ) , d = c . parent ( ) . children ( ) , e = d . index ( c ) , f = this ; if ( b > d . length - 1 || b < 0 ) return ; return this . sliding ? this . $element . one ( "slid" , function ( ) { f . to ( b ) } ) : e == b ? this . pause ( ) . cycle ( ) : this . slide ( b > e ? "next" : "prev" , a ( d [ b ] ) ) } , pause : function ( ) { return clearInterval ( this . interval ) , this } , next : function ( ) { if ( this . sliding ) return ; return this . slide ( "next" ) } , prev : function ( ) { if ( this . sliding ) return ; return this . slide ( "prev" ) } , slide : function ( b , c ) { var d = this . $element . find ( ".active" ) , e = c || d [ b ] ( ) , f = this . interval , g = b == "next" ? "left" : "right" , h = b == "next" ? "first" : "last" , i = this ; return this . sliding = ! 0 , f && this . pause ( ) , e = e . length ? e : this . $element . find ( ".item" ) [ h ] ( ) , ! a . support . transition && this . $element . hasClass ( "slide" ) ? ( this . $element . trigger ( "slide" ) , d . removeClass ( "active" ) , e . addClass ( "active" ) , this . sliding = ! 1 , this . $element . trigger ( "slid" ) ) : ( e . addClass ( b ) , e [ 0 ] . offsetWidth , d . addClass ( g ) , e . addClass ( g ) , this . $element . trigger ( "slide" ) , this . $element . one ( a . support . transition . end , function ( ) { e . removeClass ( [ b , g ] . join ( " " ) ) . addClass ( "active" ) , d . removeClass ( [ "active" , g ] . join ( " " ) ) , i . sliding = ! 1 , setTimeout ( function ( ) { i . $element . trigger ( "slid" ) } , 0 ) } ) ) , f && this . cycle ( ) , this } } , a . fn . carousel = function ( c ) { return this . each ( function ( ) { var d = a ( this ) , e = d . data ( "carousel" ) , f = typeof c == "object" && c ; e || d . data ( "carousel" , e = new b ( this , f ) ) , typeof c == "number" ? e . to ( c ) : typeof c == "string" || ( c = f . slide ) ? e [ c ] ( ) : e . cycle ( ) } ) } , a . fn . carousel . defaults = { interval : 5e3 } , a . fn . carousel . Constructor = b , a ( function ( ) { a ( "body" ) . on ( "click.carousel.data-api" , "[data-slide]" , function ( b ) { var c = a ( this ) , d , e = a ( c . attr ( "data-target" ) || ( d = c . attr ( "href" ) ) && d . replace
2012-02-14 06:14:13 +00:00
/ *
* lib / js / core . min . js
* /
2012-03-09 11:14:21 +00:00
2012-02-14 06:14:13 +00:00
/ *
* 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 / versions . js
* /
2012-05-09 06:12:52 +00:00
wn . versions = { check : function ( ) { if ( window . localStorage ) { var localversion = localStorage . _version _number ; localStorage . clear ( ) ; } } }
2012-02-14 06:14:13 +00:00
/ *
* 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 ] ; }
2012-03-02 09:26:51 +00:00
return src . split ( '.' ) . slice ( - 1 ) [ 0 ] ; } , load : function ( src ) { var t = src ; $ . ajax ( { url : t , data : { q : Math . floor ( Math . random ( ) * 1000 ) } , dataType : 'text' , success : function ( txt ) { wn . assets . add ( src , txt ) ; } , async : false } ) } , execute : function ( src ) { if ( ! wn . assets . exists ( src ) ) { wn . assets . load ( src ) ; }
2012-03-16 12:58:09 +00:00
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 ) { wn . dom . set _style ( txt ) ; } , cgi : function ( txt , src ) { wn . dom . eval ( txt ) } } }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / wn / require . js
* /
wn . require = function ( items ) { if ( typeof items === "string" ) { items = [ items ] ; }
2012-04-12 11:06:01 +00:00
var l = items . length ; for ( var i = 0 ; i < l ; i ++ ) { var src = items [ i ] ; wn . assets . execute ( src ) ; } }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / wn / dom . js
* /
2012-05-10 13:37:53 +00:00
wn . provide ( 'wn.dom' ) ; wn . dom = { id _count : 0 , by _id : function ( id ) { return document . getElementById ( id ) ; } , set _unique _id : function ( ele ) { var id = 'unique-' + wn . dom . id _count ; if ( ele )
ele . setAttribute ( 'id' , id ) ; wn . dom . id _count ++ ; return id ; } , eval : function ( txt ) { if ( ! txt ) return ; var el = document . createElement ( 'script' ) ; el . appendChild ( document . createTextNode ( txt ) ) ; document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( el ) ; } , set _style : function ( txt ) { if ( ! txt ) return ; var se = document . createElement ( 'style' ) ; se . type = "text/css" ; if ( se . styleSheet ) { se . styleSheet . cssText = txt ; } else { se . appendChild ( document . createTextNode ( txt ) ) ; }
2012-04-30 08:52:02 +00:00
document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( se ) ; } , 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 )
2012-02-14 06:14:13 +00:00
parent . appendChild ( c ) ; if ( className ) { if ( newtag . toLowerCase ( ) == 'img' )
c . src = className
else
c . className = className ; }
2012-04-30 08:52:02 +00:00
if ( cs ) wn . dom . css ( c , cs ) ; if ( innerHTML ) c . innerHTML = innerHTML ; if ( onclick ) c . onclick = onclick ; return c ; } , css : function ( ele , s ) { if ( ele && s ) { for ( var i in s ) ele . style [ i ] = s [ i ] ; } ; return ele ; } , placeholder : function ( dim , letter ) { function getsinglecol ( ) { return Math . min ( Math . round ( Math . random ( ) * 9 ) * Math . round ( Math . random ( ) * 1 ) + 3 , 9 ) }
function getcol ( ) { return '' + getsinglecol ( ) + getsinglecol ( ) + getsinglecol ( ) ; }
args = { width : Math . round ( flt ( dim ) * 0.7 ) + 'px' , height : Math . round ( flt ( dim ) * 0.7 ) + 'px' , padding : Math . round ( flt ( dim ) * 0.15 ) + 'px' , 'font-size' : Math . round ( flt ( dim ) * 0.6 ) + 'px' , col1 : getcol ( ) , col2 : getcol ( ) , letter : letter . substr ( 0 , 1 ) . toUpperCase ( ) }
return repl ( ' < div style = " \
height : % ( height ) s ; \
width : % ( width ) s ; \
font - size : % ( font - size ) s ; \
color : # fff ; \
text - align : center ; \
padding : % ( padding ) s ; \
background : - moz - linear - gradient ( top , # % ( col1 ) s 0 % , # % ( col2 ) s 99 % ) ; /* FF3.6+ */ \
background : - webkit - gradient ( linear , left top , left bottom , color - stop ( 0 % , # % ( col1 ) s ) , color - stop ( 99 % , # % ( col2 ) s ) ) ; /* Chrome,Safari4+ */ \
background : - webkit - linear - gradient ( top , # % ( col1 ) s 0 % , # % ( col2 ) s 99 % ) ; /* Chrome10+,Safari5.1+ */ \
background : - o - linear - gradient ( top , # % ( col1 ) s 0 % , # % ( col2 ) s 99 % ) ; /* Opera 11.10+ */ \
background : - ms - linear - gradient ( top , # % ( col1 ) s 0 % , # % ( col2 ) s 99 % ) ; /* IE10+ */ \
background : linear - gradient ( top , # % ( col1 ) s 0 % , # % ( col2 ) s 99 % ) ; /* W3C */ \
filter : progid : DXImageTransform . Microsoft . gradient ( startColorstr = \ '#%(col1)s\', endColorstr=\'#%(col2)s\' , GradientType = 0 ) ; /* IE6-9 */ \
" > % ( letter ) s < / d i v > ' , a r g s ) ; } }
2012-05-08 07:28:32 +00:00
wn . get _cookie = function ( c ) { var clist = ( document . cookie + '' ) . split ( ';' ) ; var cookies = { } ; for ( var i = 0 ; i < clist . length ; i ++ ) { var tmp = clist [ i ] . split ( '=' ) ; cookies [ strip ( tmp [ 0 ] ) ] = strip ( tmp [ 1 ] ) ; }
return cookies [ c ] ; }
2012-03-22 06:07:08 +00:00
wn . dom . set _box _shadow = function ( ele , spread ) { $ ( ele ) . css ( '-moz-box-shadow' , '0px 0px ' + spread + 'px rgba(0,0,0,0.3);' )
$ ( ele ) . css ( '-webkit-box-shadow' , '0px 0px ' + spread + 'px rgba(0,0,0,0.3);' )
2012-04-18 07:04:18 +00:00
$ ( ele ) . css ( '-box-shadow' , '0px 0px ' + spread + 'px rgba(0,0,0,0.3);' ) } ; ( function ( $ ) { $ . fn . add _options = function ( options _list ) { for ( var i = 0 ; i < options _list . length ; i ++ ) { var v = options _list [ i ] ; value = v . value || v ; label = v . label || v ; $ ( '<option>' ) . html ( label ) . attr ( 'value' , value ) . appendTo ( this ) ; }
$ ( this ) . val ( options _list [ 0 ] . value || options _list [ 0 ] ) ; }
2012-05-11 10:53:41 +00:00
$ . fn . set _working = function ( ) { var ele = this . get ( 0 ) ; $ ( ele ) . attr ( 'disabled' , 'disabled' ) ; if ( ele . loading _img ) { $ ( ele . loading _img ) . toggle ( true ) ; } else { ele . loading _img = $ ( ' < img src = "images/lib/ui/button-load.gif" \
2012-04-18 07:04:18 +00:00
style = "margin-left: 4px; margin-bottom: -2px; display: inline;" / > ' ) . insertAfter ( ele ) ; } }
2012-05-11 10:53:41 +00:00
$ . fn . done _working = function ( ) { var ele = this . get ( 0 ) ; $ ( ele ) . attr ( 'disabled' , null ) ; if ( ele . loading _img ) { $ ( ele . loading _img ) . toggle ( false ) ; } ; } } ) ( jQuery ) ;
2012-03-05 12:58:33 +00:00
/ *
* lib / js / wn / model . js
* /
2012-07-16 08:46:57 +00:00
wn . provide ( 'wn.model' ) ; wn . model = { no _value _type : [ 'Section Break' , 'Column Break' , 'HTML' , 'Table' , 'Button' , 'Image' ] , new _names : { } , with _doctype : function ( doctype , callback ) { if ( locals . DocType [ doctype ] ) { callback ( ) ; } else { wn . call ( { method : 'webnotes.widgets.form.load.getdoctype' , args : { doctype : doctype } , callback : callback } ) ; } } , with _doc : function ( doctype , name , callback ) { if ( ! name ) name = doctype ; if ( locals [ doctype ] && locals [ doctype ] [ name ] ) { callback ( name ) ; } else { wn . call ( { method : 'webnotes.widgets.form.load.getdoc' , args : { doctype : doctype , name : name } , callback : function ( r ) { callback ( name , r ) ; } } ) ; } } , can _delete : function ( doctype ) { if ( ! doctype ) return false ; return wn . boot . profile . can _cancel . indexOf ( doctype ) != - 1 ; } , has _value : function ( dt , dn , fn ) { var val = locals [ dt ] && locals [ dt ] [ dn ] && locals [ dt ] [ dn ] [ fn ] ; var df = wn . meta . get _docfield ( dt , fn , dn ) ; if ( df . fieldtype == 'Table' ) { var ret = false ; $ . each ( locals [ df . options ] || { } , function ( k , d ) { if ( d . parent == dn && d . parenttype == dt && d . parentfield == df . fieldname ) { ret = true ; } } ) ; } else { var ret = ! is _null ( val ) ; }
return ret ? true : false ; } }
2012-04-19 12:18:57 +00:00
/ *
* lib / js / wn / meta . js
* /
wn . provide ( 'wn.meta.docfield_map' ) ; wn . provide ( 'wn.meta.docfield_list' ) ; wn . provide ( 'wn.meta.doctypes' ) ; $ . extend ( wn . meta , { add _field : function ( df ) { wn . provide ( 'wn.meta.docfield_map.' + df . parent ) ; wn . meta . docfield _map [ df . parent ] [ df . fieldname || df . label ] = df ; if ( ! wn . meta . docfield _list [ df . parent ] )
2012-05-01 11:41:36 +00:00
wn . meta . docfield _list [ df . parent ] = [ ] ; for ( var i in wn . meta . docfield _list [ df . parent ] ) { var d = wn . meta . docfield _list [ df . parent ] [ i ] ; if ( df . fieldname == d . fieldname )
return ; }
2012-07-16 08:46:57 +00:00
wn . meta . docfield _list [ df . parent ] . push ( df ) ; } , get _docfield : function ( dt , fn , dn ) { if ( dn && local _dt [ dt ] && local _dt [ dt ] [ dn ] ) { return local _dt [ dt ] [ dn ] [ fn ] ; } else { return wn . meta . docfield _map [ dt ] [ fn ] ; } } } ) ;
2012-03-21 07:15:01 +00:00
/ *
* lib / js / wn / misc / tools . js
* /
2012-05-07 12:30:57 +00:00
wn . markdown = function ( txt ) { if ( ! wn . md2html ) { wn . require ( 'js/lib/showdown.js' ) ; wn . md2html = new Showdown . converter ( ) ; }
2012-07-11 09:09:33 +00:00
return '<div class="markdown">' + wn . md2html . makeHtml ( txt ) + '</div>' ; }
2012-02-29 13:39:20 +00:00
/ *
* lib / js / wn / misc / user . js
* /
2012-05-07 12:30:57 +00:00
wn . user _info = function ( uid ) { var def = { 'fullname' : uid , 'image' : 'images/lib/ui/no_img_m.gif' }
2012-02-29 13:39:20 +00:00
if ( ! wn . boot . user _info ) return def
if ( ! wn . boot . user _info [ uid ] ) return def
if ( ! wn . boot . user _info [ uid ] . fullname )
wn . boot . user _info [ uid ] . fullname = uid ; if ( ! wn . boot . user _info [ uid ] . image )
wn . boot . user _info [ uid ] . image = def . image ; return wn . boot . user _info [ uid ] ; }
2012-05-07 12:30:57 +00:00
wn . provide ( 'wn.user' ) ; $ . extend ( wn . user , { name : ( wn . boot ? wn . boot . profile . name : 'Guest' ) , has _role : function ( rl ) { if ( typeof rl == 'string' )
rl = [ rl ] ; for ( var i in rl ) { if ( ( wn . boot ? wn . boot . profile . roles : [ 'Guest' ] ) . indexOf ( rl [ i ] ) != - 1 )
2012-04-20 08:07:49 +00:00
return true ; } } , is _report _manager : function ( ) { return wn . user . has _role ( [ 'Administrator' , 'System Manager' , 'Report Manager' ] ) ; } } )
2012-03-19 13:12:13 +00:00
wn . session _alive = true ; $ ( document ) . bind ( 'mousemove' , function ( ) { wn . session _alive = true ; if ( wn . session _alive _timeout )
clearTimeout ( wn . session _alive _timeout ) ; wn . session _alive _timeout = setTimeout ( 'wn.session_alive=false;' , 30000 ) ; } )
2012-02-14 06:14:13 +00:00
/ *
* 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' ) ; } ; } } ( ) ) ;
2012-03-16 12:58:09 +00:00
/ *
* lib / js / wn / router . js
* /
2012-04-16 09:55:38 +00:00
wn . re _route = { }
2012-06-12 10:15:44 +00:00
wn . route = function ( ) { if ( wn . re _route [ window . location . hash ] ) { var re _route _val = wn . get _route _str ( wn . re _route [ window . location . hash ] ) ; var cur _route _val = wn . get _route _str ( wn . _cur _route ) ; if ( decodeURIComponent ( re _route _val ) === decodeURIComponent ( cur _route _val ) ) { window . history . back ( ) ; return ; } else { window . location . hash = wn . re _route [ window . location . hash ] ; } }
2012-04-16 09:55:38 +00:00
wn . _cur _route = window . location . hash ; route = wn . get _route ( ) ; switch ( route [ 0 ] ) { case "List" : wn . views . doclistview . show ( route [ 1 ] ) ; break ; case "Form" : if ( route . length > 3 ) { route [ 2 ] = route . splice ( 2 ) . join ( '/' ) ; }
2012-04-20 08:07:49 +00:00
wn . views . formview . show ( route [ 1 ] , route [ 2 ] ) ; break ; case "Report" : wn . views . reportview . show ( route [ 1 ] , route [ 2 ] ) ; break ; case "Report2" : wn . views . reportview2 . show ( ) ; break ; default : wn . views . pageview . show ( route [ 0 ] ) ; } }
2012-06-27 06:36:45 +00:00
wn . get _route = function ( route ) { return $ . map ( wn . get _route _str ( route ) . split ( '/' ) , function ( r ) { return decodeURIComponent ( r ) ; } ) ; }
2012-04-20 08:51:39 +00:00
wn . get _route _str = function ( route ) { if ( ! route )
route = window . location . hash ; if ( route . substr ( 0 , 1 ) == '#' ) route = route . substr ( 1 ) ; if ( route . substr ( 0 , 1 ) == '!' ) route = route . substr ( 1 ) ; return route ; }
2012-04-16 08:06:08 +00:00
wn . set _route = function ( ) { route = $ . map ( arguments , function ( a ) { return encodeURIComponent ( a ) } ) . join ( '/' ) ; window . location . hash = route ; wn . app . set _favicon ( ) ; }
2012-03-16 12:58:09 +00:00
wn . _cur _route = null ; $ ( window ) . bind ( 'hashchange' , function ( ) { if ( location . hash == wn . _cur _route )
2012-05-01 13:39:10 +00:00
return ; wn . route ( ) ; } ) ;
2012-03-16 12:58:09 +00:00
/ *
* lib / js / wn / ui / listing . js
* /
wn . provide ( 'wn.ui' ) ; wn . ui . Listing = Class . extend ( { init : function ( opts ) { this . opts = opts || { } ; this . page _length = 20 ; this . start = 0 ; this . data = [ ] ; if ( opts ) { this . make ( ) ; } } , prepare _opts : function ( ) { if ( this . opts . new _doctype ) { if ( wn . boot . profile . can _read . indexOf ( this . opts . new _doctype ) == - 1 ) { this . opts . new _doctype = null ; } else { this . opts . new _doctype = get _doctype _label ( this . opts . new _doctype ) ; } }
if ( ! this . opts . no _result _message ) { this . opts . no _result _message = 'Nothing to show' } } , make : function ( opts ) { if ( opts ) { this . opts = opts ; }
this . prepare _opts ( ) ; $ . extend ( this , this . opts ) ; $ ( this . parent ) . html ( repl ( ' \
< div class = "wnlist" > \
< h3 class = "title hide" > % ( title ) s < / h 3 > \
\
< div class = "list-filters hide" > \
< div class = "show_filters well" > \
2012-04-20 08:07:49 +00:00
< div class = "filter_area" > < / d i v > \
2012-03-16 12:58:09 +00:00
< div > \
2012-05-18 06:18:10 +00:00
< button class = "btn btn-small btn-info search-btn" > \
< i class = "icon-refresh icon-white" > < / i > S e a r c h < / b u t t o n > \
2012-03-16 12:58:09 +00:00
< button class = "btn btn-small add-filter-btn" > \
< i class = "icon-plus" > < / i > A d d F i l t e r < / b u t t o n > \
< / d i v > \
< / d i v > \
< / d i v > \
\
2012-04-15 17:01:32 +00:00
< div style = "margin-bottom:9px" class = "list-toolbar-wrapper" > \
2012-04-13 06:11:43 +00:00
< div class = "list-toolbar" style = "display:inline-block; margin-right: 10px;" > \
2012-03-16 12:58:09 +00:00
< / d i v > \
2012-03-22 08:54:49 +00:00
< div style = "display:inline-block; width: 24px; margin-left: 4px" > \
2012-05-07 12:30:57 +00:00
< img src = "images/lib/ui/button-load.gif" \
2012-03-22 08:54:49 +00:00
class = "img-load" / > < / d i v > \
2012-03-16 12:58:09 +00:00
< / d i v > < d i v s t y l e = " c l e a r : b o t h " > < / d i v > \
\
< div class = "no-result help hide" > \
% ( no _result _message ) s \
< / d i v > \
\
< div class = "result" > \
< div class = "result-list" > < / d i v > \
< / d i v > \
\
< div class = "paging-button" > \
< button class = "btn btn-small btn-more hide" > More ... < / d i v > \
< / d i v > \
< / d i v > \
2012-04-13 06:11:43 +00:00
',this.opts));this.$w=$(this.parent).find(' . wnlist ');this.set_events();if(this.appframe){this.$w.find(' . list - toolbar - wrapper ' ) . toggle ( false ) ; }
if ( this . show _filters ) { this . make _filters ( ) ; } } , add _button : function ( label , click , icon ) { if ( this . appframe ) { return this . appframe . add _button ( label , click , icon ) } else { $button = $ ( '<button class="btn btn-small"></button>' ) . appendTo ( this . $w . find ( '.list-toolbar' ) )
if ( icon ) { $ ( '<i>' ) . addClass ( icon ) . appendTo ( $button ) ; }
$button . html ( label ) . click ( click ) ; return $button } } , show _view : function ( $btn , $div , $btn _unsel , $div _unsel ) { $btn _unsel . removeClass ( 'btn-info' ) ; $btn _unsel . find ( 'i' ) . removeClass ( 'icon-white' ) ; $div _unsel . toggle ( false ) ; $btn . addClass ( 'btn-info' ) ; $btn . find ( 'i' ) . addClass ( 'icon-white' ) ; $div . toggle ( true ) ; } , set _events : function ( ) { var me = this ; this . $w . find ( '.btn-more' ) . click ( function ( ) { me . run ( { append : true } ) ; } ) ; if ( this . title ) { this . $w . find ( 'h3' ) . html ( this . title ) . toggle ( true ) ; }
if ( ! ( this . hide _refresh || this . no _refresh ) ) { this . add _button ( 'Refresh' , function ( ) { me . run ( ) ; } , 'icon-refresh' ) ; }
2012-05-31 12:53:16 +00:00
if ( this . new _doctype ) { this . add _button ( 'New ' + this . new _doctype , function ( ) { me . make _new _doc ( me . new _doctype ) ; } , 'icon-plus' ) ; }
2012-04-15 17:01:32 +00:00
if ( me . show _filters ) { this . add _button ( 'Show Filters' , function ( ) { me . filter _list . show _filters ( ) ; } , 'icon-search' ) . addClass ( 'btn-filter' ) ; }
2012-05-31 12:53:16 +00:00
if ( me . no _toolbar || me . hide _toolbar ) { me . $w . find ( '.list-toolbar-wrapper' ) . toggle ( false ) ; } } , make _new _doc : function ( new _doctype ) { new _doc ( new _doctype ) ; } , make _filters : function ( ) { this . filter _list = new wn . ui . FilterList ( { listobj : this , $parent : this . $w . find ( '.list-filters' ) . toggle ( true ) , doctype : this . doctype , filter _fields : this . filter _fields } ) ; } , clear : function ( ) { this . data = [ ] ; this . $w . find ( '.result-list' ) . empty ( ) ; this . $w . find ( '.result' ) . toggle ( true ) ; this . $w . find ( '.no-result' ) . toggle ( false ) ; this . start = 0 ; } , run : function ( ) { var me = this ; var a0 = arguments [ 0 ] ; var a1 = arguments [ 1 ] ; if ( a0 && typeof a0 == 'function' )
2012-03-16 12:58:09 +00:00
this . onrun = a0 ; if ( a0 && a0 . callback )
this . onrun = a0 . callback ; if ( ! a1 && ! ( a0 && a0 . append ) )
2012-06-22 14:31:07 +00:00
this . start = 0 ; me . set _working ( true ) ; wn . call ( { method : this . opts . method || 'webnotes.widgets.query_builder.runquery' , args : this . get _call _args ( a0 ) , callback : function ( r ) { me . set _working ( false ) ; me . render _results ( r ) } , no _spinner : this . opts . no _loading } ) ; } , set _working : function ( flag ) { this . $w . find ( '.img-load' ) . toggle ( flag ) ; } , get _call _args : function ( opts ) { if ( ! this . method ) { var query = this . get _query ? this . get _query ( ) : this . query ; query = this . add _limits ( query ) ; var args = { query _max : this . query _max , as _dict : 1 }
args . simple _query = query ; } else { var args = { limit _start : this . start , limit _page _length : this . page _length } }
2012-03-16 12:58:09 +00:00
if ( this . args )
$ . extend ( args , this . args )
2012-04-15 17:01:32 +00:00
if ( this . get _args ) { $ . extend ( args , this . get _args ( opts ) ) ; }
2012-04-19 12:18:57 +00:00
return args ; } , render _results : function ( r ) { if ( this . start == 0 ) this . clear ( ) ; this . $w . find ( '.btn-more' ) . toggle ( false ) ; if ( r . message ) r . values = r . message ; if ( r . values && r . values . length ) { this . data = this . data . concat ( r . values ) ; this . render _list ( r . values ) ; this . update _paging ( r . values ) ; } else { if ( this . start == 0 ) { this . $w . find ( '.result' ) . toggle ( false ) ; this . $w . find ( '.no-result' ) . toggle ( true ) ; } }
2012-06-22 14:31:07 +00:00
if ( this . onrun ) this . onrun ( ) ; if ( this . callback ) this . callback ( r ) ; } , render _list : function ( values ) { var m = Math . min ( values . length , this . page _length ) ; for ( var i = 0 ; i < m ; i ++ ) { this . render _row ( this . add _row ( ) , values [ i ] , this , i ) ; } } , update _paging : function ( values ) { if ( values . length >= this . page _length ) { this . $w . find ( '.btn-more' ) . toggle ( true ) ; this . start += this . page _length ; } } , add _row : function ( ) { return $ ( '<div class="list-row">' ) . appendTo ( this . $w . find ( '.result-list' ) ) . get ( 0 ) ; } , refresh : function ( ) { this . run ( ) ; } , add _limits : function ( query ) { query += ' LIMIT ' + this . start + ',' + ( this . page _length + 1 ) ; return query } } ) ;
2012-04-19 12:18:57 +00:00
/ *
* lib / js / wn / ui / filters . js
* /
2012-05-18 06:22:31 +00:00
wn . ui . FilterList = Class . extend ( { init : function ( opts ) { wn . require ( 'js/fields.js' ) ; $ . extend ( this , opts ) ; this . filters = [ ] ; this . $w = this . $parent ; this . set _events ( ) ; } , set _events : function ( ) { var me = this ; this . $w . find ( '.add-filter-btn' ) . bind ( 'click' , function ( ) { me . add _filter ( ) ; } ) ; this . $w . find ( '.search-btn' ) . bind ( 'click' , function ( ) { me . listobj . run ( ) ; } ) ; } , show _filters : function ( ) { this . $w . find ( '.show_filters' ) . toggle ( ) ; if ( ! this . filters . length )
2012-05-31 09:23:55 +00:00
this . add _filter ( ) ; } , add _filter : function ( fieldname , condition , value ) { this . push _new _filter ( fieldname , condition , value ) ; if ( fieldname ) { this . $w . find ( '.show_filters' ) . toggle ( true ) ; } } , push _new _filter : function ( fieldname , condition , value ) { this . filters . push ( new wn . ui . Filter ( { flist : this , fieldname : fieldname , condition : condition , value : value } ) ) ; } , get _filters : function ( ) { var values = [ ] ; $ . each ( this . filters , function ( i , f ) { if ( f . field )
2012-03-16 12:58:09 +00:00
values . push ( f . get _value ( ) ) ; } )
return values ; } , update _filters : function ( ) { var fl = [ ] ; $ . each ( this . filters , function ( i , f ) { if ( f . field ) fl . push ( f ) ; } )
this . filters = fl ; } , get _filter : function ( fieldname ) { for ( var i in this . filters ) { if ( this . filters [ i ] . field . df . fieldname == fieldname )
2012-04-19 12:18:57 +00:00
return this . filters [ i ] ; } } } ) ; wn . ui . Filter = Class . extend ( { init : function ( opts ) { $ . extend ( this , opts ) ; this . doctype = this . flist . doctype ; this . make ( ) ; this . make _select ( ) ; this . set _events ( ) ; } , make : function ( ) { this . flist . $w . find ( '.filter_area' ) . append ( ' < div class = "list_filter" > \
< span class = "fieldname_select_area" > < / s p a n > \
2012-03-16 12:58:09 +00:00
< select class = "condition" > \
< option value = "=" > Equals < / o p t i o n > \
< option value = "like" > Like < / o p t i o n > \
< option value = ">=" > Greater or equals < / o p t i o n > \
2012-04-20 08:07:49 +00:00
< option value = "<=" > Less or equals < / o p t i o n > \
2012-03-16 12:58:09 +00:00
< option value = ">" > Greater than < / o p t i o n > \
< option value = "<" > Less than < / o p t i o n > \
< option value = "in" > In < / o p t i o n > \
< option value = "!=" > Not equals < / o p t i o n > \
< / s e l e c t > \
< span class = "filter_field" > < / s p a n > \
< a class = "close" > & times ; < / a > \
2012-04-19 12:18:57 +00:00
< / d i v > ' ) ; t h i s . $ w = t h i s . f l i s t . $ w . f i n d ( ' . l i s t _ f i l t e r : l a s t - c h i l d ' ) ; } , m a k e _ s e l e c t : f u n c t i o n ( ) { t h i s . f i e l d s e l e c t = n e w w n . u i . F i e l d S e l e c t ( t h i s . $ w . f i n d ( ' . f i e l d n a m e _ s e l e c t _ a r e a ' ) , t h i s . d o c t y p e , t h i s . f i l t e r _ f i e l d s ) ; } , s e t _ e v e n t s : f u n c t i o n ( ) { v a r m e = t h i s ; t h i s . f i e l d s e l e c t . $ s e l e c t . b i n d ( ' c h a n g e ' , f u n c t i o n ( ) { m e . s e t _ f i e l d ( t h i s . v a l u e ) ; } ) ; t h i s . $ w . f i n d ( ' a . c l o s e ' ) . b i n d ( ' c l i c k ' , f u n c t i o n ( ) { m e . $ w . c s s ( ' d i s p l a y ' , ' n o n e ' ) ; v a r v a l u e = m e . f i e l d . g e t _ v a l u e ( ) ; m e . f i e l d = n u l l ; i f ( ! m e . f l i s t . g e t _ f i l t e r s ( ) . l e n g t h ) { m e . f l i s t . $ w . f i n d ( ' . s e t _ f i l t e r s ' ) . t o g g l e ( t r u e ) ; m e . f l i s t . $ w . f i n d ( ' . s h o w _ f i l t e r s ' ) . t o g g l e ( f a l s e ) ; }
2012-03-16 12:58:09 +00:00
if ( value ) { me . flist . listobj . run ( ) ; }
me . flist . update _filters ( ) ; return false ; } ) ; me . $w . find ( '.condition' ) . change ( function ( ) { if ( $ ( this ) . val ( ) == 'in' ) { me . set _field ( me . field . df . fieldname , 'Data' ) ; if ( ! me . field . desc _area )
2012-04-19 12:18:57 +00:00
me . field . desc _area = $a ( me . field . wrapper , 'span' , 'help' , null , 'values separated by comma' ) ; } else { me . set _field ( me . field . df . fieldname ) ; } } ) ; if ( me . fieldname ) { this . set _values ( me . fieldname , me . condition , me . value ) ; } else { me . set _field ( 'name' ) ; } } , set _values : function ( fieldname , condition , value ) { this . set _field ( fieldname ) ; if ( condition ) this . $w . find ( '.condition' ) . val ( condition ) . change ( ) ; if ( value ) this . field . set _input ( value ) } , set _field : function ( fieldname , fieldtype ) { var me = this ; var cur = me . field ? { fieldname : me . field . df . fieldname , fieldtype : me . field . df . fieldtype } : { }
var df = me . fieldselect . fields _by _name [ fieldname ] ; this . set _fieldtype ( df , fieldtype ) ; if ( me . field && cur . fieldname == fieldname && df . fieldtype == cur . fieldtype ) { return ; }
me . fieldselect . $select . val ( fieldname ) ; var field _area = me . $w . find ( '.filter_field' ) . empty ( ) . get ( 0 ) ; f = make _field ( df , null , field _area , null , 0 , 1 ) ; f . df . single _select = 1 ; f . not _in _form = 1 ; f . with _label = 0 ; f . refresh ( ) ; me . field = f ; this . set _default _condition ( df , fieldtype ) ; $ ( me . field . wrapper ) . find ( ':input' ) . keydown ( function ( ev ) { if ( ev . which == 13 ) { me . flist . listobj . run ( ) ; } } ) } , set _fieldtype : function ( df , fieldtype ) { if ( df . original _type )
2012-03-16 12:58:09 +00:00
df . fieldtype = df . original _type ; else
df . original _type = df . fieldtype ; df . description = '' ; df . reqd = 0 ; if ( fieldtype ) { df . fieldtype = fieldtype ; return ; }
if ( df . fieldtype == 'Check' ) { df . fieldtype = 'Select' ; df . options = 'No\nYes' ; } else if ( [ 'Text' , 'Text Editor' , 'Code' , 'Link' ] . indexOf ( df . fieldtype ) != - 1 ) { df . fieldtype = 'Data' ; } } , set _default _condition : function ( df , fieldtype ) { if ( ! fieldtype ) { if ( df . fieldtype == 'Data' ) { this . $w . find ( '.condition' ) . val ( 'like' ) ; } else { this . $w . find ( '.condition' ) . val ( '=' ) ; } } } , get _value : function ( ) { var me = this ; var val = me . field . get _value ( ) ; var cond = me . $w . find ( '.condition' ) . val ( ) ; if ( me . field . df . original _type == 'Check' ) { val = ( val == 'Yes' ? 1 : 0 ) ; }
if ( cond == 'like' ) { val = val + '%' ; }
2012-04-20 08:07:49 +00:00
return [ me . fieldselect . $select . find ( 'option:selected' ) . attr ( 'table' ) , me . field . df . fieldname , me . $w . find ( '.condition' ) . val ( ) , cstr ( val ) ] ; } } ) ; wn . ui . FieldSelect = Class . extend ( { init : function ( parent , doctype , filter _fields , with _blank ) { this . doctype = doctype ; this . fields _by _name = { } ; this . with _blank = with _blank ; this . $select = $ ( '<select>' ) . appendTo ( parent ) ; if ( filter _fields ) { for ( var i in filter _fields )
2012-06-19 12:22:37 +00:00
this . add _field _option ( this . filter _fields [ i ] ) } else { this . build _options ( ) ; } } , build _options : function ( ) { var me = this ; me . table _fields = [ ] ; var std _filters = [ { fieldname : 'name' , fieldtype : 'Data' , label : 'ID' , parent : me . doctype } , { fieldname : 'modified' , fieldtype : 'Date' , label : 'Last Modified' , parent : me . doctype } , { fieldname : 'owner' , fieldtype : 'Data' , label : 'Created By' , parent : me . doctype } , { fieldname : 'creation' , fieldtype : 'Date' , label : 'Created On' , parent : me . doctype } , { fieldname : '_user_tags' , fieldtype : 'Data' , label : 'Tags' , parent : me . doctype } , { fieldname : 'docstatus' , fieldtype : 'Int' , label : 'Doc Status' , parent : me . doctype } , ] ; var doctype _obj = locals [ 'DocType' ] [ me . doctype ] ; if ( doctype _obj && cint ( doctype _obj . istable ) ) { std _filters = std _filters . concat ( [ { fieldname : 'parent' , fieldtype : 'Data' , label : 'Parent' , parent : me . doctype } ] ) ; }
if ( this . with _blank ) { this . $select . append ( $ ( '<option>' , { value : '' } ) . text ( '' ) ) ; }
2012-04-20 08:07:49 +00:00
$ . each ( std _filters . concat ( wn . meta . docfield _list [ me . doctype ] ) , function ( i , df ) { me . add _field _option ( df ) ; } ) ; $ . each ( me . table _fields , function ( i , table _df ) { if ( table _df . options ) { $ . each ( wn . meta . docfield _list [ table _df . options ] , function ( i , df ) { me . add _field _option ( df ) ; } ) ; } } ) ; } , add _field _option : function ( df ) { var me = this ; if ( me . doctype && df . parent == me . doctype ) { var label = df . label ; var table = me . doctype ; if ( df . fieldtype == 'Table' ) me . table _fields . push ( df ) ; } else { var label = df . label + ' (' + df . parent + ')' ; var table = df . parent ; }
2012-07-23 10:35:16 +00:00
if ( wn . model . no _value _type . indexOf ( df . fieldtype ) == - 1 && ! ( me . fields _by _name [ df . fieldname ] && me . fields _by _name [ df . fieldname ] [ 'parent' ] == df . parent ) ) { this . $select . append ( $ ( '<option>' , { value : df . fieldname , table : table } ) . text ( label ) ) ; me . fields _by _name [ df . fieldname ] = df ; } } } )
2012-03-16 12:58:09 +00:00
/ *
* lib / js / wn / views / container . js
* /
2012-04-25 12:54:44 +00:00
wn . provide ( 'wn.pages' ) ; wn . provide ( 'wn.views' ) ; wn . views . Container = Class . extend ( { init : function ( ) { this . container = $ ( '#body_div' ) . get ( 0 ) ; this . page = null ; this . pagewidth = $ ( '#body_div' ) . width ( ) ; this . pagemargin = 50 ; } , add _page : function ( label , onshow , onhide ) { var page = $ ( '<div class="content"></div>' ) . attr ( 'id' , "page-" + label ) . appendTo ( this . container ) . get ( 0 ) ; if ( onshow )
2012-03-16 12:58:09 +00:00
$ ( page ) . bind ( 'show' , onshow ) ; if ( onshow )
2012-03-22 08:14:04 +00:00
$ ( page ) . bind ( 'hide' , onhide ) ; page . label = label ; wn . pages [ label ] = page ; return page ; } , change _to : function ( label ) { if ( this . page && this . page . label == label ) { return ; }
var me = this ; if ( label . tagName ) { var page = label ; } else { var page = wn . pages [ label ] ; }
2012-03-16 12:58:09 +00:00
if ( ! page ) { console . log ( 'Page not found ' + label ) ; return ; }
2012-03-22 06:07:08 +00:00
if ( this . page ) { $ ( this . page ) . toggle ( false ) ; $ ( this . page ) . trigger ( 'hide' ) ; }
2012-07-12 06:03:00 +00:00
this . page = page ; $ ( this . page ) . fadeIn ( ) ; this . page . _route = window . location . hash ; document . title = this . page . label ; $ ( this . page ) . trigger ( 'show' ) ; scroll ( 0 , 0 ) ; return this . page ; } } ) ; wn . views . add _module _btn = function ( parent , module ) { $ ( parent ) . append ( repl ( ' < span class = "label" style = "margin-right: 8px; cursor: pointer;" \
2012-03-23 08:49:49 +00:00
onclick = "wn.set_route(\'%(module_small)s-home\')" > \
< i class = "icon-home icon-white" > < / i > % ( m o d u l e ) s H o m e \
< / s p a n > ' , { m o d u l e : m o d u l e , m o d u l e _ s m a l l : m o d u l e . t o L o w e r C a s e ( ) } ) ) ; }
wn . views . add _list _btn = function ( parent , doctype ) { $ ( parent ) . append ( repl ( ' < span class = "label" style = "margin-right: 8px; cursor: pointer;" \
onclick = "wn.set_route(\'List\', \'%(doctype)s\')" > \
< i class = "icon-list icon-white" > < / i > % ( d o c t y p e ) s L i s t \
< / s p a n > ' , { d o c t y p e : d o c t y p e } ) ) ; }
2012-03-16 12:58:09 +00:00
/ *
* lib / js / wn / views / pageview . js
* /
2012-05-08 07:28:32 +00:00
wn . provide ( 'wn.views.pageview' ) ; wn . views . pageview = { with _page : function ( name , callback ) { if ( ( locals . Page && locals . Page [ name ] ) || name == window . page _name ) { callback ( ) ; } else { wn . call ( { method : 'webnotes.widgets.page.getpage' , args : { 'name' : name } , callback : callback } ) ; } } , show : function ( name ) { if ( ! name ) name = ( wn . boot ? wn . boot . home _page : window . page _name ) ; wn . views . pageview . with _page ( name , function ( r ) { if ( r && r . exc ) { if ( ! r [ '403' ] ) wn . container . change _to ( '404' ) ; } else if ( ! wn . pages [ name ] ) { new wn . views . Page ( name ) ; }
2012-03-16 12:58:09 +00:00
wn . container . change _to ( name ) ; } ) ; } }
2012-05-09 09:20:00 +00:00
wn . views . Page = Class . extend ( { init : function ( name , wrapper ) { this . name = name ; var me = this ; if ( name == window . page _name ) { this . wrapper = document . getElementById ( 'page-' + name ) ; this . wrapper . label = document . title || window . page _name ; this . wrapper . page _name = window . page _name ; wn . pages [ window . page _name ] = this . wrapper ; } else { this . pagedoc = locals . Page [ this . name ] ; this . wrapper = wn . container . add _page ( this . name ) ; this . wrapper . label = this . pagedoc . title || this . pagedoc . name ; this . wrapper . page _name = this . pagedoc . name ; this . wrapper . innerHTML = this . pagedoc . content ; wn . dom . eval ( this . pagedoc . _ _script || this . pagedoc . script || '' ) ; wn . dom . set _style ( this . pagedoc . style || '' ) ; }
2012-05-07 12:30:57 +00:00
this . trigger ( 'onload' ) ; $ ( this . wrapper ) . bind ( 'show' , function ( ) { cur _frm = null ; me . trigger ( 'onshow' ) ; me . trigger ( 'refresh' ) ; } ) ; } , trigger : function ( eventname ) { var me = this ; try { if ( pscript [ eventname + '_' + this . name ] ) { pscript [ eventname + '_' + this . name ] ( me . wrapper ) ; } else if ( me . wrapper [ eventname ] ) { me . wrapper [ eventname ] ( me . wrapper ) ; } } catch ( e ) { console . log ( e ) ; } } } )
2012-04-15 17:01:32 +00:00
wn . views . make _404 = function ( ) { var page = wn . container . add _page ( '404' ) ; $ ( page ) . html ( ' < div class = "layout-wrapper" > \
< h1 > Not Found < / h 1 > < b r > \
< p > Sorry we were unable to find what you were looking for . < / p > \
< p > < a href = "#" > Go back to home < / a > < / p > \
2012-04-16 05:48:45 +00:00
< / d i v > ' ) . t o g g l e ( f a l s e ) ; } ; w n . v i e w s . m a k e _ 4 0 3 = f u n c t i o n ( ) { v a r p a g e = w n . c o n t a i n e r . a d d _ p a g e ( ' 4 0 3 ' ) ; $ ( p a g e ) . h t m l ( ' < d i v c l a s s = " l a y o u t - w r a p p e r " > \
< h1 > Not Permitted < / h 1 > < b r > \
< p > Sorry you are not permitted to view this page . < / p > \
< p > < a href = "#" > Go back to home < / a > < / p > \
< / d i v > ' ) . t o g g l e ( f a l s e ) ; } ;
2012-03-02 09:26:51 +00:00
/ *
* lib / js / wn / request . js
* /
2012-06-15 08:30:06 +00:00
wn . provide ( 'wn.request' ) ; wn . request . url = 'server.py' ; wn . request . prepare = function ( opts ) { if ( opts . btn ) $ ( opts . btn ) . set _working ( ) ; if ( opts . show _spinner ) set _loading ( ) ; if ( opts . freeze ) freeze ( ) ; if ( ! opts . args . cmd ) { console . log ( opts )
2012-03-02 09:26:51 +00:00
throw "Incomplete Request" ; } }
2012-05-07 12:30:57 +00:00
wn . request . cleanup = function ( opts , r ) { if ( opts . btn ) $ ( opts . btn ) . done _working ( ) ; if ( opts . show _spinner ) hide _loading ( ) ; if ( opts . freeze ) unfreeze ( ) ; if ( wn . boot && wn . boot . sid && wn . get _cookie ( 'sid' ) != wn . boot . sid ) { if ( ! wn . app . logged _out ) { msgprint ( 'Session Expired. Logging you out' ) ; wn . app . logout ( ) ; }
return ; }
2012-08-06 05:45:22 +00:00
if ( r . server _messages ) { r . server _messages = JSON . parse ( r . server _messages )
msgprint ( r . server _messages ) ; }
if ( r . exc ) { r . exc = JSON . parse ( r . exc ) ; if ( r . exc instanceof Array ) { $ . each ( r . exc , function ( i , v ) { if ( v ) console . log ( v ) ; } ) } else { console . log ( r . exc ) ; } } ; if ( r [ '403' ] ) { wn . container . change _to ( '403' ) ; }
2012-06-25 14:35:35 +00:00
if ( r . docs ) { LocalDB . sync ( r . docs ) ; } }
2012-07-11 11:59:46 +00:00
wn . request . call = function ( opts ) { wn . request . prepare ( opts ) ; $ . ajax ( { url : opts . url || wn . request . url , data : opts . args , type : opts . type || 'POST' , dataType : opts . dataType || 'json' , success : function ( r , xhr ) { wn . request . cleanup ( opts , r ) ; opts . success && opts . success ( r , xhr . responseText ) ; } , error : function ( xhr , textStatus ) { wn . request . cleanup ( opts , { } ) ; show _alert ( 'Unable to complete request: ' + textStatus )
opts . error && opts . error ( xhr ) } } ) }
2012-03-15 11:13:46 +00:00
wn . call = function ( opts ) { var args = $ . extend ( { } , opts . args )
if ( opts . module && opts . page ) { args . cmd = opts . module + '.page.' + opts . page + '.' + opts . page + '.' + opts . method } else if ( opts . method ) { args . cmd = opts . method ; }
2012-03-14 13:36:20 +00:00
for ( key in args ) { if ( args [ key ] && typeof args [ key ] != 'string' ) { args [ key ] = JSON . stringify ( args [ key ] ) ; } }
2012-03-02 09:26:51 +00:00
wn . request . call ( { args : args , success : opts . callback , error : opts . error , btn : opts . btn , freeze : opts . freeze , show _spinner : ! opts . no _spinner } ) ; }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / core . js
* /
2012-05-02 04:00:53 +00:00
if ( ! console ) { var console = { log : function ( txt ) { } } }
2012-05-08 07:28:32 +00:00
$ ( document ) . ready ( function ( ) { wn . versions . check ( ) ; wn . provide ( 'wn.app' ) ; $ . extend ( wn . app , new wn . Application ( ) ) ; } ) ;
2012-03-09 11:14:21 +00:00
2012-02-14 06:14:13 +00:00
/ *
* 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-04-16 05:48:45 +00:00
wn . settings . no _history = 1 ; var NEWLINE = '\n' ; var profile = null ; var user = null ; var user _defaults = null ; var user _roles = null ; var user _fullname = null ; var user _email = null ; var user _img = { } ; var pscript = { } ; var selector = null ; var top _index = 91 ; var _f = { } ; var _p = { } ; var _e = { } ; var _r = { } ; var FILTER _SEP = '\1' ; var frms = { } ; var cur _frm = null ; var pscript = { } ; var validated = true ; var validation _message = '' ; var tinymce _loaded = null ;
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / utils / datatype . js
* /
2012-03-16 12:58:09 +00:00
wn . utils . full _name = function ( fn , ln ) { return fn + ( ln ? ' ' : '' ) + ( ln ? ln : '' ) }
2012-04-20 05:51:47 +00:00
function fmt _money ( v ) { if ( v == null || v == '' ) return '0.00' ; v = ( v + '' ) . replace ( /,/g , '' ) ; v = parseFloat ( v ) ; if ( isNaN ( v ) ) { return '' ; } else { var val = 2 ; if ( wn . boot . sysdefaults . currency _format == 'Millions' ) val = 3 ; v = v . toFixed ( 2 ) ; var delimiter = "," ; amount = v + '' ; var a = amount . split ( '.' , 2 )
2012-02-14 06:14:13 +00:00
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
2012-05-07 12:30:57 +00:00
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="images/lib/ui/tick.gif">' ; else ele . innerHTML = '' ; } else { ele . innerHTML = v ; } }
2012-02-14 06:14:13 +00:00
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 + '' ; }
2012-02-29 09:41:06 +00:00
function nth ( number ) { number = cint ( number ) ; var s = 'th' ; if ( ( number + '' ) . substr ( - 1 ) == '1' ) s = 'st' ; if ( ( number + '' ) . substr ( - 1 ) == '2' ) s = 'nd' ; if ( ( number + '' ) . substr ( - 1 ) == '3' ) s = 'rd' ; return number + s ; }
2012-02-14 06:14:13 +00:00
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 )
2012-03-13 10:41:52 +00:00
return parseFloat ( v . toFixed ( decimals ) ) ; return v ; }
2012-02-14 06:14:13 +00:00
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 ; }
2012-03-28 12:18:30 +00:00
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 , s . length - 1 ) ; last _char = s . substr ( s . length - 1 ) ; }
2012-02-14 06:14:13 +00:00
return s ; }
2012-02-29 13:08:18 +00:00
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 ; }
2012-02-14 06:14:13 +00:00
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 ; }
2012-02-29 09:41:06 +00:00
function docstring ( obj ) { return JSON . stringify ( obj ) ; }
2012-02-14 06:14:13 +00:00
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 ; }
2012-04-08 15:03:51 +00:00
var doc _link = DocLink ; function roundNumber ( num , dec ) { var result = Math . round ( num * Math . pow ( 10 , dec ) ) / Math . pow ( 10 , dec ) ; return result ; }
2012-02-14 06:14:13 +00:00
/ *
* 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 }
2012-06-04 07:50:42 +00:00
wn . datetime = { str _to _obj : function ( d ) { if ( typeof d == "object" ) return 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 ) { if ( typeof d == 'string' ) return 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 ) { if ( typeof d1 == 'string' ) d1 = dateutil . str _to _obj ( d1 ) ; if ( typeof d2 == 'string' ) d2 = dateutil . str _to _obj ( d2 ) ; return ( ( d1 - d2 ) / 86400000 ) ; } , get _day _diff : function ( d1 , d2 ) { return dateutil . get _diff ( new Date ( d1 . getYear ( ) , d1 . getMonth ( ) , d1 . getDate ( ) , 0 , 0 ) , new Date ( d2 . getYear ( ) , d2 . getMonth ( ) , d2 . getDate ( ) , 0 , 0 ) ) } , add _days : function ( d , days ) { var dt = dateutil . str _to _obj ( d ) ; var new _dt = new Date ( dt . getTime ( ) + ( days * 24 * 60 * 60 * 1000 ) ) ; return dateutil . obj _to _str ( new _dt ) ; } , add _months : function ( d , months ) { dt = dateutil . str _to _obj ( d )
2012-02-14 06:14:13 +00:00
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 ) )
2012-08-06 08:50:15 +00:00
last _date = 29 ; return y + '-' + int _to _str ( m , 2 ) + '-' + last _date ; } , get _user _fmt : function ( ) { var t = sys _defaults . 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 ] )
2012-02-14 06:14:13 +00:00
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 ] ; }
2012-02-29 09:41:06 +00:00
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 nth ( 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 ( ) + ''
2012-02-14 06:14:13 +00:00
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 ; }
2012-05-15 06:05:21 +00:00
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 ( ':' ) ; }
2012-02-14 06:14:13 +00:00
if ( t . length != 2 ) { show _alert ( '[set_time] Incorect time format' ) ; return ; }
2012-05-11 12:20:34 +00:00
if ( t [ 1 ] . length == 1 ) t [ 1 ] = '0' + t [ 1 ] ; 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 ; }
2012-02-14 06:14:13 +00:00
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 ; }
2012-05-15 06:05:21 +00:00
if ( ! mm ) mm = '00' ; if ( ! hh ) hh = '00' ; return hh + ':' + mm ; }
2012-02-14 06:14:13 +00:00
function prettyDate ( time ) { if ( ! time ) return ''
2012-02-29 09:41:06 +00:00
var date = time ; if ( typeof ( time ) == "string" )
date = new Date ( ( time || "" ) . replace ( /-/g , "/" ) . replace ( /[TZ]/g , " " ) . replace ( /\.[0-9]*/ , "" ) ) ; var diff = ( ( ( new Date ( ) ) . getTime ( ) - date . getTime ( ) ) / 1000 ) , day _diff = Math . floor ( diff / 86400 ) ; if ( isNaN ( day _diff ) || day _diff < 0 )
2012-02-14 06:14:13 +00:00
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 . tinymce = { add _simple : function ( ele , height ) { if ( ele . myid ) { tinyMCE . execCommand ( 'mceAddControl' , true , ele . myid ) ; return ; }
2012-05-07 12:30:57 +00:00
ele . myid = wn . dom . set _unique _id ( ele ) ; $ ( ele ) . tinymce ( { script _url : 'js/lib/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 = 'images/lib/ui/button-load.gif' ; span . innerHTML = args . label ; span . user _onclick = args . onclick ; span . onclick = function ( ) { if ( ! this . disabled ) this . user _onclick ( this ) ; }
2012-02-14 06:14:13 +00:00
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 } ) }
2012-03-16 12:58:09 +00:00
function $btn ( parent , label , onclick , style , css _class , is _ajax ) { if ( css _class === 'green' ) css _class = 'btn-info' ; return new wn . ui . Button ( { parent : parent , label : label , onclick : onclick , style : style , is _ajax : is _ajax , css _class : css _class } ) . btn ; }
2012-02-14 06:14:13 +00:00
$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' ) ; }
2012-04-18 07:04:18 +00:00
$item _pressed = function ( ele ) { $bg ( ele , '#F90' ) ; $fg ( ele , '#FFF' ) ; } ; 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 ; } }
2012-02-14 06:14:13 +00:00
$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 ) ; }
2012-03-05 12:58:33 +00:00
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 ; }
2012-02-14 06:14:13 +00:00
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 ; }
2012-02-27 07:49:47 +00:00
function validate _email ( id ) { if ( strip ( id . toLowerCase ( ) ) . 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 ; }
2012-02-14 06:14:13 +00:00
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 $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 $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 ) ; } }
2012-03-16 12:58:09 +00:00
function set _style ( txt ) { wn . dom . set _style ( txt ) ; }
2012-02-14 06:14:13 +00:00
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 ] ; }
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 ] ) ; }
2012-06-04 07:36:38 +00:00
return d ; } , get _base _url : function ( ) { var url = window . location . href . split ( '#' ) [ 0 ] . split ( '?' ) [ 0 ] . split ( 'app.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-03-02 09:26:51 +00:00
get _url _arg = wn . urllib . get _arg ; get _url _dict = wn . urllib . get _dict ;
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / utils / handler . js
* /
2012-03-02 09:26:51 +00:00
function $c ( command , args , callback , error , no _spinner , freeze _msg , btn ) { wn . request . call ( { args : $ . extend ( args , { cmd : command } ) , success : callback , error : error , btn : btn , freeze : freeze _msg , show _spinner : ! no _spinner } ) }
2012-03-02 09:53:59 +00:00
function $c _obj ( doclist , method , arg , callback , no _spinner , freeze _msg , btn ) { if ( arg && typeof arg != 'string' ) arg = JSON . stringify ( arg ) ; args = { cmd : 'runserverobj' , arg : arg , method : method } ; if ( typeof doclist == 'string' )
2012-03-02 09:44:11 +00:00
args . doctype = doclist ; else
args . docs = compress _doclist ( doclist )
2012-03-02 09:45:57 +00:00
wn . request . call ( { args : args , success : callback , btn : btn , freeze : freeze _msg , show _spinner : ! no _spinner } ) ; }
2012-03-02 09:53:59 +00:00
function $c _page ( module , page , method , arg , callback , no _spinner , freeze _msg , btn ) { if ( arg && typeof arg != 'string' ) arg = JSON . stringify ( arg ) ; wn . request . call ( { args : { cmd : module + '.page.' + page + '.' + page + '.' + method , arg : arg , method : method } , success : callback , btn : btn , freeze : freeze _msg , show _spinner : ! no _spinner } ) ; }
2012-02-14 06:14:13 +00:00
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
2012-03-12 10:42:09 +00:00
args . docs = compress _doclist ( doclist ) ; open _url _post ( wn . request . url , args ) ; }
2012-02-14 06:14:13 +00:00
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' ; }
2012-04-19 12:18:57 +00:00
for ( var x in PARAMS ) { var opt = document . createElement ( "textarea" ) ; opt . name = x ; var val = PARAMS [ x ] ; if ( typeof val != 'string' )
val = JSON . stringify ( val ) ; opt . value = val ; temp . appendChild ( opt ) ; }
2012-02-14 06:14:13 +00:00
document . body . appendChild ( temp ) ; temp . submit ( ) ; return temp ; }
/ *
* lib / js / legacy / utils / msgprint . js
* /
2012-08-06 05:45:22 +00:00
var msg _dialog ; function msgprint ( msg , title ) { if ( ! msg ) return ; if ( msg instanceof Array ) { $ . each ( msg , function ( i , v ) { if ( v ) msgprint ( v ) ; } )
return ; }
if ( typeof ( msg ) != 'string' )
2012-07-11 07:48:58 +00:00
msg = JSON . stringify ( msg ) ; if ( msg . substr ( 0 , 8 ) == '__small:' ) { show _alert ( msg . substr ( 8 ) ) ; return ; }
if ( ! msg _dialog ) { msg _dialog = new wn . ui . Dialog ( { title : "Message" , onhide : function ( ) { msg _dialog . msg _area . empty ( ) ; } } ) ; msg _dialog . msg _area = $ ( '<div class="msgprint">' ) . appendTo ( msg _dialog . body ) ; }
2012-07-12 10:31:20 +00:00
if ( msg . search ( /<br>|<p>|<li>/ ) == - 1 )
2012-07-11 07:48:58 +00:00
msg = replace _newlines ( msg ) ; msg _dialog . set _title ( title || 'Message' )
msg _dialog . msg _area . append ( msg ) ; msg _dialog . show ( ) ; }
2012-04-16 05:48:45 +00:00
var growl _area ; function show _alert ( txt , id ) { if ( ! growl _area ) { if ( ! $ ( '#dialog-container' ) . length ) { $ ( '<div id="dialog-container">' ) . appendTo ( 'body' ) ; }
growl _area = $a ( $i ( 'dialog-container' ) , 'div' , '' , { position : 'fixed' , bottom : '8px' , right : '8px' , width : '320px' , zIndex : 10 } ) ; }
2012-02-24 11:06:58 +00:00
var wrapper = $a ( growl _area , 'div' , '' , { position : 'relative' } ) ; var body = $a ( wrapper , 'div' , 'notice' ) ; var c = $a ( body , 'i' , 'icon-remove-sign' , { cssFloat : 'right' , cursor : 'pointer' } ) ; $ ( 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 ) ; }
2012-02-20 11:01:55 +00:00
$ ( wrapper ) . hide ( ) . fadeIn ( 1000 ) ; }
2012-04-13 06:11:43 +00:00
/ *
* lib / js / wn / ui / appframe . js
* /
2012-05-01 09:26:20 +00:00
wn . ui . AppFrame = Class . extend ( { init : function ( parent , title ) { this . buttons = { } ; this . $w = $ ( '<div></div>' ) . appendTo ( parent ) ; this . $titlebar = $ ( ' < div class = "appframe-titlebar" > \
2012-04-13 06:11:43 +00:00
< span class = "appframe-title" > < / s p a n > \
< span class = "close" > & times ; < / s p a n > \
2012-05-01 09:26:20 +00:00
< / d i v > ' ) . a p p e n d T o ( t h i s . $ w ) ; t h i s . $ w . f i n d ( ' . c l o s e ' ) . c l i c k ( f u n c t i o n ( ) { w i n d o w . h i s t o r y . b a c k ( ) ; } )
2012-07-13 05:45:25 +00:00
if ( title ) this . title ( title ) ; } , title : function ( txt ) { this . clear _breadcrumbs ( ) ; this . add _breadcrumb ( txt ) ; } , make _toolbar : function ( ) { if ( ! this . $w . find ( '.appframe-toolbar' ) . length )
2012-07-11 07:48:58 +00:00
this . $w . append ( '<div class="appframe-toolbar"></div>' ) ; } , add _button : function ( label , click , icon ) { this . make _toolbar ( ) ; args = { label : label , icon : '' } ; if ( icon ) { args . icon = '<i class="icon ' + icon + '"></i>' ; }
2012-04-13 06:11:43 +00:00
this . buttons [ label ] = $ ( repl ( ' < button class = "btn btn-small" > \
2012-07-11 07:48:58 +00:00
% ( icon ) s % ( label ) s < / b u t t o n > ' , a r g s ) ) . c l i c k ( c l i c k ) . a p p e n d T o ( t h i s . $ w . f i n d ( ' . a p p f r a m e - t o o l b a r ' ) ) ; r e t u r n t h i s . b u t t o n s [ l a b e l ] ; } , a d d _ h e l p _ b u t t o n : f u n c t i o n ( t x t ) { t h i s . m a k e _ t o o l b a r ( ) ; $ ( ' < b u t t o n c l a s s = " b t n b t n - s m a l l " s t y l e = " f l o a t : r i g h t ; " b u t t o n - t y p e = " h e l p " > \
< b > ? < / b > < / b u t t o n > ' ) . d a t a ( ' h e l p - t e x t ' , t x t ) . c l i c k ( f u n c t i o n ( ) { m s g p r i n t ( $ ( t h i s ) . d a t a ( ' h e l p - t e x t ' ) , ' H e l p ' ) ; } ) . a p p e n d T o ( t h i s . $ w . f i n d ( ' . a p p f r a m e - t o o l b a r ' ) ) ; } , c l e a r _ b u t t o n s : f u n c t i o n ( ) { t h i s . $ w . f i n d ( ' . a p p f r a m e - t o o l b a r ' ) . e m p t y ( ) ; } , a d d _ b r e a d c r u m b : f u n c t i o n ( h t m l ) { i f ( ! t h i s . $ b r e a d c r u m b s )
this . $breadcrumbs = $ ( ' < / s p a n > \
< span class = "breadcrumb-area" > < / s p a n > ' ) . a p p e n d T o ( t h i s . $ t i t l e b a r ) ; v a r c r u m b = $ ( ' < s p a n > ' ) . h t m l ( h t m l ) ; i f ( ! t h i s . $ b r e a d c r u m b s . f i n d ( ' s p a n ' ) . l e n g t h ) { c r u m b . a d d C l a s s ( ' a p p f r a m e - t i t l e ' ) ; }
crumb . appendTo ( this . $breadcrumbs ) ; } , clear _breadcrumbs : function ( ) { this . $breadcrumbs && this . $breadcrumbs . empty ( ) ; } } ) ; wn . ui . make _app _page = function ( opts ) { if ( opts . single _column ) { $ ( opts . parent ) . html ( ' < div class = "layout-wrapper layout-wrapper-appframe" > \
2012-04-19 12:18:57 +00:00
< div class = "layout-appframe" > < / d i v > \
< div class = "layout-main" > < / d i v > \
< / d i v > ' ) ; } e l s e { $ ( o p t s . p a r e n t ) . h t m l ( ' < d i v c l a s s = " l a y o u t - w r a p p e r l a y o u t - w r a p p e r - b a c k g r o u n d " > \
< div class = "layout-appframe" > < / d i v > \
< div class = "layout-main-section" > < / d i v > \
< div class = "layout-side-section" > < / d i v > \
< div class = "clear" > < / d i v > \
< / d i v > ' ) ; }
opts . parent . appframe = new wn . ui . AppFrame ( $ ( opts . parent ) . find ( '.layout-appframe' ) ) ; if ( opts . title ) opts . parent . appframe . title ( opts . title ) ; }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / wn / ui / dialog . js
* /
2012-05-07 12:30:57 +00:00
wn . widgets . FieldGroup = function ( ) { this . first _button = false ; this . make _fields = function ( body , fl ) { if ( ! window . make _field ) { wn . require ( 'css/fields.css' ) ; wn . require ( 'js/fields.js' ) ; }
2012-08-03 08:42:14 +00:00
$y ( this . body , { padding : '11px' } ) ; this . fields _dict = { } ; for ( var i = 0 ; i < fl . length ; i ++ ) { var df = fl [ i ] ; if ( ! df . fieldname && df . label ) { df . fieldname = df . label . replace ( / /g , '_' ) . toLowerCase ( ) ; }
var div = $a ( body , 'div' , '' , { margin : '6px 0px' } )
2012-02-14 06:14:13 +00:00
f = make _field ( df , null , div , null ) ; f . not _in _form = 1 ; this . fields _dict [ df . fieldname ] = f
2012-03-05 12:58:33 +00:00
f . refresh ( ) ; if ( df . fieldtype == 'Button' && ! this . first _button ) { $ ( f . input ) . addClass ( 'btn-info' ) ; this . first _button = true ; } } }
2012-07-12 06:03:00 +00:00
this . catch _enter _as _submit = function ( ) { var me = this ; $ ( this . body ) . find ( ':input[type="text"], :input[type="password"]' ) . keypress ( function ( e ) { if ( e . which == 13 ) { $ ( me . body ) . find ( '.btn-info:first' ) . click ( ) ; } } ) }
2012-02-14 06:14:13 +00:00
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' ] || '' ) ; } } } }
2012-07-11 07:48:58 +00:00
wn . widgets . Dialog = function ( opts ) { this . display = false ; this . make = function ( opts ) { if ( opts ) { this . opts = opts ; $ . extend ( this , opts ) ; }
if ( ! this . opts . width ) this . opts . width = 480 ; if ( ! $ ( '#dialog-container' ) . length ) { $ ( '<div id="dialog-container">' ) . appendTo ( 'body' ) ; }
2012-04-16 05:48:45 +00:00
this . wrapper = $ ( '<div class="dialog_wrapper">' ) . appendTo ( '#dialog-container' ) . get ( 0 ) ; if ( this . opts . width )
2012-07-12 06:03:00 +00:00
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 . catch _enter _as _submit ( ) ; } }
2012-04-13 06:11:43 +00:00
this . make _head = function ( ) { var me = this ; this . appframe = new wn . ui . AppFrame ( this . wrapper ) ; this . appframe . $titlebar . find ( '.close' ) . unbind ( 'click' ) . click ( function ( ) { if ( me . oncancel ) me . oncancel ( ) ; me . hide ( ) ; } ) ; this . set _title ( this . opts . title ) ; }
2012-04-11 12:32:23 +00:00
this . set _title = function ( t ) { this . appframe . $titlebar . find ( '.appframe-title' ) . html ( t || '' ) ; }
2012-05-11 12:20:34 +00:00
this . set _postion = function ( ) { this . wrapper . style . left = ( ( $ ( window ) . width ( ) - cint ( this . wrapper . style . width ) ) / 2 ) + 'px' ; this . wrapper . style . top = ( $ ( window ) . scrollTop ( ) + 60 ) + 'px' ; top _index ++ ; $y ( this . wrapper , { zIndex : top _index } ) ; }
2012-02-14 06:14:13 +00:00
this . show = function ( ) { if ( this . display ) return ; this . set _postion ( )
2012-07-12 06:03:00 +00:00
$ds ( this . wrapper ) ; freeze ( ) ; this . display = true ; cur _dialog = this ; if ( this . onshow ) this . onshow ( ) ; $ ( this . wrapper ) . find ( ':input:first' ) . focus ( ) ; }
2012-03-12 07:52:09 +00:00
this . hide = function ( ) { if ( this . onhide ) this . onhide ( ) ; unfreeze ( ) ; $dh ( this . wrapper ) ; this . display = false ; cur _dialog = null ; }
2012-04-11 12:32:23 +00:00
this . no _cancel = function ( ) { this . appframe . $titlebar . find ( '.close' ) . toggle ( false ) ; }
2012-07-11 07:48:58 +00:00
if ( opts ) this . make ( opts ) ; }
2012-04-16 08:03:14 +00:00
wn . widgets . Dialog . prototype = new wn . widgets . FieldGroup ( ) ; wn . provide ( 'wn.ui' ) ; wn . ui . Dialog = wn . widgets . Dialog
$ ( document ) . bind ( 'keydown' , function ( e ) { if ( cur _dialog && ! cur _dialog . no _cancel _flag && e . which == 27 ) { cur _dialog . hide ( ) ; } } ) ;
2012-05-15 06:05:21 +00:00
/ *
* lib / js / wn / ui / button . js
* /
wn . ui . Button = function ( args ) { var me = this ; $ . extend ( this , { make : function ( ) { me . btn = wn . dom . add ( args . parent , 'button' , 'btn btn-small ' + ( args . css _class || '' ) ) ; me . btn . args = args ; me . loading _img = wn . dom . add ( me . btn . args . parent , 'img' , '' , { margin : '0px 4px -2px 4px' , display : 'none' } ) ; me . loading _img . src = 'images/lib/ui/button-load.gif' ; me . btn . innerHTML = args . label ; me . btn . user _onclick = args . onclick ; $ ( me . btn ) . bind ( 'click' , function ( ) { if ( ! this . disabled && this . user _onclick )
this . user _onclick ( this ) ; } )
me . btn . set _working = me . set _working ; me . btn . done _working = me . done _working ; if ( me . btn . args . style )
wn . dom . css ( me . btn , args . style ) ; } , set _working : function ( ) { me . btn . disabled = 'disabled' ; $ ( me . loading _img ) . css ( 'display' , 'inline' ) ; } , done _working : function ( ) { me . btn . disabled = false ; $ ( me . loading _img ) . toggle ( false ) ; } } ) ; this . make ( ) ; }
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' )
2012-03-02 09:26:51 +00:00
$ ( c1 ) . text ( d [ 1 ] ) ; }
2012-02-14 06:14:13 +00:00
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 ] ; }
2012-03-05 12:58:33 +00:00
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 ( 'btn-info' ) ; this . first _button = true ; }
2012-02-14 06:14:13 +00:00
if ( d [ 2 ] ) { b . _onclick = d [ 2 ] ; }
this . widgets [ d [ 1 ] ] = b ; } }
/ *
* lib / js / legacy / webpage / page _header . js
* /
2012-03-20 13:15:28 +00:00
var def _ph _style = { wrapper : { marginBottom : '16px' , backgroundColor : '#EEE' } , main _heading : { } , sub _heading : { marginBottom : '8px' , color : '#555' , display : 'none' } , separator : { borderTop : '1px solid #ddd' } , toolbar _area : { padding : '3px 0px' , display : 'none' , borderBottom : '1px solid #ddd' } }
2012-04-08 15:03:51 +00:00
function PageHeader ( parent , main _text , sub _text ) { this . wrapper = $a ( parent , 'div' , 'page_header' ) ; this . close _btn = $a ( this . wrapper , 'a' , 'close' , { } , '×' ) ; this . close _btn . onclick = function ( ) { window . history . back ( ) ; } ; this . breadcrumbs = $a ( this . wrapper , 'div' , 'breadcrumbs-area' ) ; this . main _head = $a ( this . wrapper , 'h1' , '' , def _ph _style . main _heading ) ; this . sub _head = $a ( this . wrapper , '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' } ) ; if ( main _text ) this . main _head . innerHTML = main _text ; if ( sub _text ) this . sub _head . innerHTML = sub _text ; this . buttons = { } ; this . buttons2 = { } ; }
2012-03-14 13:36:20 +00:00
PageHeader . prototype . add _button = function ( label , fn , bold , icon , green ) { var tb = this . toolbar _area ; if ( this . buttons [ label ] ) return ; iconhtml = icon ? ( '<i class="' + icon + '"></i> ' ) : '' ; var $button = $ ( '<button class="btn btn-small">' + iconhtml + label + '</button>' ) . click ( fn ) . appendTo ( tb ) ; if ( green ) { $button . addClass ( 'btn-info' ) ; $button . find ( 'i' ) . addClass ( 'icon-white' ) ; }
if ( bold ) $button . css ( 'font-weight' , 'bold' ) ; this . buttons [ label ] = $button . get ( 0 ) ; $ds ( this . toolbar _area ) ; return this . buttons [ label ] ; }
2012-02-14 06:14:13 +00:00
PageHeader . prototype . clear _toolbar = function ( ) { this . toolbar _area . innerHTML = '' ; this . buttons = { } ; }
PageHeader . prototype . make _buttonset = function ( ) { $ ( this . toolbar _area ) . buttonset ( ) ; }
/ *
* lib / js / legacy / webpage / spinner . js
* /
2012-03-02 09:26:51 +00:00
var pending _req = 0 ; var fcount = 0 ; var dialog _back ; function set _loading ( ) { pending _req ++ ; $ ( '#spinner' ) . css ( 'visibility' , 'visible' ) ; $ ( 'body' ) . css ( 'cursor' , 'progress' ) ; }
2012-02-14 06:14:13 +00:00
function hide _loading ( ) { pending _req -- ; if ( ! pending _req ) { $ ( 'body' ) . css ( 'cursor' , 'default' ) ; $ ( '#spinner' ) . css ( 'visibility' , 'hidden' ) ; } }
2012-03-02 09:26:51 +00:00
function freeze ( ) { if ( ! dialog _back ) { dialog _back = $a ( $i ( 'body_div' ) , 'div' , 'dialog_back' ) ; $ ( dialog _back ) . css ( 'opacity' , 0.6 ) ; }
$ds ( dialog _back ) ; fcount ++ ; }
function unfreeze ( ) { if ( ! fcount ) return ; fcount -- ; if ( ! fcount ) { $dh ( dialog _back ) ; } }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / webpage / loaders . js
* /
2012-03-16 12:58:09 +00:00
function loadreport ( dt , rep _name , onload ) { if ( rep _name )
2012-03-20 09:07:44 +00:00
wn . set _route ( 'Report' , dt , rep _name ) ; else
wn . set _route ( 'Report' , dt ) ; }
2012-04-12 11:06:01 +00:00
function loaddoc ( doctype , name , onload ) { wn . model . with _doctype ( doctype , function ( ) { if ( locals . DocType [ doctype ] . in _dialog ) { _f . edit _record ( doctype , name ) ; } else { wn . set _route ( 'Form' , doctype , name ) ; } } ) }
2012-04-16 09:55:38 +00:00
var load _doc = loaddoc ; function new _doc ( doctype , onload , in _dialog , on _save _callback , cdt , cdn , cnic ) { doctype = get _label _doctype ( doctype ) ; wn . model . with _doctype ( doctype , function ( ) { if ( locals . DocType [ doctype ] . in _dialog ) { var new _name = LocalDB . create ( doctype ) ; _f . edit _record ( doctype , new _name ) ; } else { wn . views . formview . create ( doctype ) ; } } ) }
2012-03-16 12:58:09 +00:00
var newdoc = new _doc ; var pscript = { } ; function loadpage ( page _name , call _back , no _history ) { wn . set _route ( page _name ) ; }
2012-03-20 09:07:44 +00:00
function loaddocbrowser ( dt ) { wn . set _route ( 'List' , dt ) ; }
2012-02-14 06:14:13 +00:00
/ *
* 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
* /
2012-04-19 12:18:57 +00:00
var locals = { 'DocType' : { } } ; 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 ) ; } } }
2012-02-14 06:14:13 +00:00
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 ; }
2012-06-25 14:35:35 +00:00
LocalDB . sync = function ( list ) { if ( list . _kl ) list = expand _doclist ( list ) ; if ( list ) { LocalDB . clear _locals ( list [ 0 ] . doctype , list [ 0 ] . name ) ; }
for ( var i = 0 ; i < list . length ; i ++ ) { var d = list [ i ] ; if ( ! d . name )
2012-07-16 10:14:38 +00:00
d . name = LocalDB . get _localname ( d . doctype ) ; LocalDB . add ( d . doctype , d . name ) ; locals [ d . doctype ] [ d . name ] = d ; if ( cur _frm && cur _frm . doctype == d . doctype && cur _frm . docname == d . name ) { cur _frm . doc = d ; }
if ( d . doctype == 'DocField' )
wn . meta . add _field ( d ) ; if ( d . localname ) { wn . model . new _names [ d . localname ] = d . name ; $ ( document ) . trigger ( 'rename' , [ d . doctype , d . localname , d . name ] ) ; delete locals [ d . doctype ] [ d . localname ] ; } } }
2012-06-25 14:35:35 +00:00
LocalDB . clear _locals = function ( dt , dn ) { var doclist = make _doclist ( dt , dn , 1 ) ; $ . each ( doclist , function ( i , v ) { v && delete locals [ v . doctype ] [ v . name ] ; } ) ; }
2012-02-14 06:14:13 +00:00
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 ; }
2012-04-19 12:18:57 +00:00
LocalDB . set _default _values = function ( doc ) { var doctype = doc . doctype ; var docfields = wn . meta . docfield _list [ doctype ] ; if ( ! docfields ) { return ; }
2012-02-14 06:14:13 +00:00
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 ; }
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 ; }
2012-07-05 09:14:39 +00:00
LocalDB . delete _record = function ( dt , dn ) { delete locals [ dt ] [ dn ] ; }
2012-02-14 06:14:13 +00:00
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 ; }
2012-07-16 08:46:57 +00:00
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 ] ) { var df = wn . meta . get _docfield ( dt , key ) ; if ( key !== 'name' && key . substr ( 0 , 2 ) != '__' && ! ( df && ( ( ! from _amend && cint ( df . no _copy ) == 1 ) || in _list ( LocalDB . no _copy _list , df . fieldname ) ) ) ) { locals [ dt ] [ newdoc ] [ key ] = locals [ dt ] [ dn ] [ key ] ; } }
2012-02-14 06:14:13 +00:00
return locals [ dt ] [ newdoc ] ; }
2012-07-05 09:14:39 +00:00
function make _doclist ( dt , dn ) { if ( ! locals [ dt ] ) { return [ ] ; }
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 ) { dl . push ( doc ) } } } }
2012-02-14 06:14:13 +00:00
return dl ; }
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 . 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 ) ; } }
2012-08-06 05:45:22 +00:00
Meta . get _field = function ( dt , fn , dn ) { try { return local _dt [ dt ] [ dn ] [ fn ] ; } catch ( e ) { return null ; } }
2012-04-16 05:48:45 +00:00
function get _doctype _label ( dt ) { return dt }
function get _label _doctype ( label ) { return label }
2012-07-16 08:46:57 +00:00
var getchildren = LocalDB . getchildren ; var createLocal = LocalDB . create ;
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / model / doclist . js
* /
2012-07-13 09:24:40 +00:00
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' , '__newname' , '__modified' , '_user_tags' , '__temp' ] ; var fl = [ ] . concat ( tfl ) ; for ( key in wn . meta . docfield _map [ o . doctype ] ) { if ( ! in _list ( fl , key ) && ! in _list ( no _value _fields , wn . meta . docfield _map [ o . doctype ] [ key ] . fieldtype ) && ! wn . meta . docfield _map [ o . doctype ] [ key ] . no _column ) { fl [ fl . length ] = key ; tfl [ tfl . length ] = key } }
2012-02-14 06:14:13 +00:00
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 ; }
2012-04-16 09:14:47 +00:00
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 _reqd _ok = true ; if ( save _action != 'Cancel' ) { for ( var n in doclist ) { var reqd _ok = check _required ( doclist [ n ] . doctype , doclist [ n ] . name , doclist [ 0 ] . doctype ) ; if ( doclist [ n ] . docstatus + '' != '2' && all _reqd _ok )
all _reqd _ok = reqd _ok ; } }
if ( ! all _reqd _ok ) { onerr ( )
return ; }
2012-02-27 12:33:54 +00:00
var _save = function ( ) { $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 ; }
2012-02-14 06:14:13 +00:00
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 ( ) ; } }
2012-07-16 08:46:57 +00:00
function check _required ( dt , dn , parent _dt ) { var doc = locals [ dt ] [ dn ] ; if ( doc . docstatus > 1 ) return true ; var fl = wn . meta . docfield _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 df = wn . meta . get _docfield ( dt , key , dn ) ; var has _value = wn . model . has _value ( dt , dn , key ) ; if ( df . reqd && ! has _value ) { errfld [ errfld . length ] = df . label ; if ( cur _frm ) { var f = cur _frm . fields _dict [ df . fieldname ] ; if ( f ) { f . df . has _error = true ; f . refresh _label _icon ( ) ; if ( all _clear ) { $ ( document ) . scrollTop ( $ ( f . wrapper ) . offset ( ) . top - 100 ) ; }
if ( f . df . hidden ) { msgprint ( 'Oops, field "' + f . df . label + ' " is both hidden and mandatory . \
Please contact your admin for help . ' ) ; } } }
2012-02-14 06:14:13 +00:00
if ( all _clear ) all _clear = false ; } }
if ( errfld . length ) msgprint ( '<b>Mandatory fields required in ' +
2012-07-16 08:46:57 +00:00
( doc . parenttype ? ( wn . meta . docfield _map [ doc . parenttype ] [ doc . parentfield ] . label + ' (Table)' ) : doc . doctype ) + ':</b>\n' + errfld . join ( '\n' ) ) ; return all _clear ; }
2012-02-14 06:14:13 +00:00
/ *
2012-04-16 05:48:45 +00:00
* lib / js / wn / app . js
* /
2012-05-07 12:30:57 +00:00
wn . Application = Class . extend ( { init : function ( ) { var me = this ; if ( window . app ) { wn . call ( { method : 'startup' , callback : function ( r , rt ) { wn . provide ( 'wn.boot' ) ; wn . boot = r ; if ( wn . boot . profile . name == 'Guest' ) { window . location = 'index.html' ; return ; }
2012-05-11 10:23:37 +00:00
me . startup ( ) ; } } ) } else { this . startup ( ) ; } } , startup : function ( ) { this . load _bootinfo ( ) ; this . make _page _container ( ) ; this . make _nav _bar ( ) ; this . set _favicon ( ) ; $ ( document ) . trigger ( 'startup' ) ; if ( wn . boot ) { wn . route ( ) ; }
2012-08-06 05:45:22 +00:00
$ ( document ) . trigger ( 'app_ready' ) ; } , load _bootinfo : function ( ) { if ( wn . boot ) { LocalDB . sync ( wn . boot . docs ) ; wn . control _panel = wn . boot . control _panel ; this . set _globals ( ) ; } else { this . set _as _guest ( ) ; } } , set _globals : function ( ) { profile = wn . boot . profile ; user = wn . boot . profile . name ; user _fullname = wn . user _info ( user ) . fullname ; user _defaults = profile . defaults ; user _roles = profile . roles ; user _email = profile . email ; sys _defaults = wn . boot . sysdefaults ; } , set _as _guest : function ( ) { profile = { name : 'Guest' } ; user = 'Guest' ; user _fullname = 'Guest' ; user _defaults = { } ; user _roles = [ 'Guest' ] ; user _email = '' ; sys _defaults = { } ; } , make _page _container : function ( ) { wn . container = new wn . views . Container ( ) ; wn . views . make _403 ( ) ; wn . views . make _404 ( ) ; } , make _nav _bar : function ( ) { if ( wn . boot ) { wn . container . wntoolbar = new wn . ui . toolbar . Toolbar ( ) ; } } , logout : function ( ) { var me = this ; me . logged _out = true ; wn . call ( { method : 'logout' , callback : function ( r ) { if ( r . exc ) { console . log ( r . exc ) ; }
2012-05-07 12:30:57 +00:00
me . redirect _to _login ( ) ; } } ) } , redirect _to _login : function ( ) { window . location . href = 'index.html' ; } , set _favicon : function ( ) { var link = $ ( 'link[type="image/x-icon"]' ) . remove ( ) . attr ( "href" ) ; var favicon = ' \
2012-04-16 05:48:45 +00:00
< link rel = "shortcut icon" href = "'+link+'" type = "image/x-icon" > \
< link rel = "icon" href = "'+link+'" type = "image/x-icon" > '
$ ( favicon ) . appendTo ( 'head' ) ; } } )
2012-02-14 06:14:13 +00:00
/ *
* erpnext / startup / startup . js
* /
2012-03-01 05:54:45 +00:00
var current _module ; var is _system _manager = 0 ; wn . provide ( 'erpnext.startup' ) ; erpnext . modules = { 'Selling' : 'selling-home' , 'Accounts' : 'accounts-home' , 'Stock' : 'stock-home' , 'Buying' : 'buying-home' , 'Support' : 'support-home' , 'Projects' : 'projects-home' , 'Production' : 'production-home' , 'Website' : 'website-home' , 'HR' : 'hr-home' , 'Setup' : 'Setup' , 'Activity' : 'activity' , 'To Do' : 'todo' , 'Calendar' : 'calendar' , 'Messages' : 'messages' , 'Knowledge Base' : 'questions' , 'Dashboard' : 'dashboard' }
2012-04-20 08:51:39 +00:00
wn . provide ( 'wn.modules' ) ; $ . extend ( wn . modules , erpnext . modules ) ; wn . modules [ 'Core' ] = 'Setup' ; erpnext . startup . set _globals = function ( ) { if ( inList ( user _roles , 'System Manager' ) ) is _system _manager = 1 ; }
2012-05-07 12:30:57 +00:00
erpnext . startup . start = function ( ) { console . log ( 'Starting up...' ) ; $ ( '#startup_div' ) . html ( 'Starting up...' ) . toggle ( true ) ; erpnext . startup . set _globals ( ) ; if ( user != 'Guest' ) { if ( wn . boot . user _background ) { erpnext . set _user _background ( wn . boot . user _background ) ; }
wn . boot . profile . allow _modules = wn . boot . profile . allow _modules . concat ( [ 'To Do' , 'Knowledge Base' , 'Calendar' , 'Activity' , 'Messages' ] )
2012-05-01 09:26:20 +00:00
erpnext . toolbar . setup ( ) ; erpnext . startup . set _periodic _updates ( ) ; $ ( 'footer' ) . html ( ' < div class = "web-footer erpnext-footer" > \
2012-05-10 08:49:11 +00:00
< a href = "#!attributions" > ERPNext | Attributions and License < / a > < / d i v > ' ) ; i f ( i n _ l i s t ( u s e r _ r o l e s , ' S y s t e m M a n a g e r ' ) & & ( w n . b o o t . s e t u p _ c o m p l e t e = = ' N o ' ) ) { w n . r e q u i r e ( " j s / c o m p l e t e _ s e t u p . j s " ) ; e r p n e x t . c o m p l e t e _ s e t u p . s h o w ( ) ; }
2012-04-30 10:42:03 +00:00
if ( wn . boot . expires _on && in _list ( user _roles , 'System Manager' ) ) { var today = dateutil . str _to _obj ( dateutil . get _today ( ) ) ; var expires _on = dateutil . str _to _obj ( wn . boot . expires _on ) ; var diff = dateutil . get _diff ( expires _on , today ) ; if ( 0 <= diff && diff <= 15 ) { var expiry _string = diff == 0 ? "today" : repl ( "in %(diff)s day(s)" , { diff : diff } ) ; $ ( 'header' ) . append ( repl ( ' < div class = "expiry-info" > \
2012-04-30 15:36:54 +00:00
Your ERPNext subscription will < b > expire % ( expiry _string ) s < / b > . \
2012-04-27 10:00:23 +00:00
Please renew your subscription to continue using ERPNext \
( and remove this annoying banner ) . \
< / d i v > ' , { e x p i r y _ s t r i n g : e x p i r y _ s t r i n g } ) ) ; } e l s e i f ( d i f f < 0 ) { $ ( ' h e a d e r ' ) . a p p e n d ( r e p l ( ' < d i v c l a s s = " e x p i r y - i n f o " > \
2012-04-30 15:36:54 +00:00
This ERPNext subscription < b > has expired < / b > . \
2012-05-07 12:30:57 +00:00
< / d i v > ' , { e x p i r y _ s t r i n g : e x p i r y _ s t r i n g } ) ) ; } }
2012-05-02 07:33:41 +00:00
erpnext . set _about ( ) ; if ( wn . control _panel . custom _startup _code )
2012-05-07 12:30:57 +00:00
eval ( wn . control _panel . custom _startup _code ) ; }
$ ( 'body' ) . append ( ' < a class = "erpnext-logo" title = "Powered by ERPNext" \
href = "http://erpnext.com" target = "_blank" > < / a > ' ) }
2012-05-02 12:14:59 +00:00
erpnext . update _messages = function ( reset ) { if ( inList ( [ 'Guest' ] , user ) || ! wn . session _alive ) { return ; }
2012-04-30 10:13:34 +00:00
if ( ! reset ) { var set _messages = function ( r ) { if ( ! r . exc ) { erpnext . toolbar . set _new _comments ( r . message . unread _messages ) ; var show _in _circle = function ( parent _id , msg ) { var parent = $ ( '#' + parent _id ) ; if ( parent ) { if ( msg ) { parent . find ( 'span:first' ) . text ( msg ) ; parent . toggle ( true ) ; } else { parent . toggle ( false ) ; } } }
2012-06-04 07:27:23 +00:00
show _in _circle ( 'unread_messages' , r . message . unread _messages . length ) ; show _in _circle ( 'open_support_tickets' , r . message . open _support _tickets ) ; show _in _circle ( 'things_todo' , r . message . things _todo ) ; show _in _circle ( 'todays_events' , r . message . todays _events ) ; show _in _circle ( 'open_tasks' , r . message . open _tasks ) ; } else { clearInterval ( wn . updates . id ) ; } }
2012-04-30 10:13:34 +00:00
wn . call ( { method : 'startup.startup.get_global_status_messages' , callback : set _messages } ) ; } else { erpnext . toolbar . set _new _comments ( 0 ) ; $ ( '#unread_messages' ) . toggle ( false ) ; } }
2012-02-20 11:01:55 +00:00
erpnext . startup . set _periodic _updates = function ( ) { wn . updates = { } ; if ( wn . updates . id ) { clearInterval ( wn . updates . id ) ; }
2012-05-02 12:14:59 +00:00
wn . updates . id = setInterval ( erpnext . update _messages , 60000 ) ; }
2012-04-26 13:31:35 +00:00
erpnext . set _user _background = function ( src ) { set _style ( repl ( '#body_div { background: url("files/%(src)s") repeat;}' , { src : src } ) ) }
2012-04-27 13:09:14 +00:00
$ ( document ) . bind ( 'startup' , function ( ) { erpnext . startup . start ( ) ; } ) ; erpnext . send _message = function ( opts ) { if ( opts . btn ) { $ ( opts . btn ) . start _working ( ) ; }
wn . call ( { method : 'website.send_message' , args : opts , callback : function ( r ) { if ( opts . btn ) { $ ( opts . btn ) . done _working ( ) ; }
if ( opts . callback ) opts . callback ( r ) } } ) ; }
2012-05-01 08:37:41 +00:00
erpnext . hide _naming _series = function ( ) { if ( cur _frm . fields _dict . naming _series ) { hide _field ( 'naming_series' ) ; if ( cur _frm . doc . _ _islocal ) { unhide _field ( 'naming_series' ) ; } } }
2012-02-14 06:14:13 +00:00
/ *
2012-05-07 12:30:57 +00:00
* conf . js
* /
wn . provide ( 'erpnext' ) ; erpnext . set _about = function ( ) { wn . provide ( 'wn.app' ) ; $ . extend ( 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' } ) ; }
2012-05-18 06:22:31 +00:00
wn . modules _path = 'erpnext' ; $ ( document ) . bind ( 'toolbar_setup' , function ( ) { $ ( '.brand' ) . html ( ( wn . boot . website _settings . brand _html || 'erpnext' ) + ' <i class="icon-home icon-white navbar-icon-home" ></i>' ) . css ( 'max-width' , '200px' ) . css ( 'overflow' , 'hidden' ) . hover ( function ( ) { $ ( this ) . find ( '.icon-home' ) . addClass ( 'navbar-icon-home-hover' ) ; } , function ( ) { $ ( this ) . find ( '.icon-home' ) . removeClass ( 'navbar-icon-home-hover' ) ; } ) ; } ) ;