2012-02-14 06:14:13 +00:00
2012-02-14 06:33:02 +00:00
/ *
2012-03-09 11:14:21 +00:00
* lib / js / lib / jquery / jquery . ui . core . js
* /
; / * !
* jQuery UI 1.8 . 18
*
* Copyright 2011 , AUTHORS . txt ( http : //jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses .
* http : //jquery.org/license
2012-02-14 06:33:02 +00:00
*
2012-03-09 11:14:21 +00:00
* http : //docs.jquery.com/UI
* /
( function ( a , b ) { function d ( b ) { return ! a ( b ) . parents ( ) . andSelf ( ) . filter ( function ( ) { return a . curCSS ( this , "visibility" ) === "hidden" || a . expr . filters . hidden ( this ) } ) . length } function c ( b , c ) { var e = b . nodeName . toLowerCase ( ) ; if ( "area" === e ) { var f = b . parentNode , g = f . name , h ; if ( ! b . href || ! g || f . nodeName . toLowerCase ( ) !== "map" ) return ! 1 ; h = a ( "img[usemap=#" + g + "]" ) [ 0 ] ; return ! ! h && d ( h ) } return ( /input|select|textarea|button|object/ . test ( e ) ? ! b . disabled : "a" == e ? b . href || c : c ) && d ( b ) } a . ui = a . ui || { } ; a . ui . version || ( a . extend ( a . ui , { version : "1.8.18" , keyCode : { ALT : 18 , BACKSPACE : 8 , CAPS _LOCK : 20 , COMMA : 188 , COMMAND : 91 , COMMAND _LEFT : 91 , COMMAND _RIGHT : 93 , CONTROL : 17 , DELETE : 46 , DOWN : 40 , END : 35 , ENTER : 13 , ESCAPE : 27 , HOME : 36 , INSERT : 45 , LEFT : 37 , MENU : 93 , NUMPAD _ADD : 107 , NUMPAD _DECIMAL : 110 , NUMPAD _DIVIDE : 111 , NUMPAD _ENTER : 108 , NUMPAD _MULTIPLY : 106 , NUMPAD _SUBTRACT : 109 , PAGE _DOWN : 34 , PAGE _UP : 33 , PERIOD : 190 , RIGHT : 39 , SHIFT : 16 , SPACE : 32 , TAB : 9 , UP : 38 , WINDOWS : 91 } } ) , a . fn . extend ( { propAttr : a . fn . prop || a . fn . attr , _focus : a . fn . focus , focus : function ( b , c ) { return typeof b == "number" ? this . each ( function ( ) { var d = this ; setTimeout ( function ( ) { a ( d ) . focus ( ) , c && c . call ( d ) } , b ) } ) : this . _focus . apply ( this , arguments ) } , scrollParent : function ( ) { var b ; a . browser . msie && /(static|relative)/ . test ( this . css ( "position" ) ) || /absolute/ . test ( this . css ( "position" ) ) ? b = this . parents ( ) . filter ( function ( ) { return /(relative|absolute|fixed)/ . test ( a . curCSS ( this , "position" , 1 ) ) && /(auto|scroll)/ . test ( a . curCSS ( this , "overflow" , 1 ) + a . curCSS ( this , "overflow-y" , 1 ) + a . curCSS ( this , "overflow-x" , 1 ) ) } ) . eq ( 0 ) : b = this . parents ( ) . filter ( function ( ) { return /(auto|scroll)/ . test ( a . curCSS ( this , "overflow" , 1 ) + a . curCSS ( this , "overflow-y" , 1 ) + a . curCSS ( this , "overflow-x" , 1 ) ) } ) . eq ( 0 ) ; return /fixed/ . test ( this . css ( "position" ) ) || ! b . length ? a ( document ) : b } , zIndex : function ( c ) { if ( c !== b ) return this . css ( "zIndex" , c ) ; if ( this . length ) { var d = a ( this [ 0 ] ) , e , f ; while ( d . length && d [ 0 ] !== document ) { e = d . css ( "position" ) ; if ( e === "absolute" || e === "relative" || e === "fixed" ) { f = parseInt ( d . css ( "zIndex" ) , 10 ) ; if ( ! isNaN ( f ) && f !== 0 ) return f } d = d . parent ( ) } } return 0 } , disableSelection : function ( ) { return this . bind ( ( a . support . selectstart ? "selectstart" : "mousedown" ) + ".ui-disableSelection" , function ( a ) { a . preventDefault ( ) } ) } , enableSelection : function ( ) { return this . unbind ( ".ui-disableSelection" ) } } ) , a . each ( [ "Width" , "Height" ] , function ( c , d ) { function h ( b , c , d , f ) { a . each ( e , function ( ) { c -= parseFloat ( a . curCSS ( b , "padding" + this , ! 0 ) ) || 0 , d && ( c -= parseFloat ( a . curCSS ( b , "border" + this + "Width" , ! 0 ) ) || 0 ) , f && ( c -= parseFloat ( a . curCSS ( b , "margin" + this , ! 0 ) ) || 0 ) } ) ; return c } var e = d === "Width" ? [ "Left" , "Right" ] : [ "Top" , "Bottom" ] , f = d . toLowerCase ( ) , g = { innerWidth : a . fn . innerWidth , innerHeight : a . fn . innerHeight , outerWidth : a . fn . outerWidth , outerHeight : a . fn . outerHeight } ; a . fn [ "inner" + d ] = function ( c ) { if ( c === b ) return g [ "inner" + d ] . call ( this ) ; return this . each ( function ( ) { a ( this ) . css ( f , h ( this , c ) + "px" ) } ) } , a . fn [ "outer" + d ] = function ( b , c ) { if ( typeof b != "number" ) return g [ "outer" + d ] . call ( this , b ) ; return this . each ( function ( ) { a ( this ) . css ( f , h ( this , b , ! 0 , c ) + "px" ) } ) } } ) , a . extend ( a . expr [ ":" ] , { data : function ( b , c , d ) { return ! ! a . data ( b , d [ 3 ] ) } , focusable : function ( b ) { return c ( b , ! isNaN ( a . attr ( b , "tabindex" ) ) ) } , tabbable : function ( b ) { var d = a . attr ( b , "tabindex" ) , e = isNaN ( d ) ; return ( e || d >= 0 ) && c ( b , ! e ) } } ) , a ( function ( ) { var b = document . body , c = b . appendChild ( c = document . createElement ( "div" ) ) ; c . offsetHeight , a . extend ( c . style , { minHeight : "100px" , height : "auto" , padding : 0 , borderWidth : 0 } ) , a . support . minHeight = c . offsetHeight === 100 , a . support . selectstart = "onselectstart" in c , b . removeChild ( c ) . style . display = "none" } ) , a . extend ( a . ui , { plugin : { add : function ( b , c , d ) { var e = a . ui [ b ] . prototype ; for ( var f in d ) e . plugins [ f ] = e . plugins [ f ] || [ ] , e . plugins [ f ] . push ( [ c , d [ f ] ] ) } , call : function ( a , b , c ) { var d = a . plugins [ b ] ; if ( ! ! d && ! ! a . element [ 0 ] . parentNode ) for ( var e = 0 ; e < d . length ; e ++ ) a . options [ d [ e ] [ 0 ] ] && d [ e ] [ 1 ] . apply ( a . element , c ) } } , contains : function ( a , b ) { return document . compareDocumentPosition ? a . compareDocumentPosition ( b ) & 16 : a !== b && a . contains ( b ) } , hasScroll : function ( b , c ) { if ( a ( b ) . css ( "overflow" ) === "hidden" ) return ! 1 ; var d = c && c === "left" ? "scrollLeft" : "scrollTop" , e = ! 1 ; if ( b [ d ] > 0 ) return ! 0 ; b [ d ] = 1 , e = b [ d ] > 0 , b [ d ] = 0 ; return e } , isOverAxis : function ( a , b , c ) { return a > b && a < b + c } , isOver : function ( b , c , d , e , f , g ) { return
/ * !
* jQuery UI Widget 1.8 . 18
2012-02-14 06:33:02 +00:00
*
2012-03-09 11:14:21 +00:00
* Copyright 2011 , AUTHORS . txt ( http : //jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses .
* http : //jquery.org/license
2012-02-14 06:33:02 +00:00
*
2012-03-09 11:14:21 +00:00
* http : //docs.jquery.com/UI/Widget
2012-02-14 06:33:02 +00:00
* /
2012-03-09 11:14:21 +00:00
( function ( a , b ) { if ( a . cleanData ) { var c = a . cleanData ; a . cleanData = function ( b ) { for ( var d = 0 , e ; ( e = b [ d ] ) != null ; d ++ ) try { a ( e ) . triggerHandler ( "remove" ) } catch ( f ) { } c ( b ) } } else { var d = a . fn . remove ; a . fn . remove = function ( b , c ) { return this . each ( function ( ) { c || ( ! b || a . filter ( b , [ this ] ) . length ) && a ( "*" , this ) . add ( [ this ] ) . each ( function ( ) { try { a ( this ) . triggerHandler ( "remove" ) } catch ( b ) { } } ) ; return d . call ( a ( this ) , b , c ) } ) } } a . widget = function ( b , c , d ) { var e = b . split ( "." ) [ 0 ] , f ; b = b . split ( "." ) [ 1 ] , f = e + "-" + b , d || ( d = c , c = a . Widget ) , a . expr [ ":" ] [ f ] = function ( c ) { return ! ! a . data ( c , b ) } , a [ e ] = a [ e ] || { } , a [ e ] [ b ] = function ( a , b ) { arguments . length && this . _createWidget ( a , b ) } ; var g = new c ; g . options = a . extend ( ! 0 , { } , g . options ) , a [ e ] [ b ] . prototype = a . extend ( ! 0 , g , { namespace : e , widgetName : b , widgetEventPrefix : a [ e ] [ b ] . prototype . widgetEventPrefix || b , widgetBaseClass : f } , d ) , a . widget . bridge ( b , a [ e ] [ b ] ) } , a . widget . bridge = function ( c , d ) { a . fn [ c ] = function ( e ) { var f = typeof e == "string" , g = Array . prototype . slice . call ( arguments , 1 ) , h = this ; e = ! f && g . length ? a . extend . apply ( null , [ ! 0 , e ] . concat ( g ) ) : e ; if ( f && e . charAt ( 0 ) === "_" ) return h ; f ? this . each ( function ( ) { var d = a . data ( this , c ) , f = d && a . isFunction ( d [ e ] ) ? d [ e ] . apply ( d , g ) : d ; if ( f !== d && f !== b ) { h = f ; return ! 1 } } ) : this . each ( function ( ) { var b = a . data ( this , c ) ; b ? b . option ( e || { } ) . _init ( ) : a . data ( this , c , new d ( e , this ) ) } ) ; return h } } , a . Widget = function ( a , b ) { arguments . length && this . _createWidget ( a , b ) } , a . Widget . prototype = { widgetName : "widget" , widgetEventPrefix : "" , options : { disabled : ! 1 } , _createWidget : function ( b , c ) { a . data ( c , this . widgetName , this ) , this . element = a ( c ) , this . options = a . extend ( ! 0 , { } , this . options , this . _getCreateOptions ( ) , b ) ; var d = this ; this . element . bind ( "remove." + this . widgetName , function ( ) { d . destroy ( ) } ) , this . _create ( ) , this . _trigger ( "create" ) , this . _init ( ) } , _getCreateOptions : function ( ) { return a . metadata && a . metadata . get ( this . element [ 0 ] ) [ this . widgetName ] } , _create : function ( ) { } , _init : function ( ) { } , destroy : function ( ) { this . element . unbind ( "." + this . widgetName ) . removeData ( this . widgetName ) , this . widget ( ) . unbind ( "." + this . widgetName ) . removeAttr ( "aria-disabled" ) . removeClass ( this . widgetBaseClass + "-disabled " + "ui-state-disabled" ) } , widget : function ( ) { return this . element } , option : function ( c , d ) { var e = c ; if ( arguments . length === 0 ) return a . extend ( { } , this . options ) ; if ( typeof c == "string" ) { if ( d === b ) return this . options [ c ] ; e = { } , e [ c ] = d } this . _setOptions ( e ) ; return this } , _setOptions : function ( b ) { var c = this ; a . each ( b , function ( a , b ) { c . _setOption ( a , b ) } ) ; return this } , _setOption : function ( a , b ) { this . options [ a ] = b , a === "disabled" && this . widget ( ) [ b ? "addClass" : "removeClass" ] ( this . widgetBaseClass + "-disabled" + " " + "ui-state-disabled" ) . attr ( "aria-disabled" , b ) ; return this } , enable : function ( ) { return this . _setOption ( "disabled" , ! 1 ) } , disable : function ( ) { return this . _setOption ( "disabled" , ! 0 ) } , _trigger : function ( b , c , d ) { var e , f , g = this . options [ b ] ; d = d || { } , c = a . Event ( c ) , c . type = ( b === this . widgetEventPrefix ? b : this . widgetEventPrefix + b ) . toLowerCase ( ) , c . target = this . element [ 0 ] , f = c . originalEvent ; if ( f ) for ( e in f ) e in c || ( c [ e ] = f [ e ] ) ; this . element . trigger ( c , d ) ; return ! ( a . isFunction ( g ) && g . call ( this . element [ 0 ] , c , d ) === ! 1 || c . isDefaultPrevented ( ) ) } } } ) ( jQuery ) ;
/ * !
* jQuery UI Mouse 1.8 . 18
*
* Copyright 2011 , AUTHORS . txt ( http : //jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses .
* http : //jquery.org/license
*
* http : //docs.jquery.com/UI/Mouse
*
* Depends :
* jquery . ui . widget . js
* /
( function ( a , b ) { var c = ! 1 ; a ( document ) . mouseup ( function ( a ) { c = ! 1 } ) , a . widget ( "ui.mouse" , { options : { cancel : ":input,option" , distance : 1 , delay : 0 } , _mouseInit : function ( ) { var b = this ; this . element . bind ( "mousedown." + this . widgetName , function ( a ) { return b . _mouseDown ( a ) } ) . bind ( "click." + this . widgetName , function ( c ) { if ( ! 0 === a . data ( c . target , b . widgetName + ".preventClickEvent" ) ) { a . removeData ( c . target , b . widgetName + ".preventClickEvent" ) , c . stopImmediatePropagation ( ) ; return ! 1 } } ) , this . started = ! 1 } , _mouseDestroy : function ( ) { this . element . unbind ( "." + this . widgetName ) } , _mouseDown : function ( b ) { if ( ! c ) { this . _mouseStarted && this . _mouseUp ( b ) , this . _mouseDownEvent = b ; var d = this , e = b . which == 1 , f = typeof this . options . cancel == "string" && b . target . nodeName ? a ( b . target ) . closest ( this . options . cancel ) . length : ! 1 ; if ( ! e || f || ! this . _mouseCapture ( b ) ) return ! 0 ; this . mouseDelayMet = ! this . options . delay , this . mouseDelayMet || ( this . _mouseDelayTimer = setTimeout ( function ( ) { d . mouseDelayMet = ! 0 } , this . options . delay ) ) ; if ( this . _mouseDistanceMet ( b ) && this . _mouseDelayMet ( b ) ) { this . _mouseStarted = this . _mouseStart ( b ) !== ! 1 ; if ( ! this . _mouseStarted ) { b . preventDefault ( ) ; return ! 0 } } ! 0 === a . data ( b . target , this . widgetName + ".preventClickEvent" ) && a . removeData ( b . target , this . widgetName + ".preventClickEvent" ) , this . _mouseMoveDelegate = function ( a ) { return d . _mouseMove ( a ) } , this . _mouseUpDelegate = function ( a ) { return d . _mouseUp ( a ) } , a ( document ) . bind ( "mousemove." + this . widgetName , this . _mouseMoveDelegate ) . bind ( "mouseup." + this . widgetName , this . _mouseUpDelegate ) , b . preventDefault ( ) , c = ! 0 ; return ! 0 } } , _mouseMove : function ( b ) { if ( a . browser . msie && ! ( document . documentMode >= 9 ) && ! b . button ) return this . _mouseUp ( b ) ; if ( this . _mouseStarted ) { this . _mouseDrag ( b ) ; return b . preventDefault ( ) } this . _mouseDistanceMet ( b ) && this . _mouseDelayMet ( b ) && ( this . _mouseStarted = this . _mouseStart ( this . _mouseDownEvent , b ) !== ! 1 , this . _mouseStarted ? this . _mouseDrag ( b ) : this . _mouseUp ( b ) ) ; return ! this . _mouseStarted } , _mouseUp : function ( b ) { a ( document ) . unbind ( "mousemove." + this . widgetName , this . _mouseMoveDelegate ) . unbind ( "mouseup." + this . widgetName , this . _mouseUpDelegate ) , this . _mouseStarted && ( this . _mouseStarted = ! 1 , b . target == this . _mouseDownEvent . target && a . data ( b . target , this . widgetName + ".preventClickEvent" , ! 0 ) , this . _mouseStop ( b ) ) ; return ! 1 } , _mouseDistanceMet : function ( a ) { return Math . max ( Math . abs ( this . _mouseDownEvent . pageX - a . pageX ) , Math . abs ( this . _mouseDownEvent . pageY - a . pageY ) ) >= this . options . distance } , _mouseDelayMet : function ( a ) { return this . mouseDelayMet } , _mouseStart : function ( a ) { } , _mouseDrag : function ( a ) { } , _mouseStop : function ( a ) { } , _mouseCapture : function ( a ) { return ! 0 } } ) } ) ( jQuery ) ;
2012-02-14 06:42:13 +00:00
/ *
2012-03-09 11:14:21 +00:00
* jQuery UI Position 1.8 . 18
*
* Copyright 2011 , AUTHORS . txt ( http : //jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses .
* http : //jquery.org/license
*
* http : //docs.jquery.com/UI/Position
* /
( function ( a , b ) { a . ui = a . ui || { } ; var c = /left|center|right/ , d = /top|center|bottom/ , e = "center" , f = { } , g = a . fn . position , h = a . fn . offset ; a . fn . position = function ( b ) { if ( ! b || ! b . of ) return g . apply ( this , arguments ) ; b = a . extend ( { } , b ) ; var h = a ( b . of ) , i = h [ 0 ] , j = ( b . collision || "flip" ) . split ( " " ) , k = b . offset ? b . offset . split ( " " ) : [ 0 , 0 ] , l , m , n ; i . nodeType === 9 ? ( l = h . width ( ) , m = h . height ( ) , n = { top : 0 , left : 0 } ) : i . setTimeout ? ( l = h . width ( ) , m = h . height ( ) , n = { top : h . scrollTop ( ) , left : h . scrollLeft ( ) } ) : i . preventDefault ? ( b . at = "left top" , l = m = 0 , n = { top : b . of . pageY , left : b . of . pageX } ) : ( l = h . outerWidth ( ) , m = h . outerHeight ( ) , n = h . offset ( ) ) , a . each ( [ "my" , "at" ] , function ( ) { var a = ( b [ this ] || "" ) . split ( " " ) ; a . length === 1 && ( a = c . test ( a [ 0 ] ) ? a . concat ( [ e ] ) : d . test ( a [ 0 ] ) ? [ e ] . concat ( a ) : [ e , e ] ) , a [ 0 ] = c . test ( a [ 0 ] ) ? a [ 0 ] : e , a [ 1 ] = d . test ( a [ 1 ] ) ? a [ 1 ] : e , b [ this ] = a } ) , j . length === 1 && ( j [ 1 ] = j [ 0 ] ) , k [ 0 ] = parseInt ( k [ 0 ] , 10 ) || 0 , k . length === 1 && ( k [ 1 ] = k [ 0 ] ) , k [ 1 ] = parseInt ( k [ 1 ] , 10 ) || 0 , b . at [ 0 ] === "right" ? n . left += l : b . at [ 0 ] === e && ( n . left += l / 2 ) , b . at [ 1 ] === "bottom" ? n . top += m : b . at [ 1 ] === e && ( n . top += m / 2 ) , n . left += k [ 0 ] , n . top += k [ 1 ] ; return this . each ( function ( ) { var c = a ( this ) , d = c . outerWidth ( ) , g = c . outerHeight ( ) , h = parseInt ( a . curCSS ( this , "marginLeft" , ! 0 ) ) || 0 , i = parseInt ( a . curCSS ( this , "marginTop" , ! 0 ) ) || 0 , o = d + h + ( parseInt ( a . curCSS ( this , "marginRight" , ! 0 ) ) || 0 ) , p = g + i + ( parseInt ( a . curCSS ( this , "marginBottom" , ! 0 ) ) || 0 ) , q = a . extend ( { } , n ) , r ; b . my [ 0 ] === "right" ? q . left -= d : b . my [ 0 ] === e && ( q . left -= d / 2 ) , b . my [ 1 ] === "bottom" ? q . top -= g : b . my [ 1 ] === e && ( q . top -= g / 2 ) , f . fractions || ( q . left = Math . round ( q . left ) , q . top = Math . round ( q . top ) ) , r = { left : q . left - h , top : q . top - i } , a . each ( [ "left" , "top" ] , function ( c , e ) { a . ui . position [ j [ c ] ] && a . ui . position [ j [ c ] ] [ e ] ( q , { targetWidth : l , targetHeight : m , elemWidth : d , elemHeight : g , collisionPosition : r , collisionWidth : o , collisionHeight : p , offset : k , my : b . my , at : b . at } ) } ) , a . fn . bgiframe && c . bgiframe ( ) , c . offset ( a . extend ( q , { using : b . using } ) ) } ) } , a . ui . position = { fit : { left : function ( b , c ) { var d = a ( window ) , e = c . collisionPosition . left + c . collisionWidth - d . width ( ) - d . scrollLeft ( ) ; b . left = e > 0 ? b . left - e : Math . max ( b . left - c . collisionPosition . left , b . left ) } , top : function ( b , c ) { var d = a ( window ) , e = c . collisionPosition . top + c . collisionHeight - d . height ( ) - d . scrollTop ( ) ; b . top = e > 0 ? b . top - e : Math . max ( b . top - c . collisionPosition . top , b . top ) } } , flip : { left : function ( b , c ) { if ( c . at [ 0 ] !== e ) { var d = a ( window ) , f = c . collisionPosition . left + c . collisionWidth - d . width ( ) - d . scrollLeft ( ) , g = c . my [ 0 ] === "left" ? - c . elemWidth : c . my [ 0 ] === "right" ? c . elemWidth : 0 , h = c . at [ 0 ] === "left" ? c . targetWidth : - c . targetWidth , i = - 2 * c . offset [ 0 ] ; b . left += c . collisionPosition . left < 0 ? g + h + i : f > 0 ? g + h + i : 0 } } , top : function ( b , c ) { if ( c . at [ 1 ] !== e ) { var d = a ( window ) , f = c . collisionPosition . top + c . collisionHeight - d . height ( ) - d . scrollTop ( ) , g = c . my [ 1 ] === "top" ? - c . elemHeight : c . my [ 1 ] === "bottom" ? c . elemHeight : 0 , h = c . at [ 1 ] === "top" ? c . targetHeight : - c . targetHeight , i = - 2 * c . offset [ 1 ] ; b . top += c . collisionPosition . top < 0 ? g + h + i : f > 0 ? g + h + i : 0 } } } } , a . offset . setOffset || ( a . offset . setOffset = function ( b , c ) { /static/ . test ( a . curCSS ( b , "position" ) ) && ( b . style . position = "relative" ) ; var d = a ( b ) , e = d . offset ( ) , f = parseInt ( a . curCSS ( b , "top" , ! 0 ) , 10 ) || 0 , g = parseInt ( a . curCSS ( b , "left" , ! 0 ) , 10 ) || 0 , h = { top : c . top - e . top + f , left : c . left - e . left + g } ; "using" in c ? c . using . call ( b , h ) : d . css ( h ) } , a . fn . offset = function ( b ) { var c = this [ 0 ] ; if ( ! c || ! c . ownerDocument ) return null ; if ( b ) return this . each ( function ( ) { a . offset . setOffset ( this , b ) } ) ; return h . call ( this ) } ) , function ( ) { var b = document . getElementsByTagName ( "body" ) [ 0 ] , c = document . createElement ( "div" ) , d , e , g , h , i ; d = document . createElement ( b ? "div" : "body" ) , g = { visibility : "hidden" , width : 0 , height : 0 , border : 0 , margin : 0 , background : "none" } , b && a . extend ( g , { position : "absolute" , left : "-1000px" , top : "-1000px" } ) ; for ( var j in g ) d . style [ j ] = g [ j ] ; d . appendChild ( c ) , e = b || document . documentElement , e . insertBefore ( d , e . firstChild ) , c . style . cssText = "position: absolute; left: 10.7432222px; top: 10.432325px; height: 30px; width: 201px;" , h = a ( c ) . offset ( function ( a , b ) { return b } ) . offset ( ) , d . innerHTML = "" , e . removeChild ( d ) , i = h . top + h . left + ( b ? 2e3 : 0 ) , f . fractions = i > 21 && i < 22 } ( ) } ) ( jQuery ) ;
/ *
* lib / js / lib / jquery / jquery . ui . datepicker . js
* /
/ * j Q u e r y U I D a t e p i c k e r 1 . 8 . 1 8
*
* Copyright 2011 , AUTHORS . txt ( http : //jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses .
* http : //jquery.org/license
*
* http : //docs.jquery.com/UI/Datepicker
*
* Depends :
* jquery . ui . core . js
* /(function($,undefined){function isArray(a){return a&&($.browser.safari&&typeof a=="object"&&a.length||a.constructor&&a.constructor.toString().match(/ \ Array \ ( \ ) / ) ) } function extendRemove ( a , b ) { $ . extend ( a , b ) ; for ( var c in b ) if ( b [ c ] == null || b [ c ] == undefined ) a [ c ] = b [ c ] ; return a } function bindHover ( a ) { var b = "button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a" ; return a . bind ( "mouseout" , function ( a ) { var c = $ ( a . target ) . closest ( b ) ; ! c . length || c . removeClass ( "ui-state-hover ui-datepicker-prev-hover ui-datepicker-next-hover" ) } ) . bind ( "mouseover" , function ( c ) { var d = $ ( c . target ) . closest ( b ) ; ! $ . datepicker . _isDisabledDatepicker ( instActive . inline ? a . parent ( ) [ 0 ] : instActive . input [ 0 ] ) && ! ! d . length && ( d . parents ( ".ui-datepicker-calendar" ) . find ( "a" ) . removeClass ( "ui-state-hover" ) , d . addClass ( "ui-state-hover" ) , d . hasClass ( "ui-datepicker-prev" ) && d . addClass ( "ui-datepicker-prev-hover" ) , d . hasClass ( "ui-datepicker-next" ) && d . addClass ( "ui-datepicker-next-hover" ) ) } ) } function Datepicker ( ) { this . debug = ! 1 , this . _curInst = null , this . _keyEvent = ! 1 , this . _disabledInputs = [ ] , this . _datepickerShowing = ! 1 , this . _inDialog = ! 1 , this . _mainDivId = "ui-datepicker-div" , this . _inlineClass = "ui-datepicker-inline" , this . _appendClass = "ui-datepicker-append" , this . _triggerClass = "ui-datepicker-trigger" , this . _dialogClass = "ui-datepicker-dialog" , this . _disableClass = "ui-datepicker-disabled" , this . _unselectableClass = "ui-datepicker-unselectable" , this . _currentClass = "ui-datepicker-current-day" , this . _dayOverClass = "ui-datepicker-days-cell-over" , this . regional = [ ] , this . regional [ "" ] = { closeText : "Done" , prevText : "Prev" , nextText : "Next" , currentText : "Today" , monthNames : [ "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December" ] , monthNamesShort : [ "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec" ] , dayNames : [ "Sunday" , "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" ] , dayNamesShort : [ "Sun" , "Mon" , "Tue" , "Wed" , "Thu" , "Fri" , "Sat" ] , dayNamesMin : [ "Su" , "Mo" , "Tu" , "We" , "Th" , "Fr" , "Sa" ] , weekHeader : "Wk" , dateFormat : "mm/dd/yy" , firstDay : 0 , isRTL : ! 1 , showMonthAfterYear : ! 1 , yearSuffix : "" } , this . _defaults = { showOn : "focus" , showAnim : "fadeIn" , showOptions : { } , defaultDate : null , appendText : "" , buttonText : "..." , buttonImage : "" , buttonImageOnly : ! 1 , hideIfNoPrevNext : ! 1 , navigationAsDateFormat : ! 1 , gotoCurrent : ! 1 , changeMonth : ! 1 , changeYear : ! 1 , yearRange : "c-10:c+10" , showOtherMonths : ! 1 , selectOtherMonths : ! 1 , showWeek : ! 1 , calculateWeek : this . iso8601Week , shortYearCutoff : "+10" , minDate : null , maxDate : null , duration : "fast" , beforeShowDay : null , beforeShow : null , onSelect : null , onChangeMonthYear : null , onClose : null , numberOfMonths : 1 , showCurrentAtPos : 0 , stepMonths : 1 , stepBigMonths : 12 , altField : "" , altFormat : "" , constrainInput : ! 0 , showButtonPanel : ! 1 , autoSize : ! 1 , disabled : ! 1 } , $ . extend ( this . _defaults , this . regional [ "" ] ) , this . dpDiv = bindHover ( $ ( '<div id="' + this . _mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>' ) ) } $ . extend ( $ . ui , { datepicker : { version : "1.8.18" } } ) ; var PROP _NAME = "datepicker" , dpuuid = ( new Date ) . getTime ( ) , instActive ; $ . extend ( Datepicker . prototype , { markerClassName : "hasDatepicker" , maxRows : 4 , log : function ( ) { this . debug && console . log . apply ( "" , arguments ) } , _widgetDatepicker : function ( ) { return this . dpDiv } , setDefaults : function ( a ) { extendRemove ( this . _defaults , a || { } ) ; return this } , _attachDatepicker : function ( target , settings ) { var inlineSettings = null ; for ( var attrName in this . _defaults ) { var attrValue = target . getAttribute ( "date:" + attrName ) ; if ( attrValue ) { inlineSettings = inlineSettings || { } ; try { inlineSettings [ attrName ] = eval ( attrValue ) } catch ( err ) { inlineSettings [ attrName ] = attrValue } } } var nodeName = target . nodeName . toLowerCase ( ) , inline = nodeName == "div" || nodeName == "span" ; target . id || ( this . uuid += 1 , target . id = "dp" + this . uuid ) ; var inst = this . _newInst ( $ ( target ) , inline ) ; inst . settings = $ . extend ( { } , settings || { } , inlineSettings || { } ) , nodeName == "input" ? this . _connectDatepicker ( target , inst ) : inline && this . _inlineDatepicker ( target , inst ) } , _newInst : function ( a , b ) { var c = a [ 0 ] . id . replace ( /([^A-Za-z0-9_-])/g , "\\\\$1" ) ; return { id : c , input : a , selectedDay : 0 , selectedMonth : 0 , selectedYear : 0 , drawMonth : 0 , drawYear : 0 , inl
a . _keyEvent = ! 1 ; return K } , _generateMonthYearHeader : function ( a , b , c , d , e , f , g , h ) { var i = this . _get ( a , "changeMonth" ) , j = this . _get ( a , "changeYear" ) , k = this . _get ( a , "showMonthAfterYear" ) , l = '<div class="ui-datepicker-title">' , m = "" ; if ( f || ! i ) m += '<span class="ui-datepicker-month">' + g [ b ] + "</span>" ; else { var n = d && d . getFullYear ( ) == c , o = e && e . getFullYear ( ) == c ; m += '<select class="ui-datepicker-month" onchange="DP_jQuery_' + dpuuid + ".datepicker._selectMonthYear('#" + a . id + "', this, 'M');\" " + ">" ; for ( var p = 0 ; p < 12 ; p ++ ) ( ! n || p >= d . getMonth ( ) ) && ( ! o || p <= e . getMonth ( ) ) && ( m += '<option value="' + p + '"' + ( p == b ? ' selected="selected"' : "" ) + ">" + h [ p ] + "</option>" ) ; m += "</select>" } k || ( l += m + ( f || ! i || ! j ? " " : "" ) ) ; if ( ! a . yearshtml ) { a . yearshtml = "" ; if ( f || ! j ) l += '<span class="ui-datepicker-year">' + c + "</span>" ; else { var q = this . _get ( a , "yearRange" ) . split ( ":" ) , r = ( new Date ) . getFullYear ( ) , s = function ( a ) { var b = a . match ( /c[+-].*/ ) ? c + parseInt ( a . substring ( 1 ) , 10 ) : a . match ( /[+-].*/ ) ? r + parseInt ( a , 10 ) : parseInt ( a , 10 ) ; return isNaN ( b ) ? r : b } , t = s ( q [ 0 ] ) , u = Math . max ( t , s ( q [ 1 ] || "" ) ) ; t = d ? Math . max ( t , d . getFullYear ( ) ) : t , u = e ? Math . min ( u , e . getFullYear ( ) ) : u , a . yearshtml += '<select class="ui-datepicker-year" onchange="DP_jQuery_' + dpuuid + ".datepicker._selectMonthYear('#" + a . id + "', this, 'Y');\" " + ">" ; for ( ; t <= u ; t ++ ) a . yearshtml += '<option value="' + t + '"' + ( t == c ? ' selected="selected"' : "" ) + ">" + t + "</option>" ; a . yearshtml += "</select>" , l += a . yearshtml , a . yearshtml = null } } l += this . _get ( a , "yearSuffix" ) , k && ( l += ( f || ! i || ! j ? " " : "" ) + m ) , l += "</div>" ; return l } , _adjustInstDate : function ( a , b , c ) { var d = a . drawYear + ( c == "Y" ? b : 0 ) , e = a . drawMonth + ( c == "M" ? b : 0 ) , f = Math . min ( a . selectedDay , this . _getDaysInMonth ( d , e ) ) + ( c == "D" ? b : 0 ) , g = this . _restrictMinMax ( a , this . _daylightSavingAdjust ( new Date ( d , e , f ) ) ) ; a . selectedDay = g . getDate ( ) , a . drawMonth = a . selectedMonth = g . getMonth ( ) , a . drawYear = a . selectedYear = g . getFullYear ( ) , ( c == "M" || c == "Y" ) && this . _notifyChange ( a ) } , _restrictMinMax : function ( a , b ) { var c = this . _getMinMaxDate ( a , "min" ) , d = this . _getMinMaxDate ( a , "max" ) , e = c && b < c ? c : b ; e = d && e > d ? d : e ; return e } , _notifyChange : function ( a ) { var b = this . _get ( a , "onChangeMonthYear" ) ; b && b . apply ( a . input ? a . input [ 0 ] : null , [ a . selectedYear , a . selectedMonth + 1 , a ] ) } , _getNumberOfMonths : function ( a ) { var b = this . _get ( a , "numberOfMonths" ) ; return b == null ? [ 1 , 1 ] : typeof b == "number" ? [ 1 , b ] : b } , _getMinMaxDate : function ( a , b ) { return this . _determineDate ( a , this . _get ( a , b + "Date" ) , null ) } , _getDaysInMonth : function ( a , b ) { return 32 - this . _daylightSavingAdjust ( new Date ( a , b , 32 ) ) . getDate ( ) } , _getFirstDayOfMonth : function ( a , b ) { return ( new Date ( a , b , 1 ) ) . getDay ( ) } , _canAdjustMonth : function ( a , b , c , d ) { var e = this . _getNumberOfMonths ( a ) , f = this . _daylightSavingAdjust ( new Date ( c , d + ( b < 0 ? b : e [ 0 ] * e [ 1 ] ) , 1 ) ) ; b < 0 && f . setDate ( this . _getDaysInMonth ( f . getFullYear ( ) , f . getMonth ( ) ) ) ; return this . _isInRange ( a , f ) } , _isInRange : function ( a , b ) { var c = this . _getMinMaxDate ( a , "min" ) , d = this . _getMinMaxDate ( a , "max" ) ; return ( ! c || b . getTime ( ) >= c . getTime ( ) ) && ( ! d || b . getTime ( ) <= d . getTime ( ) ) } , _getFormatConfig : function ( a ) { var b = this . _get ( a , "shortYearCutoff" ) ; b = typeof b != "string" ? b : ( new Date ) . getFullYear ( ) % 100 + parseInt ( b , 10 ) ; return { shortYearCutoff : b , dayNamesShort : this . _get ( a , "dayNamesShort" ) , dayNames : this . _get ( a , "dayNames" ) , monthNamesShort : this . _get ( a , "monthNamesShort" ) , monthNames : this . _get ( a , "monthNames" ) } } , _formatDate : function ( a , b , c , d ) { b || ( a . currentDay = a . selectedDay , a . currentMonth = a . selectedMonth , a . currentYear = a . selectedYear ) ; var e = b ? typeof b == "object" ? b : this . _daylightSavingAdjust ( new Date ( d , c , b ) ) : this . _daylightSavingAdjust ( new Date ( a . currentYear , a . currentMonth , a . currentDay ) ) ; return this . formatDate ( this . _get ( a , "dateFormat" ) , e , this . _getFormatConfig ( a ) ) } } ) , $ . fn . datepicker = function ( a ) { if ( ! this . length ) return this ; $ . datepicker . initialized || ( $ ( document ) . mousedown ( $ . datepicker . _checkExternalClick ) . find ( "body" ) . append ( $ . datepicker . dpDiv ) , $ . datepicker . initialized = ! 0 ) ; var b = Array . prototype . slice . call ( arguments , 1 ) ; if ( typeof a == "string" && ( a == "isDisabled" || a == "getDate" || a == "widget" ) ) return $ . datepicker [ "_" + a + "Datepicker" ] . apply ( $ . datepicker , [ this [ 0 ] ] . concat ( b ) ) ; if ( a == "option" && arguments . length == 2 && typeof arguments [ 1 ] == "string" ) return $ . datepicker [ "_" + a + "Datepicker" ] . apply ( $ . datepicker , [ this [ 0 ] ] . concat ( b ) ) ; return
2012-02-14 06:33:02 +00:00
/ *
2012-03-09 11:14:21 +00:00
* lib / js / lib / jquery / jquery . ui . autocomplete . js
* /
/ * j Q u e r y U I A u t o c o m p l e t e 1 . 8 . 1 8
*
* Copyright 2011 , AUTHORS . txt ( http : //jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses .
* http : //jquery.org/license
*
* http : //docs.jquery.com/UI/Autocomplete
*
* Depends :
* jquery . ui . core . js
* jquery . ui . widget . js
* jquery . ui . position . js
* / ( f u n c t i o n ( a , b ) { v a r c = 0 ; a . w i d g e t ( " u i . a u t o c o m p l e t e " , { o p t i o n s : { a p p e n d T o : " b o d y " , a u t o F o c u s : ! 1 , d e l a y : 3 0 0 , m i n L e n g t h : 1 , p o s i t i o n : { m y : " l e f t t o p " , a t : " l e f t b o t t o m " , c o l l i s i o n : " n o n e " } , s o u r c e : n u l l } , p e n d i n g : 0 , _ c r e a t e : f u n c t i o n ( ) { v a r b = t h i s , c = t h i s . e l e m e n t [ 0 ] . o w n e r D o c u m e n t , d ; t h i s . e l e m e n t . a d d C l a s s ( " u i - a u t o c o m p l e t e - i n p u t " ) . a t t r ( " a u t o c o m p l e t e " , " o f f " ) . a t t r ( { r o l e : " t e x t b o x " , " a r i a - a u t o c o m p l e t e " : " l i s t " , " a r i a - h a s p o p u p " : " t r u e " } ) . b i n d ( " k e y d o w n . a u t o c o m p l e t e " , f u n c t i o n ( c ) { i f ( ! b . o p t i o n s . d i s a b l e d & & ! b . e l e m e n t . p r o p A t t r ( " r e a d O n l y " ) ) { d = ! 1 ; v a r e = a . u i . k e y C o d e ; s w i t c h ( c . k e y C o d e ) { c a s e e . P A G E _ U P : b . _ m o v e ( " p r e v i o u s P a g e " , c ) ; b r e a k ; c a s e e . P A G E _ D O W N : b . _ m o v e ( " n e x t P a g e " , c ) ; b r e a k ; c a s e e . U P : b . _ m o v e ( " p r e v i o u s " , c ) , c . p r e v e n t D e f a u l t ( ) ; b r e a k ; c a s e e . D O W N : b . _ m o v e ( " n e x t " , c ) , c . p r e v e n t D e f a u l t ( ) ; b r e a k ; c a s e e . E N T E R : c a s e e . N U M P A D _ E N T E R : b . m e n u . a c t i v e & & ( d = ! 0 , c . p r e v e n t D e f a u l t ( ) ) ; c a s e e . T A B : i f ( ! b . m e n u . a c t i v e ) r e t u r n ; b . m e n u . s e l e c t ( c ) ; b r e a k ; c a s e e . E S C A P E : b . e l e m e n t . v a l ( b . t e r m ) , b . c l o s e ( c ) ; b r e a k ; d e f a u l t : c l e a r T i m e o u t ( b . s e a r c h i n g ) , b . s e a r c h i n g = s e t T i m e o u t ( f u n c t i o n ( ) { b . t e r m ! = b . e l e m e n t . v a l ( ) & & ( b . s e l e c t e d I t e m = n u l l , b . s e a r c h ( n u l l , c ) ) } , b . o p t i o n s . d e l a y ) } } } ) . b i n d ( " k e y p r e s s . a u t o c o m p l e t e " , f u n c t i o n ( a ) { d & & ( d = ! 1 , a . p r e v e n t D e f a u l t ( ) ) } ) . b i n d ( " f o c u s . a u t o c o m p l e t e " , f u n c t i o n ( ) { b . o p t i o n s . d i s a b l e d | | ( b . s e l e c t e d I t e m = n u l l , b . p r e v i o u s = b . e l e m e n t . v a l ( ) ) } ) . b i n d ( " b l u r . a u t o c o m p l e t e " , f u n c t i o n ( a ) { b . o p t i o n s . d i s a b l e d | | ( c l e a r T i m e o u t ( b . s e a r c h i n g ) , b . c l o s i n g = s e t T i m e o u t ( f u n c t i o n ( ) { b . c l o s e ( a ) , b . _ c h a n g e ( a ) } , 1 5 0 ) ) } ) , t h i s . _ i n i t S o u r c e ( ) , t h i s . r e s p o n s e = f u n c t i o n ( ) { r e t u r n b . _ r e s p o n s e . a p p l y ( b , a r g u m e n t s ) } , t h i s . m e n u = a ( " < u l > < / u l > " ) . a d d C l a s s ( " u i - a u t o c o m p l e t e " ) . a p p e n d T o ( a ( t h i s . o p t i o n s . a p p e n d T o | | " b o d y " , c ) [ 0 ] ) . m o u s e d o w n ( f u n c t i o n ( c ) { v a r d = b . m e n u . e l e m e n t [ 0 ] ; a ( c . t a r g e t ) . c l o s e s t ( " . u i - m e n u - i t e m " ) . l e n g t h | | s e t T i m e o u t ( f u n c t i o n ( ) { a ( d o c u m e n t ) . o n e ( " m o u s e d o w n " , f u n c t i o n ( c ) { c . t a r g e t ! = = b . e l e m e n t [ 0 ] & & c . t a r g e t ! = = d & & ! a . u i . c o n t a i n s ( d , c . t a r g e t ) & & b . c l o s e ( ) } ) } , 1 ) , s e t T i m e o u t ( f u n c t i o n ( ) { c l e a r T i m e o u t ( b . c l o s i n g ) } , 1 3 ) } ) . m e n u ( { f o c u s : f u n c t i o n ( a , c ) { v a r d = c . i t e m . d a t a ( " i t e m . a u t o c o m p l e t e " ) ; ! 1 ! = = b . _ t r i g g e r ( " f o c u s " , a , { i t e m : d } ) & & / ^ k e y / . t e s t ( a . o r i g i n a l E v e n t . t y p e ) & & b . e l e m e n t . v a l ( d . v a l u e ) } , s e l e c t e d : f u n c t i o n ( a , d ) { v a r e = d . i t e m . d a t a ( " i t e m . a u t o c o m p l e t e " ) , f = b . p r e v i o u s ; b . e l e m e n t [ 0 ] ! = = c . a c t i v e E l e m e n t & & ( b . e l e m e n t . f o c u s ( ) , b . p r e v i o u s = f , s e t T i m e o u t ( f u n c t i o n ( ) { b . p r e v i o u s = f , b . s e l e c t e d I t e m = e } , 1 ) ) , ! 1 ! = = b . _ t r i g g e r ( " s e l e c t " , a , { i t e m : e } ) & & b . e l e m e n t . v a l ( e . v a l u e ) , b . t e r m = b . e l e m e n t . v a l ( ) , b . c l o s e ( a ) , b . s e l e c t e d I t e m = e } , b l u r : f u n c t i o n ( a , c ) { b . m e n u . e l e m e n t . i s ( " : v i s i b l e " ) & & b . e l e m e n t . v a l ( ) ! = = b . t e r m & & b . e l e m e n t . v a l ( b . t e r m ) } } ) . z I n d e x ( t h i s . e l e m e n t . z I n d e x ( ) + 1 ) . c s s ( { t o p : 0 , l e f t : 0 } ) . h i d e ( ) . d a t a ( " m e n u " ) , a . f n . b g i f r a m e & & t h i s . m e n u . e l e m e n t . b g i f r a m e ( ) , b . b e f o r e u n l o a d H a n d l e r = f u n c t i o n ( ) { b . e l e m e n t . r e m o v e A t t r ( " a u t o c o m p l e t e " ) } , a ( w i n d o w ) . b i n d ( " b e f o r e u n l o a d " , b . b e f o r e u n l o a d H a n d l e r ) } , d e s t r o y : f u n c t i o n ( ) { t h i s . e l e m e n t . r e m o v e C l a s s ( " u i - a u t o c o m p l e t e - i n p u t " ) . r e m o v e A t t r ( " a u t o c o m p l e t e " ) . r e m o v e A t t r ( " r o l e " ) . r e m o v e A t t r ( " a r i a - a u t o c o m p l e t e " ) . r e m o v e A t t r ( " a r i a - h a s p o p u p " ) , t h i s . m e n u . e l e m e n t . r e m o v e ( ) , a ( w i n d o w ) . u n b i n d ( " b e f o r e u n l o a d " , t h i s . b e f o r e u n l o a d H a n d l e r ) , a . W i d g e t . p r o t o t y p e . d e s t r o y . c a l l ( t h i s ) } , _ s e t O p t i o n : f u n c t i o n ( b , c ) { a . W i d g e t . p r o t o t y p e . _ s e t O p t i o n . a p p l y ( t h i s , a r g u m e n t s ) , b = = = " s o u r c e " & & t h i s . _ i n i t S o u r c e ( ) , b = = = " a p p e n d T o " & & t h i s . m e n u . e l e m e n t . a p p e n d T o ( a ( c | | " b o d y " , t h i s . e l e m e n t [ 0 ] . o w n e r D o c u m e n t ) [ 0 ] ) , b = = = " d i s a b l e d " & & c & & t h i s . x h r & & t h i s . x h r . a b o r t ( ) } , _ i n i t S o u r c e : f u n c t i o n ( ) { v a r b = t h i s , d , e ; a . i s A r r a y ( t h i s . o p t i o n s . s o u r c e ) ? ( d = t h i s . o p t i o n s . s o u r c e , t h i s . s o u r c e = f u n c t i o n ( b , c ) { c ( a . u i . a u t o c o m p l e t e . f i l t e r ( d , b . t e r m ) ) } ) : t y p e o f t h i s . o p t i o n s . s o u r c e = = " s t r i n g " ? ( e = t h i s . o p t i o n s . s o u r c e , t h i s . s o u r c e = f u n c t i o n ( d , f ) { b . x h r & & b . x h r . a b o r t ( ) , b . x h r = a . a j a x ( { u r l : e , d a t a : d , d a t a T y p e : " j s o n " , c o n t e x t : { a u t o c o m p l e t e R e q u e s t : + + c } , s u c c e s s : f u n c t i o n ( a , b ) { t h i s . a u t o c o m p l e t e R e q u e s t = = = c & & f ( a ) } , e r r o r : f u n c t i o n ( ) { t h i s . a u t o c o m p l e t e R e q u e s t = = = c & & f ( [ ] ) } } ) } ) : t h i s . s o u r c e = t h i s . o p t i o n s . s o u r c e } , s e a r c h : f u n c t i o n ( a , b ) { a = a ! = n u l l ? a : t h i s . e l e m e n t . v a l ( ) , t h i s . t e r m = t h i s . e l e m e n t . v a l ( ) ; i f ( a . l e n g t h < t h i s . o p t i o n s . m i n L e n g t h ) r e t u r n t h i s . c l o s e ( b ) ; c l e a r T i m e o u t ( t h i s . c l o s i n g ) ; i f ( t h i s . _ t r i g g e r ( " s e a r c h " , b ) ! = = ! 1 ) r e t u r n t h i s . _ s e a r c h ( a ) } , _ s e a r c h : f u n c t i o n ( a ) { t h i s . p e n d i n g + + , t h i s . e l e m e n t . a d d C l a s s ( " u i - a u t o c o m p l e t e - l o a d i n g " ) , t h i s . s o u r c e ( { t e r m : a } , t h i s . r e s p o n s e ) } , _ r e s p o n s e : f u
/ *
* lib / js / lib / tiny _mce _33 / jquery . tinymce . js
* /
( function ( b ) { var e , d , a = [ ] , c = window ; b . fn . tinymce = function ( j ) { var p = this , g , k , h , m , i , l = "" , n = "" ; if ( ! p . length ) { return p } if ( ! j ) { return tinyMCE . get ( p [ 0 ] . id ) } function o ( ) { var r = [ ] , q = 0 ; if ( f ) { f ( ) ; f = null } p . each ( function ( t , u ) { var s , w = u . id , v = j . oninit ; if ( ! w ) { u . id = w = tinymce . DOM . uniqueId ( ) } s = new tinymce . Editor ( w , j ) ; r . push ( s ) ; if ( v ) { s . onInit . add ( function ( ) { var x , y = v ; if ( ++ q == r . length ) { if ( tinymce . is ( y , "string" ) ) { x = ( y . indexOf ( "." ) === - 1 ) ? null : tinymce . resolve ( y . replace ( /\.\w+$/ , "" ) ) ; y = tinymce . resolve ( y ) } y . apply ( x || tinymce , r ) } } ) } } ) ; b . each ( r , function ( t , s ) { s . render ( ) } ) } if ( ! c . tinymce && ! d && ( g = j . script _url ) ) { d = 1 ; h = g . substring ( 0 , g . lastIndexOf ( "/" ) ) ; if ( /_(src|dev)\.js/g . test ( g ) ) { n = "_src" } m = g . lastIndexOf ( "?" ) ; if ( m != - 1 ) { l = g . substring ( m + 1 ) } c . tinyMCEPreInit = c . tinyMCEPreInit || { base : h , suffix : n , query : l } ; if ( g . indexOf ( "gzip" ) != - 1 ) { i = j . language || "en" ; g = g + ( /\?/ . test ( g ) ? "&" : "?" ) + "js=true&core=true&suffix=" + escape ( n ) + "&themes=" + escape ( j . theme ) + "&plugins=" + escape ( j . plugins ) + "&languages=" + i ; if ( ! c . tinyMCE _GZ ) { tinyMCE _GZ = { start : function ( ) { tinymce . suffix = n ; function q ( r ) { tinymce . ScriptLoader . markDone ( tinyMCE . baseURI . toAbsolute ( r ) ) } q ( "langs/" + i + ".js" ) ; q ( "themes/" + j . theme + "/editor_template" + n + ".js" ) ; q ( "themes/" + j . theme + "/langs/" + i + ".js" ) ; b . each ( j . plugins . split ( "," ) , function ( s , r ) { if ( r ) { q ( "plugins/" + r + "/editor_plugin" + n + ".js" ) ; q ( "plugins/" + r + "/langs/" + i + ".js" ) } } ) } , end : function ( ) { } } } } b . ajax ( { type : "GET" , url : g , dataType : "script" , cache : true , success : function ( ) { tinymce . dom . Event . domLoaded = 1 ; d = 2 ; if ( j . script _loaded ) { j . script _loaded ( ) } o ( ) ; b . each ( a , function ( q , r ) { r ( ) } ) } } ) } else { if ( d === 1 ) { a . push ( o ) } else { o ( ) } } return p } ; b . extend ( b . expr [ ":" ] , { tinymce : function ( g ) { return g . id && ! ! tinyMCE . get ( g . id ) } } ) ; function f ( ) { function i ( l ) { if ( l === "remove" ) { this . each ( function ( n , o ) { var m = h ( o ) ; if ( m ) { m . remove ( ) } } ) } this . find ( "span.mceEditor,div.mceEditor" ) . each ( function ( n , o ) { var m = tinyMCE . get ( o . id . replace ( /_parent$/ , "" ) ) ; if ( m ) { m . remove ( ) } } ) } function k ( n ) { var m = this , l ; if ( n !== e ) { i . call ( m ) ; m . each ( function ( p , q ) { var o ; if ( o = tinyMCE . get ( q . id ) ) { o . setContent ( n ) } } ) } else { if ( m . length > 0 ) { if ( l = tinyMCE . get ( m [ 0 ] . id ) ) { return l . getContent ( ) } } } } function h ( m ) { var l = null ; ( m ) && ( m . id ) && ( c . tinymce ) && ( l = tinyMCE . get ( m . id ) ) ; return l } function g ( l ) { return ! ! ( ( l ) && ( l . length ) && ( c . tinymce ) && ( l . is ( ":tinymce" ) ) ) } var j = { } ; b . each ( [ "text" , "html" , "val" ] , function ( n , l ) { var o = j [ l ] = b . fn [ l ] , m = ( l === "text" ) ; b . fn [ l ] = function ( s ) { var p = this ; if ( ! g ( p ) ) { return o . apply ( p , arguments ) } if ( s !== e ) { k . call ( p . filter ( ":tinymce" ) , s ) ; o . apply ( p . not ( ":tinymce" ) , arguments ) ; return p } else { var r = "" ; var q = arguments ; ( m ? p : p . eq ( 0 ) ) . each ( function ( u , v ) { var t = h ( v ) ; r += t ? ( m ? t . getContent ( ) . replace ( /<(?:"[^"]*"|'[^']*'|[^'">])*>/g , "" ) : t . getContent ( ) ) : o . apply ( b ( v ) , q ) } ) ; return r } } } ) ; b . each ( [ "append" , "prepend" ] , function ( n , m ) { var o = j [ m ] = b . fn [ m ] , l = ( m === "prepend" ) ; b . fn [ m ] = function ( q ) { var p = this ; if ( ! g ( p ) ) { return o . apply ( p , arguments ) } if ( q !== e ) { p . filter ( ":tinymce" ) . each ( function ( s , t ) { var r = h ( t ) ; r && r . setContent ( l ? q + r . getContent ( ) : r . getContent ( ) + q ) } ) ; o . apply ( p . not ( ":tinymce" ) , arguments ) ; return p } } } ) ; b . each ( [ "remove" , "replaceWith" , "replaceAll" , "empty" ] , function ( m , l ) { var n = j [ l ] = b . fn [ l ] ; b . fn [ l ] = function ( ) { i . call ( this , l ) ; return n . apply ( this , arguments ) } } ) ; j . attr = b . fn . attr ; b . fn . attr = function ( n , q , o ) { var m = this ; if ( ( ! n ) || ( n !== "value" ) || ( ! g ( m ) ) ) { return j . attr . call ( m , n , q , o ) } if ( q !== e ) { k . call ( m . filter ( ":tinymce" ) , q ) ; j . attr . call ( m . not ( ":tinymce" ) , n , q , o ) ; return m } else { var p = m [ 0 ] , l = h ( p ) ; return l ? l . getContent ( ) : j . attr . call ( b ( p ) , n , q , o ) } } } } ) ( jQuery ) ;
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-29 09:41:06 +00:00
/ *
* lib / js / lib / sprintf . js
* /
var sprintf = ( function ( ) { function get _type ( variable ) { return Object . prototype . toString . call ( variable ) . slice ( 8 , - 1 ) . toLowerCase ( ) ; }
function str _repeat ( input , multiplier ) { for ( var output = [ ] ; multiplier > 0 ; output [ -- multiplier ] = input ) { }
return output . join ( '' ) ; }
var str _format = function ( ) { if ( ! str _format . cache . hasOwnProperty ( arguments [ 0 ] ) ) { str _format . cache [ arguments [ 0 ] ] = str _format . parse ( arguments [ 0 ] ) ; }
return str _format . format . call ( null , str _format . cache [ arguments [ 0 ] ] , arguments ) ; } ; str _format . format = function ( parse _tree , argv ) { var cursor = 1 , tree _length = parse _tree . length , node _type = '' , arg , output = [ ] , i , k , match , pad , pad _character , pad _length ; for ( i = 0 ; i < tree _length ; i ++ ) { node _type = get _type ( parse _tree [ i ] ) ; if ( node _type === 'string' ) { output . push ( parse _tree [ i ] ) ; }
else if ( node _type === 'array' ) { match = parse _tree [ i ] ; if ( match [ 2 ] ) { arg = argv [ cursor ] ; for ( k = 0 ; k < match [ 2 ] . length ; k ++ ) { if ( ! arg . hasOwnProperty ( match [ 2 ] [ k ] ) ) { arg = '' ; } else { arg = arg [ match [ 2 ] [ k ] ] ; } } }
else if ( match [ 1 ] ) { arg = argv [ match [ 1 ] ] ; }
else { arg = argv [ cursor ++ ] ; }
if ( /[^s]/ . test ( match [ 8 ] ) && ( get _type ( arg ) != 'number' ) ) { throw ( sprintf ( '[sprintf] expecting number but found %s' , get _type ( arg ) ) ) ; }
switch ( match [ 8 ] ) { case 'b' : arg = arg . toString ( 2 ) ; break ; case 'c' : arg = String . fromCharCode ( arg ) ; break ; case 'd' : arg = parseInt ( arg , 10 ) ; break ; case 'e' : arg = match [ 7 ] ? arg . toExponential ( match [ 7 ] ) : arg . toExponential ( ) ; break ; case 'f' : arg = match [ 7 ] ? parseFloat ( arg ) . toFixed ( match [ 7 ] ) : parseFloat ( arg ) ; break ; case 'o' : arg = arg . toString ( 8 ) ; break ; case 's' : arg = ( ( arg = String ( arg ) ) && match [ 7 ] ? arg . substring ( 0 , match [ 7 ] ) : arg ) ; break ; case 'u' : arg = Math . abs ( arg ) ; break ; case 'x' : arg = arg . toString ( 16 ) ; break ; case 'X' : arg = arg . toString ( 16 ) . toUpperCase ( ) ; break ; }
arg = ( /[def]/ . test ( match [ 8 ] ) && match [ 3 ] && arg >= 0 ? '+' + arg : arg ) ; pad _character = match [ 4 ] ? match [ 4 ] == '0' ? '0' : match [ 4 ] . charAt ( 1 ) : ' ' ; pad _length = match [ 6 ] - String ( arg ) . length ; pad = match [ 6 ] ? str _repeat ( pad _character , pad _length ) : '' ; output . push ( match [ 5 ] ? arg + pad : pad + arg ) ; } }
return output . join ( '' ) ; } ; str _format . cache = { } ; str _format . parse = function ( fmt ) { var _fmt = fmt , match = [ ] , parse _tree = [ ] , arg _names = 0 ; while ( _fmt ) { if ( ( match = /^[^\x25]+/ . exec ( _fmt ) ) !== null ) { parse _tree . push ( match [ 0 ] ) ; }
else if ( ( match = /^\x25{2}/ . exec ( _fmt ) ) !== null ) { parse _tree . push ( '%' ) ; }
else if ( ( match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/ . exec ( _fmt ) ) !== null ) { if ( match [ 2 ] ) { arg _names |= 1 ; var field _list = [ ] , replacement _field = match [ 2 ] , field _match = [ ] ; if ( ( field _match = /^([a-z_][a-z_\d]*)/i . exec ( replacement _field ) ) !== null ) { field _list . push ( field _match [ 1 ] ) ; while ( ( replacement _field = replacement _field . substring ( field _match [ 0 ] . length ) ) !== '' ) { if ( ( field _match = /^\.([a-z_][a-z_\d]*)/i . exec ( replacement _field ) ) !== null ) { field _list . push ( field _match [ 1 ] ) ; }
else if ( ( field _match = /^\[(\d+)\]/ . exec ( replacement _field ) ) !== null ) { field _list . push ( field _match [ 1 ] ) ; }
2012-02-29 13:08:18 +00:00
else { throw ( '[sprintf] huh?' ) ; } } }
else { throw ( '[sprintf] huh?' ) ; }
2012-02-29 09:41:06 +00:00
match [ 2 ] = field _list ; }
else { arg _names |= 2 ; }
if ( arg _names === 3 ) { throw ( '[sprintf] mixing positional and named placeholders is not (yet) supported' ) ; }
parse _tree . push ( match ) ; }
2012-02-29 13:08:18 +00:00
else { throw ( '[sprintf] huh?' ) ; }
2012-02-29 09:41:06 +00:00
_fmt = _fmt . substring ( match [ 0 ] . length ) ; }
return parse _tree ; } ; return str _format ; } ) ( ) ; var vsprintf = function ( fmt , argv ) { argv . unshift ( fmt ) ; return sprintf . apply ( null , argv ) ; } ;
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-05-21 09:01:03 +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 ; } }
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-04-19 12:18:57 +00:00
wn . meta . docfield _list [ df . parent ] . push ( df ) ; } } ) ;
2012-02-14 06:14:13 +00:00
/ *
2012-03-21 07:15:01 +00:00
* lib / js / wn / misc / tools . js
2012-02-14 06:14:13 +00:00
* /
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-03-21 07:15:01 +00:00
return wn . md2html . makeHtml ( txt ) ; }
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-05-08 07:28:32 +00:00
wn . get _route = function ( route ) { if ( ! wn . boot ) { return [ window . page _name ] ; }
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-04-19 12:18:57 +00:00
if ( wn . model . no _value _type . indexOf ( df . fieldtype ) == - 1 && ! me . fields _by _name [ df . fieldname ] ) { 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-03-23 08:49:49 +00:00
this . page = page ; $ ( this . page ) . fadeIn ( ) ; $ ( this . page ) . trigger ( 'show' ) ; this . page . _route = window . location . hash ; document . title = this . page . label ; 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;" \
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-03-02 09:26:51 +00:00
if ( r . server _messages ) msgprint ( r . server _messages )
2012-04-16 05:48:45 +00:00
if ( r . exc ) { console . log ( r . exc ) ; } ; if ( r [ '403' ] ) { wn . container . change _to ( '403' ) ; }
if ( r . docs ) LocalDB . sync ( r . docs ) ; }
2012-03-28 12:18:30 +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 ( r , xhr . responseText ) ; } , error : function ( xhr , textStatus ) { wn . request . cleanup ( opts , { } ) ; show _alert ( 'Unable to complete request: ' + textStatus )
2012-03-02 09:26:51 +00:00
if ( 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 ) )
last _date = 29 ; return y + '-' + int _to _str ( m , 2 ) + '-' + last _date ; } , get _user _fmt : function ( ) { var t = wn . control _panel . date _format ; if ( ! t ) t = 'dd-mm-yyyy' ; return t ; } , str _to _user : function ( val , no _time _str ) { var user _fmt = dateutil . get _user _fmt ( ) ; var time _str = '' ; if ( val == null || val == '' ) return null ; if ( val . search ( ':' ) != - 1 ) { var tmp = val . split ( ' ' ) ; if ( tmp [ 1 ] )
time _str = ' ' + tmp [ 1 ] ; var d = tmp [ 0 ] ; } else { var d = val ; }
if ( no _time _str ) time _str = '' ; d = d . split ( '-' ) ; if ( d . length == 3 ) { if ( user _fmt == 'dd-mm-yyyy' )
val = d [ 2 ] + '-' + d [ 1 ] + '-' + d [ 0 ] + time _str ; else if ( user _fmt == 'dd/mm/yyyy' )
val = d [ 2 ] + '/' + d [ 1 ] + '/' + d [ 0 ] + time _str ; else if ( user _fmt == 'yyyy-mm-dd' )
val = d [ 0 ] + '-' + d [ 1 ] + '-' + d [ 2 ] + time _str ; else if ( user _fmt == 'mm/dd/yyyy' )
val = d [ 1 ] + '/' + d [ 2 ] + '/' + d [ 0 ] + time _str ; else if ( user _fmt == 'mm-dd-yyyy' )
val = d [ 1 ] + '-' + d [ 2 ] + '-' + d [ 0 ] + time _str ; }
return val ; } , full _str : function ( ) { var d = new Date ( ) ; return d . getFullYear ( ) + '-' + ( d . getMonth ( ) + 1 ) + '-' + d . getDate ( ) + ' '
+ d . getHours ( ) + ':' + d . getMinutes ( ) + ':' + d . getSeconds ( ) ; } , user _to _str : function ( d ) { var user _fmt = this . get _user _fmt ( ) ; if ( user _fmt == 'dd-mm-yyyy' ) { var d = d . split ( '-' ) ; return d [ 2 ] + '-' + d [ 1 ] + '-' + d [ 0 ] ; }
else if ( user _fmt == 'dd/mm/yyyy' ) { var d = d . split ( '/' ) ; return d [ 2 ] + '-' + d [ 1 ] + '-' + d [ 0 ] ; }
else if ( user _fmt == 'yyyy-mm-dd' ) { return d ; }
else if ( user _fmt == 'mm/dd/yyyy' ) { var d = d . split ( '/' ) ; return d [ 2 ] + '-' + d [ 0 ] + '-' + d [ 1 ] ; }
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
* /
var msg _dialog ; function msgprint ( msg , issmall , callback ) { if ( ! msg ) return ; if ( typeof ( msg ) != 'string' )
msg = JSON . stringify ( msg ) ; if ( issmall ) { show _alert ( msg ) ; return ; }
if ( msg . substr ( 0 , 8 ) == '__small:' ) { show _alert ( msg . substr ( 8 ) ) ; return ; }
if ( ! msg _dialog ) { msg _dialog = new Dialog ( 500 , 200 , "Message" ) ; msg _dialog . make _body ( [ [ 'HTML' , 'Msg' ] ] )
msg _dialog . onhide = function ( ) { msg _dialog . msg _area . innerHTML = '' ; $dh ( msg _dialog . msg _icon ) ; if ( msg _dialog . custom _onhide ) msg _dialog . custom _onhide ( ) ; }
$y ( msg _dialog . rows [ 'Msg' ] , { fontSize : '14px' , lineHeight : '1.5em' , padding : '16px' } )
var t = make _table ( msg _dialog . rows [ 'Msg' ] , 1 , 2 , '100%' , [ '20px' , '250px' ] , { padding : '2px' , verticalAlign : 'Top' } ) ; msg _dialog . msg _area = $td ( t , 0 , 1 ) ; msg _dialog . msg _icon = $a ( $td ( t , 0 , 0 ) , 'img' ) ; }
2012-05-07 12:30:57 +00:00
if ( ! msg _dialog . display ) msg _dialog . show ( ) ; var has _msg = msg _dialog . msg _area . innerHTML ? 1 : 0 ; var m = $a ( msg _dialog . msg _area , 'div' , '' ) ; if ( has _msg ) $y ( m , { marginTop : '4px' } ) ; $dh ( msg _dialog . msg _icon ) ; if ( msg . substr ( 0 , 6 ) . toLowerCase ( ) == 'error:' ) { msg _dialog . msg _icon . src = 'images/lib/icons/error.gif' ; $di ( msg _dialog . msg _icon ) ; msg = msg . substr ( 6 ) ; } else if ( msg . substr ( 0 , 8 ) . toLowerCase ( ) == 'message:' ) { msg _dialog . msg _icon . src = 'images/lib/icons/application.gif' ; $di ( msg _dialog . msg _icon ) ; msg = msg . substr ( 8 ) ; } else if ( msg . substr ( 0 , 3 ) . toLowerCase ( ) == 'ok:' ) { msg _dialog . msg _icon . src = 'images/lib/icons/accept.gif' ; $di ( msg _dialog . msg _icon ) ; msg = msg . substr ( 3 ) ; }
2012-02-14 06:14:13 +00:00
m . innerHTML = replace _newlines ( msg ) ; if ( m . offsetHeight > 200 ) { $y ( m , { height : '200px' , width : '400px' , overflow : 'auto' } ) }
msg _dialog . custom _onhide = callback ; }
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-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / utils / printElement . js
* / ; ( f u n c t i o n ( w i n d o w , u n d e f i n e d ) { v a r d o c u m e n t = w i n d o w [ " d o c u m e n t " ] ; v a r $ = w i n d o w [ " j Q u e r y " ] ; $ . f n [ " p r i n t E l e m e n t " ] = f u n c t i o n ( o p t i o n s ) { v a r m a i n O p t i o n s = $ . e x t e n d ( { } , $ . f n [ " p r i n t E l e m e n t " ] [ " d e f a u l t s " ] , o p t i o n s ) ; i f ( m a i n O p t i o n s [ " p r i n t M o d e " ] = = ' i f r a m e ' ) { i f ( $ . b r o w s e r . o p e r a | | ( / c h r o m e / . t e s t ( n a v i g a t o r . u s e r A g e n t . t o L o w e r C a s e ( ) ) ) )
mainOptions [ "printMode" ] = 'popup' ; }
$ ( "[id^='printElement_']" ) . remove ( ) ; return this . each ( function ( ) { var opts = $ . meta ? $ . extend ( { } , mainOptions , $ ( this ) . data ( ) ) : mainOptions ; _printElement ( $ ( this ) , opts ) ; } ) ; } ; $ . fn [ "printElement" ] [ "defaults" ] = { "printMode" : 'iframe' , "pageTitle" : '' , "overrideElementCSS" : null , "printBodyOptions" : { "styleToAdd" : 'padding:10px;margin:10px;' , "classNameToAdd" : '' } , "leaveOpen" : false , "iframeElementOptions" : { "styleToAdd" : 'border:none;position:absolute;width:0px;height:0px;bottom:0px;left:0px;' , "classNameToAdd" : '' } } ; $ . fn [ "printElement" ] [ "cssElement" ] = { "href" : '' , "media" : '' } ; function _printElement ( element , opts ) { var html = _getMarkup ( element , opts ) ; var popupOrIframe = null ; var documentToWriteTo = null ; if ( opts [ "printMode" ] . toLowerCase ( ) == 'popup' ) { popupOrIframe = window . open ( 'about:blank' , 'printElementWindow' , 'width=650,height=440,scrollbars=yes' ) ; documentToWriteTo = popupOrIframe . document ; }
else { var printElementID = "printElement_" + ( Math . round ( Math . random ( ) * 99999 ) ) . toString ( ) ; var iframe = document . createElement ( 'IFRAME' ) ; $ ( iframe ) . attr ( { style : opts [ "iframeElementOptions" ] [ "styleToAdd" ] , id : printElementID , className : opts [ "iframeElementOptions" ] [ "classNameToAdd" ] , frameBorder : 0 , scrolling : 'no' , src : 'about:blank' } ) ; document . body . appendChild ( iframe ) ; documentToWriteTo = ( iframe . contentWindow || iframe . contentDocument ) ; if ( documentToWriteTo . document )
documentToWriteTo = documentToWriteTo . document ; iframe = document . frames ? document . frames [ printElementID ] : document . getElementById ( printElementID ) ; popupOrIframe = iframe . contentWindow || iframe ; }
focus ( ) ; documentToWriteTo . open ( ) ; documentToWriteTo . write ( html ) ; documentToWriteTo . close ( ) ; _callPrint ( popupOrIframe ) ; } ; function _callPrint ( element ) { if ( element && element [ "printPage" ] )
element [ "printPage" ] ( ) ; else
setTimeout ( function ( ) { _callPrint ( element ) ; } , 50 ) ; }
function _getElementHTMLIncludingFormElements ( element ) { var $element = $ ( element ) ; var elementHtml = $ ( '<div></div>' ) . append ( $element . clone ( ) ) . html ( ) ; return elementHtml ; }
function _getBaseHref ( ) { var port = ( window . location . port ) ? ':' + window . location . port : '' ; return window . location . protocol + '//' + window . location . hostname + port + window . location . pathname ; }
function _getMarkup ( element , opts ) { var $element = $ ( element ) ; var elementHtml = _getElementHTMLIncludingFormElements ( element ) ; var html = new Array ( ) ; html . push ( '<html><head><title>' + opts [ "pageTitle" ] + '</title>' ) ; if ( opts [ "overrideElementCSS" ] ) { if ( opts [ "overrideElementCSS" ] . length > 0 ) { for ( var x = 0 ; x < opts [ "overrideElementCSS" ] . length ; x ++ ) { var current = opts [ "overrideElementCSS" ] [ x ] ; if ( typeof ( current ) == 'string' )
html . push ( '<link type="text/css" rel="stylesheet" href="' + current + '" >' ) ; else
html . push ( '<link type="text/css" rel="stylesheet" href="' + current [ "href" ] + '" media="' + current [ "media" ] + '" >' ) ; } } }
else { $ ( "link" , document ) . filter ( function ( ) { return $ ( this ) . attr ( "rel" ) . toLowerCase ( ) == "stylesheet" ; } ) . each ( function ( ) { html . push ( '<link type="text/css" rel="stylesheet" href="' + $ ( this ) . attr ( "href" ) + '" media="' + $ ( this ) . attr ( 'media' ) + '" >' ) ; } ) ; }
html . push ( '<base href="' + _getBaseHref ( ) + '" />' ) ; html . push ( '</head><body style="' + opts [ "printBodyOptions" ] [ "styleToAdd" ] + '" class="' + opts [ "printBodyOptions" ] [ "classNameToAdd" ] + '">' ) ; html . push ( '<div class="' + $element . attr ( 'class' ) + '">' + elementHtml + '</div>' ) ; html . push ( '<script type="text/javascript">function printPage(){focus();print();' + ( ( ! $ . browser . opera && ! opts [ "leaveOpen" ] && opts [ "printMode" ] . toLowerCase ( ) == 'popup' ) ? 'close();' : '' ) + '}</script>' ) ; html . push ( '</body></html>' ) ; return html . join ( '' ) ; } ; } ) ( window ) ;
/ *
* lib / js / legacy / widgets / form / fields . js
* /
var no _value _fields = [ 'Section Break' , 'Column Break' , 'HTML' , 'Table' , 'FlexTable' , 'Button' , 'Image' ] ; var codeid = 0 ; var code _editors = { } ; function Field ( ) { this . with _label = 1 ; }
Field . prototype . make _body = function ( ) { var ischk = ( this . df . fieldtype == 'Check' ? 1 : 0 ) ; if ( this . parent )
2012-03-05 12:58:33 +00:00
this . wrapper = $a ( this . parent , ( this . with _label ? 'div' : 'span' ) ) ; else
2012-03-12 10:42:09 +00:00
this . wrapper = document . createElement ( ( this . with _label ? 'div' : 'span' ) ) ; this . label _area = $a ( this . wrapper , 'div' , '' , { margin : '0px 0px 2px 0px' } ) ; if ( ischk && ! this . in _grid ) { this . input _area = $a ( this . label _area , 'span' , '' , { marginRight : '4px' } ) ; this . disp _area = $a ( this . label _area , 'span' , '' , { marginRight : '4px' } ) ; }
2012-03-21 06:17:58 +00:00
if ( this . with _label ) { this . label _span = $a ( this . label _area , 'span' , 'small' )
2012-05-07 12:30:57 +00:00
this . label _icon = $a ( this . label _area , 'img' , '' , { margin : '-3px 4px -3px 4px' } ) ; $dh ( this . label _icon ) ; this . label _icon . src = 'images/lib/icons/error.gif' ; this . label _icon . title = 'Mandatory value needs to be entered' ; this . suggest _icon = $a ( this . label _area , 'img' , '' , { margin : '-3px 4px -3px 0px' } ) ; $dh ( this . suggest _icon ) ; this . suggest _icon . src = 'images/lib/icons/bullet_arrow_down.png' ; this . suggest _icon . title = 'With suggestions' ; } else { this . label _span = $a ( this . label _area , 'span' , '' , { marginRight : '4px' } )
2012-02-14 06:14:13 +00:00
$dh ( this . label _area ) ; }
2012-03-05 12:58:33 +00:00
if ( ! this . input _area ) { this . input _area = $a ( this . wrapper , ( this . with _label ? 'div' : 'span' ) ) ; this . disp _area = $a ( this . wrapper , ( this . with _label ? 'div' : 'span' ) ) ; }
2012-03-12 10:42:09 +00:00
if ( this . in _grid ) { if ( this . label _area ) $dh ( this . label _area ) ; } else { this . input _area . className = 'input_area' ; $y ( this . wrapper , { marginBottom : '9px' } ) ; this . set _description ( ) ; }
2012-02-14 06:14:13 +00:00
if ( this . onmake ) this . onmake ( ) ; }
Field . prototype . set _max _width = function ( ) { var no _max = [ 'Code' , 'Text Editor' , 'Text' , 'Table' , 'HTML' ]
if ( this . wrapper && this . layout _cell && this . layout _cell . parentNode . cells && this . layout _cell . parentNode . cells . length == 1 && ! in _list ( no _max , this . df . fieldtype ) ) { $y ( this . wrapper , { paddingRight : '50%' } ) ; } }
Field . prototype . set _label = function ( ) { if ( this . with _label && this . label _area && this . label != this . df . label ) { this . label _span . innerHTML = this . df . label ; this . label = this . df . label ; } }
2012-03-21 06:17:58 +00:00
Field . prototype . set _description = function ( ) { if ( this . df . description ) { var p = in _list ( [ 'Text Editor' , 'Code' , 'Check' ] , this . df . fieldtype ) ? this . label _area : this . wrapper ; this . desc _area = $a ( p , 'div' , 'help small' , '' , this . df . description )
2012-02-14 06:14:13 +00:00
if ( in _list ( [ 'Text Editor' , 'Code' ] , this . df . fieldtype ) )
2012-03-21 06:17:58 +00:00
$ ( this . desc _area ) . addClass ( 'help small' ) ; } }
2012-02-14 06:14:13 +00:00
Field . prototype . get _status = function ( ) { if ( this . in _filter ) this . not _in _form = this . in _filter ; if ( this . not _in _form ) { return 'Write' ; }
2012-03-13 09:49:06 +00:00
if ( ! this . df . permlevel ) this . df . permlevel = 0 ; var p = this . perm [ this . df . permlevel ] ; var ret ; if ( cur _frm . editable && p && p [ WRITE ] ) ret = 'Write' ; else if ( p && p [ READ ] ) ret = 'Read' ; else ret = 'None' ; if ( this . df . fieldtype == 'Binary' )
2012-02-14 06:14:13 +00:00
ret = 'None' ; if ( cint ( this . df . hidden ) )
ret = 'None' ; if ( ret == 'Write' && cint ( cur _frm . doc . docstatus ) > 0 ) ret = 'Read' ; var a _o _s = cint ( this . df . allow _on _submit ) ; if ( a _o _s && ( this . in _grid || ( this . frm && this . frm . not _in _container ) ) ) { a _o _s = null ; if ( this . in _grid ) a _o _s = this . grid . field . df . allow _on _submit ; if ( this . frm && this . frm . not _in _container ) { a _o _s = cur _grid . field . df . allow _on _submit ; } }
if ( cur _frm . editable && a _o _s && cint ( cur _frm . doc . docstatus ) > 0 && ! this . df . hidden ) { tmp _perm = get _perm ( cur _frm . doctype , cur _frm . docname , 1 ) ; if ( tmp _perm [ this . df . permlevel ] && tmp _perm [ this . df . permlevel ] [ WRITE ] ) ret = 'Write' ; }
return ret ; }
Field . prototype . set _style _mandatory = function ( add ) { if ( add ) { $ ( this . txt ? this . txt : this . input ) . addClass ( 'input-mandatory' ) ; if ( this . disp _area ) $ ( this . disp _area ) . addClass ( 'input-mandatory' ) ; } else { $ ( this . txt ? this . txt : this . input ) . removeClass ( 'input-mandatory' ) ; if ( this . disp _area ) $ ( this . disp _area ) . removeClass ( 'input-mandatory' ) ; } }
Field . prototype . refresh _mandatory = function ( ) { if ( this . in _filter ) return ; if ( this . df . reqd ) { if ( this . label _area ) this . label _area . style . color = "#d22" ; this . set _style _mandatory ( 1 ) ; } else { if ( this . label _area ) this . label _area . style . color = "#222" ; this . set _style _mandatory ( 0 ) ; }
this . refresh _label _icon ( )
this . set _reqd = this . df . reqd ; }
2012-02-27 12:33:54 +00:00
Field . prototype . refresh _display = function ( ) { if ( ! this . current _status || this . current _status != this . disp _status ) { if ( this . disp _status == 'Write' ) { if ( this . make _input && ( ! this . input ) ) { this . make _input ( ) ; if ( this . onmake _input ) this . onmake _input ( ) ; }
2012-02-14 06:14:13 +00:00
if ( this . show ) this . show ( )
else { $ds ( this . wrapper ) ; }
if ( this . input ) { $ds ( this . input _area ) ; $dh ( this . disp _area ) ; if ( this . input . refresh ) this . input . refresh ( ) ; } else { $dh ( this . input _area ) ; $ds ( this . disp _area ) ; } } else if ( this . disp _status == 'Read' ) { if ( this . show ) this . show ( )
else { $ds ( this . wrapper ) ; }
$dh ( this . input _area ) ; $ds ( this . disp _area ) ; } else { if ( this . hide ) this . hide ( ) ; else $dh ( this . wrapper ) ; }
2012-02-27 12:33:54 +00:00
this . current _status = this . disp _status ; } }
2012-02-14 06:14:13 +00:00
Field . prototype . refresh = function ( ) { this . disp _status = this . get _status ( ) ; if ( this . in _grid && this . table _refresh && this . disp _status == 'Write' )
{ this . table _refresh ( ) ; return ; }
2012-02-17 06:36:33 +00:00
this . set _label ( ) ; this . refresh _display ( ) ; if ( this . onrefresh )
this . onrefresh ( ) ; if ( this . input ) { if ( this . input . refresh ) this . input . refresh ( this . df ) ; }
if ( this . wrapper ) { this . wrapper . fieldobj = this ; $ ( this . wrapper ) . trigger ( 'refresh' ) ; }
if ( ! this . not _in _form )
2012-02-14 06:14:13 +00:00
this . set _input ( _f . get _value ( this . doctype , this . docname , this . df . fieldname ) ) ; this . refresh _mandatory ( ) ; this . set _max _width ( ) ; }
Field . prototype . refresh _label _icon = function ( ) { if ( this . df . reqd ) { if ( this . get _value && is _null ( this . get _value ( ) ) ) { if ( this . label _icon ) $ds ( this . label _icon ) ; $ ( this . txt ? this . txt : this . input ) . addClass ( 'field-to-update' ) } else { if ( this . label _icon ) $dh ( this . label _icon ) ; $ ( this . txt ? this . txt : this . input ) . removeClass ( 'field-to-update' ) } } }
Field . prototype . set = function ( val ) { if ( this . not _in _form )
return ; if ( ( ! this . docname ) && this . grid ) { this . docname = this . grid . add _newrow ( ) ; }
2012-03-20 13:15:28 +00:00
var set _val = val ; if ( this . validate ) set _val = this . validate ( val ) ; _f . set _value ( this . doctype , this . docname , this . df . fieldname , set _val ) ; this . value = val ; }
2012-02-14 06:14:13 +00:00
Field . prototype . set _input = function ( val ) { this . value = val ; if ( this . input && this . input . set _input ) { if ( val == null ) this . input . set _input ( '' ) ; else this . input . set _input ( val ) ; }
var disp _val = val ; if ( val == null ) disp _val = '' ; this . set _disp ( disp _val ) ; }
Field . prototype . run _trigger = function ( ) { this . refresh _label _icon ( ) ; if ( this . df . reqd && this . get _value && ! is _null ( this . get _value ( ) ) && this . set _as _error )
this . set _as _error ( 0 ) ; if ( this . not _in _form ) { return ; }
if ( cur _frm . cscript [ this . df . fieldname ] )
cur _frm . runclientscript ( this . df . fieldname , this . doctype , this . docname ) ; cur _frm . refresh _dependency ( ) ; }
Field . prototype . set _disp _html = function ( t ) { if ( this . disp _area ) { $ ( this . disp _area ) . addClass ( 'disp_area' ) ; this . disp _area . innerHTML = ( t == null ? '' : t ) ; if ( ! t ) $ ( this . disp _area ) . addClass ( 'disp_area_no_val' ) ; } }
Field . prototype . set _disp = function ( val ) { this . set _disp _html ( val ) ; }
Field . prototype . set _as _error = function ( set ) { if ( this . in _grid || this . in _filter ) return ; var w = this . txt ? this . txt : this . input ; if ( set ) { $y ( w , { border : '2px solid RED' } ) ; } else { $y ( w , { border : '1px solid #888' } ) ; } }
2012-02-17 08:34:55 +00:00
Field . prototype . activate = function ( docname ) { this . docname = docname ; this . refresh ( ) ; if ( this . input ) { var v = _f . get _value ( this . doctype , this . docname , this . df . fieldname ) ; this . last _value = v ; if ( this . input . onchange && this . input . get _value && this . input . get _value ( ) != v ) { if ( this . validate )
2012-02-14 06:14:13 +00:00
this . input . set _value ( this . validate ( v ) ) ; else
this . input . set _value ( ( v == null ) ? '' : v ) ; if ( this . format _input )
this . format _input ( ) ; }
if ( this . input . focus ) { try { this . input . focus ( ) ; } catch ( e ) { } } }
if ( this . txt ) { try { this . txt . focus ( ) ; } catch ( e ) { }
2012-02-17 08:34:55 +00:00
this . txt . field _object = this ; } }
2012-03-13 10:41:52 +00:00
function DataField ( ) { } DataField . prototype = new Field ( ) ; DataField . prototype . make _input = function ( ) { var me = this ; this . input = $a _input ( this . input _area , this . df . fieldtype == 'Password' ? 'password' : 'text' ) ; this . get _value = function ( ) { var v = this . input . value ; if ( this . validate )
v = this . validate ( v ) ; return v ; }
2012-06-07 09:09:42 +00:00
this . input . name = this . df . fieldname ; $ ( this . input ) . change ( function ( ) { me . set _value ( me . get _value ? me . get _value ( ) : $ ( this . input ) . val ( ) ) ; } ) ; this . set _value = function ( val ) { if ( ! me . last _value ) me . last _value = '' ; if ( me . validate ) { val = me . validate ( val ) ; me . input . value = val == undefined ? '' : val ; }
2012-03-09 11:14:21 +00:00
me . set ( val ) ; if ( me . format _input )
me . format _input ( ) ; if ( in _list ( [ 'Currency' , 'Float' , 'Int' ] , me . df . fieldtype ) ) { if ( flt ( me . last _value ) == flt ( val ) ) { me . last _value = val ; return ; } }
me . last _value = val ; me . run _trigger ( ) ; }
2012-02-14 06:14:13 +00:00
this . input . set _input = function ( val ) { if ( val == null ) val = '' ; me . input . value = val ; if ( me . format _input ) me . format _input ( ) ; }
2012-03-09 11:14:21 +00:00
if ( this . df . options == 'Suggest' ) { if ( this . suggest _icon ) $di ( this . suggest _icon ) ; $ ( me . input ) . autocomplete ( { source : function ( request , response ) { wn . call ( { method : 'webnotes.widgets.search.search_link' , args : { 'txt' : request . term , 'dt' : me . df . options , 'query' : repl ( ' SELECT DISTINCT ` %(fieldname)s ` FROM \
2012-05-15 06:05:21 +00:00
` tab%(dt)s ` WHERE ` %(fieldname)s ` LIKE "%s" LIMIT 50 ' , { fieldname : me . df . fieldname , dt : me . df . parent } ) } , callback : function ( r ) { response ( r . results ) ; } } ) ; } , select : function ( event , ui ) { me . set ( ui . item . value ) ; } } ) ; } }
2012-02-14 06:14:13 +00:00
DataField . prototype . validate = function ( v ) { if ( this . df . options == 'Phone' ) { if ( v + '' == '' ) return '' ; v1 = ''
v = v . replace ( / /g , '' ) . replace ( /-/g , '' ) . replace ( /\(/g , '' ) . replace ( /\)/g , '' ) ; if ( v && v . substr ( 0 , 1 ) == '+' ) { v1 = '+' ; v = v . substr ( 1 ) ; }
if ( v && v . substr ( 0 , 2 ) == '00' ) { v1 += '00' ; v = v . substr ( 2 ) ; }
if ( v && v . substr ( 0 , 1 ) == '0' ) { v1 += '0' ; v = v . substr ( 1 ) ; }
v1 += cint ( v ) + '' ; return v1 ; } else if ( this . df . options == 'Email' ) { if ( v + '' == '' ) return '' ; if ( ! validate _email ( v ) ) { msgprint ( this . df . label + ': ' + v + ' is not a valid email id' ) ; return '' ; } else
return v ; } else { return v ; } }
DataField . prototype . onrefresh = function ( ) { if ( this . input && this . df . colour ) { var col = '#' + this . df . colour . split ( ':' ) [ 1 ] ; $bg ( this . input , col ) ; } }
function ReadOnlyField ( ) { }
ReadOnlyField . prototype = new Field ( ) ; function HTMLField ( ) { }
HTMLField . prototype = new Field ( ) ; HTMLField . prototype . with _label = 0 ; HTMLField . prototype . set _disp = function ( val ) { this . disp _area . innerHTML = val ; }
HTMLField . prototype . set _input = function ( val ) { if ( val ) this . set _disp ( val ) ; }
HTMLField . prototype . onrefresh = function ( ) { this . set _disp ( this . df . options ? this . df . options : '' ) ; }
2012-03-09 11:14:21 +00:00
var datepicker _active = 0 ; function DateField ( ) { } DateField . prototype = new Field ( ) ; DateField . prototype . make _input = function ( ) { var me = this ; this . user _fmt = wn . control _panel . date _format ; if ( ! this . user _fmt ) this . user _fmt = 'dd-mm-yy' ; this . input = $a ( this . input _area , 'input' ) ; $ ( this . input ) . datepicker ( { dateFormat : me . user _fmt . replace ( 'yyyy' , 'yy' ) , altFormat : 'yy-mm-dd' , changeYear : true , beforeShow : function ( input , inst ) { datepicker _active = 1 } , onClose : function ( dateText , inst ) { datepicker _active = 0 ; if ( _f . cur _grid _cell )
2012-02-14 06:14:13 +00:00
_f . cur _grid _cell . grid . cell _deselect ( ) ; } } ) ; var me = this ; me . input . onchange = function ( ) { if ( this . value == null ) this . value = '' ; if ( ! this . not _in _form )
me . set ( dateutil . user _to _str ( me . input . value ) ) ; me . run _trigger ( ) ; }
me . input . set _input = function ( val ) { if ( val == null ) val = '' ; else val = dateutil . str _to _user ( val ) ; me . input . value = val ; }
me . get _value = function ( ) { if ( me . input . value )
return dateutil . user _to _str ( me . input . value ) ; } }
DateField . prototype . set _disp = function ( val ) { var v = dateutil . str _to _user ( val ) ; if ( v == null ) v = '' ; this . set _disp _html ( v ) ; }
DateField . prototype . validate = function ( v ) { if ( ! v ) return ; var me = this ; this . clear = function ( ) { msgprint ( "Date must be in format " + this . user _fmt ) ; me . input . set _input ( '' ) ; return '' ; }
var t = v . split ( '-' ) ; if ( t . length != 3 ) { return this . clear ( ) ; }
else if ( cint ( t [ 1 ] ) > 12 || cint ( t [ 1 ] ) < 1 ) { return this . clear ( ) ; }
else if ( cint ( t [ 2 ] ) > 31 || cint ( t [ 2 ] ) < 1 ) { return this . clear ( ) ; }
2012-03-09 11:14:21 +00:00
return v ; } ; function LinkField ( ) { } LinkField . prototype = new Field ( ) ; LinkField . prototype . make _input = function ( ) { var me = this ; if ( me . df . no _buttons ) { this . txt = $a ( this . input _area , 'input' ) ; this . input = this . txt ; } else { makeinput _popup ( this , 'icon-search' , 'icon-play' , 'icon-plus' ) ; me . setup _buttons ( ) ; me . onrefresh = function ( ) { if ( me . can _create && cur _frm . doc . docstatus == 0 )
2012-02-24 11:06:58 +00:00
$ ( me . btn2 ) . css ( 'display' , 'inline-block' ) ; else $dh ( me . btn2 ) ; } }
2012-03-09 11:14:21 +00:00
me . txt . field _object = this ; me . input . set _input = function ( val ) { if ( val == undefined ) val = '' ; me . txt . value = val ; }
2012-02-14 06:14:13 +00:00
me . get _value = function ( ) { return me . txt . value ; }
2012-05-02 10:50:38 +00:00
$ ( me . txt ) . autocomplete ( { source : function ( request , response ) { wn . call ( { method : 'webnotes.widgets.search.search_link' , args : { 'txt' : request . term , 'dt' : me . df . options , 'query' : me . get _custom _query ( ) } , callback : function ( r ) { response ( r . results ) ; } , } ) ; } , select : function ( event , ui ) { me . set _input _value ( ui . item . value ) ; } } ) . data ( 'autocomplete' ) . _renderItem = function ( ul , item ) { return $ ( '<li></li>' ) . data ( 'item.autocomplete' , item ) . append ( repl ( '<a>%(label)s<br><span style="font-size:10px">%(info)s</span></a>' , item ) ) . appendTo ( ul ) ; } ; $ ( this . txt ) . change ( function ( ) { if ( ! $ ( this ) . val ( ) ) { if ( selector && selector . display )
return ; me . set _input _value ( '' ) ; } } ) }
2012-03-09 11:14:21 +00:00
LinkField . prototype . get _custom _query = function ( ) { this . set _get _query ( ) ; if ( this . get _query ) { if ( cur _frm )
var doc = locals [ cur _frm . doctype ] [ cur _frm . docname ] ; return this . get _query ( doc , this . doctype , this . docname ) ; } }
2012-02-14 06:14:13 +00:00
LinkField . prototype . setup _buttons = function ( ) { var me = this ; me . btn . onclick = function ( ) { selector . set ( me , me . df . options , me . df . label ) ; selector . show ( me . txt ) ; }
if ( me . btn1 ) me . btn1 . onclick = function ( ) { if ( me . txt . value && me . df . options ) { loaddoc ( me . df . options , me . txt . value ) ; } }
me . can _create = 0 ; if ( ( ! me . not _in _form ) && in _list ( profile . can _create , me . df . options ) ) { me . can _create = 1 ; me . btn2 . onclick = function ( ) { var on _save _callback = function ( new _rec ) { if ( new _rec ) { var d = _f . calling _doc _stack . pop ( ) ; locals [ d [ 0 ] ] [ d [ 1 ] ] [ me . df . fieldname ] = new _rec ; me . refresh ( ) ; if ( me . grid ) me . grid . refresh ( ) ; me . run _trigger ( ) ; } }
_f . calling _doc _stack . push ( [ me . doctype , me . docname ] ) ; new _doc ( me . df . options , me . on _new , 1 , on _save _callback , me . doctype , me . docname , me . frm . not _in _container ) ; } } else { $dh ( me . btn2 ) ; $y ( $td ( me . tab , 0 , 2 ) , { width : '0px' } ) ; } }
2012-05-02 05:53:08 +00:00
LinkField . prototype . set _input _value = function ( val ) { var me = this ; var from _selector = false ; if ( selector && selector . display ) from _selector = true ; me . refresh _label _icon ( ) ; if ( me . not _in _form ) { $ ( this . txt ) . val ( val ) ; return ; }
2012-05-02 10:50:38 +00:00
if ( cur _frm ) { if ( val == locals [ me . doctype ] [ me . docname ] [ me . df . fieldname ] ) { me . run _trigger ( ) ; return ; } }
2012-03-09 11:14:21 +00:00
me . set ( val ) ; if ( _f . cur _grid _cell )
2012-05-03 06:18:43 +00:00
_f . cur _grid _cell . grid . cell _deselect ( ) ; if ( locals [ me . doctype ] [ me . docname ] [ me . df . fieldname ] && ! val ) { me . run _trigger ( ) ; return ; }
2012-02-14 06:14:13 +00:00
var fetch = '' ; if ( cur _frm . fetch _dict [ me . df . fieldname ] )
2012-05-02 10:50:38 +00:00
fetch = cur _frm . fetch _dict [ me . df . fieldname ] . columns . join ( ', ' ) ; $c ( 'webnotes.widgets.form.utils.validate_link' , { 'value' : val , 'options' : me . df . options , 'fetch' : fetch } , function ( r , rt ) { if ( r . message == 'Ok' ) { if ( $ ( me . txt ) . val ( ) != val ) { if ( ( me . grid && ! from _selector ) || ( ! me . grid ) ) { $ ( me . txt ) . val ( val ) ; } }
2012-03-20 13:15:28 +00:00
if ( r . fetch _values )
2012-03-09 11:14:21 +00:00
me . set _fetch _values ( r . fetch _values ) ; me . run _trigger ( ) ; } else { var astr = '' ; if ( in _list ( profile . can _create , me . df . options ) ) astr = repl ( '<br><br><span class="link_type" onclick="newdoc(\'%(dt)s\')">Click here</span> to create a new %(dtl)s' , { dt : me . df . options , dtl : get _doctype _label ( me . df . options ) } )
msgprint ( repl ( 'error:<b>%(val)s</b> is not a valid %(dt)s.<br><br>You must first create a new %(dt)s <b>%(val)s</b> and then select its value. To find an existing %(dt)s, click on the magnifying glass next to the field.%(add)s' , { val : me . txt . value , dt : get _doctype _label ( me . df . options ) , add : astr } ) ) ; me . txt . value = '' ; me . set ( '' ) ; } } ) ; }
2012-02-14 06:14:13 +00:00
LinkField . prototype . set _fetch _values = function ( fetch _values ) { var fl = cur _frm . fetch _dict [ this . df . fieldname ] . fields ; var changed _fields = [ ] ; for ( var i = 0 ; i < fl . length ; i ++ ) { if ( locals [ this . doctype ] [ this . docname ] [ fl [ i ] ] != fetch _values [ i ] ) { locals [ this . doctype ] [ this . docname ] [ fl [ i ] ] = fetch _values [ i ] ; if ( ! this . grid ) { refresh _field ( fl [ i ] ) ; changed _fields . push ( fl [ i ] ) ; } } }
for ( i = 0 ; i < changed _fields . length ; i ++ ) { if ( cur _frm . fields _dict [ changed _fields [ i ] ] )
cur _frm . fields _dict [ changed _fields [ i ] ] . run _trigger ( ) ; }
if ( this . grid ) this . grid . refresh ( ) ; }
LinkField . prototype . set _get _query = function ( ) { if ( this . get _query ) return ; if ( this . grid ) { var f = this . grid . get _field ( this . df . fieldname ) ; if ( f . get _query ) this . get _query = f . get _query ; } }
LinkField . prototype . set _disp = function ( val ) { var t = null ; if ( val ) t = "<a href=\'javascript:loaddoc(\"" + this . df . options + "\", \"" + val + "\")\'>" + val + "</a>" ; this . set _disp _html ( t ) ; }
function IntField ( ) { } IntField . prototype = new DataField ( ) ; IntField . prototype . validate = function ( v ) { if ( isNaN ( parseInt ( v ) ) ) return null ; return cint ( v ) ; } ; IntField . prototype . format _input = function ( ) { if ( this . input . value == null ) this . input . value = '' ; }
2012-03-13 10:41:52 +00:00
function FloatField ( ) { } FloatField . prototype = new DataField ( ) ; FloatField . prototype . validate = function ( v ) { var v = parseFloat ( v ) ; if ( isNaN ( v ) )
return null ; return v ; } ; FloatField . prototype . format _input = function ( ) { if ( this . input . value == null ) this . input . value = '' ; }
2012-02-14 06:14:13 +00:00
function CurrencyField ( ) { } CurrencyField . prototype = new DataField ( ) ; CurrencyField . prototype . format _input = function ( ) { var v = fmt _money ( this . input . value ) ; if ( this . not _in _form ) { if ( ! flt ( this . input . value ) ) v = '' ; }
this . input . value = v ; }
CurrencyField . prototype . validate = function ( v ) { if ( v == null || v == '' )
return 0 ; return flt ( v , 2 ) ; }
CurrencyField . prototype . set _disp = function ( val ) { var v = fmt _money ( val ) ; this . set _disp _html ( v ) ; }
CurrencyField . prototype . onmake _input = function ( ) { if ( ! this . input ) return ; this . input . onfocus = function ( ) { if ( flt ( this . value ) == 0 ) this . select ( ) ; } }
2012-05-07 12:30:57 +00:00
function CheckField ( ) { } CheckField . prototype = new Field ( ) ; CheckField . prototype . validate = function ( v ) { var v = parseInt ( v ) ; if ( isNaN ( v ) ) return 0 ; return v ; } ; CheckField . prototype . onmake = function ( ) { this . checkimg = $a ( this . disp _area , 'div' ) ; var img = $a ( this . checkimg , 'img' ) ; img . src = 'images/lib/ui/tick.gif' ; $dh ( this . checkimg ) ; }
2012-02-17 08:34:55 +00:00
CheckField . prototype . make _input = function ( ) { var me = this ; this . input = $a _input ( this . input _area , 'checkbox' ) ; $y ( this . input , { width : "16px" , border : '0px' , margin : '2px' } ) ; $ ( this . input ) . click ( function ( ) { me . set ( this . checked ? 1 : 0 ) ; me . run _trigger ( ) ; } )
2012-02-14 06:14:13 +00:00
this . input . set _input = function ( v ) { v = parseInt ( v ) ; if ( isNaN ( v ) ) v = 0 ; if ( v ) me . input . checked = true ; else me . input . checked = false ; }
this . get _value = function ( ) { return this . input . checked ? 1 : 0 ; } }
CheckField . prototype . set _disp = function ( val ) { if ( val ) { $ds ( this . checkimg ) ; }
else { $dh ( this . checkimg ) ; } }
function TextField ( ) { } TextField . prototype = new Field ( ) ; TextField . prototype . set _disp = function ( val ) { this . disp _area . innerHTML = replace _newlines ( val ) ; }
TextField . prototype . make _input = function ( ) { var me = this ; if ( this . in _grid )
return ; this . input = $a ( this . input _area , 'textarea' ) ; if ( this . df . fieldtype == 'Small Text' )
this . input . style . height = "80px" ; this . input . set _input = function ( v ) { me . input . value = v ; }
this . input . onchange = function ( ) { me . set ( me . input . value ) ; me . run _trigger ( ) ; }
this . get _value = function ( ) { return this . input . value ; } }
var text _dialog ; function make _text _dialog ( ) { var d = new Dialog ( 520 , 410 , 'Edit Text' ) ; d . make _body ( [ [ 'Text' , 'Enter Text' ] , [ 'HTML' , 'Description' ] , [ 'Button' , 'Update' ] ] ) ; d . widgets [ 'Update' ] . onclick = function ( ) { var t = this . dialog ; t . field . set ( t . widgets [ 'Enter Text' ] . value ) ; t . hide ( ) ; }
d . onshow = function ( ) { this . widgets [ 'Enter Text' ] . style . height = '300px' ; var v = _f . get _value ( this . field . doctype , this . field . docname , this . field . df . fieldname ) ; this . widgets [ 'Enter Text' ] . value = v == null ? '' : v ; this . widgets [ 'Enter Text' ] . focus ( ) ; this . widgets [ 'Description' ] . innerHTML = ''
if ( this . field . df . description )
2012-03-21 06:17:58 +00:00
$a ( this . widgets [ 'Description' ] , 'div' , 'help small' , '' , this . field . df . description ) ; }
2012-02-14 06:14:13 +00:00
d . onhide = function ( ) { if ( _f . cur _grid _cell )
_f . cur _grid _cell . grid . cell _deselect ( ) ; }
text _dialog = d ; }
TextField . prototype . table _refresh = function ( ) { if ( ! this . text _dialog )
make _text _dialog ( ) ; text _dialog . set _title ( 'Enter text for "' + this . df . label + '"' ) ; text _dialog . field = this ; text _dialog . show ( ) ; }
function SelectField ( ) { } SelectField . prototype = new Field ( ) ; SelectField . prototype . make _input = function ( ) { var me = this ; var opt = [ ] ; if ( this . in _filter && ( ! this . df . single _select ) ) { this . input = $a ( this . input _area , 'select' ) ; this . input . multiple = true ; this . input . style . height = '4em' ; this . input . lab = $a ( this . input _area , 'div' , { fontSize : '9px' , color : '#999' } ) ; this . input . lab . innerHTML = '(Use Ctrl+Click to select multiple or de-select)' } else { this . input = $a ( this . input _area , 'select' ) ; this . input . onchange = function ( ) { if ( me . validate )
2012-02-17 08:34:55 +00:00
me . validate ( ) ; me . set ( sel _val ( this ) ) ; me . run _trigger ( ) ; }
2012-02-14 06:14:13 +00:00
if ( this . df . options == 'attach_files:' ) { this . file _attach = true ; } }
this . set _as _single = function ( ) { var i = this . input ; i . multiple = false ; i . style . height = null ; if ( i . lab ) $dh ( i . lab ) }
this . refresh _options = function ( options ) { if ( options )
me . df . options = options ; if ( this . file _attach )
2012-04-30 10:13:34 +00:00
this . set _attach _options ( ) ; me . options _list = me . df . options ? me . df . options . split ( '\n' ) : [ '' ] ; empty _select ( this . input ) ; if ( me . in _filter && me . options _list [ 0 ] != '' ) { me . options _list = add _lists ( [ '' ] , me . options _list ) ; }
2012-02-14 06:14:13 +00:00
add _sel _options ( this . input , me . options _list ) ; }
this . onrefresh = function ( ) { this . refresh _options ( ) ; if ( this . not _in _form ) { this . input . value = '' ; return ; }
if ( _f . get _value )
var v = _f . get _value ( this . doctype , this . docname , this . df . fieldname ) ; else { if ( this . options _list && this . options _list . length )
var v = this . options _list [ 0 ] ; else
var v = null ; }
this . input . set _input ( v ) ; }
2012-03-15 06:20:26 +00:00
this . input . set _input = function ( v ) { if ( ! v ) { if ( ! me . input . multiple ) { if ( me . docname ) { if ( me . options _list && me . options _list . length ) { me . set ( me . options _list [ 0 ] ) ; me . input . value = me . options _list [ 0 ] ; } else { me . input . value = '' ; } } } } else { if ( me . options _list ) { if ( me . input . multiple ) { for ( var i = 0 ; i < me . input . options . length ; i ++ ) { me . input . options [ i ] . selected = 0 ; if ( me . input . options [ i ] . value && inList ( typeof ( v ) == 'string' ? v . split ( "," ) : v , me . input . options [ i ] . value ) )
2012-02-14 06:14:13 +00:00
me . input . options [ i ] . selected = 1 ; } } else if ( in _list ( me . options _list , v ) ) { me . input . value = v ; } } } }
this . get _value = function ( ) { if ( me . input . multiple ) { var l = [ ] ; for ( var i = 0 ; i < me . input . options . length ; i ++ ) { if ( me . input . options [ i ] . selected ) l [ l . length ] = me . input . options [ i ] . value ; }
return l ; } else { if ( me . input . options ) { var val = sel _val ( me . input ) ; if ( ! val && ! me . input . selectedIndex )
val = me . input . options [ 0 ] . value ; return val ; }
return me . input . value ; } }
this . set _attach _options = function ( ) { if ( ! cur _frm ) return ; var fl = cur _frm . doc . file _list ; if ( fl ) { this . df . options = '' ; var fl = fl . split ( '\n' ) ; for ( var i in fl ) { this . df . options += '\n' + fl [ i ] . split ( ',' ) [ 1 ] ; } } else { this . df . options = '' } }
this . refresh ( ) ; }
function TimeField ( ) { } TimeField . prototype = new Field ( ) ; TimeField . prototype . get _time = function ( ) { return time _to _hhmm ( sel _val ( this . input _hr ) , sel _val ( this . input _mn ) , sel _val ( this . input _am ) ) ; }
TimeField . prototype . set _time = function ( v ) { ret = time _to _ampm ( v ) ; this . input _hr . inp . value = ret [ 0 ] ; this . input _mn . inp . value = ret [ 1 ] ; this . input _am . inp . value = ret [ 2 ] ; }
TimeField . prototype . set _style _mandatory = function ( ) { }
TimeField . prototype . set _as _error = function ( ) { }
2012-02-17 08:34:55 +00:00
TimeField . prototype . make _input = function ( ) { var me = this ; this . input = $a ( this . input _area , 'div' , 'time_field' ) ; var t = make _table ( this . input , 1 , 3 , '200px' ) ; var opt _hr = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' , '12' ] ; var opt _mn = [ '00' , '05' , '10' , '15' , '20' , '25' , '30' , '35' , '40' , '45' , '50' , '55' ] ; var opt _am = [ 'AM' , 'PM' ] ; this . input _hr = new SelectWidget ( $td ( t , 0 , 0 ) , opt _hr , '50px' ) ; this . input _mn = new SelectWidget ( $td ( t , 0 , 1 ) , opt _mn , '50px' ) ; this . input _am = new SelectWidget ( $td ( t , 0 , 2 ) , opt _am , '50px' ) ; var onchange _fn = function ( ) { me . set ( me . get _time ( ) ) ; me . run _trigger ( ) ; }
2012-02-14 06:14:13 +00:00
this . input _hr . inp . onchange = onchange _fn ; this . input _mn . inp . onchange = onchange _fn ; this . input _am . inp . onchange = onchange _fn ; this . onrefresh = function ( ) { var v = _f . get _value ? _f . get _value ( me . doctype , me . docname , me . df . fieldname ) : null ; me . set _time ( v ) ; if ( ! v )
me . set ( me . get _time ( ) ) ; }
this . input . set _input = function ( v ) { if ( v == null ) v = '' ; me . set _time ( v ) ; }
this . get _value = function ( ) { return this . get _time ( ) ; }
this . refresh ( ) ; }
TimeField . prototype . set _disp = function ( v ) { var t = time _to _ampm ( v ) ; var t = t [ 0 ] + ':' + t [ 1 ] + ' ' + t [ 2 ] ; this . set _disp _html ( t ) ; }
2012-02-24 11:06:58 +00:00
function makeinput _popup ( me , iconsrc , iconsrc1 , iconsrc2 ) { var icon _style = { cursor : 'pointer' , width : '16px' , verticalAlign : 'middle' , marginBottom : '-3px' } ; me . input = $a ( me . input _area , 'div' ) ; if ( ! me . not _in _form )
2012-02-14 06:14:13 +00:00
$y ( me . input , { width : '80%' } ) ; me . input . set _width = function ( w ) { $y ( me . input , { width : ( w - 2 ) + 'px' } ) ; }
2012-02-24 11:06:58 +00:00
var tab = $a ( me . input , 'table' ) ; me . tab = tab ; $y ( tab , { width : '100%' , borderCollapse : 'collapse' , tableLayout : 'fixed' } ) ; var c0 = tab . insertRow ( 0 ) . insertCell ( 0 ) ; var c1 = tab . rows [ 0 ] . insertCell ( 1 ) ; $y ( c1 , { width : '20px' } ) ; me . txt = $a ( $a ( $a ( c0 , 'div' , '' , { paddingRight : '8px' } ) , 'div' ) , 'input' , '' , { width : '100%' } ) ; me . btn = $a ( c1 , 'i' , iconsrc , icon _style )
if ( iconsrc1 )
2012-02-14 06:14:13 +00:00
me . btn . setAttribute ( 'title' , 'Search' ) ; else
2012-02-24 11:06:58 +00:00
me . btn . setAttribute ( 'title' , 'Select Date' ) ; if ( iconsrc1 ) { var c2 = tab . rows [ 0 ] . insertCell ( 2 ) ; $y ( c2 , { width : '20px' } ) ; me . btn1 = $a ( c2 , 'i' , iconsrc1 , icon _style )
me . btn1 . setAttribute ( 'title' , 'Open Link' ) ; }
if ( iconsrc2 ) { var c3 = tab . rows [ 0 ] . insertCell ( 3 ) ; $y ( c3 , { width : '20px' } ) ; me . btn2 = $a ( c3 , 'i' , iconsrc2 , icon _style )
me . btn2 . setAttribute ( 'title' , 'Create New' ) ; $dh ( me . btn2 ) ; }
2012-02-14 06:14:13 +00:00
if ( me . df . colour )
me . txt . style . background = '#' + me . df . colour . split ( ':' ) [ 1 ] ; me . txt . name = me . df . fieldname ; me . setdisabled = function ( tf ) { me . txt . disabled = tf ; } }
var tmpid = 0 ; _f . ButtonField = function ( ) { } ; _f . ButtonField . prototype = new Field ( ) ; _f . ButtonField . prototype . with _label = 0 ; _f . ButtonField . prototype . init = function ( ) { this . prev _button = null ; if ( ! this . frm ) return ; if ( cur _frm && cur _frm . fields [ cur _frm . fields . length - 1 ] && cur _frm . fields [ cur _frm . fields . length - 1 ] . df . fieldtype == 'Button' ) { this . make _body = function ( ) { this . prev _button = cur _frm . fields [ cur _frm . fields . length - 1 ] ; if ( ! this . prev _button . prev _button ) { this . prev _button . button _area = $a ( this . prev _button . input _area , 'span' ) ; }
this . wrapper = this . prev _button . wrapper ; this . input _area = this . prev _button . input _area ; this . disp _area = this . prev _button . disp _area ; this . button _area = $a ( this . prev _button . input _area , 'span' ) ; } } }
_f . ButtonField . prototype . make _input = function ( ) { var me = this ; if ( ! this . prev _button ) { $y ( this . input _area , { marginTop : '4px' , marginBottom : '4px' } ) ; }
if ( ! this . button _area )
2012-02-27 07:14:28 +00:00
this . button _area = $a ( this . input _area , 'span' , '' , { marginRight : '4px' } ) ; this . input = $btn ( this . button _area , me . df . label , null , { fontWeight : 'bold' } , null , 1 )
2012-05-11 10:53:41 +00:00
$ ( this . input ) . click ( function ( ) { if ( me . not _in _form ) return ; if ( cur _frm . cscript [ me . df . fieldname ] && ( ! me . in _filter ) ) { cur _frm . runclientscript ( me . df . fieldname , me . doctype , me . docname ) ; } else { cur _frm . runscript ( me . df . options , me ) ; } } ) ; }
2012-02-14 06:14:13 +00:00
_f . ButtonField . prototype . hide = function ( ) { $dh ( this . button _area ) ; } ; _f . ButtonField . prototype . show = function ( ) { $ds ( this . button _area ) ; } ; _f . ButtonField . prototype . set = function ( v ) { } ; _f . ButtonField . prototype . set _disp = function ( val ) { }
function make _field ( docfield , doctype , parent , frm , in _grid , hide _label ) { switch ( docfield . fieldtype . toLowerCase ( ) ) { case 'data' : var f = new DataField ( ) ; break ; case 'password' : var f = new DataField ( ) ; break ; case 'int' : var f = new IntField ( ) ; break ; case 'float' : var f = new FloatField ( ) ; break ; case 'currency' : var f = new CurrencyField ( ) ; break ; case 'read only' : var f = new ReadOnlyField ( ) ; break ; case 'link' : var f = new LinkField ( ) ; break ; case 'date' : var f = new DateField ( ) ; break ; case 'time' : var f = new TimeField ( ) ; break ; case 'html' : var f = new HTMLField ( ) ; break ; case 'check' : var f = new CheckField ( ) ; break ; case 'text' : var f = new TextField ( ) ; break ; case 'small text' : var f = new TextField ( ) ; break ; case 'select' : var f = new SelectField ( ) ; break ; case 'button' : var f = new _f . ButtonField ( ) ; break ; case 'code' : var f = new _f . CodeField ( ) ; break ; case 'text editor' : var f = new _f . CodeField ( ) ; break ; case 'table' : var f = new _f . TableField ( ) ; break ; case 'section break' : var f = new _f . SectionBreak ( ) ; break ; case 'column break' : var f = new _f . ColumnBreak ( ) ; break ; case 'image' : var f = new _f . ImageField ( ) ; break ; }
f . parent = parent ; f . doctype = doctype ; f . df = docfield ; f . perm = frm ? frm . perm : [ [ 1 , 1 , 1 ] ] ; if ( _f )
f . col _break _width = _f . cur _col _break _width ; if ( in _grid ) { f . in _grid = true ; f . with _label = 0 ; }
if ( hide _label ) { f . with _label = 0 ; }
if ( frm ) { f . frm = frm ; if ( parent )
f . layout _cell = parent . parentNode ; }
if ( f . init ) f . init ( ) ; f . make _body ( ) ; return f ; }
2012-04-11 11:56:03 +00:00
/ *
2012-04-13 06:11:43 +00:00
* lib / js / wn / ui / appframe . js
2012-04-11 11:56:03 +00:00
* /
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-11 12:32:23 +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 ( ) ; } )
if ( title ) this . title ( title ) ; } , title : function ( txt ) { this . $titlebar . find ( '.appframe-title' ) . html ( txt ) ; } , add _button : function ( label , click , icon ) { if ( ! this . $w . find ( '.appframe-toolbar' ) . length )
2012-04-11 11:56:03 +00:00
this . $w . append ( '<div class="appframe-toolbar"></div>' ) ; args = { label : label , icon : '' } ; if ( icon ) { args . icon = '<i class="' + icon + '"></i>' ; }
this . buttons [ label ] = $ ( repl ( ' < button class = "btn btn-small" > \
2012-04-19 12:18:57 +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 ] ; } , 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 ( ) ; } } ) ; w n . u i . m a k e _ a p p _ p a g e = f u n c t i o n ( o p t s ) { i f ( o p t s . s i n g l e _ c o l u m n ) { $ ( 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 - a p p f r a m e " > \
< 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-04-16 08:03:14 +00:00
$y ( this . body , { padding : '11px' } ) ; this . fields _dict = { } ; for ( var i = 0 ; i < fl . length ; i ++ ) { var df = fl [ i ] ; var div = $a ( body , 'div' , '' , { margin : '6px 0px' } )
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-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' ] || '' ) ; } } } }
wn . widgets . Dialog = function ( opts ) { this . opts = opts ; this . display = false ; this . make = function ( opts ) { if ( opts )
2012-04-16 05:48:45 +00:00
this . opts = opts ; if ( ! this . opts . width ) this . opts . width = 480 ; if ( ! $ ( '#dialog-container' ) . length ) { $ ( '<div id="dialog-container">' ) . appendTo ( 'body' ) ; }
this . wrapper = $ ( '<div class="dialog_wrapper">' ) . appendTo ( '#dialog-container' ) . get ( 0 ) ; if ( this . opts . width )
2012-02-14 06:14:13 +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 ) ; }
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 ( )
$ds ( this . wrapper ) ; freeze ( ) ; this . display = true ; cur _dialog = this ; if ( this . onshow ) this . onshow ( ) ; }
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-02-14 06:14:13 +00:00
if ( opts ) this . make ( ) ; }
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-03-16 12:58:09 +00:00
/ *
* lib / js / wn / ui / button . js
* /
2012-05-11 10:53:41 +00:00
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 )
2012-03-16 12:58:09 +00:00
this . user _onclick ( this ) ; } )
me . btn . set _working = me . set _working ; me . btn . done _working = me . done _working ; if ( me . btn . args . style )
2012-05-11 10:53:41 +00:00
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-05-03 06:18:43 +00:00
/ *
* lib / js / wn / ui / search . js
* /
2012-05-04 07:34:40 +00:00
wn . ui . Search = Class . extend ( { init : function ( opts ) { $ . extend ( this , opts ) ; var me = this ; wn . model . with _doctype ( this . doctype , function ( r ) { me . make ( ) ; me . dialog . show ( ) ; me . list . $w . find ( '.list-filters input[type="text"]' ) . focus ( ) ; } ) ; } , make : function ( ) { var me = this ; this . dialog = new wn . ui . Dialog ( { title : this . doctype + ' Search' , width : 500 } ) ; this . list = new wn . ui . Listing ( { parent : $ ( this . dialog . body ) , appframe : this . dialog . appframe , new _doctype : this . doctype , doctype : this . doctype , method : 'webnotes.widgets.doclistview.get' , show _filters : true , style : 'compact' , get _args : function ( ) { if ( me . query ) { me . page _length = 50 ; return { query : me . query } } else { return { doctype : me . doctype , fields : [ '`tab' + me . doctype + '`.name' ] , filters : me . list . filter _list . get _filters ( ) , docstatus : [ '0' , '1' ] } } } , render _row : function ( parent , data ) { $ln = $ ( '<a style="cursor: pointer;" data-name="' + data . name + '">'
2012-05-03 06:18:43 +00:00
+ data . name + '</a>' ) . appendTo ( parent ) . click ( function ( ) { var val = $ ( this ) . attr ( 'data-name' ) ; me . dialog . hide ( ) ; if ( me . callback )
me . callback ( val ) ; else
wn . set _route ( 'Form' , me . doctype , val ) ; } ) ; } } ) ; this . list . filter _list . add _filter ( 'name' , 'like' ) ; this . list . run ( ) ; } } )
2012-05-07 12:30:57 +00:00
/ *
* lib / js / wn / ui / tree . js
* /
wn . ui . Tree = Class . extend ( { init : function ( args ) { $ . extend ( this , args ) ; this . nodes = { } ; this . $w = $ ( '<div class="tree">' ) . appendTo ( this . parent ) ; this . rootnode = new wn . ui . TreeNode ( { tree : this , parent : this . $w , label : this . label , expandable : true } ) ; this . set _style ( ) ; } , set _style : function ( ) { wn . dom . set _style ( " \
. tree li { list - style : none ; } \
. tree ul { margin - top : 2 px ; } \
. tree - link { cursor : pointer ; } \
" ) } } )
wn . ui . TreeNode = Class . extend ( { init : function ( args ) { var me = this ; $ . extend ( this , args ) ; this . loaded = false ; this . expanded = false ; this . tree . nodes [ this . label ] = this ; this . $a = $ ( '<a class="tree-link">' ) . click ( function ( ) { if ( me . expandable && me . tree . method && ! me . loaded ) { me . load ( ) } else { me . selectnode ( ) ; }
2012-05-23 09:42:22 +00:00
if ( me . tree . click ) me . tree . click ( this ) ; } ) . bind ( 'reload' , function ( ) { me . reload ( ) ; } ) . data ( 'label' , this . label ) . appendTo ( this . parent ) ; if ( this . expandable ) { this . $a . append ( '<i class="icon-folder-close"></i> ' + this . label ) ; } else { this . $a . append ( '<i class="icon-file"></i> ' + this . label ) ; }
if ( this . tree . onrender ) { this . tree . onrender ( this ) ; } } , selectnode : function ( ) { if ( this . $ul ) { this . $ul . toggle ( ) ; this . $a . find ( 'i' ) . removeClass ( ) ; if ( this . $ul . css ( 'display' ) . toLowerCase ( ) == 'block' ) { this . $a . find ( 'i' ) . addClass ( 'icon-folder-open' ) ; } else { this . $a . find ( 'i' ) . addClass ( 'icon-folder-close' ) ; } }
2012-05-07 12:30:57 +00:00
this . tree . $w . find ( 'a.selected' ) . removeClass ( 'selected' ) ; this . $a . toggleClass ( 'selected' ) ; this . expanded = ! this . expanded ; } , reload : function ( ) { if ( this . expanded ) { this . $a . click ( ) ; }
if ( this . $ul ) { this . $ul . empty ( ) ; }
2012-05-23 09:42:22 +00:00
this . load ( ) ; } , addnode : function ( data ) { if ( ! this . $ul ) { this . $ul = $ ( '<ul>' ) . toggle ( false ) . appendTo ( this . parent ) ; }
return new wn . ui . TreeNode ( { tree : this . tree , parent : $ ( '<li>' ) . appendTo ( this . $ul ) , label : data . value , expandable : data . expandable , data : data } ) ; } , load : function ( ) { var me = this ; args = $ . extend ( this . tree . args , { parent : this . label } ) ; $ ( me . $a ) . set _working ( ) ; wn . call ( { method : this . tree . method , args : args , callback : function ( r ) { $ ( me . $a ) . done _working ( ) ; $ . each ( r . message , function ( i , v ) { node = me . addnode ( v ) ; node . $a . data ( 'node-data' , v ) ; } ) ; me . loaded = true ; me . selectnode ( ) ; } } ) } } )
2012-05-10 13:37:53 +00:00
/ *
* lib / js / wn / upload . js
* /
wn . upload = { make : function ( opts ) { var id = wn . dom . set _unique _id ( ) ; $ ( opts . parent ) . append ( repl ( ' < iframe id = "%(id)s" name = "%(id)s" src = "blank.html" \
style = "width:0px; height:0px; border:0px" > < / i f r a m e > \
< form method = "POST" enctype = "multipart/form-data" \
action = "%(action)s" target = "%(id)s" > \
2012-05-11 10:23:37 +00:00
< input type = "file" name = "filedata" / > < br > < br > \
2012-05-10 13:37:53 +00:00
< input type = "submit" class = "btn btn-small" value = "Upload" / > \
< / f o r m > ' , { i d : i d , a c t i o n : w n . r e q u e s t . u r l } ) ) ; o p t s . a r g s . c m d = ' u p l o a d f i l e ' ; o p t s . a r g s . _ i d = i d ; f o r ( k e y i n o p t s . a r g s ) { i f ( o p t s . a r g s [ k e y ] ) { $ ( ' < i n p u t t y p e = " h i d d e n " > ' ) . a t t r ( ' n a m e ' , k e y ) . a t t r ( ' v a l u e ' , o p t s . a r g s [ k e y ] ) . a p p e n d T o ( $ ( o p t s . p a r e n t ) . f i n d ( ' f o r m ' ) ) ; } }
$ ( '#' + id ) . get ( 0 ) . callback = opts . callback } , callback : function ( id , file _id , args ) { $ ( '#' + id ) . get ( 0 ) . callback ( file _id , args ) ; } }
2012-05-07 12:30:57 +00:00
/ *
* lib / js / wn / misc / about . js
* /
wn . provide ( 'wn.ui.misc' ) ; wn . ui . misc . about = function ( ) { if ( ! wn . ui . misc . about _dialog ) { var d = new wn . widgets . Dialog ( { title : 'About wnframework' } )
$ ( d . body ) . html ( repl ( " < div style = 'padding: 20px' < p > < b > Application Name : < / b > % ( n a m e ) s < / p > \
< p > < b > Version : < / b > % ( v e r s i o n ) s < / p > \
< p > < b > License : < / b > % ( l i c e n s e ) s < / p > \
< p > < b > Source Code : < / b > % ( s o u r c e ) s < / p > \
< p > < b > Publisher : < / b > % ( p u b l i s h e r ) s < / p > \
< p > < b > Copyright : < / b > % ( c o p y r i g h t ) s < / p > < / d i v > " , w n . a p p ) ) ; w n . u i . m i s c . a b o u t _ d i a l o g = d ; }
wn . ui . misc . about _dialog . show ( ) ; }
/ *
* lib / js / wn / views / doclistview . js
* /
wn . provide ( 'wn.views.doclistview' ) ; wn . provide ( 'wn.doclistviews' ) ; wn . views . doclistview . show = function ( doctype ) { var page _name = wn . get _route _str ( ) ; if ( wn . pages [ page _name ] ) { wn . container . change _to ( wn . pages [ page _name ] ) ; } else { var route = wn . get _route ( ) ; if ( route [ 1 ] ) { wn . model . with _doctype ( route [ 1 ] , function ( r ) { if ( r && r [ '403' ] ) { return ; }
new wn . views . DocListView ( route [ 1 ] ) ; } ) ; } } }
2012-06-14 05:35:09 +00:00
wn . views . DocListView = wn . ui . Listing . extend ( { init : function ( doctype ) { this . doctype = doctype ; this . label = get _doctype _label ( doctype ) ; this . label = ( this . label . toLowerCase ( ) . substr ( - 4 ) == 'list' ) ? this . label : ( this . label + ' List' ) ; this . make _page ( ) ; this . setup ( ) ; } , make _page : function ( ) { var me = this ; var page _name = wn . get _route _str ( ) ; var page = wn . container . add _page ( page _name ) ; wn . container . change _to ( page _name ) ; this . $page = $ ( page ) ; this . $page . html ( ' < div class = "layout-wrapper layout-wrapper-background" > \
2012-05-07 12:30:57 +00:00
< div class = "appframe-area" > < / d i v > \
< div class = "layout-main-section" > \
< div class = "wnlist-area" > < div class = "help" > Loading ... < / d i v > < / d i v > \
< / d i v > \
< div class = "layout-side-section" > \
2012-05-29 08:35:53 +00:00
< div class = "show-docstatus hide" style = "margin-bottom: 19px" > \
2012-05-07 12:30:57 +00:00
< h4 > Show < / h 4 > \
< div > < input data - docstatus = "0" type = "checkbox" checked = "checked" / > Drafts < / d i v > \
< div > < input data - docstatus = "1" type = "checkbox" checked = "checked" / > Submitted < / d i v > \
< div > < input data - docstatus = "2" type = "checkbox" / > Cancelled < / d i v > \
< / d i v > \
< / d i v > \
< div style = "clear: both" > < / d i v > \
2012-06-14 05:35:09 +00:00
< / d i v > ' ) ; t h i s . a p p f r a m e = n e w w n . u i . A p p F r a m e ( t h i s . $ p a g e . f i n d ( ' . a p p f r a m e - a r e a ' ) ) ; w n . v i e w s . b r e a d c r u m b s ( $ ( ' < s p a n c l a s s = " b r e a d c r u m b - a r e a " > ' ) . a p p e n d T o ( t h i s . a p p f r a m e . $ t i t l e b a r ) , l o c a l s . D o c T y p e [ t h i s . d o c t y p e ] . m o d u l e , t h i s . d o c t y p e ) ; } , s e t u p : f u n c t i o n ( ) { v a r m e = t h i s ; m e . c a n _ d e l e t e = w n . m o d e l . c a n _ d e l e t e ( m e . d o c t y p e ) ; m e . m e t a = l o c a l s . D o c T y p e [ m e . d o c t y p e ] ; m e . $ p a g e . f i n d ( ' . w n l i s t - a r e a ' ) . e m p t y ( ) , m e . s e t u p _ d o c s t a t u s _ f i l t e r ( ) ; m e . s e t u p _ l i s t v i e w ( ) ; m e . i n i t _ l i s t ( ) ; m e . i n i t _ s t a t s ( ) ; m e . m a k e _ r e p o r t _ b u t t o n ( ) ; m e . a d d _ d e l e t e _ o p t i o n ( ) ; } , m a k e _ r e p o r t _ b u t t o n : f u n c t i o n ( ) { v a r m e = t h i s ; i f ( w n . b o o t . p r o f i l e . c a n _ g e t _ r e p o r t . i n d e x O f ( t h i s . d o c t y p e ) ! = - 1 ) { t h i s . a p p f r a m e . a d d _ b u t t o n ( ' B u i l d R e p o r t ' , f u n c t i o n ( ) { w n . s e t _ r o u t e ( ' R e p o r t 2 ' , m e . d o c t y p e ) ; } , ' i c o n - t h ' ) } } , s e t u p _ d o c s t a t u s _ f i l t e r : f u n c t i o n ( ) { v a r m e = t h i s ; t h i s . c a n _ s u b m i t = $ . m a p ( l o c a l s . D o c P e r m , f u n c t i o n ( d ) { i f ( d . p a r e n t = = m e . m e t a . n a m e & & d . s u b m i t ) r e t u r n 1
2012-05-07 12:30:57 +00:00
else return null ; } ) . length ; if ( this . can _submit ) { this . $page . find ( '.show-docstatus' ) . removeClass ( 'hide' ) ; this . $page . find ( '.show-docstatus input' ) . click ( function ( ) { me . run ( ) ; } ) } } , setup _listview : function ( ) { if ( this . meta . _ _listjs ) { eval ( this . meta . _ _listjs ) ; this . listview = new wn . doclistviews [ this . doctype ] ( this ) ; } else { this . listview = new wn . views . ListView ( this ) ; }
2012-05-31 12:53:16 +00:00
this . listview . parent = this ; this . wrapper = this . $page . find ( '.wnlist-area' ) ; this . page _length = 20 ; this . allow _delete = true ; } , init _list : function ( auto _run ) { this . make ( { method : 'webnotes.widgets.doclistview.get' , get _args : this . get _args , parent : this . wrapper , start : 0 , page _length : this . page _length , show _filters : true , show _grid : true , new _doctype : this . doctype , allow _delete : this . allow _delete , no _result _message : this . make _no _result ( ) , columns : this . listview . fields } ) ; if ( ( auto _run !== false ) && ( auto _run !== 0 ) ) this . run ( ) ; } , make _no _result : function ( ) { return repl ( ' < div class = "well" > < p > No % ( doctype _label ) s found < / p > \
2012-05-07 12:30:57 +00:00
% ( description ) s \
< hr > \
< p > < button class = "btn btn-info btn-small" \
onclick = "newdoc(\'%(doctype)s\');" \
> Make a new % ( doctype _label ) s < / b u t t o n > \
2012-06-05 14:40:45 +00:00
< / p > < / d i v > ' , { d o c t y p e _ l a b e l : g e t _ d o c t y p e _ l a b e l ( t h i s . d o c t y p e ) , d o c t y p e : t h i s . d o c t y p e , d e s c r i p t i o n : w n . m a r k d o w n ( l o c a l s . D o c T y p e [ t h i s . d o c t y p e ] . d e s c r i p t i o n | | ' ' ) } ) ; } , r e n d e r _ r o w : f u n c t i o n ( r o w , d a t a ) { d a t a . d o c t y p e = t h i s . d o c t y p e ; t h i s . l i s t v i e w . r e n d e r ( r o w , d a t a , t h i s ) ; } , g e t _ q u e r y _ f i e l d s : f u n c t i o n ( ) { r e t u r n t h i s . l i s t v i e w . f i e l d s ; } , g e t _ a r g s : f u n c t i o n ( ) { r e t u r n { d o c t y p e : t h i s . d o c t y p e , f i e l d s : t h i s . g e t _ q u e r y _ f i e l d s ( ) , f i l t e r s : t h i s . f i l t e r _ l i s t . g e t _ f i l t e r s ( ) , d o c s t a t u s : t h i s . c a n _ s u b m i t ? $ . m a p ( t h i s . $ p a g e . f i n d ( ' . s h o w - d o c s t a t u s : c h e c k e d ' ) , f u n c t i o n ( i n p ) { r e t u r n $ ( i n p ) . a t t r ( ' d a t a - d o c s t a t u s ' ) } ) : [ ] , o r d e r _ b y : t h i s . l i s t v i e w . o r d e r _ b y | | u n d e f i n e d , } } , a d d _ d e l e t e _ o p t i o n : f u n c t i o n ( ) { v a r m e = t h i s ; i f ( t h i s . c a n _ d e l e t e ) { t h i s . a d d _ b u t t o n ( ' D e l e t e ' , f u n c t i o n ( ) { m e . d e l e t e _ i t e m s ( ) ; } , ' i c o n - r e m o v e ' ) } } , d e l e t e _ i t e m s : f u n c t i o n ( ) { v a r m e = t h i s ; v a r d l = $ . m a p ( m e . $ p a g e . f i n d ( ' . l i s t - d e l e t e : c h e c k e d ' ) , f u n c t i o n ( e ) { r e t u r n $ ( e ) . d a t a ( ' n a m e ' ) ; } ) ; i f ( ! d l . l e n g t h )
2012-05-07 12:30:57 +00:00
return ; if ( ! confirm ( 'This is PERMANENT action and you cannot undo. Continue?' ) ) { return ; }
me . set _working ( true ) ; wn . call ( { method : 'webnotes.widgets.doclistview.delete_items' , args : { items : dl , doctype : me . doctype } , callback : function ( ) { me . set _working ( false ) ; me . refresh ( ) ; } } ) } , init _stats : function ( ) { var me = this
2012-05-29 05:36:08 +00:00
wn . call ( { method : 'webnotes.widgets.doclistview.get_stats' , args : { stats : me . listview . stats , doctype : me . doctype } , callback : function ( r ) { $ . each ( me . listview . stats , function ( i , v ) { me . render _stat ( v , r . message [ v ] ) ; } ) ; if ( me . listview . stats . length ) { $ ( '<button class="btn btn-small"><i class="refresh"></i> Refresh</button>' ) . click ( function ( ) { me . reload _stats ( ) ; } ) . appendTo ( $ ( '<div class="stat-wrapper">' ) . appendTo ( me . $page . find ( '.layout-side-section' ) ) ) } } } ) ; } , render _stat : function ( field , stat ) { var me = this ; if ( ! stat || ! stat . length ) { if ( field == '_user_tags' ) { this . $page . find ( '.layout-side-section' ) . append ( ' < div class = "stat-wrapper" > < h4 > Tags < / h 4 > \
2012-05-07 12:30:57 +00:00
< div class = "help small" > < i > No records tagged . < / i > < b r > < b r > \
To add a tag , open the document and click on \
"Add Tag" on the sidebar < / d i v > < / d i v > ' ) ; }
return ; }
var label = wn . meta . docfield _map [ this . doctype ] [ field ] ? wn . meta . docfield _map [ this . doctype ] [ field ] . label : field ; if ( label == '_user_tags' ) label = 'Tags' ; var $w = $ ( ' < div class = "stat-wrapper" > \
< h4 > '+label+' < / h 4 > \
< div class = "stat-grid" > \
< / d i v > \
< / d i v > ' ) ; s t a t = s t a t . s o r t ( f u n c t i o n ( a , b ) { r e t u r n b [ 1 ] - a [ 1 ] } ) ; v a r s u m = 0 ; $ . e a c h ( s t a t , f u n c t i o n ( i , v ) { s u m = s u m + v [ 1 ] ; } )
$ . each ( stat , function ( i , v ) { me . render _stat _item ( i , v , sum , field ) . appendTo ( $w . find ( '.stat-grid' ) ) ; } ) ; $w . appendTo ( this . $page . find ( '.layout-side-section' ) ) ; } , render _stat _item : function ( i , v , max , field ) { var me = this ; var args = { }
args . label = v [ 0 ] ; args . width = flt ( v [ 1 ] ) / max * 100 ; args . count = v [ 1 ] ; args . field = field ; $item = $ ( repl ( ' < div class = "stat-item" > \
< div class = "stat-bar" style = "width: %(width)s%" > < / d i v > \
< div class = "stat-label" > \
< a href = "#" data - label = "%(label)s" data - field = "%(field)s" > \
% ( label ) s < / a > \
( % ( count ) s ) < / d i v > \
2012-05-29 05:36:08 +00:00
< / d i v > ' , a r g s ) ) ; t h i s . s e t u p _ s t a t _ i t e m _ c l i c k ( $ i t e m ) ; r e t u r n $ i t e m ; } , r e l o a d _ s t a t s : f u n c t i o n ( ) { t h i s . $ p a g e . f i n d ( ' . l a y o u t - s i d e - s e c t i o n . s t a t - w r a p p e r ' ) . r e m o v e ( ) ; t h i s . i n i t _ s t a t s ( ) ; } , s e t u p _ s t a t _ i t e m _ c l i c k : f u n c t i o n ( $ i t e m ) { v a r m e = t h i s ; $ i t e m . f i n d ( ' a ' ) . c l i c k ( f u n c t i o n ( ) { v a r f i e l d n a m e = $ ( t h i s ) . a t t r ( ' d a t a - f i e l d ' ) ; v a r l a b e l = $ ( t h i s ) . a t t r ( ' d a t a - l a b e l ' ) ; m e . s e t _ f i l t e r ( f i e l d n a m e , l a b e l ) ; r e t u r n f a l s e ; } ) ; } , s e t _ f i l t e r : f u n c t i o n ( f i e l d n a m e , l a b e l ) { v a r f i l t e r = t h i s . f i l t e r _ l i s t . g e t _ f i l t e r ( f i e l d n a m e ) ; i f ( f i l t e r ) { v a r v = f i l t e r . f i e l d . g e t _ v a l u e ( ) ; i f ( v . i n d e x O f ( l a b e l ) ! = - 1 ) { r e t u r n f a l s e ; } e l s e { i f ( f i e l d n a m e = = ' _ u s e r _ t a g s ' ) { t h i s . f i l t e r _ l i s t . a d d _ f i l t e r ( f i e l d n a m e , ' l i k e ' , ' % ' + l a b e l ) ; } e l s e { f i l t e r . s e t _ v a l u e s ( f i e l d n a m e , ' i n ' , v + ' , ' + l a b e l ) ; } } } e l s e { i f ( f i e l d n a m e = = ' _ u s e r _ t a g s ' ) { t h i s . f i l t e r _ l i s t . a d d _ f i l t e r ( f i e l d n a m e , ' l i k e ' , ' % ' + l a b e l ) ; } e l s e { t h i s . f i l t e r _ l i s t . a d d _ f i l t e r ( f i e l d n a m e , ' = ' , l a b e l ) ; } }
2012-05-09 10:45:51 +00:00
this . run ( ) ; } } ) ; wn . views . ListView = Class . extend ( { init : function ( doclistview ) { this . doclistview = doclistview ; this . doctype = doclistview . doctype ; var t = "`tab" + this . doctype + "`." ; this . fields = [ t + 'name' , t + 'owner' , t + 'docstatus' , t + '_user_tags' , t + 'modified' ] ; this . stats = [ '_user_tags' ] ; this . show _hide _check _column ( ) ; } , columns : [ { width : '3%' , content : 'check' } , { width : '4%' , content : 'avatar' } , { width : '3%' , content : 'docstatus' , css : { "text-align" : "center" } } , { width : '35%' , content : 'name' } , { width : '40%' , content : 'tags' , css : { 'color' : '#aaa' } } , { width : '15%' , content : 'modified' , css : { 'text-align' : 'right' , 'color' : '#222' } } ] , render _column : function ( data , parent , opts ) { var me = this ; if ( opts . css ) { $ . each ( opts . css , function ( k , v ) { $ ( parent ) . css ( k , v ) } ) ; }
2012-05-07 12:30:57 +00:00
if ( opts . content . indexOf && opts . content . indexOf ( '+' ) != - 1 ) { $ . map ( opts . content . split ( '+' ) , function ( v ) { me . render _column ( data , parent , { content : v } ) ; } ) ; return ; }
if ( typeof opts . content == 'function' ) { opts . content ( parent , data ) ; }
else if ( opts . content == 'name' ) { $ ( parent ) . append ( repl ( '<a href="#!Form/%(doctype)s/%(name)s">%(name)s</a>' , data ) ) ; }
else if ( opts . content == 'avatar' ) { $ ( parent ) . append ( repl ( ' < span class = "avatar-small" > < img src = "%(avatar)s" \
title = "%(fullname)s" / > < / s p a n > ' , d a t a ) ) ; }
else if ( opts . content == 'check' ) { $ ( parent ) . append ( '<input class="list-delete" type="checkbox">' ) ; $ ( parent ) . find ( 'input' ) . data ( 'name' , data . name ) ; }
else if ( opts . content == 'docstatus' ) { $ ( parent ) . append ( repl ( ' < span class = "docstatus" > < i class = "%(docstatus_icon)s" \
title = "%(docstatus_title)s" > < / i > < / s p a n > ' , d a t a ) ) ; }
else if ( opts . content == 'tags' ) { this . add _user _tags ( parent , data ) ; }
else if ( opts . content == 'modified' ) { $ ( parent ) . append ( data . when ) ; }
else if ( opts . type == 'bar-graph' ) { args = { percent : data [ opts . content ] , fully _delivered : ( data [ opts . content ] > 99 ? 'bar-complete' : '' ) , label : opts . label }
$ ( parent ) . append ( repl ( ' < span class = "bar-outer" style = "width: 30px; float: right" \
title = "%(percent)s% %(label)s" > \
< span class = "bar-inner %(fully_delivered)s" \
style = "width: %(percent)s%;" > < / s p a n > \
< / s p a n > ' , a r g s ) ) ; }
else if ( opts . type == 'link' && opts . doctype ) { $ ( parent ) . append ( repl ( '<a href="#!Form/' + opts . doctype + '/'
+ data [ opts . content ] + '">' + data [ opts . content ] + '</a>' , data ) ) ; }
else if ( opts . template ) { $ ( parent ) . append ( repl ( opts . template , data ) ) ; }
2012-05-09 10:45:51 +00:00
else if ( data [ opts . content ] ) { $ ( parent ) . append ( ' ' + data [ opts . content ] ) ; } } , render : function ( row , data ) { var me = this ; this . prepare _data ( data ) ; rowhtml = '' ; $ . each ( this . columns , function ( i , v ) { rowhtml += repl ( '<td style="width: %(width)s"></td>' , v ) ; } ) ; var tr = $ ( row ) . html ( '<table><tbody><tr>' + rowhtml + '</tr></tbody></table>' ) . find ( 'tr' ) . get ( 0 ) ; $ . each ( this . columns , function ( i , v ) { me . render _column ( data , tr . cells [ i ] , v ) ; } ) ; } , prepare _data : function ( data ) { data . fullname = wn . user _info ( data . owner ) . fullname ; data . avatar = wn . user _info ( data . owner ) . image ; data . when = dateutil . str _to _user ( data . modified ) . split ( ' ' ) [ 0 ] ; var diff = dateutil . get _diff ( dateutil . get _today ( ) , data . modified . split ( ' ' ) [ 0 ] ) ; if ( diff == 0 ) { data . when = dateutil . comment _when ( data . modified ) ; }
2012-05-07 12:30:57 +00:00
if ( diff == 1 ) { data . when = 'Yesterday' }
if ( diff == 2 ) { data . when = '2 days ago' }
if ( data . docstatus == 0 || data . docstatus == null ) { data . docstatus _icon = 'icon-pencil' ; data . docstatus _title = 'Editable' ; } else if ( data . docstatus == 1 ) { data . docstatus _icon = 'icon-lock' ; data . docstatus _title = 'Submitted' ; } else if ( data . docstatus == 2 ) { data . docstatus _icon = 'icon-remove' ; data . docstatus _title = 'Cancelled' ; }
2012-05-23 09:42:22 +00:00
for ( key in data ) { if ( data [ key ] == null ) { data [ key ] = '' ; } } } , add _user _tags : function ( parent , data ) { var me = this ; if ( data . _user _tags ) { if ( $ ( parent ) . html ( ) . length > 0 ) { $ ( parent ) . append ( '<br />' ) ; }
$ . each ( data . _user _tags . split ( ',' ) , function ( i , t ) { if ( t ) { $ ( '<span class="label label-info" style="cursor: pointer; line-height: 200%">'
2012-05-31 12:53:16 +00:00
+ strip ( t ) + '</span>' ) . click ( function ( ) { me . doclistview . set _filter ( '_user_tags' , $ ( this ) . text ( ) ) } ) . appendTo ( parent ) ; } } ) ; } } , show _hide _check _column : function ( ) { if ( ! this . doclistview . can _delete ) { this . columns = $ . map ( this . columns , function ( v , i ) { if ( v . content != 'check' ) return v } ) ; } } } ) ; wn . provide ( 'wn.views.RecordListView' ) ; wn . views . RecordListView = wn . views . DocListView . extend ( { init : function ( doctype , wrapper , ListView ) { this . doctype = doctype ; this . wrapper = wrapper ; this . listview = new ListView ( this ) ; this . listview . parent = this ; this . setup ( ) ; } , setup : function ( ) { var me = this ; me . page _length = 10 ; $ ( me . wrapper ) . empty ( ) ; me . init _list ( ) ; } , get _args : function ( ) { var args = this . _super ( ) ; $ . each ( ( this . default _filters || [ ] ) , function ( i , f ) { args . filters . push ( f ) ; } ) ; args . docstatus = args . docstatus . concat ( ( this . default _docstatus || [ ] ) ) ; return args ; } , } ) ;
2012-05-07 12:30:57 +00:00
/ *
* lib / js / wn / views / formview . js
* /
wn . provide ( 'wn.views.formview' ) ; wn . views . formview = { show : function ( dt , dn ) { if ( wn . model . new _names [ dn ] )
dn = wn . model . new _names [ dn ] ; wn . model . with _doctype ( dt , function ( ) { wn . model . with _doc ( dt , dn , function ( dn , r ) { if ( r && r [ '403' ] ) return ; if ( ! ( locals [ dt ] && locals [ dt ] [ dn ] ) ) { wn . container . change _to ( '404' ) ; return ; }
if ( ! wn . views . formview [ dt ] ) { wn . views . formview [ dt ] = wn . container . add _page ( 'Form - ' + dt ) ; wn . views . formview [ dt ] . frm = new _f . Frm ( dt , wn . views . formview [ dt ] ) ; }
wn . container . change _to ( 'Form - ' + dt ) ; wn . views . formview [ dt ] . frm . refresh ( dn ) ; } ) ; } ) } , create : function ( dt ) { var new _name = LocalDB . create ( dt ) ; wn . set _route ( 'Form' , dt , new _name ) ; } }
/ *
* lib / js / wn / views / reportview . js
* /
wn . views . reportview = { show : function ( dt , rep _name ) { wn . require ( 'js/report-legacy.js' ) ; dt = get _label _doctype ( dt ) ; if ( ! _r . rb _con ) { _r . rb _con = new _r . ReportContainer ( ) ; }
_r . rb _con . set _dt ( dt , function ( rb ) { if ( rep _name ) { var t = rb . current _loaded ; rb . load _criteria ( rep _name ) ; if ( ( rb . dt ) && ( ! rb . dt . has _data ( ) || rb . current _loaded != t ) ) { rb . dt . run ( ) ; } }
if ( ! rb . forbidden ) { wn . container . change _to ( 'Report Builder' ) ; } } ) ; } }
2012-05-14 09:32:35 +00:00
wn . views . reportview2 = { show : function ( dt ) { var page _name = wn . get _route _str ( ) ; if ( wn . pages [ page _name ] ) { wn . container . change _to ( wn . pages [ page _name ] ) ; } else { var route = wn . get _route ( ) ; if ( route [ 1 ] ) { new wn . views . ReportViewPage ( route [ 1 ] , route [ 2 ] ) ; } else { wn . set _route ( '404' ) ; } } } }
wn . views . ReportViewPage = Class . extend ( { init : function ( doctype , docname ) { this . doctype = doctype ; this . docname = docname ; this . page _name = wn . get _route _str ( ) ; this . make _page ( ) ; var me = this ; wn . model . with _doctype ( doctype , function ( ) { me . make _report _view ( ) ; if ( docname ) { wn . model . with _doc ( 'Report' , docname , function ( r ) { me . reportview . set _columns _and _filters ( JSON . parse ( locals [ 'Report' ] [ docname ] . json ) ) ; me . reportview . run ( ) ; } ) ; } else { me . reportview . run ( ) ; } } ) ; } , make _page : function ( ) { this . page = wn . container . add _page ( this . page _name ) ; wn . ui . make _app _page ( { parent : this . page , single _column : true } ) ; wn . container . change _to ( this . page _name ) ; } , make _report _view : function ( ) { wn . views . breadcrumbs ( $ ( '<span>' ) . appendTo ( this . page . appframe . $titlebar ) , locals . DocType [ this . doctype ] . module ) ; this . reportview = new wn . views . ReportView ( this . doctype , this . docname , this . page ) } } )
2012-06-11 05:08:47 +00:00
wn . views . ReportView = wn . ui . Listing . extend ( { init : function ( doctype , docname , page ) { var me = this ; $ ( page ) . find ( '.layout-main' ) . html ( 'Loading Report...' ) ; this . import _slickgrid ( ) ; $ ( page ) . find ( '.layout-main' ) . empty ( ) ; this . doctype = doctype ; this . docname = docname ; this . page = page ; this . tab _name = '`tab' + doctype + '`' ; this . setup ( ) ; } , import _slickgrid : function ( ) { wn . require ( 'js/lib/slickgrid/slick.grid.css' ) ; wn . require ( 'js/lib/slickgrid/slick-default-theme.css' ) ; wn . require ( 'js/lib/slickgrid/jquery.event.drag.min.js' ) ; wn . require ( 'js/lib/slickgrid/slick.core.js' ) ; wn . require ( 'js/lib/slickgrid/slick.grid.js' ) ; wn . dom . set _style ( '.slick-cell { font-size: 12px; }' ) ; } , set _init _columns : function ( ) { var columns = [ [ 'name' ] , [ 'owner' ] ] ; $ . each ( wn . meta . docfield _list [ this . doctype ] , function ( i , df ) { if ( df . in _filter && df . fieldname != 'naming_series' && df . fieldtype != 'Table' ) { columns . push ( [ df . fieldname ] ) ; } } ) ; this . columns = columns ; } , setup : function ( ) { var me = this ; this . make ( { title : 'Report: ' + ( this . docname ? ( this . doctype + ' - ' + this . docname ) : this . doctype ) , appframe : this . page . appframe , method : 'webnotes.widgets.doclistview.get' , get _args : this . get _args , parent : $ ( this . page ) . find ( '.layout-main' ) , start : 0 , page _length : 20 , show _filters : true , new _doctype : this . doctype , allow _delete : true , } ) ; this . make _column _picker ( ) ; this . make _sorter ( ) ; this . make _export ( ) ; this . set _init _columns ( ) ; this . make _save ( ) ; } , set _columns _and _filters : function ( opts ) { var me = this ; if ( opts . columns ) this . columns = opts . columns ; if ( opts . filters ) $ . each ( opts . filters , function ( i , f ) { me . filter _list . add _filter ( f [ 1 ] , f [ 2 ] , f [ 3 ] ) ; } ) ; if ( opts . sort _by ) this . sort _by _select . val ( opts . sort _by ) ; if ( opts . sort _order ) this . sort _order _select . val ( opts . sort _order ) ; if ( opts . sort _by _next ) this . sort _by _next _select . val ( opts . sort _by _next ) ; if ( opts . sort _order _next ) this . sort _order _next _select . val ( opts . sort _order _next ) ; } , get _args : function ( ) { var me = this ; return { doctype : this . doctype , fields : $ . map ( this . columns , function ( v ) { return me . get _full _column _name ( v ) } ) , order _by : this . get _order _by ( ) , filters : this . filter _list . get _filters ( ) , docstatus : [ '0' , '1' , '2' ] } } , get _order _by : function ( ) { var order _by = this . get _full _column _name ( [ this . sort _by _select . val ( ) ] )
2012-05-07 12:30:57 +00:00
+ ' ' + this . sort _order _select . val ( )
if ( this . sort _by _next _select . val ( ) ) { order _by += ', ' + this . get _full _column _name ( [ this . sort _by _next _select . val ( ) ] )
+ ' ' + this . sort _order _next _select . val ( ) }
2012-05-09 11:25:58 +00:00
return order _by ; } , get _full _column _name : function ( v ) { return ( v [ 1 ] ? ( '`tab' + v [ 1 ] + '`' ) : this . tab _name ) + '.' + v [ 0 ] ; } , build _columns : function ( ) { var me = this ; return $ . map ( this . columns , function ( c ) { var docfield = wn . meta . docfield _map [ c [ 1 ] || me . doctype ] [ c [ 0 ] ] ; coldef = { id : c [ 0 ] , field : c [ 0 ] , docfield : docfield , name : ( docfield ? docfield . label : toTitle ( c [ 0 ] ) ) , width : ( docfield ? cint ( docfield . width ) : 120 ) || 120 }
2012-05-14 09:32:35 +00:00
if ( c [ 0 ] == 'name' ) { coldef . formatter = function ( row , cell , value , columnDef , dataContext ) { return repl ( "<a href='#!Form/%(doctype)s/%(name)s'>%(name)s</a>" , { doctype : me . doctype , name : value } ) ; } } else if ( docfield && docfield . fieldtype == 'Link' ) { coldef . formatter = function ( row , cell , value , columnDef , dataContext ) { if ( value ) { return repl ( "<a href='#!Form/%(doctype)s/%(name)s'>%(name)s</a>" , { doctype : columnDef . docfield . options , name : value } ) ; } else { return '' ; } } }
2012-05-09 11:25:58 +00:00
return coldef ; } ) ; } , render _list : function ( ) { var me = this ; var columns = [ { id : '_idx' , field : '_idx' , name : 'Sr.' , width : 40 } ] . concat ( this . build _columns ( ) ) ; $ . each ( this . data , function ( i , v ) { v . _idx = i + 1 ; } ) ; var options = { enableCellNavigation : true , enableColumnReorder : false } ; var grid = new Slick . Grid ( this . $w . find ( '.result-list' ) . css ( 'border' , '1px solid grey' ) . css ( 'height' , '500px' ) . get ( 0 ) , this . data , columns , options ) ; } , make _column _picker : function ( ) { var me = this ; this . column _picker = new wn . ui . ColumnPicker ( this ) ; this . page . appframe . add _button ( 'Pick Columns' , function ( ) { me . column _picker . show ( me . columns ) ; } , 'icon-th-list' ) ; } , make _sorter : function ( ) { var me = this ; this . sort _dialog = new wn . ui . Dialog ( { title : 'Sorting Preferences' } ) ; $ ( this . sort _dialog . body ) . html ( ' < p class = "help" > Sort By < / p > \
2012-05-07 12:30:57 +00:00
< div class = "sort-column" > < / d i v > \
< div > < select class = "sort-order" style = "margin-top: 10px; width: 60%;" > \
< option value = "asc" > Ascending < / o p t i o n > \
< option value = "desc" > Descending < / o p t i o n > \
< / s e l e c t > < / d i v > \
< hr > < p class = "help" > Then By ( optional ) < / p > \
< div class = "sort-column-1" > < / d i v > \
< div > < select class = "sort-order-1" style = "margin-top: 10px; width: 60%;" > \
< option value = "asc" > Ascending < / o p t i o n > \
< option value = "desc" > Descending < / o p t i o n > \
< / s e l e c t > < / d i v > < h r > \
< div > < button class = "btn btn-small btn-info" > Update < / d i v > ' ) ; t h i s . s o r t _ b y _ 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 . s o r t _ d i a l o g . b o d y ) . f i n d ( ' . s o r t - c o l u m n ' ) , t h i s . d o c t y p e ) . $ s e l e c t ; t h i s . s o r t _ b y _ s e l e c t . c s s ( ' w i d t h ' , ' 6 0 % ' ) ; t h i s . s o r t _ o r d e r _ s e l e c t = $ ( t h i s . s o r t _ d i a l o g . b o d y ) . f i n d ( ' . s o r t - o r d e r ' ) ; t h i s . s o r t _ b y _ n e x t _ 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 . s o r t _ d i a l o g . b o d y ) . f i n d ( ' . s o r t - c o l u m n - 1 ' ) , t h i s . d o c t y p e , n u l l , t r u e ) . $ s e l e c t ; t h i s . s o r t _ b y _ n e x t _ s e l e c t . c s s ( ' w i d t h ' , ' 6 0 % ' ) ; t h i s . s o r t _ o r d e r _ n e x t _ s e l e c t = $ ( t h i s . s o r t _ d i a l o g . b o d y ) . f i n d ( ' . s o r t - o r d e r - 1 ' ) ; t h i s . s o r t _ b y _ s e l e c t . v a l ( ' m o d i f i e d ' ) ; t h i s . s o r t _ o r d e r _ s e l e c t . v a l ( ' d e s c ' ) ; t h i s . s o r t _ b y _ n e x t _ s e l e c t . v a l ( ' ' ) ; t h i s . s o r t _ o r d e r _ n e x t _ s e l e c t . v a l ( ' d e s c ' ) ; t h i s . p a g e . a p p f r a m e . a d d _ b u t t o n ( ' S o r t B y ' , f u n c t i o n ( ) { m e . s o r t _ d i a l o g . s h o w ( ) ; } , ' i c o n - a r r o w - d o w n ' ) ; $ ( t h i s . s o r t _ d i a l o g . b o d y ) . f i n d ( ' . b t n - i n f o ' ) . c l i c k ( f u n c t i o n ( ) { m e . s o r t _ d i a l o g . h i d e ( ) ; m e . r u n ( ) ; } ) ; } , m a k e _ e x p o r t : f u n c t i o n ( ) { v a r m e = t h i s ; i f ( w n . u s e r . i s _ r e p o r t _ m a n a g e r ( ) ) { t h i s . p a g e . a p p f r a m e . a d d _ b u t t o n ( ' E x p o r t ' , f u n c t i o n ( ) { v a r a r g s = m e . g e t _ a r g s ( ) ; a r g s . c m d = ' w e b n o t e s . w i d g e t s . d o c l i s t v i e w . e x p o r t _ q u e r y '
open _url _post ( wn . request . url , args ) ; } , 'icon-download-alt' ) ; } } , make _save : function ( ) { var me = this ; if ( wn . user . is _report _manager ( ) ) { this . page . appframe . add _button ( 'Save' , function ( ) { if ( me . docname ) { var name = me . docname } else { var name = prompt ( 'Select Report Name' ) ; if ( ! name ) { return ; } }
wn . call ( { method : 'webnotes.widgets.doclistview.save_report' , args : { name : name , doctype : me . doctype , json : JSON . stringify ( { filters : me . filter _list . get _filters ( ) , columns : me . columns , sort _by : me . sort _by _select . val ( ) , sort _order : me . sort _order _select . val ( ) , sort _by _next : me . sort _by _next _select . val ( ) , sort _order _next : me . sort _order _next _select . val ( ) } ) } , callback : function ( r ) { if ( r . exc ) return ; if ( r . message != me . docname )
wn . set _route ( 'Report2' , me . doctype , r . message ) ; } } ) ; } , 'icon-upload' ) ; } } } ) ; wn . ui . ColumnPicker = Class . extend ( { init : function ( list ) { this . list = list ; this . doctype = list . doctype ; this . selects = { } ; } , show : function ( columns ) { wn . require ( 'js/lib/jquery/jquery.ui.sortable.js' ) ; var me = this ; if ( ! this . dialog ) { this . dialog = new wn . ui . Dialog ( { title : 'Pick Columns' , width : '400' } ) ; }
$ ( this . dialog . body ) . html ( ' < div class = "help" > Drag to sort columns < / d i v > \
< div class = "column-list" > < / d i v > \
< div > < button class = "btn btn-small btn-add" > < i class = "icon-plus" > < / i > \
Add Column < / b u t t o n > < / d i v > \
< hr > \
< div > < button class = "btn btn-small btn-info" > Update < / d i v > ' ) ; $ . e a c h ( c o l u m n s , f u n c t i o n ( i , c ) { m e . a d d _ c o l u m n ( c ) ; } ) ; $ ( t h i s . d i a l o g . b o d y ) . f i n d ( ' . c o l u m n - l i s t ' ) . s o r t a b l e ( ) ; $ ( t h i s . d i a l o g . b o d y ) . f i n d ( ' . b t n - a d d ' ) . c l i c k ( f u n c t i o n ( ) { m e . a d d _ c o l u m n ( ' n a m e ' ) ; } ) ; $ ( t h i s . d i a l o g . b o d y ) . f i n d ( ' . b t n - i n f o ' ) . c l i c k ( f u n c t i o n ( ) { m e . d i a l o g . h i d e ( ) ; m e . l i s t . c o l u m n s = [ ] ; $ ( m e . d i a l o g . b o d y ) . f i n d ( ' s e l e c t ' ) . e a c h ( f u n c t i o n ( ) { m e . l i s t . c o l u m n s . p u s h ( [ $ ( t h i s ) . v a l ( ) , $ ( t h i s ) . f i n d ( ' o p t i o n : s e l e c t e d ' ) . a t t r ( ' t a b l e ' ) ] ) ; } )
me . list . run ( ) ; } ) ; this . dialog . show ( ) ; } , add _column : function ( c ) { var w = $ ( ' < div style = " padding : 5 px 5 px 5 px 35 px ; background - color : # eee ; width : 70 % ; \
margin - bottom : 10 px ; border - radius : 3 px ; cursor : move ; " > \
< a class = "close" style = "margin-top: 5px;" > & times < / a > \
< / d i v > ' ) . a p p e n d T o ( $ ( t h i s . d i a l o g . b o d y ) . f i n d ( ' . c o l u m n - l i s t ' ) ) ; v a r 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 ( w , t h i s . d o c t y p e ) ; f i e l d s e l e c t . $ s e l e c t . c s s ( ' w i d t h ' , ' 9 0 % ' ) . v a l ( c ) ; w . f i n d ( ' . c l o s e ' ) . c l i c k ( f u n c t i o n ( ) { $ ( t h i s ) . p a r e n t ( ) . r e m o v e ( ) ; } ) ; } } ) ;
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 / widgets / layout . js
* /
function Layout ( parent , width ) { if ( parent && parent . substr ) { parent = $i ( parent ) ; }
this . wrapper = $a ( parent , 'div' , '' , { display : 'none' } ) ; if ( width ) { this . width = this . wrapper . style . width ; }
this . myrows = [ ] ; }
Layout . prototype . addrow = function ( ) { this . cur _row = new LayoutRow ( this , this . wrapper ) ; this . myrows [ this . myrows . length ] = this . cur _row ; return this . cur _row }
Layout . prototype . addsubrow = function ( ) { this . cur _row = new LayoutRow ( this , this . cur _row . main _body ) ; this . myrows [ this . myrows . length ] = this . cur _row ; return this . cur _row }
Layout . prototype . addcell = function ( width ) { return this . cur _row . addCell ( width ) ; }
Layout . prototype . setcolour = function ( col ) { $bg ( cc , col ) ; }
Layout . prototype . show = function ( ) { $ds ( this . wrapper ) ; }
Layout . prototype . hide = function ( ) { $dh ( this . wrapper ) ; }
Layout . prototype . close _borders = function ( ) { if ( this . with _border ) { this . myrows [ this . myrows . length - 1 ] . wrapper . style . borderBottom = '1px solid #000' ; } }
2012-03-13 09:49:06 +00:00
function LayoutRow ( layout , parent ) { this . layout = layout ; this . wrapper = $a ( parent , 'div' , 'form-layout-row' ) ; this . main _head = $a ( this . wrapper , 'div' ) ; this . main _body = $a ( this . wrapper , 'div' ) ; if ( layout . with _border ) { this . wrapper . style . border = '1px solid #000' ; this . wrapper . style . borderBottom = '0px' ; }
2012-02-14 06:14:13 +00:00
this . header = $a ( this . main _body , 'div' , '' , { padding : ( layout . with _border ? '0px 8px' : '0px' ) } ) ; this . body = $a ( this . main _body , 'div' ) ; this . table = $a ( this . body , 'table' , '' , { width : '100%' , borderCollapse : 'collapse' } ) ; this . row = this . table . insertRow ( 0 ) ; this . mycells = [ ] ; }
LayoutRow . prototype . hide = function ( ) { $dh ( this . wrapper ) ; }
LayoutRow . prototype . show = function ( ) { $ds ( this . wrapper ) ; }
LayoutRow . prototype . addCell = function ( wid ) { var lc = new LayoutCell ( this . layout , this , wid ) ; this . mycells [ this . mycells . length ] = lc ; return lc ; }
function LayoutCell ( layout , layoutRow , width ) { if ( width ) { var w = width + '' ; if ( w . substr ( w . length - 2 , 2 ) != 'px' ) { if ( w . substr ( w . length - 1 , 1 ) != "%" ) { width = width + '%' } ; } }
2012-03-12 10:42:09 +00:00
this . width = width ; this . layout = layout ; var cidx = layoutRow . row . cells . length ; this . cell = layoutRow . row . insertCell ( cidx ) ; this . cell . style . verticalAlign = 'top' ; this . set _width ( layoutRow . row , width ) ; var h = $a ( this . cell , 'div' , '' , { padding : ( layout . with _border ? '0px 8px' : '0px' ) } ) ; this . wrapper = $a ( this . cell , 'div' , '' , { padding : ( layout . with _border ? '8px' : '0px' ) } ) ; layout . cur _cell = this . wrapper ; layout . cur _cell . header = h ; }
2012-02-14 06:14:13 +00:00
LayoutCell . prototype . set _width = function ( row , width ) { var w = 100 ; var n _cells = row . cells . length ; var cells _with _no _width = n _cells ; if ( width ) { $y ( row . cells [ n _cells - 1 ] , { width : cint ( width ) + '%' } ) } else { row . cells [ n _cells - 1 ] . estimated _width = 1 ; }
for ( var i = 0 ; i < n _cells ; i ++ ) { if ( ! row . cells [ i ] . estimated _width ) { w = w - cint ( row . cells [ i ] . style . width ) ; cells _with _no _width -- ; } }
for ( var i = 0 ; i < n _cells ; i ++ ) { if ( row . cells [ i ] . estimated _width )
$y ( row . cells [ i ] , { width : cint ( w / cells _with _no _width ) + '%' } ) } }
LayoutCell . prototype . show = function ( ) { $ds ( this . wrapper ) ; }
LayoutCell . prototype . hide = function ( ) { $dh ( this . wrapper ) ; }
/ *
* lib / js / legacy / widgets / tabbedpage . js
* /
function TabbedPage ( parent , only _labels ) { this . tabs = { } ; this . items = this . tabs
this . cur _tab = null ; this . label _wrapper = $a ( parent , 'div' , 'box_label_wrapper' , { marginTop : '16px' } ) ; this . label _body = $a ( this . label _wrapper , 'div' , 'box_label_body' ) ; this . label _area = $a ( this . label _body , 'ul' , 'box_tabs' ) ; if ( ! only _labels ) this . body _area = $a ( parent , 'div' , '' , { backgroundColor : '#FFF' } ) ; else this . body _area = null ; this . add _item = function ( label , onclick , no _body , with _heading ) { this . add _tab ( label , onclick , no _body , with _heading ) ; return this . items [ label ] ; } }
TabbedPage . prototype . add _tab = function ( n , onshow , no _body , with _heading ) { var tab = $a ( this . label _area , 'li' ) ; tab . label = $a ( tab , 'a' ) ; tab . label . innerHTML = n ; if ( this . body _area && ! no _body ) { tab . tab _body = $a ( this . body _area , 'div' ) ; $dh ( tab . tab _body ) ; tab . body = tab . tab _body ; } else { tab . tab _body = null ; }
2012-03-12 07:52:09 +00:00
tab . onshow = onshow ; var me = this ; tab . collapse = function ( ) { if ( this . tab _body ) $dh ( this . tab _body ) ; this . className = '' ; }
2012-03-02 09:26:51 +00:00
tab . set _selected = function ( ) { if ( me . cur _tab ) me . cur _tab . collapse ( ) ; this . className = 'box_tab_selected' ; $ ( this ) . css ( 'opacity' , 1 ) ; me . cur _tab = this ; }
2012-02-14 06:14:13 +00:00
tab . expand = function ( arg ) { this . set _selected ( ) ; if ( this . tab _body ) $ds ( this . tab _body ) ; if ( this . onshow ) this . onshow ( arg ) ; }
tab . onmouseover = function ( ) { if ( me . cur _tab != this ) this . className = 'box_tab_mouseover' ; }
tab . onmouseout = function ( ) { if ( me . cur _tab != this ) this . className = '' }
tab . hide = function ( ) { this . collapse ( ) ; $dh ( this ) ; }
tab . show = function ( ) { $ds ( this ) ; }
tab . onclick = function ( ) { this . expand ( ) ; }
this . tabs [ n ] = tab ; return tab ; }
function TrayPage ( parent , height , width , width _body ) { var me = this ; if ( ! width ) width = ( 100 / 8 ) + '%' ; this . body _style = { margin : '4px 8px' }
this . cur _item = null ; this . items = { } ; this . tabs = this . items
this . tab = make _table ( $a ( parent , 'div' ) , 1 , 2 , '100%' , [ width , width _body ] ) ; $y ( $td ( this . tab , 0 , 0 ) , { backgroundColor : this . tray _bg , width : width } ) ; this . body = $a ( $td ( this . tab , 0 , 1 ) , 'div' ) ; if ( height ) { $y ( this . body , { height : height , overflow : 'auto' } ) ; }
this . add _item = function ( label , onclick , no _body , with _heading ) { this . items [ label ] = new TrayItem ( me , label , onclick , no _body , with _heading ) ; return this . items [ label ] ; } }
function TrayItem ( tray , label , onclick , no _body , with _heading ) { this . label = label ; this . onclick = onclick ; var me = this ; this . ldiv = $a ( $td ( tray . tab , 0 , 0 ) , 'div' ) ; $item _normal ( this . ldiv ) ; if ( ! no _body ) { this . wrapper = $a ( tray . body , 'div' , '' , tray . body _style ) ; if ( with _heading ) { this . header = $a ( this . wrapper , 'div' , 'sectionHeading' , { marginBottom : '16px' , paddingBottom : '0px' } ) ; this . header . innerHTML = label ; }
this . body = $a ( this . wrapper , 'div' ) ; this . tab _body = this . body ; $dh ( this . wrapper ) ; }
$ ( this . ldiv ) . html ( label ) . hover ( function ( ) { if ( tray . cur _item . label != this . label ) $item _active ( this ) ; } , function ( ) { if ( tray . cur _item . label != this . label ) $item _normal ( this ) ; } ) . click ( function ( ) { me . expand ( ) ; } )
this . ldiv . label = label ; this . ldiv . setAttribute ( 'title' , label ) ; this . ldiv . onmousedown = function ( ) { $item _pressed ( this ) ; }
this . ldiv . onmouseup = function ( ) { $item _selected ( this ) ; }
this . expand = function ( ) { if ( tray . cur _item ) tray . cur _item . collapse ( ) ; if ( me . wrapper ) $ds ( me . wrapper ) ; if ( me . onclick ) me . onclick ( me . label ) ; me . show _as _expanded ( ) ; }
this . show _as _expanded = function ( ) { $item _selected ( me . ldiv ) ; tray . cur _item = me ; }
this . collapse = function ( ) { if ( me . wrapper ) $dh ( me . wrapper ) ; $item _normal ( me . ldiv ) ; }
this . hide = function ( ) { me . collapse ( ) ; $dh ( me . ldiv ) ; }
this . show = function ( ) { $ds ( me . ldiv ) ; } }
/ *
* 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 / widgets / tags . js
* /
_tags = { dialog : null , color _map : { } , all _tags : [ ] , colors : { 'Default' : '#add8e6' } }
TagList = function ( parent , start _list , dt , dn , static , onclick ) { this . start _list = start _list ? start _list : [ ] ; this . tag _list = [ ] ; this . dt = dt ; this . onclick = onclick ; this . dn = dn ; this . static ; this . parent = parent ; this . make _body ( ) ; }
TagList . prototype . make = function ( parent ) { for ( var i = 0 ; i < this . start _list . length ; i ++ ) { if ( this . start _list [ i ] )
new SingleTag ( { parent : this . body , label : this . start _list [ i ] , dt : this . dt , dn : this . dn , fieldname : '_user_tags' , static : this . static , taglist : this , onclick : this . onclick } ) ; } }
TagList . prototype . make _body = function ( ) { var div = $a ( this . parent , 'span' , '' , { margin : '3px 0px' , padding : '3px 0px' } ) ; this . body = $a ( div , 'span' , '' , { marginRight : '4px' } ) ; this . add _tag _area = $a ( div , 'span' ) ; this . make _add _tag ( ) ; this . make ( ) ; }
TagList . prototype . add _tag = function ( label , static , fieldname , color ) { if ( ! label ) return ; if ( in _list ( this . tag _list , label ) ) return ; var tag = new SingleTag ( { parent : this . body , label : label , dt : this . dt , dn : this . dn , fieldname : fieldname , static : static , taglist : this , color : color , onclick : this . onclick } ) ; }
TagList . prototype . make _add _tag = function ( ) { var me = this ; this . add _tag _span = $a ( this . add _tag _area , 'span' , '' , { color : '#888' , textDecoration : 'underline' , cursor : 'pointer' , marginLeft : '4px' , fontSize : '11px' } ) ; this . add _tag _span . innerHTML = 'Add tag' ; this . add _tag _span . onclick = function ( ) { me . new _tag ( ) ; } }
TagList . prototype . make _tag _dialog = function ( ) { var me = this ; var d = new wn . widgets . Dialog ( { title : 'Add a tag' , width : 400 , fields : [ { fieldtype : 'Link' , fieldname : 'tag' , label : 'Tag' , options : 'Tag' , reqd : 1 , description : 'Max chars (20)' , no _buttons : 1 } , { fieldtype : 'Button' , fieldname : 'add' , label : 'Add' } ] } )
$ ( d . fields _dict . tag . input ) . attr ( 'maxlength' , 20 ) ; d . fields _dict . add . input . onclick = function ( ) { me . save _tag ( d ) ; }
return d ; }
TagList . prototype . is _text _okay = function ( val ) { if ( ! val ) { msgprint ( "Please type something" ) ; return ; }
if ( validate _spl _chars ( val ) ) { msgprint ( "Special charaters, commas etc not allowed in tags" ) ; return ; }
return 1 }
TagList . prototype . add _to _locals = function ( tag ) { if ( locals [ this . dt ] && locals [ this . dt ] [ this . dn ] ) { var doc = locals [ this . dt ] [ this . dn ] ; if ( ! doc . _user _tags ) { doc . _user _tags = '' }
var tl = doc . _user _tags . split ( ',' )
tl . push ( tag )
doc . _user _tags = tl . join ( ',' ) ; } }
TagList . prototype . remove _from _locals = function ( tag ) { if ( locals [ this . dt ] && locals [ this . dt ] [ this . dn ] ) { var doc = locals [ this . dt ] [ this . dn ] ; var tl = doc . _user _tags . split ( ',' ) ; var new _tl = [ ] ; for ( var i = 0 ; i < tl . length ; i ++ ) { if ( tl [ i ] != tag ) new _tl . push ( tl [ i ] ) ; }
doc . _user _tags = new _tl . join ( ',' ) ; } }
TagList . prototype . save _tag = function ( d ) { var val = d . get _values ( ) ; if ( val ) val = val . tag ; var me = this ; if ( ! this . is _text _okay ( val ) ) return ; var callback = function ( r , rt ) { var d = me . dialog ; d . fields _dict . add . input . done _working ( ) ; d . fields _dict . tag . input . set _input ( '' ) ; d . hide ( ) ; me . add _to _locals ( val )
if ( ! r . message ) return ; me . add _tag ( r . message , 0 , '_user_tags' ) ; }
me . dialog . fields _dict . add . input . set _working ( ) ; $c ( 'webnotes.widgets.tags.add_tag' , { 'dt' : me . dt , 'dn' : me . dn , 'tag' : val , 'color' : 'na' } , callback ) ; }
TagList . prototype . new _tag = function ( ) { var me = this ; if ( ! this . dialog ) { this . dialog = this . make _tag _dialog ( ) ; }
this . dialog . show ( ) ; }
TagList . prototype . refresh _tags = function ( ) { }
function SingleTag ( opts ) { $ . extend ( this , opts ) ; if ( ! this . color ) this . color = '#add8e6' ; if ( this . taglist && ! in _list ( this . taglist . tag _list , this . label ) )
this . taglist . tag _list . push ( this . label ) ; this . make _body ( this . parent ) ; }
2012-03-02 09:26:51 +00:00
SingleTag . prototype . make _body = function ( parent ) { var me = this ; this . body = $a ( parent , 'span' , '' , { padding : '2px 4px' , backgroundColor : this . color , color : '#226' , marginRight : '4px' } ) ; $br ( this . body , '3px' ) ; if ( this . onclick ) $y ( this . body , { cursor : 'pointer' } ) ; $ ( this . body ) . hover ( function ( ) { $ ( this ) . css ( 'opacity' , 0.6 ) ; } , function ( ) { $ ( this ) . css ( 'opacity' , 1 ) ; } ) ; this . make _label ( ) ; if ( ! this . static ) this . make _remove _btn ( ) ; _tags . all _tags . push ( this ) ; }
2012-02-14 06:14:13 +00:00
SingleTag . prototype . make _remove _btn = function ( ) { var me = this ; var span = $a ( this . body , 'span' ) ; span . innerHTML += ' |' ; var span = $a ( this . body , 'span' , '' , { cursor : 'pointer' } ) ; span . innerHTML = ' x'
span . onclick = function ( ) { me . remove ( me ) ; } }
SingleTag . prototype . make _label = function ( ) { var me = this ; this . label _span = $a ( this . body , 'span' , 'social' , null , this . label ) ; this . label _span . onclick = function ( ) { if ( me . onclick ) me . onclick ( me ) ; } }
SingleTag . prototype . remove _tag _body = function ( ) { $dh ( this . body ) ; var nl = [ ] ; for ( var i in this . tag _list )
if ( this . tag _list [ i ] != this . label )
nl . push ( this . tag _list [ i ] ) ; if ( this . taglist )
this . taglist . tag _list = nl ; }
SingleTag . prototype . remove = function ( ) { var me = this ; var callback = function ( r , rt ) { me . remove _tag _body ( )
me . taglist . remove _from _locals ( me . label ) ; }
$c ( 'webnotes.widgets.tags.remove_tag' , { 'dt' : me . dt , 'dn' : me . dn , 'tag' : me . label } , callback )
$bg ( me . body , '#DDD' ) ; }
wn . widgets . TagCloud = function ( parent , doctype , onclick ) { var me = this ; this . make = function ( r , rt ) { parent . innerHTML = '' ; if ( r . message && r . message . length ) { me . tab = make _table ( parent , r . message . length , 2 , '100%' , [ '40px' , null ] , { padding : '5px 3px 5px 0px' } )
$y ( $td ( me . tab , 0 , 0 ) , { textAlign : 'right' } ) ; for ( var i = 0 ; i < r . message . length ; i ++ ) { new wn . widgets . TagCloud . Tag ( { parent : $td ( me . tab , i , 1 ) , label : r . message [ i ] [ 0 ] , onclick : onclick , fieldname : r . message [ i ] [ 2 ] } , $td ( me . tab , i , 0 ) , r . message [ i ] ) } } else { me . set _no _tags ( ) ; }
me . refresh = $ln ( $a ( parent , 'div' ) , 'refresh' , function ( ) { me . refresh . set _working ( ) ; me . render ( 1 ) ; } , { fontSize : '11px' , margin : '3px 0px' , color : '#888' } , 1 ) ; }
this . set _no _tags = function ( ) { $a ( parent , 'div' , 'social comment' , { fontSize : '11px' , margin : '3px 0px' } , '<i>No tags yet!, please start tagging</i>' ) ; }
this . render = function ( refresh ) { $c ( 'webnotes.widgets.tags.get_top_tags' , { doctype : doctype , refresh : ( refresh ? 1 : 0 ) } , this . make ) ; }
this . render ( ) ; }
wn . widgets . TagCloud . Tag = function ( args , count _cell , det ) { $ ( count _cell ) . css ( 'text-align' , 'right' ) . html ( det [ 1 ] + ' x' ) ; args . static = 1 ; this . tag = new SingleTag ( args ) }
/ *
* lib / js / legacy / widgets / export _query . js
* /
var export _dialog ; function export _query ( query , callback ) { if ( ! export _dialog ) { var d = new Dialog ( 400 , 300 , "Export..." ) ; d . make _body ( [ [ 'Data' , 'Max rows' , 'Blank to export all rows' ] , [ 'Button' , 'Go' ] , ] ) ; d . widgets [ 'Go' ] . onclick = function ( ) { export _dialog . hide ( ) ; n = export _dialog . widgets [ 'Max rows' ] . value ; if ( cint ( n ) )
export _dialog . query += ' LIMIT 0,' + cint ( n ) ; callback ( export _dialog . query ) ; }
d . onshow = function ( ) { this . widgets [ 'Max rows' ] . value = '500' ; }
export _dialog = d ; }
export _dialog . query = query ; export _dialog . show ( ) ; }
function export _csv ( q , report _name , sc _id , is _simple , filter _values , colnames ) { var args = { }
args . cmd = 'webnotes.widgets.query_builder.runquery_csv' ; if ( is _simple )
args . simple _query = q ; else
args . query = q ; args . sc _id = sc _id ? sc _id : '' ; args . filter _values = filter _values ? filter _values : '' ; if ( colnames )
2012-03-12 10:42:09 +00:00
args . colnames = colnames . join ( ',' ) ; args . report _name = report _name ? report _name : '' ; open _url _post ( wn . request . url , args ) ; }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / webpage / search . js
* /
2012-05-02 05:53:08 +00:00
search _fields = { } ; function setlinkvalue ( name ) { selector . input . set _input _value ( name ) ; selector . hide ( ) ; }
2012-02-14 06:14:13 +00:00
function makeselector ( ) { var d = new Dialog ( 540 , 440 , 'Search' ) ; d . make _body ( [ [ 'Data' , 'Beginning With' , 'Tip: You can use wildcard "%"' ] , [ 'Select' , 'Search By' ] , [ 'Button' , 'Search' ] , [ 'HTML' , 'Help' ] , [ 'HTML' , 'Result' ] ] ) ; var inp = d . widgets [ 'Beginning With' ] ; var field _sel = d . widgets [ 'Search By' ] ; var btn = d . widgets [ 'Search' ] ; d . sel _type = '' ; d . values _len = 0 ; d . set = function ( input , type , label ) { d . sel _type = type ; d . input = input ; if ( d . style != 'Link' ) { d . rows [ 'Result' ] . innerHTML = '' ; d . values _len = 0 ; }
d . style = 'Link' ; d . set _query _description ( )
if ( ! d . sel _type ) d . sel _type = 'Value' ; d . set _title ( 'Select a "' + d . sel _type + '" for field "' + label + '"' ) ; }
d . set _search = function ( dt ) { if ( d . style != 'Search' ) { d . rows [ 'Result' ] . innerHTML = '' ; d . values _len = 0 ; }
d . style = 'Search' ; if ( d . input ) { d . input = null ; sel _type = null ; }
d . sel _type = get _label _doctype ( dt ) ; d . set _title ( 'Quick Search for ' + dt ) ; }
2012-02-17 08:34:55 +00:00
$ ( inp ) . keydown ( function ( e ) { if ( e . which == 13 ) { if ( ! btn . disabled ) btn . onclick ( ) ; } } )
2012-02-14 06:14:13 +00:00
d . set _query _description = function ( ) { if ( d . input && d . input . query _description ) { d . rows [ 'Help' ] . innerHTML = '<div class="help_box">' + d . input . query _description + '</div>' ; } else { d . rows [ 'Help' ] . innerHTML = '' } }
d . onshow = function ( ) { if ( d . set _doctype != d . sel _type ) { d . rows [ 'Result' ] . innerHTML = '' ; d . values _len = 0 ; }
inp . value = '' ; if ( d . input && d . input . txt . value ) { inp . value = d . input . txt . value ; }
try { inp . focus ( ) ; } catch ( e ) { }
if ( d . input ) d . input . set _get _query ( ) ; var get _sf _list = function ( dt ) { var l = [ ] ; var lf = search _fields [ dt ] ; for ( var i = 0 ; i < lf . length ; i ++ ) l . push ( lf [ i ] [ 1 ] ) ; return l ; }
$ds ( d . rows [ 'Search By' ] ) ; if ( search _fields [ d . sel _type ] ) { empty _select ( field _sel ) ; add _sel _options ( field _sel , get _sf _list ( d . sel _type ) , 'ID' ) ; } else { empty _select ( field _sel ) ; add _sel _options ( field _sel , [ 'ID' ] , 'ID' ) ; $c ( 'webnotes.widgets.search.getsearchfields' , { 'doctype' : d . sel _type } , function ( r , rt ) { search _fields [ d . sel _type ] = r . searchfields ; empty _select ( field _sel ) ; add _sel _options ( field _sel , get _sf _list ( d . sel _type ) ) ; field _sel . selectedIndex = 0 ; } ) ; } }
2012-03-09 12:21:39 +00:00
d . onhide = function ( ) { }
2012-02-14 06:14:13 +00:00
btn . onclick = function ( ) { if ( this . disabled ) return ; this . args . is _ajax = true ; this . set _working ( ) ; d . set _doctype = d . sel _type ; var q = '' ; args = { } ; if ( d . input && d . input . get _query ) { var doc = { } ; args . is _simple = 1 ; if ( cur _frm ) doc = locals [ cur _frm . doctype ] [ cur _frm . docname ] ; var q = d . input . get _query ( doc , d . input . doctype , d . input . docname ) ; if ( ! q ) { return '' ; } }
var get _sf _fieldname = function ( v ) { var lf = search _fields [ d . sel _type ] ; if ( ! lf )
return 'name'
for ( var i = 0 ; i < lf . length ; i ++ ) if ( lf [ i ] [ 1 ] == v ) return lf [ i ] [ 0 ] ; }
$ . extend ( args , { 'txt' : strip ( inp . value ) , 'doctype' : d . sel _type , 'query' : q , 'searchfield' : get _sf _fieldname ( sel _val ( field _sel ) ) } ) ; $c ( 'webnotes.widgets.search.search_widget' , args , function ( r , rtxt ) { btn . done _working ( ) ; if ( r . coltypes ) r . coltypes [ 0 ] = 'Link' ; d . values _len = r . values . length ; d . set _result ( r ) ; } , function ( ) { btn . done _working ( ) ; } ) ; }
d . set _result = function ( r ) { d . rows [ 'Result' ] . innerHTML = '' ; var c = $a ( d . rows [ 'Result' ] , 'div' , 'comment' , { paddingBottom : '4px' , marginBottom : '4px' , borderBottom : '1px solid #CCC' , marginLeft : '4px' } ) ; if ( r . values . length == 50 )
c . innerHTML = 'Showing max 50 results. Use filters to narrow down your search' ; else
c . innerHTML = 'Showing ' + r . values . length + ' resuts.' ; var w = $a ( d . rows [ 'Result' ] , 'div' , '' , { height : '240px' , overflow : 'auto' , margin : '4px' } ) ; for ( var i = 0 ; i < r . values . length ; i ++ ) { var div = $a ( w , 'div' , '' , { marginBottom : '4px' , paddingBottom : '4px' , borderBottom : '1px dashed #CCC' } ) ; var l = $a ( $a ( div , 'div' ) , 'span' , 'link_type' ) ; l . innerHTML = r . values [ i ] [ 0 ] ; l . link _name = r . values [ i ] [ 0 ] ; l . dt = r . coloptions [ 0 ] ; if ( d . input )
l . onclick = function ( ) { setlinkvalue ( this . link _name ) ; }
else
l . onclick = function ( ) { loaddoc ( this . dt , this . link _name ) ; d . hide ( ) ; }
var cl = [ ]
for ( var j = 1 ; j < r . values [ i ] . length ; j ++ ) cl . push ( r . values [ i ] [ j ] ) ; var c = $a ( div , 'div' , 'comment' , { marginTop : '2px' } ) ; c . innerHTML = cl . join ( ', ' ) ; } }
selector = d ; }
/ *
* lib / js / legacy / webpage / spinner . js
* /
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 / page _layout . js
* /
wn . PageLayout = function ( args ) { $ . extend ( this , args )
2012-06-14 05:35:09 +00:00
this . wrapper = $a ( this . parent , 'div' , 'layout-wrapper layout-wrapper-background' ) ; this . head = $a ( this . wrapper , 'div' ) ; this . main = $a ( this . wrapper , 'div' , 'layout-main-section' ) ; this . sidebar _area = $a ( this . wrapper , 'div' , 'layout-side-section' ) ; $a ( this . wrapper , 'div' , '' , { clear : 'both' } ) ; this . body = $a ( this . main , 'div' ) ; this . footer = $a ( this . main , 'div' ) ; if ( this . heading ) { this . page _head = new PageHeader ( this . head , this . heading ) ; } }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / wn / widgets / page _sidebar . js
* /
wn . widgets . PageSidebar = function ( parent , opts ) { this . opts = opts
this . sections = { }
2012-02-20 13:00:52 +00:00
this . wrapper = $a ( parent , 'div' , 'psidebar' )
2012-02-14 06:14:13 +00:00
this . refresh = function ( ) { this . wrapper . innerHTML = ''
if ( this . opts . title )
this . make _head ( ) ; for ( var i = 0 ; i < this . opts . sections . length ; i ++ ) { var section = this . opts . sections [ i ] ; if ( ( section . display && section . display ( ) ) || ! section . display ) { this . sections [ section . title ] = new wn . widgets . PageSidebarSection ( this , section ) ; } }
if ( this . opts . onrefresh ) { this . opts . onrefresh ( this ) } }
2012-02-20 13:00:52 +00:00
this . make _head = function ( ) { this . head = $a ( this . wrapper , 'div' , 'head' , '' , this . opts . title ) ; }
2012-02-14 06:14:13 +00:00
this . refresh ( ) ; }
2012-03-21 06:17:58 +00:00
wn . widgets . PageSidebarSection = function ( sidebar , opts ) { this . items = [ ] ; this . sidebar = sidebar ; this . wrapper = $a ( sidebar . wrapper , 'div' , 'section' ) ; this . head = $a ( this . wrapper , 'div' , 'section-head' , '' , opts . title ) ; this . body = $a ( this . wrapper , 'div' , 'section-body' ) ; $br ( this . wrapper , '5px' ) ; this . opts = opts ; this . make _items = function ( ) { for ( var i = 0 ; i < this . opts . items . length ; i ++ ) { var item = this . opts . items [ i ] ; if ( ( item . display && item . display ( ) ) || ! item . display ) { var div = $a ( this . body , 'div' , 'section-item small' ) ; this . make _one _item ( item , div ) ; } } }
2012-02-14 06:14:13 +00:00
this . make _one _item = function ( item , div ) { if ( item . type . toLowerCase ( ) == 'link' )
this . items [ item . label ] = new wn . widgets . PageSidebarLink ( this , item , div ) ; else if ( item . type . toLowerCase ( ) == 'button' )
this . items [ item . label ] = new wn . widgets . PageSidebarButton ( this , this . opts . items [ i ] , div ) ; else if ( item . type . toLowerCase ( ) == 'html' )
this . items [ item . label ] = new wn . widgets . PageSidebarHTML ( this , this . opts . items [ i ] , div ) ; }
2012-02-24 11:06:58 +00:00
this . add _icon = function ( parent , icon ) { var img = $a ( parent , 'i' , icon , { marginRight : '7px' , marginBottom : '-3px' } ) ; }
2012-02-14 06:14:13 +00:00
this . refresh = function ( ) { this . body . innerHTML = '' ; if ( this . opts . render ) { this . opts . render ( this . body ) ; }
else
this . make _items ( ) ; }
this . refresh ( ) ; }
wn . widgets . PageSidebarLink = function ( section , opts , wrapper ) { this . wrapper = wrapper ; this . section = section ; this . opts = opts ; var me = this ; if ( opts . icon ) { section . add _icon ( this . wrapper , opts . icon ) ; }
2012-03-21 06:17:58 +00:00
this . ln = $a ( this . wrapper , 'span' , 'link_type section-link small' , opts . style , opts . label ) ; this . ln . onclick = function ( ) { me . opts . onclick ( me ) } ; }
2012-02-14 06:14:13 +00:00
wn . widgets . PageSidebarButton = function ( section , opts , wrapper ) { this . wrapper = wrapper ; this . section = section ; this . opts = opts ; var me = this ; this . btn = $btn ( this . wrapper , opts . label , opts . onclick , opts . style , opts . color ) ; }
wn . widgets . PageSidebarHTML = function ( section , opts , wrapper ) { wrapper . innerHTML = opts . content }
/ *
* 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 ; }
LocalDB . sync = function ( list ) { if ( list . _kl ) list = expand _doclist ( list ) ; for ( var i = 0 ; i < list . length ; i ++ ) { var d = list [ i ] ; if ( ! d . name )
2012-05-05 14:35:58 +00:00
d . name = LocalDB . get _localname ( d . doctype ) ; LocalDB . add ( d . doctype , d . name ) ; locals [ d . doctype ] [ d . name ] = 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-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 ; }
LocalDB . delete _record = function ( dt , dn ) { var d = locals [ dt ] [ dn ] ; if ( ! d . _ _islocal )
d . _ _oldparent = d . parent ; d . parent = 'old_parent:' + d . parent ; d . docstatus = 2 ; d . _ _deleted = 1 ; }
LocalDB . get _default _value = function ( fn , ft , df ) { if ( df == '_Login' || df == '__user' )
return user ; else if ( df == '_Full Name' )
return user _fullname ; else if ( ft == 'Date' && ( df == 'Today' || df == '__today' ) ) { return get _today ( ) ; }
else if ( df )
return df ; else if ( user _defaults [ fn ] )
return user _defaults [ fn ] [ 0 ] ; else if ( sys _defaults [ fn ] )
return sys _defaults [ fn ] ; }
LocalDB . add _child = function ( doc , childtype , parentfield ) { var n = LocalDB . create ( childtype ) ; var d = locals [ childtype ] [ n ] ; d . parent = doc . name ; d . parentfield = parentfield ; d . parenttype = doc . doctype ; return d ; }
2012-05-16 08:40:27 +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 = get _field ( 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 ] ; }
function make _doclist ( dt , dn , deleted ) { var dl = [ ] ; dl [ 0 ] = locals [ dt ] [ dn ] ; for ( var ndt in locals ) { if ( locals [ ndt ] ) { for ( var ndn in locals [ ndt ] ) { var doc = locals [ ndt ] [ ndn ] ; if ( doc && doc . parenttype == dt && ( doc . parent == dn || ( deleted && doc . _ _oldparent == dn ) ) ) { dl [ dl . length ] = doc ; } } } }
return dl ; }
var 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 ) ; } } }
2012-04-19 12:18:57 +00:00
Meta . get _field = function ( dt , fn , dn ) { if ( dn && local _dt [ dt ] && local _dt [ dt ] [ dn ] ) { return local _dt [ dt ] [ dn ] [ fn ] ; } else { if ( wn . meta . docfield _map [ dt ] ) var d = wn . meta . docfield _map [ dt ] [ fn ] ; if ( d ) return d ; }
2012-02-14 06:14:13 +00:00
return { } ; }
Meta . set _field _property = function ( fn , key , val , doc ) { if ( ! doc && ( cur _frm . doc ) ) doc = cur _frm . doc ; try { local _dt [ doc . doctype ] [ doc . name ] [ fn ] [ key ] = val ; refresh _field ( fn ) ; } catch ( e ) { alert ( "Client Script Error: Unknown values for " + doc . name + ',' + fn + '.' + key + '=' + val ) ; } }
2012-04-16 05:48:45 +00:00
function get _doctype _label ( dt ) { return dt }
function get _label _doctype ( label ) { return label }
2012-02-14 06:14:13 +00:00
var getchildren = LocalDB . getchildren ; var get _field = Meta . get _field ; var createLocal = LocalDB . create ;
/ *
* lib / js / legacy / model / doclist . js
* /
2012-04-19 12:18:57 +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' , '__deleted' , '__newname' , '__modified' , '_user_tags' ] ; var fl = [ 'doctype' , 'name' , 'docstatus' , 'owner' , 'parent' , 'parentfield' , 'parenttype' , 'idx' , 'creation' , 'modified' , 'modified_by' , '__islocal' , '__deleted' , '__newname' , '__modified' , '_user_tags' ] ; for ( key in 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-04-19 12:18: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 v = doc [ key ] ; if ( fl [ i ] . reqd && is _null ( v ) && fl [ i ] . fieldname ) { errfld [ errfld . length ] = fl [ i ] . label ; if ( cur _frm ) { var f = cur _frm . fields _dict [ fl [ i ] . fieldname ] ; if ( f ) { if ( f . set _as _error ) f . set _as _error ( 1 ) ; if ( ! cur _frm . error _in _section && f . parent _section ) { cur _frm . error _in _section = 1 ; } } }
2012-02-14 06:14:13 +00:00
if ( all _clear ) all _clear = false ; } }
if ( errfld . length ) msgprint ( '<b>Mandatory fields required in ' +
2012-04-19 12:18:57 +00:00
( doc . parenttype ? ( wn . meta . docfield _map [ doc . parenttype ] [ doc . parentfield ] . label + ' (Table)' ) : get _doctype _label ( doc . doctype ) ) + ':</b>\n' + errfld . join ( '\n' ) ) ; return all _clear ; }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / wn / ui / toolbar . min . js
* /
2012-03-09 11:14:21 +00:00
2012-02-14 06:14:13 +00:00
/ *
* lib / js / wn / ui / toolbar / selector _dialog . js
* /
wn . provide ( 'wn.ui.toolbar' ) ; wn . ui . toolbar . SelectorDialog = Class . extend ( { init : function ( opts ) { this . opts = opts ; try { this . make _dialog ( ) ; } catch ( e ) { console . log ( e ) ; }
this . bind _events ( ) ; } , make _dialog : function ( ) { this . dialog = new wn . widgets . Dialog ( { title : this . opts . title , width : 300 , fields : [ { fieldtype : 'Select' , fieldname : 'doctype' , options : 'Select...' , label : 'Select Type' } , { fieldtype : 'Button' , label : 'Go' , fieldname : 'go' } ] } ) ; } , bind _events : function ( ) { var me = this ; $ ( this . dialog . fields _dict . go . input ) . click ( function ( ) { if ( ! me . dialog . display ) return ; me . dialog . hide ( ) ; me . opts . execute ( me . dialog . fields _dict . doctype . get _value ( ) ) ; } ) ; $ ( this . dialog . fields _dict . doctype . input ) . change ( function ( ) { me . dialog . fields _dict . go . input . click ( ) ; } ) . keypress ( function ( ev ) { if ( ev . which == 13 ) { me . dialog . fields _dict . go . input . click ( ) ; } } ) ; } , show : function ( ) { this . dialog . show ( ) ; this . dialog . fields _dict . doctype . input . focus ( ) ; return false ; } , set _values : function ( lst ) { for ( var i = 0 ; i < lst . length ; i ++ )
lst [ i ] = get _doctype _label ( lst [ i ] ) ; var sel = this . dialog . fields _dict . doctype . input ; $ ( sel ) . empty ( ) ; add _sel _options ( sel , lst . sort ( ) ) ; } } )
/ *
* lib / js / wn / ui / toolbar / new . js
* /
wn . ui . toolbar . NewDialog = wn . ui . toolbar . SelectorDialog . extend ( { init : function ( ) { this . _super ( { title : "New Record" , execute : function ( val ) { new _doc ( val ) ; } , } ) ; this . set _values ( profile . can _create . join ( ',' ) . split ( ',' ) ) ; } } ) ;
/ *
* lib / js / wn / ui / toolbar / search . js
* /
2012-05-03 06:18:43 +00:00
wn . ui . toolbar . Search = wn . ui . toolbar . SelectorDialog . extend ( { init : function ( ) { this . _super ( { title : "Search" , execute : function ( val ) { new wn . ui . Search ( { doctype : val } ) ; } , } ) ; this . set _values ( wn . boot . profile . can _search . join ( ',' ) . split ( ',' ) ) ; makeselector ( ) ; } } ) ;
2012-02-14 06:14:13 +00:00
/ *
* lib / js / wn / ui / toolbar / report . js
* /
2012-05-10 13:37:53 +00:00
wn . ui . toolbar . Report = wn . ui . toolbar . SelectorDialog . extend ( { init : function ( ) { this . _super ( { title : "Start Report For" , execute : function ( val ) { wn . set _route ( 'Report2' , val ) ; } , } ) ; this . set _values ( profile . can _get _report . join ( ',' ) . split ( ',' ) ) ; } } ) ;
2012-02-14 06:14:13 +00:00
/ *
* lib / js / wn / ui / toolbar / recent . js
* /
2012-02-21 05:49:24 +00:00
wn . ui . toolbar . RecentDocs = Class . extend ( { init : function ( ) { $ ( '.navbar .nav:first' ) . append ( ' < li class = "dropdown" > \
< a class = "dropdown-toggle" data - toggle = "dropdown" href = "#" \
onclick = "return false;" > Recent < b class = "caret" > < / b > < / a > \
2012-02-14 06:14:13 +00:00
< ul class = "dropdown-menu" id = "toolbar-recent" > < / u l > \
2012-03-20 09:07:44 +00:00
< /li>');this.setup();this.bind_events();},bind_events:function(){var me=this;$(document).bind('rename',function(event,dt,old_name,new_name){me.rename_notify(dt,old_name,new_name)});},rename_notify:function(dt,old,name){this.remove(dt,old);this.add(dt,name,1);},add:function(dt,dn,on_top){if(this.istable(dt))return;this.remove(dt,dn);var html=repl('<li data-docref="%(dt)s/ % ( dn ) s " > \
2012-02-14 06:14:13 +00:00
< a href = "#Form/%(dt)s/%(dn)s" > \
2012-02-21 05:49:24 +00:00
% ( dn ) s < span style = "font-size: 10px" > ( % ( dt ) s ) < / s p a n > \
2012-04-30 10:13:34 +00:00
< / a > < / l i > ' , { d t : d t , d n : d n } ) ; i f ( o n _ t o p ) { $ ( ' # t o o l b a r - r e c e n t ' ) . p r e p e n d ( h t m l ) ; } e l s e { $ ( ' # t o o l b a r - r e c e n t ' ) . a p p e n d ( h t m l ) ; } } , i s t a b l e : f u n c t i o n ( d t ) { r e t u r n l o c a l s . D o c T y p e [ d t ] & & l o c a l s . D o c T y p e [ d t ] . i s t a b l e | | f a l s e ; } , r e m o v e : f u n c t i o n ( d t , d n ) { $ ( r e p l ( ' # t o o l b a r - r e c e n t l i [ d a t a - d o c r e f = " % ( d t ) s / % ( d n ) s " ] ' , { d t : d t , d n : d n } ) ) . r e m o v e ( ) ; } , s e t u p : f u n c t i o n ( ) { v a r r l i s t = J S O N . p a r s e ( p r o f i l e . r e c e n t | | " [ ] " ) ; v a r m = r l i s t . l e n g t h ; i f ( m > 1 5 ) m = 1 5 ; f o r ( v a r i = 0 ; i < m ; i + + ) { v a r r d = r l i s t [ i ]
2012-02-14 06:14:13 +00:00
if ( rd [ 1 ] ) { var dt = rd [ 0 ] ; var dn = rd [ 1 ] ; this . add ( dt , dn , 0 ) ; } } } } ) ;
/ *
* lib / js / wn / ui / toolbar / toolbar . js
* /
2012-02-27 11:47:48 +00:00
wn . ui . toolbar . Toolbar = Class . extend ( { init : function ( ) { this . make ( ) ; this . make _home ( ) ; this . make _document ( ) ; wn . ui . toolbar . recent = new wn . ui . toolbar . RecentDocs ( ) ; this . make _tools ( ) ; this . set _user _name ( ) ; this . make _logout ( ) ; $ ( '.dropdown-toggle' ) . dropdown ( ) ; $ ( document ) . trigger ( 'toolbar_setup' ) ; } , make : function ( ) { $ ( 'header' ) . append ( ' < div class = "navbar navbar-fixed-top" > \
2012-02-21 05:00:43 +00:00
< div class = "navbar-inner" > \
2012-02-14 06:14:13 +00:00
< div class = "container" > \
< a class = "brand" > < / a > \
< ul class = "nav" > \
< / u l > \
2012-05-07 12:30:57 +00:00
< img src = "images/lib/ui/spinner.gif" id = "spinner" / > \
2012-02-21 05:49:24 +00:00
< ul class = "nav pull-right" > \
2012-02-14 06:14:13 +00:00
< li class = "dropdown" > \
2012-02-21 05:49:24 +00:00
< a class = "dropdown-toggle" data - toggle = "dropdown" href = "#" \
2012-02-21 05:00:43 +00:00
onclick = "return false;" id = "toolbar-user-link" > < / a > \
2012-02-14 06:14:13 +00:00
< ul class = "dropdown-menu" id = "toolbar-user" > \
< / u l > \
< / l i > \
< / u l > \
< / d i v > \
< / d i v > \
2012-04-16 05:48:45 +00:00
< / d i v > ' ) ; } , m a k e _ h o m e : f u n c t i o n ( ) { $ ( ' . n a v b a r . b r a n d ' ) . a t t r ( ' h r e f ' , " # " ) ; } , m a k e _ d o c u m e n t : f u n c t i o n ( ) { w n . u i . t o o l b a r . n e w _ d i a l o g = n e w w n . u i . t o o l b a r . N e w D i a l o g ( ) ; w n . u i . t o o l b a r . s e a r c h = n e w w n . u i . t o o l b a r . S e a r c h ( ) ; w n . u i . t o o l b a r . r e p o r t = n e w w n . u i . t o o l b a r . R e p o r t ( ) ; $ ( ' . n a v b a r . n a v : f i r s t ' ) . a p p e n d ( ' < l i c l a s s = " d r o p d o w n " > \
2012-02-21 05:49:24 +00:00
< a class = "dropdown-toggle" href = "#" data - toggle = "dropdown" \
onclick = "return false;" > Document < b class = "caret" > < / b > < / a > \
2012-02-20 11:01:55 +00:00
< ul class = "dropdown-menu" id = "toolbar-document" > \
2012-02-24 05:56:31 +00:00
< li > < a href = "#" onclick = "return wn.ui.toolbar.new_dialog.show();" > \
< i class = "icon-plus" > < / i > N e w < / a > < / l i > \
< li > < a href = "#" onclick = "return wn.ui.toolbar.search.show();" > \
< i class = "icon-search" > < / i > S e a r c h < / a > < / l i > \
< li > < a href = "#" onclick = "return wn.ui.toolbar.report.show();" > \
< i class = "icon-list" > < / i > R e p o r t < / a > < / l i > \
2012-02-20 11:01:55 +00:00
< / u l > \
2012-02-21 05:49:24 +00:00
< / l i > ' ) ; } , m a k e _ t o o l s : f u n c t i o n ( ) { $ ( ' . n a v b a r . n a v : f i r s t ' ) . a p p e n d ( ' < l i c l a s s = " d r o p d o w n " > \
2012-02-21 05:00:43 +00:00
< a class = "dropdown-toggle" data - toggle = "dropdown" href = "#" \
onclick = "return false;" > Tools < b class = "caret" > < / b > < / a > \
2012-02-14 06:14:13 +00:00
< ul class = "dropdown-menu" id = "toolbar-tools" > \
2012-04-17 07:49:45 +00:00
< li > < a href = "#" onclick = "return wn.ui.toolbar.clear_cache();" > Clear Cache & Refresh < / a > < / l i > \
2012-02-14 06:14:13 +00:00
< li > < a href = "#" onclick = "return wn.ui.toolbar.show_about();" > About < / a > < / l i > \
< / u l > \
< / l i > ' ) ; i f ( h a s _ c o m m o n ( u s e r _ r o l e s , [ ' A d m i n i s t r a t o r ' , ' S y s t e m M a n a g e r ' ] ) ) { $ ( ' # t o o l b a r - t o o l s ' ) . a p p e n d ( ' < l i > < a h r e f = " # " \
onclick = "return wn.ui.toolbar.download_backup();" > \
2012-04-17 07:49:45 +00:00
Download Backup < / a > < / l i > ' ) ; } } , s e t _ u s e r _ n a m e : f u n c t i o n ( ) { v a r f n = u s e r _ f u l l n a m e ; i f ( f n . l e n g t h > 1 5 ) f n = f n . s u b s t r ( 0 , 1 2 ) + ' . . . ' ; $ ( ' # t o o l b a r - u s e r - l i n k ' ) . h t m l ( f n + ' < b c l a s s = " c a r e t " > < / b > ' ) ; } , m a k e _ l o g o u t : f u n c t i o n ( ) { $ ( ' # t o o l b a r - u s e r ' ) . a p p e n d ( ' < l i > < a h r e f = " # " o n c l i c k = " r e t u r n w n . a p p . l o g o u t ( ) ; " > L o g o u t < / a > < / l i > ' ) ; } } ) ; w n . u i . t o o l b a r . c l e a r _ c a c h e = f u n c t i o n ( ) { l o c a l S t o r a g e & & l o c a l S t o r a g e . c l e a r ( ) ; $ c ( ' w e b n o t e s . s e s s i o n _ c a c h e . c l e a r ' , { } , f u n c t i o n ( r , r t ) { i f ( ! r . e x c ) { s h o w _ a l e r t ( r . m e s s a g e ) ; l o c a t i o n . r e l o a d ( ) ; } } ) ; r e t u r n f a l s e ; }
2012-02-14 06:14:13 +00:00
wn . ui . toolbar . download _backup = function ( ) { $c ( 'webnotes.utils.backups.get_backup' , { } , function ( r , rt ) { } ) ; return false ; }
2012-05-07 12:30:57 +00:00
wn . ui . toolbar . show _about = function ( ) { try { wn . ui . misc . about ( ) ; } catch ( e ) { console . log ( e ) ; }
2012-02-14 06:14:13 +00:00
return false ; }
2012-03-09 11:14:21 +00:00
2012-03-23 08:49:49 +00:00
/ *
* lib / js / wn / views / breadcrumbs . js
* /
2012-06-14 05:35:09 +00:00
wn . provide ( 'wn.views' ) ; wn . views . breadcrumbs = function ( parent , module , doctype , name ) { $ ( parent ) . empty ( ) ; var $bspan = $ ( parent ) ; if ( name ) { $bspan . append ( '<span class="appframe-title">' + name + '</span>' ) ; } else if ( doctype ) { $bspan . append ( '<span class="appframe-title">' + doctype + ' List </span>' ) ; } else if ( module ) { $bspan . append ( '<span class="appframe-title">' + module + '</span>' ) ; }
if ( name && doctype && ( ! locals [ 'DocType' ] [ doctype ] . issingle ) ) { $bspan . append ( repl ( '<span> in <a href="#!List/%(doctype)s">%(doctype)s List</a></span>' , { doctype : doctype } ) ) } ; if ( doctype && module && wn . modules && wn . modules [ module ] ) { $bspan . append ( repl ( '<span> in <a href="#!%(module_page)s">%(module)s</a></span>' , { module : module , module _page : wn . modules [ module ] } ) ) } }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / widgets / form / fields . js
* /
var no _value _fields = [ 'Section Break' , 'Column Break' , 'HTML' , 'Table' , 'FlexTable' , 'Button' , 'Image' ] ; var codeid = 0 ; var code _editors = { } ; function Field ( ) { this . with _label = 1 ; }
Field . prototype . make _body = function ( ) { var ischk = ( this . df . fieldtype == 'Check' ? 1 : 0 ) ; if ( this . parent )
2012-03-05 12:58:33 +00:00
this . wrapper = $a ( this . parent , ( this . with _label ? 'div' : 'span' ) ) ; else
2012-03-12 10:42:09 +00:00
this . wrapper = document . createElement ( ( this . with _label ? 'div' : 'span' ) ) ; this . label _area = $a ( this . wrapper , 'div' , '' , { margin : '0px 0px 2px 0px' } ) ; if ( ischk && ! this . in _grid ) { this . input _area = $a ( this . label _area , 'span' , '' , { marginRight : '4px' } ) ; this . disp _area = $a ( this . label _area , 'span' , '' , { marginRight : '4px' } ) ; }
2012-03-21 06:17:58 +00:00
if ( this . with _label ) { this . label _span = $a ( this . label _area , 'span' , 'small' )
2012-05-07 12:30:57 +00:00
this . label _icon = $a ( this . label _area , 'img' , '' , { margin : '-3px 4px -3px 4px' } ) ; $dh ( this . label _icon ) ; this . label _icon . src = 'images/lib/icons/error.gif' ; this . label _icon . title = 'Mandatory value needs to be entered' ; this . suggest _icon = $a ( this . label _area , 'img' , '' , { margin : '-3px 4px -3px 0px' } ) ; $dh ( this . suggest _icon ) ; this . suggest _icon . src = 'images/lib/icons/bullet_arrow_down.png' ; this . suggest _icon . title = 'With suggestions' ; } else { this . label _span = $a ( this . label _area , 'span' , '' , { marginRight : '4px' } )
2012-02-14 06:14:13 +00:00
$dh ( this . label _area ) ; }
2012-03-05 12:58:33 +00:00
if ( ! this . input _area ) { this . input _area = $a ( this . wrapper , ( this . with _label ? 'div' : 'span' ) ) ; this . disp _area = $a ( this . wrapper , ( this . with _label ? 'div' : 'span' ) ) ; }
2012-03-12 10:42:09 +00:00
if ( this . in _grid ) { if ( this . label _area ) $dh ( this . label _area ) ; } else { this . input _area . className = 'input_area' ; $y ( this . wrapper , { marginBottom : '9px' } ) ; this . set _description ( ) ; }
2012-02-14 06:14:13 +00:00
if ( this . onmake ) this . onmake ( ) ; }
Field . prototype . set _max _width = function ( ) { var no _max = [ 'Code' , 'Text Editor' , 'Text' , 'Table' , 'HTML' ]
if ( this . wrapper && this . layout _cell && this . layout _cell . parentNode . cells && this . layout _cell . parentNode . cells . length == 1 && ! in _list ( no _max , this . df . fieldtype ) ) { $y ( this . wrapper , { paddingRight : '50%' } ) ; } }
Field . prototype . set _label = function ( ) { if ( this . with _label && this . label _area && this . label != this . df . label ) { this . label _span . innerHTML = this . df . label ; this . label = this . df . label ; } }
2012-03-21 06:17:58 +00:00
Field . prototype . set _description = function ( ) { if ( this . df . description ) { var p = in _list ( [ 'Text Editor' , 'Code' , 'Check' ] , this . df . fieldtype ) ? this . label _area : this . wrapper ; this . desc _area = $a ( p , 'div' , 'help small' , '' , this . df . description )
2012-02-14 06:14:13 +00:00
if ( in _list ( [ 'Text Editor' , 'Code' ] , this . df . fieldtype ) )
2012-03-21 06:17:58 +00:00
$ ( this . desc _area ) . addClass ( 'help small' ) ; } }
2012-02-14 06:14:13 +00:00
Field . prototype . get _status = function ( ) { if ( this . in _filter ) this . not _in _form = this . in _filter ; if ( this . not _in _form ) { return 'Write' ; }
2012-03-13 09:49:06 +00:00
if ( ! this . df . permlevel ) this . df . permlevel = 0 ; var p = this . perm [ this . df . permlevel ] ; var ret ; if ( cur _frm . editable && p && p [ WRITE ] ) ret = 'Write' ; else if ( p && p [ READ ] ) ret = 'Read' ; else ret = 'None' ; if ( this . df . fieldtype == 'Binary' )
2012-02-14 06:14:13 +00:00
ret = 'None' ; if ( cint ( this . df . hidden ) )
ret = 'None' ; if ( ret == 'Write' && cint ( cur _frm . doc . docstatus ) > 0 ) ret = 'Read' ; var a _o _s = cint ( this . df . allow _on _submit ) ; if ( a _o _s && ( this . in _grid || ( this . frm && this . frm . not _in _container ) ) ) { a _o _s = null ; if ( this . in _grid ) a _o _s = this . grid . field . df . allow _on _submit ; if ( this . frm && this . frm . not _in _container ) { a _o _s = cur _grid . field . df . allow _on _submit ; } }
if ( cur _frm . editable && a _o _s && cint ( cur _frm . doc . docstatus ) > 0 && ! this . df . hidden ) { tmp _perm = get _perm ( cur _frm . doctype , cur _frm . docname , 1 ) ; if ( tmp _perm [ this . df . permlevel ] && tmp _perm [ this . df . permlevel ] [ WRITE ] ) ret = 'Write' ; }
return ret ; }
Field . prototype . set _style _mandatory = function ( add ) { if ( add ) { $ ( this . txt ? this . txt : this . input ) . addClass ( 'input-mandatory' ) ; if ( this . disp _area ) $ ( this . disp _area ) . addClass ( 'input-mandatory' ) ; } else { $ ( this . txt ? this . txt : this . input ) . removeClass ( 'input-mandatory' ) ; if ( this . disp _area ) $ ( this . disp _area ) . removeClass ( 'input-mandatory' ) ; } }
Field . prototype . refresh _mandatory = function ( ) { if ( this . in _filter ) return ; if ( this . df . reqd ) { if ( this . label _area ) this . label _area . style . color = "#d22" ; this . set _style _mandatory ( 1 ) ; } else { if ( this . label _area ) this . label _area . style . color = "#222" ; this . set _style _mandatory ( 0 ) ; }
this . refresh _label _icon ( )
this . set _reqd = this . df . reqd ; }
2012-02-27 12:33:54 +00:00
Field . prototype . refresh _display = function ( ) { if ( ! this . current _status || this . current _status != this . disp _status ) { if ( this . disp _status == 'Write' ) { if ( this . make _input && ( ! this . input ) ) { this . make _input ( ) ; if ( this . onmake _input ) this . onmake _input ( ) ; }
2012-02-14 06:14:13 +00:00
if ( this . show ) this . show ( )
else { $ds ( this . wrapper ) ; }
if ( this . input ) { $ds ( this . input _area ) ; $dh ( this . disp _area ) ; if ( this . input . refresh ) this . input . refresh ( ) ; } else { $dh ( this . input _area ) ; $ds ( this . disp _area ) ; } } else if ( this . disp _status == 'Read' ) { if ( this . show ) this . show ( )
else { $ds ( this . wrapper ) ; }
$dh ( this . input _area ) ; $ds ( this . disp _area ) ; } else { if ( this . hide ) this . hide ( ) ; else $dh ( this . wrapper ) ; }
2012-02-27 12:33:54 +00:00
this . current _status = this . disp _status ; } }
2012-02-14 06:14:13 +00:00
Field . prototype . refresh = function ( ) { this . disp _status = this . get _status ( ) ; if ( this . in _grid && this . table _refresh && this . disp _status == 'Write' )
{ this . table _refresh ( ) ; return ; }
2012-02-17 06:36:33 +00:00
this . set _label ( ) ; this . refresh _display ( ) ; if ( this . onrefresh )
this . onrefresh ( ) ; if ( this . input ) { if ( this . input . refresh ) this . input . refresh ( this . df ) ; }
if ( this . wrapper ) { this . wrapper . fieldobj = this ; $ ( this . wrapper ) . trigger ( 'refresh' ) ; }
if ( ! this . not _in _form )
2012-02-14 06:14:13 +00:00
this . set _input ( _f . get _value ( this . doctype , this . docname , this . df . fieldname ) ) ; this . refresh _mandatory ( ) ; this . set _max _width ( ) ; }
Field . prototype . refresh _label _icon = function ( ) { if ( this . df . reqd ) { if ( this . get _value && is _null ( this . get _value ( ) ) ) { if ( this . label _icon ) $ds ( this . label _icon ) ; $ ( this . txt ? this . txt : this . input ) . addClass ( 'field-to-update' ) } else { if ( this . label _icon ) $dh ( this . label _icon ) ; $ ( this . txt ? this . txt : this . input ) . removeClass ( 'field-to-update' ) } } }
Field . prototype . set = function ( val ) { if ( this . not _in _form )
return ; if ( ( ! this . docname ) && this . grid ) { this . docname = this . grid . add _newrow ( ) ; }
2012-03-20 13:15:28 +00:00
var set _val = val ; if ( this . validate ) set _val = this . validate ( val ) ; _f . set _value ( this . doctype , this . docname , this . df . fieldname , set _val ) ; this . value = val ; }
2012-02-14 06:14:13 +00:00
Field . prototype . set _input = function ( val ) { this . value = val ; if ( this . input && this . input . set _input ) { if ( val == null ) this . input . set _input ( '' ) ; else this . input . set _input ( val ) ; }
var disp _val = val ; if ( val == null ) disp _val = '' ; this . set _disp ( disp _val ) ; }
Field . prototype . run _trigger = function ( ) { this . refresh _label _icon ( ) ; if ( this . df . reqd && this . get _value && ! is _null ( this . get _value ( ) ) && this . set _as _error )
this . set _as _error ( 0 ) ; if ( this . not _in _form ) { return ; }
if ( cur _frm . cscript [ this . df . fieldname ] )
cur _frm . runclientscript ( this . df . fieldname , this . doctype , this . docname ) ; cur _frm . refresh _dependency ( ) ; }
Field . prototype . set _disp _html = function ( t ) { if ( this . disp _area ) { $ ( this . disp _area ) . addClass ( 'disp_area' ) ; this . disp _area . innerHTML = ( t == null ? '' : t ) ; if ( ! t ) $ ( this . disp _area ) . addClass ( 'disp_area_no_val' ) ; } }
Field . prototype . set _disp = function ( val ) { this . set _disp _html ( val ) ; }
Field . prototype . set _as _error = function ( set ) { if ( this . in _grid || this . in _filter ) return ; var w = this . txt ? this . txt : this . input ; if ( set ) { $y ( w , { border : '2px solid RED' } ) ; } else { $y ( w , { border : '1px solid #888' } ) ; } }
2012-02-17 08:34:55 +00:00
Field . prototype . activate = function ( docname ) { this . docname = docname ; this . refresh ( ) ; if ( this . input ) { var v = _f . get _value ( this . doctype , this . docname , this . df . fieldname ) ; this . last _value = v ; if ( this . input . onchange && this . input . get _value && this . input . get _value ( ) != v ) { if ( this . validate )
2012-02-14 06:14:13 +00:00
this . input . set _value ( this . validate ( v ) ) ; else
this . input . set _value ( ( v == null ) ? '' : v ) ; if ( this . format _input )
this . format _input ( ) ; }
if ( this . input . focus ) { try { this . input . focus ( ) ; } catch ( e ) { } } }
if ( this . txt ) { try { this . txt . focus ( ) ; } catch ( e ) { }
2012-02-17 08:34:55 +00:00
this . txt . field _object = this ; } }
2012-03-13 10:41:52 +00:00
function DataField ( ) { } DataField . prototype = new Field ( ) ; DataField . prototype . make _input = function ( ) { var me = this ; this . input = $a _input ( this . input _area , this . df . fieldtype == 'Password' ? 'password' : 'text' ) ; this . get _value = function ( ) { var v = this . input . value ; if ( this . validate )
v = this . validate ( v ) ; return v ; }
2012-06-07 09:09:42 +00:00
this . input . name = this . df . fieldname ; $ ( this . input ) . change ( function ( ) { me . set _value ( me . get _value ? me . get _value ( ) : $ ( this . input ) . val ( ) ) ; } ) ; this . set _value = function ( val ) { if ( ! me . last _value ) me . last _value = '' ; if ( me . validate ) { val = me . validate ( val ) ; me . input . value = val == undefined ? '' : val ; }
2012-03-09 11:14:21 +00:00
me . set ( val ) ; if ( me . format _input )
me . format _input ( ) ; if ( in _list ( [ 'Currency' , 'Float' , 'Int' ] , me . df . fieldtype ) ) { if ( flt ( me . last _value ) == flt ( val ) ) { me . last _value = val ; return ; } }
me . last _value = val ; me . run _trigger ( ) ; }
2012-02-14 06:14:13 +00:00
this . input . set _input = function ( val ) { if ( val == null ) val = '' ; me . input . value = val ; if ( me . format _input ) me . format _input ( ) ; }
2012-03-09 11:14:21 +00:00
if ( this . df . options == 'Suggest' ) { if ( this . suggest _icon ) $di ( this . suggest _icon ) ; $ ( me . input ) . autocomplete ( { source : function ( request , response ) { wn . call ( { method : 'webnotes.widgets.search.search_link' , args : { 'txt' : request . term , 'dt' : me . df . options , 'query' : repl ( ' SELECT DISTINCT ` %(fieldname)s ` FROM \
2012-05-15 06:05:21 +00:00
` tab%(dt)s ` WHERE ` %(fieldname)s ` LIKE "%s" LIMIT 50 ' , { fieldname : me . df . fieldname , dt : me . df . parent } ) } , callback : function ( r ) { response ( r . results ) ; } } ) ; } , select : function ( event , ui ) { me . set ( ui . item . value ) ; } } ) ; } }
2012-02-14 06:14:13 +00:00
DataField . prototype . validate = function ( v ) { if ( this . df . options == 'Phone' ) { if ( v + '' == '' ) return '' ; v1 = ''
v = v . replace ( / /g , '' ) . replace ( /-/g , '' ) . replace ( /\(/g , '' ) . replace ( /\)/g , '' ) ; if ( v && v . substr ( 0 , 1 ) == '+' ) { v1 = '+' ; v = v . substr ( 1 ) ; }
if ( v && v . substr ( 0 , 2 ) == '00' ) { v1 += '00' ; v = v . substr ( 2 ) ; }
if ( v && v . substr ( 0 , 1 ) == '0' ) { v1 += '0' ; v = v . substr ( 1 ) ; }
v1 += cint ( v ) + '' ; return v1 ; } else if ( this . df . options == 'Email' ) { if ( v + '' == '' ) return '' ; if ( ! validate _email ( v ) ) { msgprint ( this . df . label + ': ' + v + ' is not a valid email id' ) ; return '' ; } else
return v ; } else { return v ; } }
DataField . prototype . onrefresh = function ( ) { if ( this . input && this . df . colour ) { var col = '#' + this . df . colour . split ( ':' ) [ 1 ] ; $bg ( this . input , col ) ; } }
function ReadOnlyField ( ) { }
ReadOnlyField . prototype = new Field ( ) ; function HTMLField ( ) { }
HTMLField . prototype = new Field ( ) ; HTMLField . prototype . with _label = 0 ; HTMLField . prototype . set _disp = function ( val ) { this . disp _area . innerHTML = val ; }
HTMLField . prototype . set _input = function ( val ) { if ( val ) this . set _disp ( val ) ; }
HTMLField . prototype . onrefresh = function ( ) { this . set _disp ( this . df . options ? this . df . options : '' ) ; }
2012-03-09 11:14:21 +00:00
var datepicker _active = 0 ; function DateField ( ) { } DateField . prototype = new Field ( ) ; DateField . prototype . make _input = function ( ) { var me = this ; this . user _fmt = wn . control _panel . date _format ; if ( ! this . user _fmt ) this . user _fmt = 'dd-mm-yy' ; this . input = $a ( this . input _area , 'input' ) ; $ ( this . input ) . datepicker ( { dateFormat : me . user _fmt . replace ( 'yyyy' , 'yy' ) , altFormat : 'yy-mm-dd' , changeYear : true , beforeShow : function ( input , inst ) { datepicker _active = 1 } , onClose : function ( dateText , inst ) { datepicker _active = 0 ; if ( _f . cur _grid _cell )
2012-02-14 06:14:13 +00:00
_f . cur _grid _cell . grid . cell _deselect ( ) ; } } ) ; var me = this ; me . input . onchange = function ( ) { if ( this . value == null ) this . value = '' ; if ( ! this . not _in _form )
me . set ( dateutil . user _to _str ( me . input . value ) ) ; me . run _trigger ( ) ; }
me . input . set _input = function ( val ) { if ( val == null ) val = '' ; else val = dateutil . str _to _user ( val ) ; me . input . value = val ; }
me . get _value = function ( ) { if ( me . input . value )
return dateutil . user _to _str ( me . input . value ) ; } }
DateField . prototype . set _disp = function ( val ) { var v = dateutil . str _to _user ( val ) ; if ( v == null ) v = '' ; this . set _disp _html ( v ) ; }
DateField . prototype . validate = function ( v ) { if ( ! v ) return ; var me = this ; this . clear = function ( ) { msgprint ( "Date must be in format " + this . user _fmt ) ; me . input . set _input ( '' ) ; return '' ; }
var t = v . split ( '-' ) ; if ( t . length != 3 ) { return this . clear ( ) ; }
else if ( cint ( t [ 1 ] ) > 12 || cint ( t [ 1 ] ) < 1 ) { return this . clear ( ) ; }
else if ( cint ( t [ 2 ] ) > 31 || cint ( t [ 2 ] ) < 1 ) { return this . clear ( ) ; }
2012-03-09 11:14:21 +00:00
return v ; } ; function LinkField ( ) { } LinkField . prototype = new Field ( ) ; LinkField . prototype . make _input = function ( ) { var me = this ; if ( me . df . no _buttons ) { this . txt = $a ( this . input _area , 'input' ) ; this . input = this . txt ; } else { makeinput _popup ( this , 'icon-search' , 'icon-play' , 'icon-plus' ) ; me . setup _buttons ( ) ; me . onrefresh = function ( ) { if ( me . can _create && cur _frm . doc . docstatus == 0 )
2012-02-24 11:06:58 +00:00
$ ( me . btn2 ) . css ( 'display' , 'inline-block' ) ; else $dh ( me . btn2 ) ; } }
2012-03-09 11:14:21 +00:00
me . txt . field _object = this ; me . input . set _input = function ( val ) { if ( val == undefined ) val = '' ; me . txt . value = val ; }
2012-02-14 06:14:13 +00:00
me . get _value = function ( ) { return me . txt . value ; }
2012-05-02 10:50:38 +00:00
$ ( me . txt ) . autocomplete ( { source : function ( request , response ) { wn . call ( { method : 'webnotes.widgets.search.search_link' , args : { 'txt' : request . term , 'dt' : me . df . options , 'query' : me . get _custom _query ( ) } , callback : function ( r ) { response ( r . results ) ; } , } ) ; } , select : function ( event , ui ) { me . set _input _value ( ui . item . value ) ; } } ) . data ( 'autocomplete' ) . _renderItem = function ( ul , item ) { return $ ( '<li></li>' ) . data ( 'item.autocomplete' , item ) . append ( repl ( '<a>%(label)s<br><span style="font-size:10px">%(info)s</span></a>' , item ) ) . appendTo ( ul ) ; } ; $ ( this . txt ) . change ( function ( ) { if ( ! $ ( this ) . val ( ) ) { if ( selector && selector . display )
return ; me . set _input _value ( '' ) ; } } ) }
2012-03-09 11:14:21 +00:00
LinkField . prototype . get _custom _query = function ( ) { this . set _get _query ( ) ; if ( this . get _query ) { if ( cur _frm )
var doc = locals [ cur _frm . doctype ] [ cur _frm . docname ] ; return this . get _query ( doc , this . doctype , this . docname ) ; } }
2012-02-14 06:14:13 +00:00
LinkField . prototype . setup _buttons = function ( ) { var me = this ; me . btn . onclick = function ( ) { selector . set ( me , me . df . options , me . df . label ) ; selector . show ( me . txt ) ; }
if ( me . btn1 ) me . btn1 . onclick = function ( ) { if ( me . txt . value && me . df . options ) { loaddoc ( me . df . options , me . txt . value ) ; } }
me . can _create = 0 ; if ( ( ! me . not _in _form ) && in _list ( profile . can _create , me . df . options ) ) { me . can _create = 1 ; me . btn2 . onclick = function ( ) { var on _save _callback = function ( new _rec ) { if ( new _rec ) { var d = _f . calling _doc _stack . pop ( ) ; locals [ d [ 0 ] ] [ d [ 1 ] ] [ me . df . fieldname ] = new _rec ; me . refresh ( ) ; if ( me . grid ) me . grid . refresh ( ) ; me . run _trigger ( ) ; } }
_f . calling _doc _stack . push ( [ me . doctype , me . docname ] ) ; new _doc ( me . df . options , me . on _new , 1 , on _save _callback , me . doctype , me . docname , me . frm . not _in _container ) ; } } else { $dh ( me . btn2 ) ; $y ( $td ( me . tab , 0 , 2 ) , { width : '0px' } ) ; } }
2012-05-02 05:53:08 +00:00
LinkField . prototype . set _input _value = function ( val ) { var me = this ; var from _selector = false ; if ( selector && selector . display ) from _selector = true ; me . refresh _label _icon ( ) ; if ( me . not _in _form ) { $ ( this . txt ) . val ( val ) ; return ; }
2012-05-02 10:50:38 +00:00
if ( cur _frm ) { if ( val == locals [ me . doctype ] [ me . docname ] [ me . df . fieldname ] ) { me . run _trigger ( ) ; return ; } }
2012-03-09 11:14:21 +00:00
me . set ( val ) ; if ( _f . cur _grid _cell )
2012-05-03 06:18:43 +00:00
_f . cur _grid _cell . grid . cell _deselect ( ) ; if ( locals [ me . doctype ] [ me . docname ] [ me . df . fieldname ] && ! val ) { me . run _trigger ( ) ; return ; }
2012-02-14 06:14:13 +00:00
var fetch = '' ; if ( cur _frm . fetch _dict [ me . df . fieldname ] )
2012-05-02 10:50:38 +00:00
fetch = cur _frm . fetch _dict [ me . df . fieldname ] . columns . join ( ', ' ) ; $c ( 'webnotes.widgets.form.utils.validate_link' , { 'value' : val , 'options' : me . df . options , 'fetch' : fetch } , function ( r , rt ) { if ( r . message == 'Ok' ) { if ( $ ( me . txt ) . val ( ) != val ) { if ( ( me . grid && ! from _selector ) || ( ! me . grid ) ) { $ ( me . txt ) . val ( val ) ; } }
2012-03-20 13:15:28 +00:00
if ( r . fetch _values )
2012-03-09 11:14:21 +00:00
me . set _fetch _values ( r . fetch _values ) ; me . run _trigger ( ) ; } else { var astr = '' ; if ( in _list ( profile . can _create , me . df . options ) ) astr = repl ( '<br><br><span class="link_type" onclick="newdoc(\'%(dt)s\')">Click here</span> to create a new %(dtl)s' , { dt : me . df . options , dtl : get _doctype _label ( me . df . options ) } )
msgprint ( repl ( 'error:<b>%(val)s</b> is not a valid %(dt)s.<br><br>You must first create a new %(dt)s <b>%(val)s</b> and then select its value. To find an existing %(dt)s, click on the magnifying glass next to the field.%(add)s' , { val : me . txt . value , dt : get _doctype _label ( me . df . options ) , add : astr } ) ) ; me . txt . value = '' ; me . set ( '' ) ; } } ) ; }
2012-02-14 06:14:13 +00:00
LinkField . prototype . set _fetch _values = function ( fetch _values ) { var fl = cur _frm . fetch _dict [ this . df . fieldname ] . fields ; var changed _fields = [ ] ; for ( var i = 0 ; i < fl . length ; i ++ ) { if ( locals [ this . doctype ] [ this . docname ] [ fl [ i ] ] != fetch _values [ i ] ) { locals [ this . doctype ] [ this . docname ] [ fl [ i ] ] = fetch _values [ i ] ; if ( ! this . grid ) { refresh _field ( fl [ i ] ) ; changed _fields . push ( fl [ i ] ) ; } } }
for ( i = 0 ; i < changed _fields . length ; i ++ ) { if ( cur _frm . fields _dict [ changed _fields [ i ] ] )
cur _frm . fields _dict [ changed _fields [ i ] ] . run _trigger ( ) ; }
if ( this . grid ) this . grid . refresh ( ) ; }
LinkField . prototype . set _get _query = function ( ) { if ( this . get _query ) return ; if ( this . grid ) { var f = this . grid . get _field ( this . df . fieldname ) ; if ( f . get _query ) this . get _query = f . get _query ; } }
LinkField . prototype . set _disp = function ( val ) { var t = null ; if ( val ) t = "<a href=\'javascript:loaddoc(\"" + this . df . options + "\", \"" + val + "\")\'>" + val + "</a>" ; this . set _disp _html ( t ) ; }
function IntField ( ) { } IntField . prototype = new DataField ( ) ; IntField . prototype . validate = function ( v ) { if ( isNaN ( parseInt ( v ) ) ) return null ; return cint ( v ) ; } ; IntField . prototype . format _input = function ( ) { if ( this . input . value == null ) this . input . value = '' ; }
2012-03-13 10:41:52 +00:00
function FloatField ( ) { } FloatField . prototype = new DataField ( ) ; FloatField . prototype . validate = function ( v ) { var v = parseFloat ( v ) ; if ( isNaN ( v ) )
return null ; return v ; } ; FloatField . prototype . format _input = function ( ) { if ( this . input . value == null ) this . input . value = '' ; }
2012-02-14 06:14:13 +00:00
function CurrencyField ( ) { } CurrencyField . prototype = new DataField ( ) ; CurrencyField . prototype . format _input = function ( ) { var v = fmt _money ( this . input . value ) ; if ( this . not _in _form ) { if ( ! flt ( this . input . value ) ) v = '' ; }
this . input . value = v ; }
CurrencyField . prototype . validate = function ( v ) { if ( v == null || v == '' )
return 0 ; return flt ( v , 2 ) ; }
CurrencyField . prototype . set _disp = function ( val ) { var v = fmt _money ( val ) ; this . set _disp _html ( v ) ; }
CurrencyField . prototype . onmake _input = function ( ) { if ( ! this . input ) return ; this . input . onfocus = function ( ) { if ( flt ( this . value ) == 0 ) this . select ( ) ; } }
2012-05-07 12:30:57 +00:00
function CheckField ( ) { } CheckField . prototype = new Field ( ) ; CheckField . prototype . validate = function ( v ) { var v = parseInt ( v ) ; if ( isNaN ( v ) ) return 0 ; return v ; } ; CheckField . prototype . onmake = function ( ) { this . checkimg = $a ( this . disp _area , 'div' ) ; var img = $a ( this . checkimg , 'img' ) ; img . src = 'images/lib/ui/tick.gif' ; $dh ( this . checkimg ) ; }
2012-02-17 08:34:55 +00:00
CheckField . prototype . make _input = function ( ) { var me = this ; this . input = $a _input ( this . input _area , 'checkbox' ) ; $y ( this . input , { width : "16px" , border : '0px' , margin : '2px' } ) ; $ ( this . input ) . click ( function ( ) { me . set ( this . checked ? 1 : 0 ) ; me . run _trigger ( ) ; } )
2012-02-14 06:14:13 +00:00
this . input . set _input = function ( v ) { v = parseInt ( v ) ; if ( isNaN ( v ) ) v = 0 ; if ( v ) me . input . checked = true ; else me . input . checked = false ; }
this . get _value = function ( ) { return this . input . checked ? 1 : 0 ; } }
CheckField . prototype . set _disp = function ( val ) { if ( val ) { $ds ( this . checkimg ) ; }
else { $dh ( this . checkimg ) ; } }
function TextField ( ) { } TextField . prototype = new Field ( ) ; TextField . prototype . set _disp = function ( val ) { this . disp _area . innerHTML = replace _newlines ( val ) ; }
TextField . prototype . make _input = function ( ) { var me = this ; if ( this . in _grid )
return ; this . input = $a ( this . input _area , 'textarea' ) ; if ( this . df . fieldtype == 'Small Text' )
this . input . style . height = "80px" ; this . input . set _input = function ( v ) { me . input . value = v ; }
this . input . onchange = function ( ) { me . set ( me . input . value ) ; me . run _trigger ( ) ; }
this . get _value = function ( ) { return this . input . value ; } }
var text _dialog ; function make _text _dialog ( ) { var d = new Dialog ( 520 , 410 , 'Edit Text' ) ; d . make _body ( [ [ 'Text' , 'Enter Text' ] , [ 'HTML' , 'Description' ] , [ 'Button' , 'Update' ] ] ) ; d . widgets [ 'Update' ] . onclick = function ( ) { var t = this . dialog ; t . field . set ( t . widgets [ 'Enter Text' ] . value ) ; t . hide ( ) ; }
d . onshow = function ( ) { this . widgets [ 'Enter Text' ] . style . height = '300px' ; var v = _f . get _value ( this . field . doctype , this . field . docname , this . field . df . fieldname ) ; this . widgets [ 'Enter Text' ] . value = v == null ? '' : v ; this . widgets [ 'Enter Text' ] . focus ( ) ; this . widgets [ 'Description' ] . innerHTML = ''
if ( this . field . df . description )
2012-03-21 06:17:58 +00:00
$a ( this . widgets [ 'Description' ] , 'div' , 'help small' , '' , this . field . df . description ) ; }
2012-02-14 06:14:13 +00:00
d . onhide = function ( ) { if ( _f . cur _grid _cell )
_f . cur _grid _cell . grid . cell _deselect ( ) ; }
text _dialog = d ; }
TextField . prototype . table _refresh = function ( ) { if ( ! this . text _dialog )
make _text _dialog ( ) ; text _dialog . set _title ( 'Enter text for "' + this . df . label + '"' ) ; text _dialog . field = this ; text _dialog . show ( ) ; }
function SelectField ( ) { } SelectField . prototype = new Field ( ) ; SelectField . prototype . make _input = function ( ) { var me = this ; var opt = [ ] ; if ( this . in _filter && ( ! this . df . single _select ) ) { this . input = $a ( this . input _area , 'select' ) ; this . input . multiple = true ; this . input . style . height = '4em' ; this . input . lab = $a ( this . input _area , 'div' , { fontSize : '9px' , color : '#999' } ) ; this . input . lab . innerHTML = '(Use Ctrl+Click to select multiple or de-select)' } else { this . input = $a ( this . input _area , 'select' ) ; this . input . onchange = function ( ) { if ( me . validate )
2012-02-17 08:34:55 +00:00
me . validate ( ) ; me . set ( sel _val ( this ) ) ; me . run _trigger ( ) ; }
2012-02-14 06:14:13 +00:00
if ( this . df . options == 'attach_files:' ) { this . file _attach = true ; } }
this . set _as _single = function ( ) { var i = this . input ; i . multiple = false ; i . style . height = null ; if ( i . lab ) $dh ( i . lab ) }
this . refresh _options = function ( options ) { if ( options )
me . df . options = options ; if ( this . file _attach )
2012-04-30 10:13:34 +00:00
this . set _attach _options ( ) ; me . options _list = me . df . options ? me . df . options . split ( '\n' ) : [ '' ] ; empty _select ( this . input ) ; if ( me . in _filter && me . options _list [ 0 ] != '' ) { me . options _list = add _lists ( [ '' ] , me . options _list ) ; }
2012-02-14 06:14:13 +00:00
add _sel _options ( this . input , me . options _list ) ; }
this . onrefresh = function ( ) { this . refresh _options ( ) ; if ( this . not _in _form ) { this . input . value = '' ; return ; }
if ( _f . get _value )
var v = _f . get _value ( this . doctype , this . docname , this . df . fieldname ) ; else { if ( this . options _list && this . options _list . length )
var v = this . options _list [ 0 ] ; else
var v = null ; }
this . input . set _input ( v ) ; }
2012-03-15 06:20:26 +00:00
this . input . set _input = function ( v ) { if ( ! v ) { if ( ! me . input . multiple ) { if ( me . docname ) { if ( me . options _list && me . options _list . length ) { me . set ( me . options _list [ 0 ] ) ; me . input . value = me . options _list [ 0 ] ; } else { me . input . value = '' ; } } } } else { if ( me . options _list ) { if ( me . input . multiple ) { for ( var i = 0 ; i < me . input . options . length ; i ++ ) { me . input . options [ i ] . selected = 0 ; if ( me . input . options [ i ] . value && inList ( typeof ( v ) == 'string' ? v . split ( "," ) : v , me . input . options [ i ] . value ) )
2012-02-14 06:14:13 +00:00
me . input . options [ i ] . selected = 1 ; } } else if ( in _list ( me . options _list , v ) ) { me . input . value = v ; } } } }
this . get _value = function ( ) { if ( me . input . multiple ) { var l = [ ] ; for ( var i = 0 ; i < me . input . options . length ; i ++ ) { if ( me . input . options [ i ] . selected ) l [ l . length ] = me . input . options [ i ] . value ; }
return l ; } else { if ( me . input . options ) { var val = sel _val ( me . input ) ; if ( ! val && ! me . input . selectedIndex )
val = me . input . options [ 0 ] . value ; return val ; }
return me . input . value ; } }
this . set _attach _options = function ( ) { if ( ! cur _frm ) return ; var fl = cur _frm . doc . file _list ; if ( fl ) { this . df . options = '' ; var fl = fl . split ( '\n' ) ; for ( var i in fl ) { this . df . options += '\n' + fl [ i ] . split ( ',' ) [ 1 ] ; } } else { this . df . options = '' } }
this . refresh ( ) ; }
function TimeField ( ) { } TimeField . prototype = new Field ( ) ; TimeField . prototype . get _time = function ( ) { return time _to _hhmm ( sel _val ( this . input _hr ) , sel _val ( this . input _mn ) , sel _val ( this . input _am ) ) ; }
TimeField . prototype . set _time = function ( v ) { ret = time _to _ampm ( v ) ; this . input _hr . inp . value = ret [ 0 ] ; this . input _mn . inp . value = ret [ 1 ] ; this . input _am . inp . value = ret [ 2 ] ; }
TimeField . prototype . set _style _mandatory = function ( ) { }
TimeField . prototype . set _as _error = function ( ) { }
2012-02-17 08:34:55 +00:00
TimeField . prototype . make _input = function ( ) { var me = this ; this . input = $a ( this . input _area , 'div' , 'time_field' ) ; var t = make _table ( this . input , 1 , 3 , '200px' ) ; var opt _hr = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , '11' , '12' ] ; var opt _mn = [ '00' , '05' , '10' , '15' , '20' , '25' , '30' , '35' , '40' , '45' , '50' , '55' ] ; var opt _am = [ 'AM' , 'PM' ] ; this . input _hr = new SelectWidget ( $td ( t , 0 , 0 ) , opt _hr , '50px' ) ; this . input _mn = new SelectWidget ( $td ( t , 0 , 1 ) , opt _mn , '50px' ) ; this . input _am = new SelectWidget ( $td ( t , 0 , 2 ) , opt _am , '50px' ) ; var onchange _fn = function ( ) { me . set ( me . get _time ( ) ) ; me . run _trigger ( ) ; }
2012-02-14 06:14:13 +00:00
this . input _hr . inp . onchange = onchange _fn ; this . input _mn . inp . onchange = onchange _fn ; this . input _am . inp . onchange = onchange _fn ; this . onrefresh = function ( ) { var v = _f . get _value ? _f . get _value ( me . doctype , me . docname , me . df . fieldname ) : null ; me . set _time ( v ) ; if ( ! v )
me . set ( me . get _time ( ) ) ; }
this . input . set _input = function ( v ) { if ( v == null ) v = '' ; me . set _time ( v ) ; }
this . get _value = function ( ) { return this . get _time ( ) ; }
this . refresh ( ) ; }
TimeField . prototype . set _disp = function ( v ) { var t = time _to _ampm ( v ) ; var t = t [ 0 ] + ':' + t [ 1 ] + ' ' + t [ 2 ] ; this . set _disp _html ( t ) ; }
2012-02-24 11:06:58 +00:00
function makeinput _popup ( me , iconsrc , iconsrc1 , iconsrc2 ) { var icon _style = { cursor : 'pointer' , width : '16px' , verticalAlign : 'middle' , marginBottom : '-3px' } ; me . input = $a ( me . input _area , 'div' ) ; if ( ! me . not _in _form )
2012-02-14 06:14:13 +00:00
$y ( me . input , { width : '80%' } ) ; me . input . set _width = function ( w ) { $y ( me . input , { width : ( w - 2 ) + 'px' } ) ; }
2012-02-24 11:06:58 +00:00
var tab = $a ( me . input , 'table' ) ; me . tab = tab ; $y ( tab , { width : '100%' , borderCollapse : 'collapse' , tableLayout : 'fixed' } ) ; var c0 = tab . insertRow ( 0 ) . insertCell ( 0 ) ; var c1 = tab . rows [ 0 ] . insertCell ( 1 ) ; $y ( c1 , { width : '20px' } ) ; me . txt = $a ( $a ( $a ( c0 , 'div' , '' , { paddingRight : '8px' } ) , 'div' ) , 'input' , '' , { width : '100%' } ) ; me . btn = $a ( c1 , 'i' , iconsrc , icon _style )
if ( iconsrc1 )
2012-02-14 06:14:13 +00:00
me . btn . setAttribute ( 'title' , 'Search' ) ; else
2012-02-24 11:06:58 +00:00
me . btn . setAttribute ( 'title' , 'Select Date' ) ; if ( iconsrc1 ) { var c2 = tab . rows [ 0 ] . insertCell ( 2 ) ; $y ( c2 , { width : '20px' } ) ; me . btn1 = $a ( c2 , 'i' , iconsrc1 , icon _style )
me . btn1 . setAttribute ( 'title' , 'Open Link' ) ; }
if ( iconsrc2 ) { var c3 = tab . rows [ 0 ] . insertCell ( 3 ) ; $y ( c3 , { width : '20px' } ) ; me . btn2 = $a ( c3 , 'i' , iconsrc2 , icon _style )
me . btn2 . setAttribute ( 'title' , 'Create New' ) ; $dh ( me . btn2 ) ; }
2012-02-14 06:14:13 +00:00
if ( me . df . colour )
me . txt . style . background = '#' + me . df . colour . split ( ':' ) [ 1 ] ; me . txt . name = me . df . fieldname ; me . setdisabled = function ( tf ) { me . txt . disabled = tf ; } }
var tmpid = 0 ; _f . ButtonField = function ( ) { } ; _f . ButtonField . prototype = new Field ( ) ; _f . ButtonField . prototype . with _label = 0 ; _f . ButtonField . prototype . init = function ( ) { this . prev _button = null ; if ( ! this . frm ) return ; if ( cur _frm && cur _frm . fields [ cur _frm . fields . length - 1 ] && cur _frm . fields [ cur _frm . fields . length - 1 ] . df . fieldtype == 'Button' ) { this . make _body = function ( ) { this . prev _button = cur _frm . fields [ cur _frm . fields . length - 1 ] ; if ( ! this . prev _button . prev _button ) { this . prev _button . button _area = $a ( this . prev _button . input _area , 'span' ) ; }
this . wrapper = this . prev _button . wrapper ; this . input _area = this . prev _button . input _area ; this . disp _area = this . prev _button . disp _area ; this . button _area = $a ( this . prev _button . input _area , 'span' ) ; } } }
_f . ButtonField . prototype . make _input = function ( ) { var me = this ; if ( ! this . prev _button ) { $y ( this . input _area , { marginTop : '4px' , marginBottom : '4px' } ) ; }
if ( ! this . button _area )
2012-02-27 07:14:28 +00:00
this . button _area = $a ( this . input _area , 'span' , '' , { marginRight : '4px' } ) ; this . input = $btn ( this . button _area , me . df . label , null , { fontWeight : 'bold' } , null , 1 )
2012-05-11 10:53:41 +00:00
$ ( this . input ) . click ( function ( ) { if ( me . not _in _form ) return ; if ( cur _frm . cscript [ me . df . fieldname ] && ( ! me . in _filter ) ) { cur _frm . runclientscript ( me . df . fieldname , me . doctype , me . docname ) ; } else { cur _frm . runscript ( me . df . options , me ) ; } } ) ; }
2012-02-14 06:14:13 +00:00
_f . ButtonField . prototype . hide = function ( ) { $dh ( this . button _area ) ; } ; _f . ButtonField . prototype . show = function ( ) { $ds ( this . button _area ) ; } ; _f . ButtonField . prototype . set = function ( v ) { } ; _f . ButtonField . prototype . set _disp = function ( val ) { }
function make _field ( docfield , doctype , parent , frm , in _grid , hide _label ) { switch ( docfield . fieldtype . toLowerCase ( ) ) { case 'data' : var f = new DataField ( ) ; break ; case 'password' : var f = new DataField ( ) ; break ; case 'int' : var f = new IntField ( ) ; break ; case 'float' : var f = new FloatField ( ) ; break ; case 'currency' : var f = new CurrencyField ( ) ; break ; case 'read only' : var f = new ReadOnlyField ( ) ; break ; case 'link' : var f = new LinkField ( ) ; break ; case 'date' : var f = new DateField ( ) ; break ; case 'time' : var f = new TimeField ( ) ; break ; case 'html' : var f = new HTMLField ( ) ; break ; case 'check' : var f = new CheckField ( ) ; break ; case 'text' : var f = new TextField ( ) ; break ; case 'small text' : var f = new TextField ( ) ; break ; case 'select' : var f = new SelectField ( ) ; break ; case 'button' : var f = new _f . ButtonField ( ) ; break ; case 'code' : var f = new _f . CodeField ( ) ; break ; case 'text editor' : var f = new _f . CodeField ( ) ; break ; case 'table' : var f = new _f . TableField ( ) ; break ; case 'section break' : var f = new _f . SectionBreak ( ) ; break ; case 'column break' : var f = new _f . ColumnBreak ( ) ; break ; case 'image' : var f = new _f . ImageField ( ) ; break ; }
f . parent = parent ; f . doctype = doctype ; f . df = docfield ; f . perm = frm ? frm . perm : [ [ 1 , 1 , 1 ] ] ; if ( _f )
f . col _break _width = _f . cur _col _break _width ; if ( in _grid ) { f . in _grid = true ; f . with _label = 0 ; }
if ( hide _label ) { f . with _label = 0 ; }
if ( frm ) { f . frm = frm ; if ( parent )
f . layout _cell = parent . parentNode ; }
if ( f . init ) f . init ( ) ; f . make _body ( ) ; return f ; }
/ *
2012-03-20 09:07:44 +00:00
* lib / js / legacy / widgets / form / form _dialog . js
2012-02-14 06:14:13 +00:00
* /
2012-04-11 12:32:23 +00:00
_f . frm _dialog = null ; _f . calling _doc _stack = [ ] ; _f . temp _access = { } ; _f . FrmDialog = function ( ) { var me = this ; this . last _displayed = null ; var d = new Dialog ( 640 , null , 'Edit Row' ) ; this . body = $a ( d . body , 'div' , 'dialog_frm' ) ; d . done _btn _area = $a ( d . body , 'div' , '' , { margin : '8px' } ) ; me . on _complete = function ( ) { if ( me . table _form ) { me . dialog . hide ( ) ; } else { var callback = function ( r ) { var dn = cur _frm . docname ; if ( ! r . exc ) { me . dialog . hide ( ) ; }
2012-02-14 06:14:13 +00:00
if ( me . on _save _callback )
me . on _save _callback ( dn ) ; }
cur _frm . save ( 'Save' , callback ) ; } }
d . onshow = function ( ) { d . done _btn _area . innerHTML = '' ; d . done _btn = $btn ( d . done _btn _area , 'Save' , null , null , 'green' ) ; d . done _btn . onclick = function ( ) { me . on _complete ( ) } ; if ( me . table _form ) { d . set _title ( "Editing Row #" + ( _f . cur _grid _ridx + 1 ) ) ; d . done _btn . innerHTML = 'Done Editing' ; } else { d . set _title ( cur _frm . doctype == cur _frm . doctype ? ( cur _frm . doctype ) : ( cur _frm . doctype + ': ' + cur _frm . docname ) ) ; d . done _btn . innerHTML = 'Save' ; } }
2012-03-20 13:15:28 +00:00
d . onhide = function ( ) { if ( _f . cur _grid ) { _f . cur _grid . refresh _row ( _f . cur _grid _ridx , me . dn ) ; }
if ( wn . container . page . frm ) { cur _frm = wn . container . page . frm ; }
2012-04-11 12:32:23 +00:00
if ( me . cur _frm . cscript . hide _dialog ) { me . cur _frm . cscript . hide _dialog ( ) ; }
2012-05-05 14:35:58 +00:00
$ ( me . cur _frm . page _layout . wrapper ) . toggle ( false ) ; }
2012-02-14 06:14:13 +00:00
this . dialog = d ; }
2012-03-20 09:07:44 +00:00
_f . edit _record = function ( dt , dn ) { if ( ! _f . frm _dialog ) { _f . frm _dialog = new _f . FrmDialog ( ) ; }
var d = _f . frm _dialog ; wn . model . with _doctype ( dt , function ( ) { wn . model . with _doc ( dt , dn , function ( dn ) { if ( ! _f . frms [ dt ] ) { _f . frms [ dt ] = new _f . Frm ( dt , d . body ) ; }
var f = _f . frms [ dt ] ; if ( f . meta . istable ) { f . parent _doctype = cur _frm . doctype ; f . parent _docname = cur _frm . docname ; }
2012-04-11 12:32:23 +00:00
d . cur _frm = f ; d . dn = dn ; d . table _form = f . meta . istable ; f . refresh ( dn ) ; $ ( f . page _layout . wrapper ) . removeClass ( 'layout-wrapper' ) . removeClass ( 'layout-wrapper-background' ) . toggle ( true ) ; d . dialog . show ( ) ; } ) } ) }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / widgets / form / form _header . js
* /
2012-04-13 06:11:43 +00:00
_f . FrmHeader = Class . extend ( { init : function ( parent , frm ) { this . appframe = new wn . ui . AppFrame ( parent )
2012-06-14 05:35:09 +00:00
this . appframe . $titlebar . append ( ' < / s p a n > \
2012-05-02 06:05:04 +00:00
< span class = "breadcrumb-area" > < / s p a n > ' ) ; t h i s . $ w = t h i s . a p p f r a m e . $ w ; } , r e f r e s h : f u n c t i o n ( ) { w n . v i e w s . b r e a d c r u m b s ( $ ( t h i s . $ w . f i n d ( ' . b r e a d c r u m b - a r e a ' ) ) , c u r _ f r m . m e t a . m o d u l e , c u r _ f r m . m e t a . n a m e , c u r _ f r m . d o c n a m e ) ; t h i s . r e f r e s h _ l a b e l s ( ) ; t h i s . r e f r e s h _ t o o l b a r ( ) ; } , r e f r e s h _ l a b e l s : f u n c t i o n ( ) { v a r l a b i n f o = { 0 : [ ' S a v e d ' , ' l a b e l - s u c c e s s ' ] , 1 : [ ' S u b m i t t e d ' , ' l a b e l - i n f o ' ] , 2 : [ ' C a n c e l l e d ' , ' l a b e l - i m p o r t a n t ' ] } [ c i n t ( c u r _ f r m . d o c . d o c s t a t u s ) ] ; i f ( l a b i n f o [ 0 ] = = ' S a v e d ' & & c u r _ f r m . m e t a . i s _ s u b m i t t a b l e ) { l a b i n f o [ 0 ] = ' S a v e d , t o S u b m i t ' ; }
2012-05-02 10:35:58 +00:00
if ( cur _frm . doc . _ _unsaved || cur _frm . doc . _ _islocal ) { labinfo [ 0 ] = 'Not Saved' ; labinfo [ 1 ] = 'label-warning' }
2012-06-14 05:35:09 +00:00
this . set _label ( labinfo ) ; if ( cur _frm . doc . _ _unsaved && cint ( cur _frm . doc . docstatus ) == 1 && this . appframe . buttons [ 'Update' ] ) { this . appframe . buttons [ 'Update' ] . toggle ( true ) ; } } , set _label : function ( labinfo ) { this . $w . find ( '.label' ) . remove ( ) ; $ ( repl ( ' < span class = "label %(lab_class)s" > \
% ( lab _status ) s < / s p a n > ' , { l a b _ s t a t u s : l a b i n f o [ 0 ] , l a b _ c l a s s : l a b i n f o [ 1 ] } ) ) . i n s e r t B e f o r e ( t h i s . $ w . f i n d ( ' . b r e a d c r u m b - a r e a ' ) ) } , r e f r e s h _ t o o l b a r : f u n c t i o n ( ) { t h i s . a p p f r a m e . c l e a r _ b u t t o n s ( ) ; v a r p = c u r _ f r m . g e t _ d o c _ p e r m s ( ) ; i f ( c u r _ f r m . m e t a . r e a d _ o n l y _ o n l o a d & & ! c u r _ f r m . d o c . _ _ i s l o c a l ) { i f ( ! c u r _ f r m . e d i t a b l e )
2012-04-11 11:56:03 +00:00
this . appframe . add _button ( 'Edit' , function ( ) { cur _frm . edit _doc ( ) ; } , 'icon-pencil' ) ; else
this . appframe . add _button ( 'Print View' , function ( ) { cur _frm . is _editable [ cur _frm . docname ] = 0 ; cur _frm . refresh ( ) ; } , 'icon-print' ) ; }
var docstatus = cint ( cur _frm . doc . docstatus ) ; if ( docstatus == 0 && p [ WRITE ] ) { this . appframe . add _button ( 'Save' , function ( ) { cur _frm . save ( 'Save' ) ; } , '' ) ; this . appframe . buttons [ 'Save' ] . addClass ( 'btn-info' ) ; }
2012-04-11 09:48:24 +00:00
if ( docstatus == 0 && p [ SUBMIT ] && ( ! cur _frm . doc . _ _islocal ) )
2012-04-18 13:05:30 +00:00
this . appframe . add _button ( 'Submit' , function ( ) { cur _frm . savesubmit ( ) ; } , 'icon-lock' ) ; if ( docstatus == 1 && p [ SUBMIT ] ) { this . appframe . add _button ( 'Update' , function ( ) { cur _frm . saveupdate ( ) ; } , '' ) ; if ( ! cur _frm . doc . _ _unsaved ) this . appframe . buttons [ 'Update' ] . toggle ( false ) ; }
2012-04-11 09:48:24 +00:00
if ( docstatus == 1 && p [ CANCEL ] )
2012-04-11 11:56:03 +00:00
this . appframe . add _button ( 'Cancel' , function ( ) { cur _frm . savecancel ( ) } , 'icon-remove' ) ; if ( docstatus == 2 && p [ AMEND ] )
this . appframe . add _button ( 'Amend' , function ( ) { cur _frm . amend _doc ( ) } , 'icon-pencil' ) ; } , show : function ( ) { } , hide : function ( ) { } , hide _close : function ( ) { this . $w . find ( '.close' ) . toggle ( false ) ; } } )
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / widgets / form / form . js
* /
2012-05-05 14:35:58 +00:00
wn . provide ( '_f' ) ; _f . frms = { } ; _f . Frm = function ( doctype , parent ) { this . docname = '' ; this . doctype = doctype ; this . display = 0 ; var me = this ; this . is _editable = { } ; this . opendocs = { } ; this . sections = [ ] ; this . grids = [ ] ; this . cscript = { } ; this . pformat = { } ; this . fetch _dict = { } ; this . parent = parent ; this . tinymce _id _list = [ ] ; this . setup _meta ( doctype ) ; var me = this ; $ ( document ) . bind ( 'rename' , function ( event , dt , old _name , new _name ) { if ( dt == me . doctype )
2012-03-20 09:07:44 +00:00
me . rename _notify ( dt , old _name , new _name ) } ) ; }
2012-03-22 07:10:09 +00:00
_f . Frm . prototype . check _doctype _conflict = function ( docname ) { var me = this ; if ( this . doctype == 'DocType' && docname == 'DocType' ) { msgprint ( 'Allowing DocType, DocType. Be careful!' ) } else if ( this . doctype == 'DocType' ) { if ( wn . views . formview [ docname ] ) { msgprint ( "Cannot open DocType when its instance is open" )
2012-03-16 12:58:09 +00:00
throw 'doctype open conflict' } } else { if ( wn . views . formview . DocType && wn . views . formview . DocType . frm . opendocs [ this . doctype ] ) { msgprint ( "Cannot open instance when its DocType is open" )
throw 'doctype open conflict' } } }
_f . Frm . prototype . setup = function ( ) { var me = this ; this . fields = [ ] ; this . fields _dict = { } ; this . wrapper = this . parent ; this . setup _print _layout ( ) ; this . saved _wrapper = $a ( this . wrapper , 'div' ) ; this . setup _std _layout ( ) ; this . setup _client _script ( ) ; this . setup _done = true ; }
2012-05-04 07:34:40 +00:00
_f . Frm . prototype . setup _print _layout = function ( ) { this . print _wrapper = $a ( this . wrapper , 'div' ) ; this . print _head = $a ( this . print _wrapper , 'div' ) ; this . print _body = $a ( this . print _wrapper , 'div' , 'layout_wrapper' , { padding : '23px' , minHeight : '800px' } ) ; var t = make _table ( this . print _head , 1 , 2 , '100%' , [ ] , { padding : '6px' } ) ; this . view _btn _wrapper = $a ( $td ( t , 0 , 0 ) , 'span' , 'green_buttons' ) ; this . view _btn = $btn ( this . view _btn _wrapper , 'View Details' , function ( ) { cur _frm . edit _doc ( ) } , { marginRight : '4px' } , 'green' ) ; this . print _btn = $btn ( $td ( t , 0 , 0 ) , 'Print' , function ( ) { cur _frm . print _doc ( ) } ) ; $y ( $td ( t , 0 , 1 ) , { textAlign : 'right' } ) ; this . print _close _btn = $btn ( $td ( t , 0 , 1 ) , 'Close' , function ( ) { window . history . back ( ) ; } ) ; }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . onhide = function ( ) { if ( _f . cur _grid _cell ) _f . cur _grid _cell . grid . cell _deselect ( ) ; }
2012-03-20 09:07:44 +00:00
_f . Frm . prototype . setup _std _layout = function ( ) { this . page _layout = new wn . PageLayout ( { parent : this . wrapper , main _width : this . meta . in _dialog ? '100%' : '75%' , sidebar _width : this . meta . in _dialog ? '0%' : '25%' } )
this . meta . section _style = 'Simple' ; this . layout = new Layout ( this . page _layout . body , '100%' ) ; if ( this . meta . in _dialog ) { $ ( this . page _layout . wrapper ) . removeClass ( 'layout-wrapper-background' ) ; $ ( this . page _layout . main ) . removeClass ( 'layout-main-section' ) ; $ ( this . page _layout . sidebar _area ) . toggle ( false ) ; } else { this . setup _sidebar ( ) ; }
2012-04-11 11:56:03 +00:00
this . setup _footer ( ) ; if ( ! ( this . meta . istable || user == 'Guest' || this . meta . in _dialog ) )
this . frm _head = new _f . FrmHeader ( this . page _layout . head , this ) ; if ( this . meta . colour )
2012-03-13 09:49:06 +00:00
this . layout . wrapper . style . backgroundColor = '#' + this . meta . colour . split ( ':' ) [ 1 ] ; this . setup _fields _std ( ) ; }
2012-03-07 14:07:23 +00:00
_f . Frm . prototype . setup _print = function ( ) { var l = [ ]
this . default _format = 'Standard' ; for ( var key in locals [ 'Print Format' ] ) { if ( locals [ 'Print Format' ] [ key ] . doc _type == this . meta . name ) { l . push ( locals [ 'Print Format' ] [ key ] . name ) ; } }
2012-02-14 06:14:13 +00:00
if ( this . meta . default _print _format )
this . default _format = this . meta . default _print _format ; l . push ( 'Standard' ) ; this . print _sel = $a ( null , 'select' , '' , { width : '160px' } ) ; add _sel _options ( this . print _sel , l ) ; this . print _sel . value = this . default _format ; }
_f . Frm . prototype . print _doc = function ( ) { if ( this . doc . docstatus == 2 ) { msgprint ( "Cannot Print Cancelled Documents." ) ; return ; }
_p . show _dialog ( ) ; }
2012-06-13 07:23:03 +00:00
_f . Frm . prototype . email _doc = function ( ) { if ( ! _e . dialog ) _e . make ( ) ; _e . dialog . widgets [ 'To' ] . value = '' ; if ( cur _frm . doc && cur _frm . doc . contact _email ) { _e . dialog . widgets [ 'To' ] . value = cur _frm . doc . contact _email ; }
sel = this . print _sel ; var c = $td ( _e . dialog . rows [ 'Format' ] . tab , 0 , 1 ) ; if ( c . cur _sel ) { c . removeChild ( c . cur _sel ) ; c . cur _sel = null ; }
2012-02-14 06:14:13 +00:00
c . appendChild ( this . print _sel ) ; c . cur _sel = this . print _sel ; _e . dialog . widgets [ 'Send With Attachments' ] . checked = 0 ; if ( cur _frm . doc . file _list ) { $ds ( _e . dialog . rows [ 'Send With Attachments' ] ) ; } else { $dh ( _e . dialog . rows [ 'Send With Attachments' ] ) ; }
_e . dialog . widgets [ 'Subject' ] . value = get _doctype _label ( this . meta . name ) + ': ' + this . docname ; _e . dialog . show ( ) ; }
2012-05-02 04:15:28 +00:00
_f . Frm . prototype . rename _notify = function ( dt , old , name ) { if ( this . meta . in _dialog )
return ; if ( this . docname == old )
2012-04-25 12:54:44 +00:00
this . docname = name ; else
2012-04-26 13:31:35 +00:00
return ; this . is _editable [ name ] = this . is _editable [ old ] ; delete this . is _editable [ old ] ; if ( this && this . opendocs [ old ] ) { local _dt [ dt ] [ name ] = local _dt [ dt ] [ old ] ; local _dt [ dt ] [ old ] = null ; }
2012-06-12 10:15:44 +00:00
delete this . opendocs [ old ] ; this . opendocs [ name ] = true ; wn . re _route [ window . location . hash ] = '#Form/' + encodeURIComponent ( this . doctype ) + '/' + encodeURIComponent ( name ) ; wn . set _route ( 'Form' , this . doctype , name ) ; }
2012-03-20 13:15:28 +00:00
_f . Frm . prototype . setup _meta = function ( ) { this . meta = get _local ( 'DocType' , this . doctype ) ; this . perm = get _perm ( this . doctype ) ; if ( this . meta . istable ) { this . meta . in _dialog = 1 }
this . setup _print ( ) ; }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . setup _sidebar = function ( ) { this . sidebar = new wn . widgets . form . sidebar . Sidebar ( this ) ; }
2012-03-13 09:49:06 +00:00
_f . Frm . prototype . setup _footer = function ( ) { var me = this ; var f = this . page _layout . footer ; f . save _area = $a ( this . page _layout . footer , 'div' , '' , { display : 'none' , marginTop : '11px' } ) ; f . help _area = $a ( this . page _layout . footer , 'div' ) ; var b = $btn ( f . save _area , 'Save' , function ( ) { cur _frm . save ( 'Save' ) ; } , { marginLeft : '0px' } , 'green' ) ; f . show _save = function ( ) { $ds ( me . page _layout . footer . save _area ) ; }
2012-02-14 06:14:13 +00:00
f . hide _save = function ( ) { $dh ( me . page _layout . footer . save _area ) ; } }
2012-04-19 12:18:57 +00:00
_f . Frm . prototype . setup _fields _std = function ( ) { var fl = wn . meta . docfield _list [ this . doctype ] ; fl . sort ( function ( a , b ) { return a . idx - b . idx } ) ; if ( fl [ 0 ] && fl [ 0 ] . fieldtype != "Section Break" || get _url _arg ( 'embed' ) ) { this . layout . addrow ( ) ; if ( fl [ 0 ] . fieldtype != "Column Break" ) { var c = this . layout . addcell ( ) ; $y ( c . wrapper , { padding : '8px' } ) ; } }
2012-03-13 09:49:06 +00:00
var sec ; for ( var i = 0 ; i < fl . length ; i ++ ) { var f = fl [ i ] ; if ( f . fieldtype == 'Section Break' && fl [ i + 1 ] && fl [ i + 1 ] . fieldtype == 'Section Break' )
continue ; var fn = f . fieldname ? f . fieldname : f . label ; var fld = make _field ( f , this . doctype , this . layout . cur _cell , this ) ; this . fields [ this . fields . length ] = fld ; this . fields _dict [ fn ] = fld ; if ( sec && [ 'Section Break' , 'Column Break' ] . indexOf ( f . fieldtype ) == - 1 ) { fld . parent _section = sec ; sec . fields . push ( fld ) ; }
2012-03-13 10:41:52 +00:00
if ( f . fieldtype == 'Section Break' ) { sec = fld ; this . sections . push ( fld ) ; }
if ( ( f . fieldtype == 'Section Break' ) && ( fl [ i + 1 ] ) && ( fl [ i + 1 ] . fieldtype != 'Column Break' ) && ! f . hidden ) { var c = this . layout . addcell ( ) ; $y ( c . wrapper , { padding : '8px' } ) ; } } }
2012-04-12 11:06:01 +00:00
_f . Frm . prototype . add _custom _button = function ( label , fn , icon ) { this . frm _head . appframe . add _button ( label , fn , icon ) ; }
2012-06-18 12:34:28 +00:00
_f . Frm . prototype . clear _custom _buttons = function ( ) { this . frm _head . refresh _toolbar ( ) }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . add _fetch = function ( link _field , src _field , tar _field ) { if ( ! this . fetch _dict [ link _field ] ) { this . fetch _dict [ link _field ] = { 'columns' : [ ] , 'fields' : [ ] } }
this . fetch _dict [ link _field ] . columns . push ( src _field ) ; this . fetch _dict [ link _field ] . fields . push ( tar _field ) ; }
_f . Frm . prototype . setup _client _script = function ( ) { if ( this . meta . client _script _core || this . meta . client _script || this . meta . _ _js ) { this . runclientscript ( 'setup' , this . doctype , this . docname ) ; } }
_f . Frm . prototype . refresh _print _layout = function ( ) { $ds ( this . print _wrapper ) ; $dh ( this . page _layout . wrapper ) ; var me = this ; var print _callback = function ( print _html ) { me . print _body . innerHTML = print _html ; }
if ( cur _frm . doc . select _print _heading )
cur _frm . set _print _heading ( cur _frm . doc . select _print _heading )
if ( user != 'Guest' ) { $di ( this . view _btn _wrapper ) ; if ( cur _frm . doc . _ _archived ) { $dh ( this . view _btn _wrapper ) ; } } else { $dh ( this . view _btn _wrapper ) ; $dh ( this . print _close _btn ) ; }
_p . build ( this . default _format , print _callback , null , 1 ) ; }
2012-03-16 12:58:09 +00:00
_f . Frm . prototype . show _the _frm = function ( ) { if ( this . meta . in _dialog && ! this . parent . dialog . display ) { if ( ! this . meta . istable )
this . parent . table _form = false ; this . parent . dialog . show ( ) ; } }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . set _print _heading = function ( txt ) { this . pformat [ cur _frm . docname ] = txt ; }
2012-03-16 12:58:09 +00:00
_f . Frm . prototype . defocus _rest = function ( ) { if ( _f . cur _grid _cell ) _f . cur _grid _cell . grid . cell _deselect ( ) ; }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . get _doc _perms = function ( ) { var p = [ 0 , 0 , 0 , 0 , 0 , 0 ] ; for ( var i = 0 ; i < this . perm . length ; i ++ ) { if ( this . perm [ i ] ) { if ( this . perm [ i ] [ READ ] ) p [ READ ] = 1 ; if ( this . perm [ i ] [ WRITE ] ) p [ WRITE ] = 1 ; if ( this . perm [ i ] [ SUBMIT ] ) p [ SUBMIT ] = 1 ; if ( this . perm [ i ] [ CANCEL ] ) p [ CANCEL ] = 1 ; if ( this . perm [ i ] [ AMEND ] ) p [ AMEND ] = 1 ; } }
return p ; }
_f . Frm . prototype . refresh _header = function ( ) { if ( ! this . meta . in _dialog ) { set _title ( this . meta . issingle ? this . doctype : this . docname ) ; }
2012-06-14 05:35:09 +00:00
if ( this . frm _head ) this . frm _head . refresh ( ) ; if ( wn . ui . toolbar . recent )
2012-04-11 11:56:03 +00:00
wn . ui . toolbar . recent . add ( this . doctype , this . docname , 1 ) ; }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . check _doc _perm = function ( ) { var dt = this . parent _doctype ? this . parent _doctype : this . doctype ; var dn = this . parent _docname ? this . parent _docname : this . docname ; this . perm = get _perm ( dt , dn ) ; this . orig _perm = get _perm ( dt , dn , 1 ) ; if ( ! this . perm [ 0 ] [ READ ] ) { if ( user == 'Guest' ) { if ( _f . temp _access [ dt ] && _f . temp _access [ dt ] [ dn ] ) { this . perm = [ [ 1 , 0 , 0 ] ]
return 1 ; } }
2012-03-16 12:58:09 +00:00
window . back ( ) ; return 0 ; }
2012-02-14 06:14:13 +00:00
return 1 }
_f . Frm . prototype . refresh = function ( docname ) { if ( docname ) { if ( this . docname != docname && ! this . meta . in _dialog && ! this . meta . istable ) scroll ( 0 , 0 ) ; this . docname = docname ; }
if ( ! this . meta . istable ) { cur _frm = this ; this . parent . cur _frm = this ; }
2012-03-01 05:26:50 +00:00
if ( this . docname ) { if ( ! this . check _doc _perm ( ) ) return ; if ( ! this . setup _done ) this . setup ( ) ; this . runclientscript ( 'set_perm' , this . doctype , this . docname ) ; this . doc = get _local ( this . doctype , this . docname ) ; cur _frm . cscript . is _onload = false ; if ( ! this . opendocs [ this . docname ] ) { cur _frm . cscript . is _onload = true ; this . setnewdoc ( this . docname ) ; }
2012-02-14 06:14:13 +00:00
if ( this . doc . _ _islocal )
this . is _editable [ this . docname ] = 1 ; this . editable = this . is _editable [ this . docname ] ; if ( ! this . doc . _ _archived && ( this . editable || ( ! this . editable && this . meta . istable ) ) ) { if ( this . print _wrapper ) { $dh ( this . print _wrapper ) ; $ds ( this . page _layout . wrapper ) ; }
if ( ! this . meta . istable ) { this . refresh _header ( ) ; this . sidebar && this . sidebar . refresh ( ) ; }
2012-03-20 09:07:44 +00:00
this . runclientscript ( 'refresh' ) ; $ ( document ) . trigger ( 'form_refresh' ) ; this . refresh _fields ( ) ; this . refresh _dependency ( ) ; this . refresh _footer ( ) ; if ( this . layout ) this . layout . show ( ) ; if ( cur _frm . cscript . is _onload ) { this . runclientscript ( 'onload_post_render' , this . doctype , this . docname ) ; }
2012-03-22 06:07:50 +00:00
if ( this . doc . docstatus == 0 ) { $ ( this . wrapper ) . find ( '.form-layout-row :input:first' ) . focus ( ) ; } } else { this . refresh _header ( ) ; if ( this . print _wrapper ) { this . refresh _print _layout ( ) ; }
2012-02-14 06:14:13 +00:00
this . runclientscript ( 'edit_status_changed' ) ; }
2012-03-16 12:58:09 +00:00
$ ( cur _frm . wrapper ) . trigger ( 'render_complete' ) ; } }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . refresh _footer = function ( ) { var f = this . page _layout . footer ; if ( f . save _area ) { if ( get _url _arg ( 'embed' ) || ( this . editable && ! this . meta . in _dialog && this . doc . docstatus == 0 && ! this . meta . istable && this . get _doc _perms ( ) [ WRITE ] ) ) { f . show _save ( ) ; } else { f . hide _save ( ) ; } } }
2012-03-13 09:49:06 +00:00
_f . Frm . prototype . refresh _fields = function ( ) { for ( var i = 0 ; i < this . fields . length ; i ++ ) { var f = this . fields [ i ] ; f . perm = this . perm ; f . docname = this . docname ; var fn = f . df . fieldname || f . df . label ; if ( fn )
2012-03-13 10:41:52 +00:00
f . df = get _field ( this . doctype , fn , this . docname ) ; if ( f . df . fieldtype != 'Section Break' && f . refresh ) { f . refresh ( ) ; } }
2012-03-14 13:36:20 +00:00
$ . each ( this . sections , function ( i , f ) { f . refresh ( true ) ; } )
2012-02-14 06:14:13 +00:00
this . cleanup _refresh ( this ) ; }
_f . Frm . prototype . cleanup _refresh = function ( ) { var me = this ; if ( me . fields _dict [ 'amended_from' ] ) { if ( me . doc . amended _from ) { unhide _field ( 'amended_from' ) ; unhide _field ( 'amendment_date' ) ; } else { hide _field ( 'amended_from' ) ; hide _field ( 'amendment_date' ) ; } }
if ( me . fields _dict [ 'trash_reason' ] ) { if ( me . doc . trash _reason && me . doc . docstatus == 2 ) { unhide _field ( 'trash_reason' ) ; } else { hide _field ( 'trash_reason' ) ; } }
if ( me . meta . autoname && me . meta . autoname . substr ( 0 , 6 ) == 'field:' && ! me . doc . _ _islocal ) { var fn = me . meta . autoname . substr ( 6 ) ; set _field _permlevel ( fn , 1 ) ; } }
_f . Frm . prototype . refresh _dependency = function ( ) { var me = this ; var doc = locals [ this . doctype ] [ this . docname ] ; var dep _dict = { } ; var has _dep = false ; for ( fkey in me . fields ) { var f = me . fields [ fkey ] ; f . dependencies _clear = true ; var guardian = f . df . depends _on ; if ( guardian ) { if ( ! dep _dict [ guardian ] )
dep _dict [ guardian ] = [ ] ; dep _dict [ guardian ] [ dep _dict [ guardian ] . length ] = f ; has _dep = true ; } }
if ( ! has _dep ) return ; for ( var i = me . fields . length - 1 ; i >= 0 ; i -- ) { var f = me . fields [ i ] ; f . guardian _has _value = true ; if ( f . df . depends _on ) { var v = doc [ f . df . depends _on ] ; if ( f . df . depends _on . substr ( 0 , 5 ) == 'eval:' ) { f . guardian _has _value = eval ( f . df . depends _on . substr ( 5 ) ) ; } else if ( f . df . depends _on . substr ( 0 , 3 ) == 'fn:' ) { f . guardian _has _value = me . runclientscript ( f . df . depends _on . substr ( 3 ) , me . doctype , me . docname ) ; } else { if ( v || ( v == 0 && ! v . substr ) ) { } else { f . guardian _has _value = false ; } }
if ( f . guardian _has _value ) { if ( f . grid ) f . grid . show ( ) ; else $ds ( f . wrapper ) ; } else { if ( f . grid ) f . grid . hide ( ) ; else $dh ( f . wrapper ) ; } } } }
2012-03-16 12:58:09 +00:00
_f . Frm . prototype . setnewdoc = function ( docname ) { this . check _doctype _conflict ( docname ) ; if ( this . opendocs [ docname ] ) { this . docname = docname ; return ; }
2012-03-13 09:49:06 +00:00
Meta . make _local _dt ( this . doctype , docname ) ; this . docname = docname ; var me = this ; var viewname = docname ; if ( this . meta . issingle ) viewname = this . doctype ; this . runclientscript ( 'onload' , this . doctype , this . docname ) ; this . is _editable [ docname ] = 1 ; if ( this . meta . read _only _onload ) this . is _editable [ docname ] = 0 ; this . opendocs [ docname ] = true ; }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . edit _doc = function ( ) { this . is _editable [ this . docname ] = true ; this . refresh ( ) ; }
_f . Frm . prototype . show _doc = function ( dn ) { this . refresh ( dn ) ; }
var validated ; _f . Frm . prototype . save = function ( save _action , call _back ) { if ( ! save _action ) save _action = 'Save' ; var me = this ; if ( this . savingflag ) { msgprint ( "Document is currently saving...." ) ; return ; }
if ( save _action == 'Submit' ) { locals [ this . doctype ] [ this . docname ] . submitted _on = dateutil . full _str ( ) ; locals [ this . doctype ] [ this . docname ] . submitted _by = user ; }
if ( save _action == 'Trash' ) { var reason = prompt ( 'Reason for trash (mandatory)' , '' ) ; if ( ! strip ( reason ) ) { msgprint ( 'Reason is mandatory, not trashed' ) ; return ; }
locals [ this . doctype ] [ this . docname ] . trash _reason = reason ; }
if ( save _action == 'Cancel' ) { var reason = prompt ( 'Reason for cancellation (mandatory)' , '' ) ; if ( ! strip ( reason ) ) { msgprint ( 'Reason is mandatory, not cancelled' ) ; return ; }
locals [ this . doctype ] [ this . docname ] . cancel _reason = reason ; locals [ this . doctype ] [ this . docname ] . cancelled _on = dateutil . full _str ( ) ; locals [ this . doctype ] [ this . docname ] . cancelled _by = user ; } else if ( save _action == 'Update' ) { } else { validated = true ; if ( this . cscript . validate )
this . runclientscript ( 'validate' , this . doctype , this . docname ) ; if ( ! validated ) { this . savingflag = false ; return 'Error' ; } }
2012-03-20 09:07:44 +00:00
var ret _fn = function ( r ) { me . savingflag = false ; if ( user == 'Guest' && ! r . exc ) { $dh ( me . page _layout . wrapper ) ; $ds ( me . saved _wrapper ) ; me . saved _wrapper . innerHTML = '<div style="padding: 150px 16px; text-align: center; font-size: 14px;">'
2012-02-14 06:14:13 +00:00
+ ( cur _frm . message _after _save ? cur _frm . message _after _save : 'Your information has been sent. Thank you!' )
+ '</div>' ; return ; }
2012-05-05 14:35:58 +00:00
if ( ! me . meta . istable ) { me . refresh ( r . docname ) ; }
2012-03-20 09:07:44 +00:00
if ( call _back ) { call _back ( r ) ; } }
2012-02-14 06:14:13 +00:00
var me = this ; var ret _fn _err = function ( r ) { var doc = locals [ me . doctype ] [ me . docname ] ; me . savingflag = false ; ret _fn ( r ) ; }
this . savingflag = true ; if ( this . docname && validated ) { scroll ( 0 , 0 ) ; return this . savedoc ( save _action , ret _fn , ret _fn _err ) ; } }
2012-05-11 10:53:41 +00:00
_f . Frm . prototype . runscript = function ( scriptname , callingfield , onrefresh ) { var me = this ; if ( this . docname ) { var doclist = compress _doclist ( make _doclist ( this . doctype , this . docname ) ) ; if ( callingfield )
$ ( callingfield . input ) . set _working ( ) ; $c ( 'runserverobj' , { 'docs' : doclist , 'method' : scriptname } , function ( r , rtxt ) { if ( onrefresh )
onrefresh ( r , rtxt ) ; me . refresh _fields ( ) ; me . refresh _dependency ( ) ; if ( callingfield )
$ ( callingfield . input ) . done _working ( ) ; } ) ; } }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . runclientscript = function ( caller , cdt , cdn ) { var _dt = this . parent _doctype ? this . parent _doctype : this . doctype ; var _dn = this . parent _docname ? this . parent _docname : this . docname ; var doc = get _local ( _dt , _dn ) ; if ( ! cdt ) cdt = this . doctype ; if ( ! cdn ) cdn = this . docname ; var ret = null ; try { if ( this . cscript [ caller ] )
ret = this . cscript [ caller ] ( doc , cdt , cdn ) ; if ( this . cscript [ 'custom_' + caller ] )
ret += this . cscript [ 'custom_' + caller ] ( doc , cdt , cdn ) ; } catch ( e ) { console . log ( e ) ; }
if ( caller && caller . toLowerCase ( ) == 'setup' ) { var doctype = get _local ( 'DocType' , this . doctype ) ; var cs = doctype . _ _js || ( doctype . client _script _core + doctype . client _script ) ; if ( cs ) { try { var tmp = eval ( cs ) ; } catch ( e ) { console . log ( e ) ; } }
if ( doctype . _ _css ) set _style ( doctype . _ _css )
if ( doctype . client _string ) { this . cstring = { } ; var elist = doctype . client _string . split ( '---' ) ; for ( var i = 1 ; i < elist . length ; i = i + 2 ) { this . cstring [ strip ( elist [ i ] ) ] = elist [ i + 1 ] ; } } }
return ret ; }
_f . Frm . prototype . copy _doc = function ( onload , from _amend ) { if ( ! this . perm [ 0 ] [ CREATE ] ) { msgprint ( 'You are not allowed to create ' + this . meta . name ) ; return ; }
var dn = this . docname ; var newdoc = LocalDB . copy ( this . doctype , dn , from _amend ) ; if ( this . meta . allow _attach && newdoc . file _list )
newdoc . file _list = null ; var dl = make _doclist ( this . doctype , dn ) ; var tf _dict = { } ; for ( var d in dl ) { d1 = dl [ d ] ; if ( ! tf _dict [ d1 . parentfield ] ) { tf _dict [ d1 . parentfield ] = get _field ( d1 . parenttype , d1 . parentfield ) ; }
if ( d1 . parent == dn && cint ( tf _dict [ d1 . parentfield ] . no _copy ) != 1 ) { var ch = LocalDB . copy ( d1 . doctype , d1 . name , from _amend ) ; ch . parent = newdoc . name ; ch . docstatus = 0 ; ch . owner = user ; ch . creation = '' ; ch . modified _by = user ; ch . modified = '' ; } }
newdoc . _ _islocal = 1 ; newdoc . docstatus = 0 ; newdoc . owner = user ; newdoc . creation = '' ; newdoc . modified _by = user ; newdoc . modified = '' ; if ( onload ) onload ( newdoc ) ; loaddoc ( newdoc . doctype , newdoc . name ) ; }
2012-03-16 12:58:09 +00:00
_f . Frm . prototype . reload _doc = function ( ) { this . check _doctype _conflict ( this . docname ) ; var me = this ; var ret _fn = function ( r , rtxt ) { me . runclientscript ( 'setup' , me . doctype , me . docname ) ; me . refresh ( ) ; }
2012-02-14 06:14:13 +00:00
if ( me . doc . _ _islocal ) { $c ( 'webnotes.widgets.form.load.getdoctype' , { 'doctype' : me . doctype } , ret _fn , null , null , 'Refreshing ' + me . doctype + '...' ) ; } else { var gl = me . grids ; for ( var i = 0 ; i < gl . length ; i ++ ) { var dt = gl [ i ] . df . options ; for ( var dn in locals [ dt ] ) { if ( locals [ dt ] [ dn ] . _ _islocal && locals [ dt ] [ dn ] . parent == me . docname ) { var d = locals [ dt ] [ dn ] ; d . parent = '' ; d . docstatus = 2 ; d . _ _deleted = 1 ; } } }
$c ( 'webnotes.widgets.form.load.getdoc' , { 'name' : me . docname , 'doctype' : me . doctype , 'getdoctype' : 1 , 'user' : user } , ret _fn , null , null , 'Refreshing ' + me . docname + '...' ) ; } }
_f . Frm . prototype . savedoc = function ( save _action , onsave , onerr ) { this . error _in _section = 0 ; save _doclist ( this . doctype , this . docname , save _action , onsave , onerr ) ; }
_f . Frm . prototype . saveupdate = function ( ) { this . save ( 'Update' ) ; }
_f . Frm . prototype . savesubmit = function ( ) { var answer = confirm ( "Permanently Submit " + this . docname + "?" ) ; var me = this ; if ( answer ) { this . save ( 'Submit' , function ( r ) { if ( ! r . exc && me . cscript . on _submit ) { me . runclientscript ( 'on_submit' , me . doctype , me . docname ) ; } } ) ; } }
_f . Frm . prototype . savecancel = function ( ) { var answer = confirm ( "Permanently Cancel " + this . docname + "?" ) ; if ( answer ) this . save ( 'Cancel' ) ; }
2012-03-16 12:58:09 +00:00
_f . Frm . prototype . savetrash = function ( ) { var me = this ; var answer = confirm ( "Permanently Delete " + this . docname + "? This action cannot be reversed" ) ; if ( answer ) { $c ( 'webnotes.model.delete_doc' , { dt : this . doctype , dn : this . docname } , function ( r , rt ) { if ( r . message == 'okay' ) { LocalDB . delete _doc ( me . doctype , me . docname ) ; if ( wn . ui . toolbar . recent ) wn . ui . toolbar . recent . remove ( me . doctype , me . docname ) ; window . back ( ) ; } } ) } }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . amend _doc = function ( ) { if ( ! this . fields _dict [ 'amended_from' ] ) { alert ( '"amended_from" field must be present to do an amendment.' ) ; return ; }
var me = this ; var fn = function ( newdoc ) { newdoc . amended _from = me . docname ; if ( me . fields _dict && me . fields _dict [ 'amendment_date' ] )
newdoc . amendment _date = dateutil . obj _to _str ( new Date ( ) ) ; }
this . copy _doc ( fn , 1 ) ; }
_f . get _value = function ( dt , dn , fn ) { if ( locals [ dt ] && locals [ dt ] [ dn ] )
return locals [ dt ] [ dn ] [ fn ] ; }
2012-03-16 12:58:09 +00:00
_f . set _value = function ( dt , dn , fn , v ) { var d = locals [ dt ] [ dn ] ; if ( ! d ) { console . log ( '_f.set_value - ' + fn + ': "' + dt + ',' + dn + '" not found' ) ; return ; }
2012-04-18 13:05:30 +00:00
var changed = d [ fn ] != v ; if ( changed && ( d [ fn ] == null || v == null ) && ( cstr ( d [ fn ] ) == cstr ( v ) ) ) changed = 0 ; if ( changed ) { var prev _unsaved = d . _ _unsaved
2012-05-16 06:49:17 +00:00
d [ fn ] = v ; d . _ _unsaved = 1 ; if ( d . parent && d . parenttype ) { var doc = locals [ d . parenttype ] [ d . parent ] ; doc . _ _unsaved = 1 ; var frm = wn . views . formview [ d . parenttype ] . frm ; } else { var doc = locals [ d . doctype ] [ d . name ]
doc . _ _unsaved = 1 ; var frm = wn . views . formview [ d . doctype ] && wn . views . formview [ d . doctype ] . frm ; }
if ( frm && frm == cur _frm && frm . frm _head && ! prev _unsaved ) { frm . frm _head . refresh _labels ( ) ; } } }
2012-02-14 06:14:13 +00:00
_f . Frm . prototype . show _comments = function ( ) { if ( ! cur _frm . comments ) { cur _frm . comments = new Dialog ( 540 , 400 , 'Comments' ) ; cur _frm . comments . comment _body = $a ( cur _frm . comments . body , 'div' , 'dialog_frm' ) ; $y ( cur _frm . comments . body , { backgroundColor : '#EEE' } ) ; cur _frm . comments . list = new CommentList ( cur _frm . comments . comment _body ) ; }
cur _frm . comments . list . dt = cur _frm . doctype ; cur _frm . comments . list . dn = cur _frm . docname ; cur _frm . comments . show ( ) ; cur _frm . comments . list . run ( ) ; }
/ *
* lib / js / legacy / widgets / form / form _fields . js
* /
_f . ColumnBreak = function ( ) { this . set _input = function ( ) { } ; }
_f . ColumnBreak . prototype . make _body = function ( ) { if ( ( ! this . perm [ this . df . permlevel ] ) || ( ! this . perm [ this . df . permlevel ] [ READ ] ) || this . df . hidden ) { return ; }
2012-02-21 11:56:50 +00:00
this . cell = this . frm . layout . addcell ( this . df . width ) ; $y ( this . cell . wrapper , { padding : '8px' } ) ; _f . cur _col _break _width = this . df . width ; var fn = this . df . fieldname ? this . df . fieldname : this . df . label ; if ( this . df && this . df . label ) { this . label = $a ( this . cell . wrapper , 'div' , '' , '' , this . df . label ) ; } }
2012-03-13 09:49:06 +00:00
_f . ColumnBreak . prototype . refresh = function ( layout ) { if ( ! this . cell ) return ; if ( this . set _hidden != this . df . hidden ) { if ( this . df . hidden )
2012-02-14 06:14:13 +00:00
this . cell . hide ( ) ; else
2012-03-13 09:49:06 +00:00
this . cell . show ( ) ; this . set _hidden = this . df . hidden ; } }
_f . SectionBreak = function ( ) { this . fields = [ ] ; this . set _input = function ( ) { } ; this . make _row = function ( ) { this . row = this . df . label ? this . frm . layout . addrow ( ) : this . frm . layout . addsubrow ( ) ; } }
_f . SectionBreak . prototype . make _body = function ( ) { var me = this ; if ( ( ! this . perm [ this . df . permlevel ] ) || ( ! this . perm [ this . df . permlevel ] [ READ ] ) || this . df . hidden ) { return ; }
this . make _row ( ) ; if ( this . df . label ) { if ( ! this . df . description )
2012-04-11 09:48:24 +00:00
this . df . description = '' ; $ ( this . row . main _head ) . html ( repl ( ' < div class = "form-section-head" > \
2012-04-11 11:56:03 +00:00
< h3 class = "head" > % ( label ) s < / h 3 > \
2012-04-11 09:48:24 +00:00
< div class = "help small" \
style = "margin-top: 4px; margin-bottom: 8px;" > % ( description ) s < / d i v > \
< / d i v > ' , t h i s . d f ) ) ; } e l s e { $ ( t h i s . w r a p p e r ) . h t m l ( ' < d i v c l a s s = " f o r m - s e c t i o n - h e a d " > < / d i v > ' ) ; }
2012-03-14 13:36:20 +00:00
this . section _collapse = function ( ) { $ ( me . row . main _head ) . find ( '.head' ) . html ( ' < i class = "icon-chevron-right" > < / i > \
2012-03-13 09:49:06 +00:00
< a href = "#" onclick = "return false;" > Show "'+me.df.label+'" < / a > ' ) ; $ ( m e . r o w . m a i n _ b o d y ) . t o g g l e ( f a l s e ) ; }
2012-03-14 13:36:20 +00:00
this . section _expand = function ( no _animation ) { $ ( me . row . main _head ) . find ( '.head' ) . html ( '<h3><i class="icon-chevron-down" style="vertical-align: middle; margin-bottom: 2px"></i> '
+ me . df . label + '</h3>' ) ; if ( no _animation )
$ ( me . row . main _body ) . toggle ( true ) ; else
2012-04-13 06:11:43 +00:00
$ ( me . row . main _body ) . slideDown ( ) ; } }
2012-03-13 10:41:52 +00:00
_f . SectionBreak . prototype . has _data = function ( ) { var me = this ; for ( var i in me . fields ) { var f = me . fields [ i ] ; var v = f . get _value ? f . get _value ( ) : null ; defaultval = f . df [ 'default' ] || sys _defaults [ f . fieldname ] || user _defaults [ f . fieldname ] ; if ( v && v != defaultval ) { return true ; }
if ( f . df . reqd && ! v ) { return true ; }
if ( f . df . fieldtype == 'Table' ) { if ( f . grid . get _children ( ) . length || f . df . reqd ) { return true ; } } }
2012-03-13 09:49:06 +00:00
return false ; }
2012-04-11 09:48:24 +00:00
_f . SectionBreak . prototype . refresh = function ( from _form ) { if ( this . df . hidden ) { if ( this . row ) this . row . hide ( ) ; } else { if ( this . collapsible ) { } } }
2012-02-14 06:14:13 +00:00
_f . ImageField = function ( ) { this . images = { } ; }
_f . ImageField . prototype = new Field ( ) ; _f . ImageField . prototype . onmake = function ( ) { this . no _img = $a ( this . wrapper , 'div' , 'no_img' ) ; this . no _img . innerHTML = "No Image" ; $dh ( this . no _img ) ; }
2012-03-12 10:42:09 +00:00
_f . ImageField . prototype . get _image _src = function ( doc ) { if ( doc . file _list ) { file = doc . file _list . split ( ',' ) ; extn = file [ 0 ] . split ( '.' ) ; extn = extn [ extn . length - 1 ] . toLowerCase ( ) ; var img _extn _list = [ 'gif' , 'jpg' , 'bmp' , 'jpeg' , 'jp2' , 'cgm' , 'ief' , 'jpm' , 'jpx' , 'png' , 'tiff' , 'jpe' , 'tif' ] ; if ( in _list ( img _extn _list , extn ) ) { var src = wn . request . url + "?cmd=downloadfile&file_id=" + file [ 1 ] ; } } else { var src = "" ; }
2012-02-14 06:14:13 +00:00
return src ; }
_f . ImageField . prototype . onrefresh = function ( ) { var me = this ; if ( ! this . images [ this . docname ] ) this . images [ this . docname ] = $a ( this . wrapper , 'img' ) ; else $di ( this . images [ this . docname ] ) ; var img = this . images [ this . docname ]
2012-03-12 10:42:09 +00:00
for ( var dn in this . images ) if ( dn != this . docname ) $dh ( this . images [ dn ] ) ; var doc = locals [ this . frm . doctype ] [ this . frm . docname ] ; if ( ! this . df . options ) var src = this . get _image _src ( doc ) ; else var src = wn . request . url + '?cmd=get_file&fname=' + this . df . options + "&__account=" + account _id + ( _ _sid150 ? ( "&sid150=" + _ _sid150 ) : '' ) ; if ( src ) { $dh ( this . no _img ) ; if ( img . getAttribute ( 'src' ) != src ) img . setAttribute ( 'src' , src ) ; canvas = this . wrapper ; canvas . img = this . images [ this . docname ] ; canvas . style . overflow = "auto" ; $w ( canvas , "100%" ) ; if ( ! this . col _break _width ) this . col _break _width = '100%' ; var allow _width = cint ( 1000 * ( cint ( this . col _break _width ) - 10 ) / 100 ) ; if ( ( ! img . naturalWidth ) || cint ( img . naturalWidth ) > allow _width )
2012-02-14 06:14:13 +00:00
$w ( img , allow _width + 'px' ) ; } else { $ds ( this . no _img ) ; } }
_f . ImageField . prototype . set _disp = function ( val ) { }
_f . ImageField . prototype . set = function ( val ) { }
2012-03-21 06:17:58 +00:00
_f . TableField = function ( ) { } ; _f . TableField . prototype = new Field ( ) ; _f . TableField . prototype . with _label = 0 ; _f . TableField . prototype . make _body = function ( ) { if ( this . perm [ this . df . permlevel ] && this . perm [ this . df . permlevel ] [ READ ] ) { if ( this . df . description ) { this . desc _area = $a ( this . parent , 'div' , 'help small' , '' , this . df . description ) }
2012-02-14 06:14:13 +00:00
this . grid = new _f . FormGrid ( this ) ; if ( this . frm ) this . frm . grids [ this . frm . grids . length ] = this ; this . grid . make _buttons ( ) ; } }
_f . TableField . prototype . refresh = function ( ) { if ( ! this . grid ) return ; var st = this . get _status ( ) ; if ( ! this . df [ 'default' ] )
this . df [ 'default' ] = '' ; this . grid . can _add _rows = false ; this . grid . can _edit = false
if ( st == 'Write' ) { if ( cur _frm . editable && this . perm [ this . df . permlevel ] && this . perm [ this . df . permlevel ] [ WRITE ] ) { this . grid . can _edit = true ; if ( this . df [ 'default' ] . toLowerCase ( ) != 'no toolbar' )
this . grid . can _add _rows = true ; }
if ( cur _frm . editable && cur _frm . doc . docstatus > 0 ) { if ( this . df . allow _on _submit && cur _frm . doc . docstatus == 1 ) { this . grid . can _edit = true ; if ( this . df [ 'default' ] . toLowerCase ( ) == 'no toolbar' ) { this . grid . can _add _rows = false ; } else { this . grid . can _add _rows = true ; } } else { this . grid . can _add _rows = false ; this . grid . can _edit = false ; } }
if ( this . df [ 'default' ] . toLowerCase ( ) == 'no add rows' ) { this . grid . can _add _rows = false ; } }
2012-02-14 06:33:02 +00:00
if ( st == 'Write' ) { this . grid . show ( ) ; } else if ( st == 'Read' ) { this . grid . show ( ) ; } else { this . grid . hide ( ) ; }
2012-02-14 06:14:13 +00:00
this . grid . refresh ( ) ; }
2012-05-07 12:30:57 +00:00
_f . TableField . prototype . set = function ( v ) { } ; _f . TableField . prototype . set _input = function ( v ) { } ; _f . CodeField = function ( ) { } ; _f . CodeField . prototype = new Field ( ) ; _f . CodeField . prototype . make _input = function ( ) { var me = this ; this . label _span . innerHTML = this . df . label ; if ( this . df . fieldtype == 'Text Editor' ) { this . input = $a ( this . input _area , 'text_area' , '' , { fontSize : '12px' } ) ; this . myid = wn . dom . set _unique _id ( this . input ) ; $ ( me . input ) . tinymce ( { script _url : 'js/lib/tiny_mce_33/tiny_mce.js' , theme : "advanced" , plugins : "style,inlinepopups,table" , extended _valid _elements : "div[id|dir|class|align|style]" , width : '100%' , height : '360px' , theme _advanced _buttons1 : "bold,italic,underline,strikethrough,hr,|,justifyleft,justifycenter,justifyright,|,formatselect,fontselect,fontsizeselect" , theme _advanced _buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,code,|,forecolor,backcolor,|,tablecontrols" , theme _advanced _buttons3 : "" , theme _advanced _toolbar _location : "top" , theme _advanced _toolbar _align : "left" , content _css : "js/lib/tiny_mce_33/custom_content.css" , oninit : function ( ) { me . init _editor ( ) ; } } ) ; this . input . set _input = function ( v ) { if ( me . editor ) { me . editor . setContent ( v ) ; } else { $ ( me . input ) . val ( v ) ; } }
2012-05-02 10:00:15 +00:00
this . input . onchange = function ( ) { me . set ( me . editor . getContent ( ) ) ; me . run _trigger ( ) ; }
2012-05-07 12:30:57 +00:00
this . get _value = function ( ) { return me . editor . getContent ( ) ; } } else { wn . require ( 'js/lib/ace/ace.js' ) ; $ ( this . input _area ) . css ( 'border' , '1px solid #aaa' ) ; this . pre = $a ( this . input _area , 'pre' , '' , { position : 'relative' , height : '400px' , width : '100%' } ) ; this . input = { } ; this . myid = wn . dom . set _unique _id ( this . pre ) ; this . editor = ace . edit ( this . myid ) ; if ( me . df . options == 'Markdown' || me . df . options == 'HTML' ) { wn . require ( 'js/lib/ace/mode-html.js' ) ; var HTMLMode = require ( "ace/mode/html" ) . Mode ; me . editor . getSession ( ) . setMode ( new HTMLMode ( ) ) ; }
else if ( me . df . options == 'Javascript' ) { wn . require ( 'js/lib/ace/mode-javascript.js' ) ; var JavascriptMode = require ( "ace/mode/javascript" ) . Mode ; me . editor . getSession ( ) . setMode ( new JavascriptMode ( ) ) ; }
else if ( me . df . options == 'Python' ) { wn . require ( 'js/lib/ace/mode-python.js' ) ; var PythonMode = require ( "ace/mode/python" ) . Mode ; me . editor . getSession ( ) . setMode ( new PythonMode ( ) ) ; }
2012-05-02 13:55:53 +00:00
this . input . set _input = function ( v ) { me . setting _value = true ; me . editor . getSession ( ) . setValue ( v ) ; me . setting _value = false ; }
2012-05-02 10:00:15 +00:00
this . get _value = function ( ) { return me . editor . getSession ( ) . getValue ( ) ; }
2012-05-02 13:55:53 +00:00
$ ( cur _frm . wrapper ) . bind ( 'render_complete' , function ( ) { me . editor . resize ( ) ; me . editor . getSession ( ) . on ( 'change' , function ( ) { if ( me . setting _value ) return ; var val = me . get _value ( ) ; if ( locals [ cur _frm . doctype ] [ cur _frm . docname ] [ me . df . fieldname ] != val ) { me . set ( me . get _value ( ) ) ; me . run _trigger ( ) ; } } ) } ) ; } }
2012-02-14 06:14:13 +00:00
_f . CodeField . prototype . init _editor = function ( ) { var me = this ; this . editor = tinymce . get ( this . myid ) ; this . editor . onKeyUp . add ( function ( ed , e ) { me . set ( ed . getContent ( ) ) ; } ) ; this . editor . onPaste . add ( function ( ed , e ) { me . set ( ed . getContent ( ) ) ; } ) ; this . editor . onSetContent . add ( function ( ed , e ) { me . set ( ed . getContent ( ) ) ; } ) ; var c = locals [ cur _frm . doctype ] [ cur _frm . docname ] [ this . df . fieldname ] ; if ( cur _frm && c ) { this . editor . setContent ( c ) ; } }
_f . CodeField . prototype . set _disp = function ( val ) { $y ( this . disp _area , { width : '90%' } )
if ( this . df . fieldtype == 'Text Editor' ) { this . disp _area . innerHTML = val ; } else { this . disp _area . innerHTML = '<textarea class="code_text" readonly=1>' + val + '</textarea>' ; } }
/ *
* lib / js / legacy / widgets / form / grid . js
* /
_f . cur _grid _cell = null ; _f . Grid = function ( parent ) { }
2012-02-17 08:34:55 +00:00
_f . Grid . prototype . init = function ( parent , row _height ) { var me = this ; this . col _idx _by _name = { }
this . alt _row _bg = '#F2F2FF' ; this . row _height = row _height ; if ( ! row _height ) this . row _height = '26px' ; this . make _ui ( parent ) ; this . insert _column ( '' , '' , 'Int' , 'Sr' , '50px' , '' , [ 1 , 0 , 0 ] ) ; if ( this . oninit ) this . oninit ( ) ; $ ( this . wrapper ) . bind ( 'keydown' , function ( e ) { me . notify _keypress ( e , e . which ) ; } )
$ ( cur _frm . wrapper ) . bind ( 'render_complete' , function ( ) { me . set _ht ( ) ; } ) ; }
_f . Grid . prototype . make _ui = function ( parent ) { var ht = make _table ( $a ( parent , 'div' ) , 1 , 2 , '100%' , [ '60%' , '40%' ] ) ; this . main _title = $td ( ht , 0 , 0 ) ; this . main _title . className = 'columnHeading' ; $td ( ht , 0 , 1 ) . style . textAlign = 'right' ; this . tbar _div = $a ( $td ( ht , 0 , 1 ) , 'div' , 'grid_tbarlinks' ) ; this . tbar _tab = make _table ( this . tbar _div , 1 , 4 , '100%' , [ '25%' , '25%' , '25%' , '25%' ] ) ; this . wrapper = $a ( parent , 'div' , 'grid_wrapper' ) ; this . head _wrapper = $a ( this . wrapper , 'div' , 'grid_head_wrapper' ) ; this . head _tab = $a ( this . head _wrapper , 'table' , 'grid_head_table' ) ; this . head _row = this . head _tab . insertRow ( 0 ) ; this . tab _wrapper = $a ( this . wrapper , 'div' , 'grid_tab_wrapper' ) ; this . tab = $a ( this . tab _wrapper , 'table' , 'grid_table' ) ; var me = this ; this . wrapper . onscroll = function ( ) { me . head _wrapper . style . top = me . wrapper . scrollTop + 'px' ; } }
2012-02-14 06:14:13 +00:00
_f . Grid . prototype . show = function ( ) { if ( this . can _edit && this . field . df [ 'default' ] . toLowerCase ( ) != 'no toolbar' ) { $ds ( this . tbar _div ) ; if ( this . can _add _rows ) { $td ( this . tbar _tab , 0 , 0 ) . style . display = 'table-cell' ; $td ( this . tbar _tab , 0 , 1 ) . style . display = 'table-cell' ; } else { $td ( this . tbar _tab , 0 , 0 ) . style . display = 'none' ; $td ( this . tbar _tab , 0 , 1 ) . style . display = 'none' ; } } else { $dh ( this . tbar _div ) ; }
$ds ( this . wrapper ) ; }
_f . Grid . prototype . hide = function ( ) { $dh ( this . wrapper ) ; $dh ( this . tbar _div ) ; }
_f . Grid . prototype . insert _column = function ( doctype , fieldname , fieldtype , label , width , options , perm , reqd ) { var idx = this . head _row . cells . length ; if ( ! width ) width = '100px' ; if ( ( width + '' ) . slice ( - 2 ) != 'px' ) { width = width + 'px' ; }
2012-02-27 07:14:28 +00:00
var col = this . head _row . insertCell ( idx ) ; col . doctype = doctype ; col . fieldname = fieldname ; col . fieldtype = fieldtype ; col . innerHTML = '<div data-grid-fieldname = "' + doctype + '-' + fieldname + '">' + label + '</div>' ; col . label = label ; if ( reqd )
2012-02-14 06:14:13 +00:00
col . childNodes [ 0 ] . style . color = "#D22" ; col . style . width = width ; col . options = options ; col . perm = perm ; this . col _idx _by _name [ fieldname ] = idx ; }
2012-03-22 06:29:46 +00:00
_f . Grid . prototype . reset _table _width = function ( ) { var w = 0 ; $ . each ( this . head _row . cells , function ( i , cell ) { if ( ( cell . style . display || '' ) . toLowerCase ( ) != 'none' )
w += cint ( cell . style . width ) ; } )
2012-02-14 06:14:13 +00:00
this . head _tab . style . width = w + 'px' ; this . tab . style . width = w + 'px' ; }
_f . Grid . prototype . set _column _disp = function ( fieldname , show ) { var cidx = this . col _idx _by _name [ fieldname ] ; if ( ! cidx ) { msgprint ( 'Trying to hide unknown column: ' + fieldname ) ; return ; }
var disp = show ? 'table-cell' : 'none' ; this . head _row . cells [ cidx ] . style . display = disp ; for ( var i = 0 , len = this . tab . rows . length ; i < len ; i ++ ) { var cell = this . tab . rows [ i ] . cells [ cidx ] ; cell . style . display = disp ; }
this . reset _table _width ( ) ; }
_f . Grid . prototype . append _row = function ( idx , docname ) { if ( ! idx ) idx = this . tab . rows . length ; var row = this . tab . insertRow ( idx ) ; row . docname = docname ; if ( idx % 2 ) var odd = true ; else var odd = false ; var me = this ; for ( var i = 0 ; i < this . head _row . cells . length ; i ++ ) { var cell = row . insertCell ( i ) ; var hc = this . head _row . cells [ i ] ; cell . style . width = hc . style . width ; cell . style . display = hc . style . display ; cell . row = row ; cell . grid = this ; cell . className = 'grid_cell' ; cell . div = $a ( cell , 'div' , 'grid_cell_div' ) ; if ( this . row _height ) { cell . div . style . height = this . row _height ; }
2012-02-17 08:34:55 +00:00
cell . div . cell = cell ; cell . div . onclick = function ( e ) { me . cell _select ( this . cell ) ; }
2012-02-14 06:14:13 +00:00
if ( odd ) { $bg ( cell , this . alt _row _bg ) ; cell . is _odd = 1 ; cell . div . style . border = '2px solid ' + this . alt _row _bg ; } else $bg ( cell , '#FFF' ) ; if ( ! hc . fieldname ) cell . div . style . cursor = 'default' ; }
this . set _ht ( ) ; return row ; }
_f . Grid . prototype . refresh _cell = function ( docname , fieldname ) { for ( var r = 0 ; r < this . tab . rows . length ; r ++ ) { if ( this . tab . rows [ r ] . docname == docname ) { for ( var c = 0 ; c < this . head _row . cells . length ; c ++ ) { var hc = this . head _row . cells [ c ] ; if ( hc . fieldname == fieldname ) { this . set _cell _value ( this . tab . rows [ r ] . cells [ c ] ) ; } } } } }
_f . cur _grid ; _f . cur _grid _ridx ; _f . Grid . prototype . set _cell _value = function ( cell ) { if ( cell . row . is _newrow ) return ; var hc = this . head _row . cells [ cell . cellIndex ] ; if ( hc . fieldname ) { var v = locals [ hc . doctype ] [ cell . row . docname ] [ hc . fieldname ] ; } else { var v = ( cell . row . rowIndex + 1 ) ; }
if ( v == null ) { v = '' ; }
2012-02-24 11:06:58 +00:00
var me = this ; if ( cell . cellIndex ) { var ft = hc . fieldtype ; if ( ft == 'Link' && cur _frm . doc . docstatus < 1 ) ft = 'Data' ; $s ( cell . div , v , ft , hc . options ) ; } else { cell . div . style . padding = '2px' ; cell . div . style . textAlign = 'left' ; cell . innerHTML = '' ; var t = make _table ( cell , 1 , 3 , '60px' , [ '20px' , '20px' , '20px' ] , { verticalAlign : 'middle' , padding : '2px' } ) ; $y ( $td ( t , 0 , 0 ) , { paddingLeft : '4px' } ) ; $td ( t , 0 , 0 ) . innerHTML = cell . row . rowIndex + 1 ; if ( cur _frm . editable && this . can _edit ) { var ed = $a ( $td ( t , 0 , 1 ) , 'i' , 'icon-edit' , { cursor : 'pointer' } ) ; ed . cell = cell ; ed . title = 'Edit Row' ; ed . onclick = function ( ) { _f . cur _grid = me ; _f . cur _grid _ridx = this . cell . row . rowIndex ; _f . edit _record ( me . doctype , this . cell . row . docname , 1 ) ; } } else { cell . div . innerHTML = ( cell . row . rowIndex + 1 ) ; cell . div . style . cursor = 'default' ; cell . div . onclick = function ( ) { } } } }
2012-04-30 08:52:02 +00:00
$ ( document ) . bind ( 'click' , function ( e ) { var me = this ; var is _target _toolbar = function ( ) { return $ ( e . target ) . parents ( '.grid_tbarlinks' ) . length ; }
2012-03-22 06:07:08 +00:00
var is _target _input = function ( ) { if ( e . target . tagName . toLowerCase ( ) == 'option' ) return true ; return $ ( e . target ) . parents ( ) . get ( ) . indexOf ( _f . cur _grid _cell ) != - 1 ; }
2012-03-23 10:24:49 +00:00
if ( _f . cur _grid _cell && ! is _target _input ( ) && ! is _target _toolbar ( ) ) { if ( ! ( text _dialog && text _dialog . display ) && ! datepicker _active && ! ( selector && selector . display ) ) { setTimeout ( '_f.cur_grid_cell.grid.cell_deselect()' , 500 ) ; return false ; } } } ) ; _f . Grid . prototype . cell _deselect = function ( ) { if ( _f . cur _grid _cell ) { var c = _f . cur _grid _cell ; c . grid . remove _template ( c ) ; c . div . className = 'grid_cell_div' ; if ( c . is _odd ) c . div . style . border = '2px solid ' + c . grid . alt _row _bg ; else c . div . style . border = '2px solid #FFF' ; _f . cur _grid _cell = null ; } }
2012-04-30 08:52:02 +00:00
_f . Grid . prototype . cell _select = function ( cell , ri , ci ) { if ( _f . cur _grid _cell == cell && cell . hc ) return ; if ( ri != null && ci != null )
2012-02-14 06:14:13 +00:00
cell = this . tab . rows [ ri ] . cells [ ci ] ; var hc = this . head _row . cells [ cell . cellIndex ] ; if ( ! hc . template ) { this . make _template ( hc ) ; }
2012-02-17 08:34:55 +00:00
hc . template . perm = this . field ? this . field . perm : hc . perm ; if ( hc . fieldname && hc . template . get _status ( ) == 'Write' ) { this . cell _deselect ( ) ; cell . div . style . border = '2px solid #88F' ; _f . cur _grid _cell = cell ; this . add _template ( cell ) ; } }
2012-04-30 08:52:02 +00:00
_f . Grid . prototype . add _template = function ( cell ) { if ( ! cell . row . docname && this . add _newrow ) { this . add _newrow ( ) ; this . cell _select ( cell ) ; } else { var hc = this . head _row . cells [ cell . cellIndex ] ; cell . div . innerHTML = '' ; cell . div . appendChild ( hc . template . wrapper ) ; hc . template . activate ( cell . row . docname ) ; hc . template . activated = 1 ; cell . hc = hc ; if ( hc . template . input && hc . template . input . set _width ) { hc . template . input . set _width ( $ ( cell ) . width ( ) ) ; } } }
2012-02-14 06:14:13 +00:00
_f . Grid . prototype . get _field = function ( fieldname ) { for ( var i = 0 ; i < this . head _row . cells . length ; i ++ ) { var hc = this . head _row . cells [ i ] ; if ( hc . fieldname == fieldname ) { if ( ! hc . template ) { this . make _template ( hc ) ; }
return hc . template ; } }
return { } }
_f . grid _date _cell = '' ; _f . grid _refresh _date = function ( ) { _f . grid _date _cell . grid . set _cell _value ( _f . grid _date _cell ) ; }
2012-04-30 08:52:02 +00:00
_f . grid _refresh _field = function ( temp , input ) { if ( $ ( input ) . val ( ) != _f . get _value ( temp . doctype , temp . docname , temp . df . fieldname ) )
$ ( input ) . trigger ( 'change' ) ; }
2012-05-03 06:18:43 +00:00
_f . Grid . prototype . remove _template = function ( cell ) { var hc = this . head _row . cells [ cell . cellIndex ] ; if ( ! hc . template ) return ; if ( ! hc . template . activated ) return ; if ( hc . template && hc . template . wrapper . parentNode )
2012-02-17 08:34:55 +00:00
cell . div . removeChild ( hc . template . wrapper ) ; this . set _cell _value ( cell ) ; hc . template . activated = 0 ; }
2012-02-14 06:14:13 +00:00
_f . Grid . prototype . notify _keypress = function ( e , keycode ) { if ( keycode >= 37 && keycode <= 40 && e . shiftKey ) { if ( text _dialog && text _dialog . display ) { return ; } } else
return ; if ( ! _f . cur _grid _cell ) return ; if ( _f . cur _grid _cell . grid != this ) return ; var ri = _f . cur _grid _cell . row . rowIndex ; var ci = _f . cur _grid _cell . cellIndex ; switch ( keycode ) { case 38 : if ( ri > 0 ) { this . cell _select ( '' , ri - 1 , ci ) ; } break ; case 40 : if ( ri < ( this . tab . rows . length - 1 ) ) { this . cell _select ( '' , ri + 1 , ci ) ; } break ; case 39 : if ( ci < ( this . head _row . cells . length - 1 ) ) { this . cell _select ( '' , ri , ci + 1 ) ; } break ; case 37 : if ( ci > 1 ) { this . cell _select ( '' , ri , ci - 1 ) ; } break ; } }
_f . Grid . prototype . make _template = function ( hc ) { hc . template = make _field ( get _field ( hc . doctype , hc . fieldname ) , hc . doctype , '' , this . field . frm , true ) ; hc . template . grid = this ; }
_f . Grid . prototype . append _rows = function ( n ) { for ( var i = 0 ; i < n ; i ++ ) this . append _row ( ) ; }
_f . Grid . prototype . truncate _rows = function ( n ) { for ( var i = 0 ; i < n ; i ++ ) this . tab . deleteRow ( this . tab . rows . length - 1 ) ; }
_f . Grid . prototype . set _data = function ( data ) { this . cell _deselect ( ) ; this . reset _table _width ( ) ; if ( data . length > this . tab . rows . length )
this . append _rows ( data . length - this . tab . rows . length ) ; if ( data . length < this . tab . rows . length )
this . truncate _rows ( this . tab . rows . length - data . length ) ; for ( var ridx = 0 ; ridx < data . length ; ridx ++ ) { this . refresh _row ( ridx , data [ ridx ] ) ; }
if ( this . can _add _rows && this . make _newrow ) { this . make _newrow ( ) ; }
if ( this . wrapper . onscroll ) this . wrapper . onscroll ( ) ; }
_f . Grid . prototype . set _ht = function ( ) { var max _ht = cint ( 0.37 * screen . width ) ; var ht = $ ( this . tab ) . height ( ) + $ ( this . head _tab ) . height ( ) + 30 ; if ( ht < 100 )
ht = 100 ; if ( ht > max _ht ) ht = max _ht ; ht += 4 ; $y ( this . wrapper , { height : ht + 'px' } ) ; }
_f . Grid . prototype . refresh _row = function ( ridx , docname ) { var row = this . tab . rows [ ridx ] ; row . docname = docname ; row . is _newrow = false ; for ( var cidx = 0 ; cidx < row . cells . length ; cidx ++ ) { this . set _cell _value ( row . cells [ cidx ] ) ; } }
/ *
* lib / js / legacy / widgets / form / form _grid . js
* /
_f . FormGrid = function ( field ) { this . field = field ; this . doctype = field . df . options ; if ( ! this . doctype ) { show _alert ( 'No Options for table ' + field . df . label ) ; }
this . col _break _width = cint ( this . field . col _break _width ) ; if ( ! this . col _break _width ) this . col _break _width = 100 ; $y ( field . parent , { marginTop : '8px' } ) ; this . init ( field . parent , field . df . width ) ; this . setup ( ) ; }
_f . FormGrid . prototype = new _f . Grid ( ) ; _f . FormGrid . prototype . setup = function ( ) { this . make _columns ( ) ; }
2012-02-24 11:06:58 +00:00
_f . FormGrid . prototype . make _tbar _link = function ( parent , label , fn , icon ) { var div = $a ( parent , 'div' , '' , { cursor : 'pointer' } ) ; var t = make _table ( div , 1 , 2 , '90%' , [ '20px' , null ] ) ; var img = $a ( $td ( t , 0 , 0 ) , 'i' , icon ) ; $y ( $td ( t , 0 , 0 ) , { textAlign : 'right' } ) ; var l = $a ( $td ( t , 0 , 1 ) , 'span' , 'link_type' , { color : '#333' } ) ; l . style . fontSize = '11px' ; l . innerHTML = label ; div . onclick = fn ; div . show = function ( ) { $ds ( this ) ; }
2012-02-14 06:14:13 +00:00
div . hide = function ( ) { $dh ( this ) ; }
$td ( t , 0 , 0 ) . isactive = 1 ; $td ( t , 0 , 1 ) . isactive = 1 ; l . isactive = 1 ; div . isactive = 1 ; img . isactive = 1 ; return div ; }
2012-02-24 11:06:58 +00:00
_f . FormGrid . prototype . make _buttons = function ( ) { var me = this ; this . tbar _btns = { } ; this . tbar _btns [ 'Del' ] = this . make _tbar _link ( $td ( this . tbar _tab , 0 , 0 ) , 'Del' , function ( ) { me . delete _row ( ) ; } , 'icon-remove-sign' ) ; this . tbar _btns [ 'Ins' ] = this . make _tbar _link ( $td ( this . tbar _tab , 0 , 1 ) , 'Ins' , function ( ) { me . insert _row ( ) ; } , 'icon-plus' ) ; this . tbar _btns [ 'Up' ] = this . make _tbar _link ( $td ( this . tbar _tab , 0 , 2 ) , 'Up' , function ( ) { me . move _row ( true ) ; } , 'icon-arrow-up' ) ; this . tbar _btns [ 'Dn' ] = this . make _tbar _link ( $td ( this . tbar _tab , 0 , 3 ) , 'Dn' , function ( ) { me . move _row ( false ) ; } , 'icon-arrow-down' ) ; for ( var i in this . btns )
2012-02-14 06:14:13 +00:00
this . btns [ i ] . isactive = true ; }
2012-04-19 12:18:57 +00:00
_f . FormGrid . prototype . make _columns = function ( ) { var gl = wn . meta . docfield _list [ this . field . df . options ] ; if ( ! gl ) { alert ( 'Table details not found "' + this . field . df . options + '"' ) ; }
2012-02-14 06:14:13 +00:00
gl . sort ( function ( a , b ) { return a . idx - b . idx } ) ; var p = this . field . perm ; for ( var i = 0 ; i < gl . length ; i ++ ) { if ( p [ this . field . df . permlevel ] && p [ this . field . df . permlevel ] [ READ ] ) { this . insert _column ( this . field . df . options , gl [ i ] . fieldname , gl [ i ] . fieldtype , gl [ i ] . label , gl [ i ] . width , gl [ i ] . options , this . field . perm , gl [ i ] . reqd ) ; if ( gl [ i ] . hidden ) { this . set _column _disp ( gl [ i ] . fieldname , false ) ; } } } }
_f . FormGrid . prototype . set _column _label = function ( fieldname , label ) { for ( var i = 0 ; i < this . head _row . cells . length ; i ++ ) { var c = this . head _row . cells [ i ] ; if ( c . fieldname == fieldname ) { c . innerHTML = '<div class="grid_head_div">' + label + '</div>' ; c . cur _label = label ; break ; } } }
2012-03-13 09:49:06 +00:00
_f . FormGrid . prototype . get _children = function ( ) { return getchildren ( this . doctype , this . field . frm . docname , this . field . df . fieldname , this . field . frm . doctype ) ; }
_f . FormGrid . prototype . refresh = function ( ) { var docset = this . get _children ( ) ; var data = [ ] ; for ( var i = 0 ; i < docset . length ; i ++ ) { locals [ this . doctype ] [ docset [ i ] . name ] . idx = i + 1 ; data [ data . length ] = docset [ i ] . name ; }
2012-02-20 07:05:23 +00:00
this . set _data ( data ) ; if ( _f . frm _dialog && _f . frm _dialog . dialog . display && _f . frm _dialog . cur _frm ) { _f . frm _dialog . cur _frm . refresh ( ) ; } }
2012-04-13 06:11:43 +00:00
_f . FormGrid . prototype . set _unsaved = function ( ) { locals [ cur _frm . doctype ] [ cur _frm . docname ] . _ _unsaved = 1 ; cur _frm . frm _head && cur _frm . frm _head . refresh _labels ( ) ; }
2012-02-14 06:14:13 +00:00
_f . FormGrid . prototype . insert _row = function ( ) { var d = this . new _row _doc ( ) ; var ci = _f . cur _grid _cell . cellIndex ; var row _idx = _f . cur _grid _cell . row . rowIndex ; d . idx = row _idx + 1 ; for ( var ri = row _idx ; ri < this . tab . rows . length ; ri ++ ) { var r = this . tab . rows [ ri ] ; if ( r . docname )
locals [ this . doctype ] [ r . docname ] . idx ++ ; }
this . refresh ( ) ; this . cell _select ( '' , row _idx , ci ) ; this . set _unsaved ( ) ; }
_f . FormGrid . prototype . new _row _doc = function ( ) { var n = LocalDB . create ( this . doctype ) ; var d = locals [ this . doctype ] [ n ] ; d . parent = this . field . frm . docname ; d . parentfield = this . field . df . fieldname ; d . parenttype = this . field . frm . doctype ; return d ; }
_f . FormGrid . prototype . add _newrow = function ( ) { var r = this . tab . rows [ this . tab . rows . length - 1 ] ; if ( ! r . is _newrow )
show _alert ( 'fn: add_newrow: Adding a row which is not flagged as new' ) ; var d = this . new _row _doc ( ) ; d . idx = r . rowIndex + 1 ; r . docname = d . name ; r . is _newrow = false ; this . set _cell _value ( r . cells [ 0 ] ) ; this . make _newrow ( ) ; this . refresh _row ( r . rowIndex , d . name ) ; if ( this . onrowadd ) this . onrowadd ( cur _frm . doc , d . doctype , d . name ) ; return d . name ; }
_f . FormGrid . prototype . make _newrow = function ( from _add _btn ) { if ( ! this . can _add _rows )
return ; if ( this . tab . rows . length ) { var r = this . tab . rows [ this . tab . rows . length - 1 ] ; if ( r . is _newrow )
return ; }
var r = this . append _row ( ) ; r . cells [ 0 ] . div . innerHTML = '<b style="font-size: 18px;">*</b>' ; r . is _newrow = true ; }
_f . FormGrid . prototype . check _selected = function ( ) { if ( ! _f . cur _grid _cell ) { show _alert ( 'Select a cell first' ) ; return false ; }
if ( _f . cur _grid _cell . grid != this ) { show _alert ( 'Select a cell first' ) ; return false ; }
return true ; }
_f . FormGrid . prototype . delete _row = function ( dt , dn ) { if ( dt && dn ) { LocalDB . delete _record ( dt , dn ) ; this . refresh ( ) ; } else { if ( ! this . check _selected ( ) ) return ; var r = _f . cur _grid _cell . row ; if ( r . is _newrow ) return ; var ci = _f . cur _grid _cell . cellIndex ; var ri = _f . cur _grid _cell . row . rowIndex ; LocalDB . delete _record ( this . doctype , r . docname ) ; this . refresh ( ) ; if ( ri < ( this . tab . rows . length - 2 ) )
this . cell _select ( null , ri , ci ) ; else _f . cur _grid _cell = null ; }
this . set _unsaved ( ) ; }
_f . FormGrid . prototype . move _row = function ( up ) { if ( ! this . check _selected ( ) ) return ; var r = _f . cur _grid _cell . row ; if ( r . is _newrow ) return ; if ( up && r . rowIndex > 0 ) { var swap _row = this . tab . rows [ r . rowIndex - 1 ] ; } else if ( ! up ) { var len = this . tab . rows . length ; if ( this . tab . rows [ len - 1 ] . is _newrow )
len = len - 1 ; if ( r . rowIndex < ( len - 1 ) )
var swap _row = this . tab . rows [ r . rowIndex + 1 ] ; }
if ( swap _row ) { var cidx = _f . cur _grid _cell . cellIndex ; this . cell _deselect ( ) ; var aidx = locals [ this . doctype ] [ r . docname ] . idx ; locals [ this . doctype ] [ r . docname ] . idx = locals [ this . doctype ] [ swap _row . docname ] . idx ; locals [ this . doctype ] [ swap _row . docname ] . idx = aidx ; var adocname = swap _row . docname ; this . refresh _row ( swap _row . rowIndex , r . docname ) ; this . refresh _row ( r . rowIndex , adocname ) ; this . cell _select ( this . tab . rows [ swap _row . rowIndex ] . cells [ cidx ] ) ; this . set _unsaved ( ) ; } }
/ *
* lib / js / legacy / widgets / form / print _format . js
* /
2012-04-16 05:48:45 +00:00
_p . def _print _style _body = "html, body, div, span, td { font-family: Arial, Helvetica; font-size: 12px; }" + "\npre { margin:0; padding:0;}"
_p . def _print _style _other = "\n.simpletable, .noborder { border-collapse: collapse; margin-bottom: 10px;}"
+ "\n.simpletable td {border: 1pt solid #000; vertical-align: top; padding: 2px; }"
+ "\n.noborder td { vertical-align: top; }"
_p . go = function ( html ) { var d = document . createElement ( 'div' )
d . innerHTML = html
$ ( d ) . printElement ( ) ; }
2012-05-04 07:34:40 +00:00
_p . preview = function ( html ) { var w = window . open ( '' ) ; if ( ! w ) return ; w . document . write ( html )
2012-04-16 05:48:45 +00:00
w . document . close ( ) ; }
2012-02-14 06:14:13 +00:00
$ . extend ( _p , { show _dialog : function ( ) { if ( ! _p . dialog ) { _p . make _dialog ( ) ; }
_p . dialog . show ( ) ; } , make _dialog : function ( ) { var d = new Dialog ( 360 , 140 , 'Print Formats' , [ [ 'HTML' , 'Select' ] , [ 'Check' , 'No Letterhead' ] , [ 'HTML' , 'Buttons' ] ] ) ; $btn ( d . widgets . Buttons , 'Print' , function ( ) { _p . build ( sel _val ( cur _frm . print _sel ) , _p . go , d . widgets [ 'No Letterhead' ] . checked ) ; } , { cssFloat : 'right' , marginBottom : '16px' , marginLeft : '7px' } , 'green' ) ; $btn ( d . widgets . Buttons , 'Preview' , function ( ) { _p . build ( sel _val ( cur _frm . print _sel ) , _p . preview , d . widgets [ 'No Letterhead' ] . checked ) ; } , { cssFloat : 'right' , marginBottom : '16px' } , '' ) ; d . onshow = function ( ) { var c = _p . dialog . widgets [ 'Select' ] ; if ( c . cur _sel && c . cur _sel . parentNode == c ) { c . removeChild ( c . cur _sel ) ; }
c . appendChild ( cur _frm . print _sel ) ; c . cur _sel = cur _frm . print _sel ; }
_p . dialog = d ; } , formats : { } , build : function ( fmtname , onload , no _letterhead , only _body ) { args = { fmtname : fmtname , onload : onload , no _letterhead : no _letterhead , only _body : only _body } ; if ( ! cur _frm ) { alert ( 'No Document Selected' ) ; return ; }
var doc = locals [ cur _frm . doctype ] [ cur _frm . docname ] ; if ( args . fmtname == 'Standard' ) { args . onload ( _p . render ( { body : _p . print _std ( args . no _letterhead ) , style : _p . print _style , doc : doc , title : doc . name , no _letterhead : args . no _letterhead , only _body : args . only _body } ) ) ; } else { if ( ! _p . formats [ args . fmtname ] ) { var build _args = args ; $c ( command = 'webnotes.widgets.form.print_format.get' , args = { 'name' : build _args . fmtname } , fn = function ( r , rt ) { _p . formats [ build _args . fmtname ] = r . message ; build _args . onload ( _p . render ( { body : _p . formats [ build _args . fmtname ] , style : '' , doc : doc , title : doc . name , no _letterhead : build _args . no _letterhead , only _body : build _args . only _body } ) ) ; } ) ; } else { args . onload ( _p . render ( { body : _p . formats [ args . fmtname ] , style : '' , doc : doc , title : doc . name , no _letterhead : args . no _letterhead , only _body : args . only _body } ) ) ; } } } , render : function ( args ) { var container = document . createElement ( 'div' ) ; var stat = '' ; stat += _p . show _draft ( args ) ; stat += _p . show _archived ( args ) ; stat += _p . show _cancelled ( args ) ; container . innerHTML = args . body ; _p . show _letterhead ( container , args ) ; _p . run _embedded _js ( container , args . doc ) ; var style = _p . consolidate _css ( container , args ) ; _p . render _header _on _break ( container , args ) ; return _p . render _final ( style , stat , container , args ) ; } , head _banner _format : function ( ) { return " \
< div style = ' \
text - align : center ; \
padding : 8 px ; \
background - color : # CCC ; ' > \
< div style = ' \
font - size : 20 px ; \
font - weight : bold ; ' > \
{ { HEAD } } \
< / d i v > \
{ { DESCRIPTION } } \
< / d i v > " } , s h o w _ d r a f t : f u n c t i o n ( a r g s ) { v a r i s _ d o c t y p e _ s u b m i t t a b l e = 0 ; v a r p l i s t = l o c a l s [ ' D o c P e r m ' ] ; f o r ( v a r p e r m i n p l i s t ) { v a r p = p l i s t [ p e r m ] ; i f ( ( p . p a r e n t = = a r g s . d o c . d o c t y p e ) & & ( p . s u b m i t = = 1 ) ) { i s _ d o c t y p e _ s u b m i t t a b l e = 1 ; b r e a k ; } }
if ( args . doc && cint ( args . doc . docstatus ) == 0 && is _doctype _submittable ) { draft = _p . head _banner _format ( ) ; draft = draft . replace ( "{{HEAD}}" , "DRAFT" ) ; draft = draft . replace ( "{{DESCRIPTION}}" , "This box will go away after the document is submitted." ) ; return draft ; } else { return "" ; } } , show _archived : function ( args ) { if ( args . doc && args . doc . _ _archived ) { archived = _p . head _banner _format ( ) ; archived = archived . replace ( "{{HEAD}}" , "ARCHIVED" ) ; archived = archived . replace ( "{{DESCRIPTION}}" , "You must restore this document to make it editable." ) ; return archived ; } else { return "" ; } } , show _cancelled : function ( args ) { if ( args . doc && args . doc . docstatus == 2 ) { cancelled = _p . head _banner _format ( ) ; cancelled = cancelled . replace ( "{{HEAD}}" , "CANCELLED" ) ; cancelled = cancelled . replace ( "{{DESCRIPTION}}" , "You must amend this document to make it editable." ) ; return cancelled ; } else { return "" ; } } , consolidate _css : function ( container , args ) { var body _style = '' ; var style _list = container . getElementsByTagName ( 'style' ) ; while ( style _list && style _list . length > 0 ) { for ( i in style _list ) { if ( style _list [ i ] && style _list [ i ] . innerHTML ) { body _style += style _list [ i ] . innerHTML ; var parent = style _list [ i ] . parentNode ; if ( parent ) { parent . removeChild ( style _list [ i ] ) ; } else { container . removeChild ( style _list [ i ] ) ; } } }
style _list = container . getElementsByTagName ( 'style' ) ; }
style _concat = ( args . only _body ? '' : _p . def _print _style _body )
+ _p . def _print _style _other + args . style + body _style ; return style _concat ; } , run _embedded _js : function ( container , doc ) { var jslist = container . getElementsByTagName ( 'script' ) ; while ( jslist && jslist . length > 0 ) { for ( i in jslist ) { if ( jslist [ i ] && jslist [ i ] . innerHTML ) { var code = jslist [ i ] . innerHTML ; var parent = jslist [ i ] . parentNode ; var span = $a ( parent , 'span' ) ; parent . replaceChild ( span , jslist [ i ] ) ; var val = code ? eval ( code ) : '' ; if ( ! val || typeof ( val ) == 'object' ) { val = '' ; }
span . innerHTML = val ; } }
jslist = container . getElementsByTagName ( 'script' ) ; } } , show _letterhead : function ( container , args ) { if ( ! ( args . no _letterhead || args . only _body ) ) { container . innerHTML = '<div>' + _p . get _letter _head ( ) + '</div>'
+ container . innerHTML ; } } , render _header _on _break : function ( container , args ) { var page _set = container . getElementsByClassName ( 'page-settings' ) ; if ( page _set . length ) { for ( var i = 0 ; i < page _set . length ; i ++ ) { var tmp = '' ; tmp += _p . show _draft ( args ) ; tmp += _p . show _archived ( args ) ; _p . show _letterhead ( page _set [ i ] , args ) ; page _set [ i ] . innerHTML = tmp + page _set [ i ] . innerHTML ; } } } , render _final : function ( style , stat , container , args ) { var header = '<div class="page-settings">\n' ; var footer = '\n</div>' ; if ( ! args . only _body ) { header = ' < ! DOCTYPE html > \ n \
< html > \
< head > \
< title > '+args.title+' < / t i t l e > \
< style > '+style+' < / s t y l e > \
< / h e a d > \
< body > \ n '+header;footer=footer+' \ n < / b o d y > \ n \
< / h t m l > ' ; }
var finished = header
+ stat
+ container . innerHTML . replace ( /<div/g , '\n<div' ) . replace ( /<td/g , '\n<td' )
2012-04-16 05:48:45 +00:00
+ footer ; return finished ; } , get _letter _head : function ( ) { var cp = wn . control _panel ; var lh = '' ; if ( cur _frm . doc . letter _head ) { lh = cstr ( wn . boot . letter _heads [ cur _frm . doc . letter _head ] ) ; } else if ( cp . letter _head ) { lh = cp . letter _head ; }
2012-02-14 06:14:13 +00:00
return lh ; } , print _style : " \
. datalabelcell { \
padding : 2 px 0 px ; \
width : 38 % ; \
vertical - align : top ; \
} \
. datainputcell { \
padding : 2 px 0 px ; \
width : 62 % ; \
text - align : left ; \
} \
. sectionHeading { \
font - size : 16 px ; \
font - weight : bold ; \
margin : 8 px 0 px ; \
} \
. columnHeading { \
font - size : 14 px ; \
font - weight : bold ; \
margin : 8 px 0 px ; \
2012-06-08 07:04:57 +00:00
} " , print _std : function ( no _letterhead ) { var docname = cur _frm . docname ; var doctype = cur _frm . doctype ; var data = getchildren ( 'DocField' , doctype , 'fields' , 'DocType' ) ; var layout = _p . add _layout ( doctype ) ; this . pf _list = [ layout ] ; var me = this ; me . layout = layout ; $ . extend ( this , { build _head : function ( data , doctype , docname ) { var h1 _style = { fontSize : '22px' , marginBottom : '8px' }
var h1 = $a ( me . layout . cur _row . header , 'h1' , '' , h1 _style ) ; if ( cur _frm . pformat [ docname ] ) { h1 . innerHTML = cur _frm . pformat [ docname ] ; } else { var val = null ; for ( var i = 0 ; i < data . length ; i ++ ) { if ( data [ i ] . fieldname === 'select_print_heading' ) { val = _f . get _value ( doctype , docname , data [ i ] . fieldname ) ; break ; } }
h1 . innerHTML = val ? val : get _doctype _label ( doctype ) ; }
var h2 _style = { fontSize : '16px' , color : '#888' , marginBottom : '8px' , paddingBottom : '8px' , borderBottom : ( me . layout . with _border ? '0px' : '1px solid #000' ) }
2012-02-14 06:14:13 +00:00
var h2 = $a ( me . layout . cur _row . header , 'div' , '' , h2 _style ) ; h2 . innerHTML = docname ; } , build _data : function ( data , doctype , docname ) { if ( data [ 0 ] && data [ 0 ] . fieldtype != "Section Break" ) { me . layout . addrow ( ) ; if ( data [ 0 ] . fieldtype != "Column Break" ) { me . layout . addcell ( ) ; } }
$ . extend ( this , { generate _custom _html : function ( field , doctype , docname ) { var container = $a ( me . layout . cur _cell , 'div' ) ; container . innerHTML = cur _frm . pformat [ field . fieldname ] ( locals [ doctype ] [ docname ] ) ; } , render _normal : function ( field , data , i ) { switch ( field . fieldtype ) { case 'Section Break' : me . layout . addrow ( ) ; if ( data [ i + 1 ] && data [ i + 1 ] . fieldtype != 'Column Break' ) { me . layout . addcell ( ) ; }
break ; case 'Column Break' : me . layout . addcell ( field . width , field . label ) ; break ; case 'Table' : var table = print _table ( doctype , docname , field . fieldname , field . options , null , null , null , null ) ; me . layout = _p . print _std _add _table ( table , me . layout , me . pf _list , doctype , no _letterhead ) ; break ; case 'HTML' : var div = $a ( me . layout . cur _cell , 'div' ) ; div . innerHTML = field . options ; break ; case 'Code' : var div = $a ( me . layout . cur _cell , 'div' ) ; var val = _f . get _value ( doctype , docname , field . fieldname ) ; div . innerHTML = '<div>' + field . label + ': </div><pre style="font-family: Courier, Fixed;">' + ( val ? val : '' ) + '</pre>' ; break ; case 'Text Editor' : var div = $a ( me . layout . cur _cell , 'div' ) ; var val = _f . get _value ( doctype , docname , field . fieldname ) ; div . innerHTML = val ? val : '' ; break ; default : _p . print _std _add _field ( doctype , docname , field , me . layout ) ; break ; } } } ) ; for ( var i = 0 ; i < data . length ; i ++ ) { var fieldname = data [ i ] . fieldname ? data [ i ] . fieldname : data [ i ] . label ; var field = fieldname ? get _field ( doctype , fieldname , docname ) : data [ i ] ; if ( ! field . print _hide ) { if ( cur _frm . pformat [ field . fieldname ] ) { this . generate _custom _html ( field , doctype , docname ) ; } else { this . render _normal ( field , data , i ) ; } } }
me . layout . close _borders ( ) ; } , build _html : function ( ) { var html = '' ; for ( var i = 0 ; i < me . pf _list . length ; i ++ ) { if ( me . pf _list [ i ] . wrapper ) { html += me . pf _list [ i ] . wrapper . innerHTML ; } else if ( me . pf _list [ i ] . innerHTML ) { html += me . pf _list [ i ] . innerHTML ; } else { html += me . pf _list [ i ] ; } }
2012-06-08 07:04:57 +00:00
this . pf _list = [ ] ; return html ; } } ) ; this . build _head ( data , doctype , docname ) ; this . build _data ( data , doctype , docname ) ; var html = this . build _html ( ) ; return html ; } , add _layout : function ( doctype ) { var layout = new Layout ( ) ; layout . addrow ( ) ; if ( locals [ 'DocType' ] [ doctype ] . print _outline == 'Yes' ) { layout . with _border = 1 }
2012-02-14 06:14:13 +00:00
return layout ; } , print _std _add _table : function ( t , layout , pf _list , dt , no _letterhead ) { if ( t . appendChild ) { layout . cur _cell . appendChild ( t ) ; } else { page _break = ' \ n \
< div style = "page-break-after: always;" \
class = "page_break" > < / d i v > < d i v c l a s s = " p a g e - s e t t i n g s " > < / d i v > ' ; f o r ( v a r i = 0 ; i < t . l e n g t h - 1 ; i + + ) { l a y o u t . c u r _ c e l l . a p p e n d C h i l d ( t [ i ] ) ; l a y o u t . c l o s e _ b o r d e r s ( ) ; p f _ l i s t . p u s h ( p a g e _ b r e a k ) ; l a y o u t = _ p . a d d _ l a y o u t ( d t , n o _ l e t t e r h e a d ) ; p f _ l i s t . p u s h ( l a y o u t ) ; l a y o u t . a d d r o w ( ) ; l a y o u t . a d d c e l l ( ) ; v a r d i v = $ a ( l a y o u t . c u r _ c e l l , ' d i v ' ) ; d i v . i n n e r H T M L = ' C o n t i n u e d f r o m p r e v i o u s p a g e . . . ' ; d i v . s t y l e . p a d d i n g = ' 4 p x ' ; }
layout . cur _cell . appendChild ( t [ t . length - 1 ] ) ; }
2012-04-19 12:18:57 +00:00
return layout ; } , print _std _add _field : function ( dt , dn , f , layout ) { var val = _f . get _value ( dt , dn , f . fieldname ) ; if ( f . fieldtype != 'Button' ) { if ( val || in _list ( [ 'Float' , 'Int' , 'Currency' ] , f . fieldtype ) ) { row = _p . field _tab ( layout . cur _cell ) ; row . cells [ 0 ] . innerHTML = f . label ? f . label : f . fieldname ; $s ( row . cells [ 1 ] , val , f . fieldtype ) ; if ( f . fieldtype == 'Currency' ) { $y ( row . cells [ 1 ] , { textAlign : 'left' } ) ; } } } } , field _tab : function ( layout _cell ) { var tab = $a ( layout _cell , 'table' , '' , { width : '100%' } ) ; var row = tab . insertRow ( 0 ) ; _p . row = row ; row . insertCell ( 0 ) ; row . insertCell ( 1 ) ; row . cells [ 0 ] . className = 'datalabelcell' ; row . cells [ 1 ] . className = 'datainputcell' ; return row ; } } ) ; print _table = function ( dt , dn , fieldname , tabletype , cols , head _labels , widths , condition , cssClass , modifier , hide _empty ) { var me = this ; $ . extend ( this , { flist : ( function ( ) { var f _list = [ ] ; var fl = wn . meta . docfield _list [ tabletype ] ; if ( fl ) { for ( var i = 0 ; i < fl . length ; i ++ ) { f _list . push ( copy _dict ( fl [ i ] ) ) ; } }
2012-02-14 06:14:13 +00:00
return f _list ; } ) ( ) , data : function ( ) { var children = getchildren ( tabletype , dn , fieldname , dt ) ; var data = [ ]
for ( var i = 0 ; i < children . length ; i ++ ) { data . push ( copy _dict ( children [ i ] ) ) ; }
return data ; } ( ) , cell _style : { border : '1px solid #000' , padding : '2px' , verticalAlign : 'top' } , head _cell _style : { border : '1px solid #000' , padding : '2px' , verticalAlign : 'top' , backgroundColor : '#ddd' , fontWeight : 'bold' } , table _style : { width : '100%' , borderCollapse : 'collapse' , marginBottom : '10px' } , remove _empty _cols : function ( flist ) { var non _empty _cols = [ ]
for ( var i = 0 ; i < me . data . length ; i ++ ) { for ( var c = 0 ; c < flist . length ; c ++ ) { if ( flist [ c ] . print _hide || ! inList ( [ '' , null ] , me . data [ i ] [ flist [ c ] . fieldname ] ) ) { if ( ! inList ( non _empty _cols , flist [ c ] ) ) { non _empty _cols . push ( flist [ c ] ) ; } } } }
for ( var c = 0 ; c < flist . length ; c ++ ) { if ( ! inList ( non _empty _cols , flist [ c ] ) ) { flist . splice ( c , 1 ) ; c = c - 1 ; } } } , prepare _col _heads : function ( flist ) { var new _flist = [ ] ; if ( ! cols || ( cols && cols . length && hide _empty ) ) { me . remove _empty _cols ( flist ) ; }
if ( cols && cols . length ) { if ( cols [ 0 ] == 'SR' ) { new _flist . push ( 'SR' ) }
for ( var i = 0 ; i < cols . length ; i ++ ) { for ( var j = 0 ; j < flist . length ; j ++ ) { if ( flist [ j ] . fieldname == cols [ i ] ) { new _flist . push ( flist [ j ] ) ; break ; } } } } else { new _flist . push ( 'SR' ) ; for ( var i = 0 ; i < flist . length ; i ++ ) { if ( ! flist [ i ] . print _hide ) { new _flist . push ( flist [ i ] ) ; } } }
me . flist = new _flist ; } , make _print _table : function ( flist ) { var wrapper = document . createElement ( 'div' ) ; var table = $a ( wrapper , 'table' , '' , me . table _style ) ; table . wrapper = wrapper ; table . insertRow ( 0 ) ; var col _start = 0 ; if ( flist [ 0 ] == 'SR' ) { var cell = table . rows [ 0 ] . insertCell ( 0 ) ; cell . innerHTML = head _labels ? head _labels [ 0 ] : '<b>SR</b>' ; $y ( cell , { width : '30px' } ) ; $y ( cell , me . head _cell _style ) ; col _start ++ ; }
for ( var c = col _start ; c < flist . length ; c ++ ) { var cell = table . rows [ 0 ] . insertCell ( c ) ; $y ( cell , me . head _cell _style ) ; cell . innerHTML = head _labels ? head _labels [ c ] : flist [ c ] . label ; if ( flist [ c ] . width ) { $y ( cell , { width : flist [ c ] . width } ) ; }
if ( widths ) { $y ( cell , { width : widths [ c ] } ) ; }
if ( in _list ( [ 'Currency' , 'Float' ] , flist [ c ] . fieldtype ) ) { $y ( cell , { textAlign : 'right' } ) ; } }
return table ; } , populate _table : function ( table , data ) { for ( var r = 0 ; r < data . length ; r ++ ) { if ( ( ! condition ) || ( condition ( data [ r ] ) ) ) { if ( data [ r ] . page _break ) { table = me . make _print _table ( me . flist ) ; me . table _list . push ( table . wrapper ) ; }
var row = table . insertRow ( table . rows . length ) ; if ( me . flist [ 0 ] == 'SR' ) { var cell = row . insertCell ( 0 ) ; cell . innerHTML = r + 1 ; $y ( cell , me . cell _style ) ; }
for ( var c = me . flist . indexOf ( 'SR' ) + 1 ; c < me . flist . length ; c ++ ) { var cell = row . insertCell ( c ) ; $y ( cell , me . cell _style ) ; if ( modifier && me . flist [ c ] . fieldname in modifier ) { data [ r ] [ me . flist [ c ] . fieldname ] = modifier [ me . flist [ c ] . fieldname ] ( data [ r ] ) ; }
$s ( cell , data [ r ] [ me . flist [ c ] . fieldname ] , me . flist [ c ] . fieldtype ) ; if ( in _list ( [ 'Currency' , 'Float' ] , me . flist [ c ] . fieldtype ) ) { cell . style . textAlign = 'right' ; } } } } } } ) ; if ( ! this . data . length ) { return document . createElement ( 'div' ) ; }
this . prepare _col _heads ( this . flist ) ; var table = me . make _print _table ( this . flist ) ; this . table _list = [ table . wrapper ] ; this . populate _table ( table , this . data ) ; return ( me . table _list . length > 1 ) ? me . table _list : me . table _list [ 0 ] ; }
/ *
* lib / js / legacy / widgets / form / email . js
* /
2012-06-07 06:00:02 +00:00
_e . email _as _field = 'email_id' ; _e . email _as _dt = 'Contact' ; _e . email _as _in = 'email_id,contact_name' ; sendmail = function ( emailto , emailfrom , cc , subject , message , fmt , with _attachments ) { var fn = function ( html ) { $c ( 'webnotes.utils.email_lib.send_form' , { 'sendto' : emailto , 'sendfrom' : emailfrom ? emailfrom : '' , 'cc' : cc ? cc : '' , 'subject' : subject , 'message' : replace _newlines ( message ) , 'body' : html , 'full_domain' : wn . urllib . get _base _url ( ) , 'with_attachments' : with _attachments ? 1 : 0 , 'dt' : cur _frm . doctype , 'dn' : cur _frm . docname , 'customer' : cur _frm . doc . customer || '' , 'supplier' : cur _frm . doc . supplier || '' } , function ( r , rtxt ) { } ) ; }
2012-02-14 06:14:13 +00:00
_p . build ( fmt , fn ) ; }
_e . make = function ( ) { var d = new Dialog ( 440 , 440 , "Send Email" ) ; var email _go = function ( ) { var emailfrom = d . widgets [ 'From' ] . value ; var emailto = d . widgets [ 'To' ] . value ; if ( ! emailfrom )
2012-05-08 06:47:26 +00:00
emailfrom = user _email ; emailto = emailto . replace ( / /g , "" ) ; var email _list = emailto . split ( /[,|;]/ ) ; var valid = 1 ; for ( var i = 0 ; i < email _list . length ; i ++ ) { if ( ! email _list [ i ] ) { email _list . splice ( i , 1 ) ; } else if ( ! validate _email ( email _list [ i ] ) ) { msgprint ( 'error:' + email _list [ i ] + ' is not a valid email id' ) ; valid = 0 ; } }
emailto = email _list . join ( "," ) ; if ( emailfrom && ! validate _email ( emailfrom ) ) { msgprint ( 'error:' + emailfrom + ' is not a valid email id. To change the default please click on Profile on the top right of the screen and change it.' ) ; return ; }
2012-02-14 06:14:13 +00:00
if ( ! valid ) return ; var cc = emailfrom ; if ( ! emailfrom ) { emailfrom = wn . control _panel . auto _email _id ; cc = '' ; }
sendmail ( emailto , emailfrom , emailfrom , d . widgets [ 'Subject' ] . value , d . widgets [ 'Message' ] . value , sel _val ( cur _frm . print _sel ) , d . widgets [ 'Send With Attachments' ] . checked ) ; _e . dialog . hide ( ) ; }
2012-03-12 07:52:09 +00:00
d . onhide = function ( ) { }
d . make _body ( [ [ 'Data' , 'To' , 'Example: abc@hotmail.com, xyz@yahoo.com' ] , [ 'Select' , 'Format' ] , [ 'Data' , 'Subject' ] , [ 'Data' , 'From' , 'Optional' ] , [ 'Check' , 'Send With Attachments' , 'Will send all attached documents (if any)' ] , [ 'Text' , 'Message' ] , [ 'Button' , 'Send' , email _go ] ] ) ; d . widgets [ 'From' ] . value = ( user _email ? user _email : '' ) ; $td ( d . rows [ 'Format' ] . tab , 0 , 1 ) . cur _sel = d . widgets [ 'Format' ] ; function split ( val ) { return val . split ( /,\s*/ ) ; }
function extractLast ( term ) { return split ( term ) . pop ( ) ; }
$ ( d . widgets [ 'To' ] ) . bind ( "keydown" , function ( event ) { if ( event . keyCode === $ . ui . keyCode . TAB && $ ( this ) . data ( "autocomplete" ) . menu . active ) { event . preventDefault ( ) ; } } ) . autocomplete ( { source : function ( request , response ) { wn . call ( { method : 'webnotes.utils.email_lib.get_contact_list' , args : { 'select' : _e . email _as _field , 'from' : _e . email _as _dt , 'where' : _e . email _as _in , 'txt' : extractLast ( request . term ) . value || '%' } , callback : function ( r ) { response ( $ . ui . autocomplete . filter ( r . cl || [ ] , extractLast ( request . term ) ) ) ; } } ) ; } , focus : function ( ) { return false ; } , select : function ( event , ui ) { var terms = split ( this . value ) ; terms . pop ( ) ; terms . push ( ui . item . value ) ; terms . push ( "" ) ; this . value = terms . join ( ", " ) ; return false ; } } ) ; _e . dialog = d ; }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / widgets / form / clientscriptAPI . js
* /
$c _get _values = function ( args , doc , dt , dn , user _callback ) { var call _back = function ( r , rt ) { if ( ! r . message ) return ; if ( user _callback ) user _callback ( r . message ) ; var fl = args . fields . split ( ',' ) ; for ( var i in fl ) { locals [ dt ] [ dn ] [ fl [ i ] ] = r . message [ fl [ i ] ] ; if ( args . table _field )
refresh _field ( fl [ i ] , dn , args . table _field ) ; else
refresh _field ( fl [ i ] ) ; } }
$c ( 'webnotes.widgets.form.utils.get_fields' , args , call _back ) ; }
get _server _fields = function ( method , arg , table _field , doc , dt , dn , allow _edit , call _back ) { if ( ! allow _edit ) freeze ( 'Fetching Data...' ) ; $c ( 'runserverobj' , args = { 'method' : method , 'docs' : compress _doclist ( [ doc ] ) , 'arg' : arg } , function ( r , rt ) { if ( r . message ) { var d = locals [ dt ] [ dn ] ; var field _dict = r . message ; for ( var key in field _dict ) { d [ key ] = field _dict [ key ] ; if ( table _field ) refresh _field ( key , d . name , table _field ) ; else refresh _field ( key ) ; } }
if ( call _back ) { doc = locals [ doc . doctype ] [ doc . name ] ; call _back ( doc , dt , dn ) ; }
if ( ! allow _edit ) unfreeze ( ) ; } ) ; }
set _multiple = function ( dt , dn , dict , table _field ) { var d = locals [ dt ] [ dn ] ; for ( var key in dict ) { d [ key ] = dict [ key ] ; if ( table _field ) refresh _field ( key , d . name , table _field ) ; else refresh _field ( key ) ; } }
refresh _many = function ( flist , dn , table _field ) { for ( var i in flist ) { if ( table _field ) refresh _field ( flist [ i ] , dn , table _field ) ; else refresh _field ( flist [ i ] ) ; } }
set _field _tip = function ( n , txt ) { var df = get _field ( cur _frm . doctype , n , cur _frm . docname ) ; if ( df ) df . description = txt ; if ( cur _frm && cur _frm . fields _dict ) { if ( cur _frm . fields _dict [ n ] )
cur _frm . fields _dict [ n ] . comment _area . innerHTML = replace _newlines ( txt ) ; else
errprint ( '[set_field_tip] Unable to set field tip: ' + n ) ; } }
refresh _field = function ( n , docname , table _field ) { if ( typeof n == typeof [ ] ) refresh _many ( n , docname , table _field ) ; if ( table _field ) { if ( _f . frm _dialog && _f . frm _dialog . display ) { if ( _f . frm _dialog . cur _frm . fields _dict [ n ] && _f . frm _dialog . cur _frm . fields _dict [ n ] . refresh )
_f . frm _dialog . cur _frm . fields _dict [ n ] . refresh ( ) ; } else { var g = _f . cur _grid _cell ; if ( g ) var hc = g . grid . head _row . cells [ g . cellIndex ] ; if ( g && hc && hc . fieldname == n && g . row . docname == docname ) { hc . template . refresh ( ) ; } else { cur _frm . fields _dict [ table _field ] . grid . refresh _cell ( docname , n ) ; } } } else if ( cur _frm && cur _frm . fields _dict ) { if ( cur _frm . fields _dict [ n ] && cur _frm . fields _dict [ n ] . refresh )
cur _frm . fields _dict [ n ] . refresh ( ) ; } }
set _field _options = function ( n , txt ) { var df = get _field ( cur _frm . doctype , n , cur _frm . docname ) ; if ( df ) df . options = txt ; refresh _field ( n ) ; }
set _field _permlevel = function ( n , level ) { var df = get _field ( cur _frm . doctype , n , cur _frm . docname ) ; if ( df ) df . permlevel = level ; refresh _field ( n ) ; }
2012-04-13 06:16:38 +00:00
hide _field = function ( n ) { function _hide _field ( n , hidden ) { var df = get _field ( cur _frm . doctype , n , cur _frm . docname ) ; if ( df ) { df . hidden = hidden ; refresh _field ( n ) ; }
else { console . log ( "hide_field cannot find field " + n ) ; } }
2012-02-14 06:14:13 +00:00
if ( cur _frm ) { if ( n . substr ) _hide _field ( n , 1 ) ; else { for ( var i in n ) _hide _field ( n [ i ] , 1 ) } } }
2012-04-13 06:16:38 +00:00
unhide _field = function ( n ) { function _hide _field ( n , hidden ) { var df = get _field ( cur _frm . doctype , n , cur _frm . docname ) ; if ( df ) { df . hidden = hidden ; refresh _field ( n ) ; }
else { console . log ( "unhide_field cannot find field " + n ) ; } }
2012-02-14 06:14:13 +00:00
if ( cur _frm ) { if ( n . substr ) _hide _field ( n , 0 ) ; else { for ( var i in n ) _hide _field ( n [ i ] , 0 ) } } }
get _field _obj = function ( fn ) { return cur _frm . fields _dict [ fn ] ; }
/ *
* lib / js / legacy / widgets / form / form _comments . js
* /
wn . widgets . form . comments = { n _comments : { } , comment _list : { } , sync : function ( dt , dn , r ) { var f = wn . widgets . form . comments ; f . n _comments [ dn ] = r . n _comments ; f . comment _list [ dn ] = r . comment _list ; } , add : function ( input , dt , dn , callback ) { $c ( 'webnotes.widgets.form.comments.add_comment' , wn . widgets . form . comments . get _args ( input , dt , dn ) , function ( r , rt ) { wn . widgets . form . comments . update _comment _list ( input , dt , dn ) ; input . value = '' ; callback ( input , dt , dn ) ; } ) ; } , remove : function ( dt , dn , comment _id , callback ) { $c ( 'webnotes.widgets.form.comments.remove_comment' , { id : comment _id , dt : dt , dn : dn } , callback ) ; } , get _args : function ( input , dt , dn ) { return { comment : input . value , comment _by : user , comment _by _fullname : user _fullname , comment _doctype : dt , comment _docname : dn } } , update _comment _list : function ( input , dt , dn ) { var f = wn . widgets . form . comments ; f . n _comments [ dn ] = cint ( f . n _comments [ dn ] ) + 1 ; f . comment _list [ dn ] = add _lists ( [ f . get _args ( input , dt , dn ) ] , f . comment _list [ dn ] ) ; } }
CommentList = function ( parent , dt , dn ) { this . wrapper = $a ( parent , 'div' , '' , { margin : '16px' } ) ; this . input _area = $a ( this . wrapper , 'div' , '' , { margin : '2px' } ) ; this . lst _area = $a ( this . wrapper , 'div' , '' , { margin : '2px' } ) ; this . make _input ( ) ; this . make _lst ( ) ; this . dt ; this . dn ; }
CommentList . prototype . run = function ( ) { this . lst . run ( ) ; }
CommentList . prototype . make _input = function ( ) { var me = this ; this . input = $a ( this . input _area , 'textarea' , '' , { height : '60px' , width : '300px' , fontSize : '14px' } ) ; this . btn = $btn ( $a ( this . input _area , 'div' ) , 'Post' , function ( ) { me . add _comment ( ) ; } , { marginTop : '8px' } ) ; }
CommentList . prototype . add _comment = function ( ) { var me = this ; var callback = function ( input , dt , dn ) { me . lst . run ( ) ; }
wn . widgets . form . comments . add ( this . input , cur _frm . docname , cur _frm . doctype , callback ) }
2012-05-07 12:30:57 +00:00
CommentList . prototype . make _lst = function ( ) { if ( ! this . lst ) { wn . require ( 'js/listing.js' ) ; var l = new Listing ( 'Comments' , 1 ) ; var me = this ; l . colwidths = [ '100%' ] ; l . opts . hide _export = 1 ; l . opts . hide _print = 1 ; l . opts . hide _refresh = 1 ; l . opts . no _border = 1 ; l . opts . hide _rec _label = 0 ; l . opts . show _calc = 0 ; l . opts . round _corners = 0 ; l . opts . alt _cell _style = { } ; l . opts . cell _style = { padding : '3px' } ; l . no _rec _message = 'No comments yet. Be the first one to comment!' ; l . get _query = function ( ) { this . query = repl ( " select t1 . name , t1 . comment , t1 . comment _by , '' , \
2012-02-14 06:14:13 +00:00
t1 . creation , t1 . comment _doctype , t1 . comment _docname , \
ifnull ( concat _ws ( ' ' , ifnull ( t2 . first _name , '' ) , ifnull ( t2 . middle _name , '' ) , \
ifnull ( t2 . last _name , '' ) ) , '' ) , '' , \
DAYOFMONTH ( t1 . creation ) , MONTHNAME ( t1 . creation ) , YEAR ( t1 . creation ) , \
hour ( t1 . creation ) , minute ( t1 . creation ) , second ( t1 . creation ) \
2012-03-30 06:59:06 +00:00
from ` tabComment ` t1 , ` tabProfile ` t2 \
2012-02-14 06:14:13 +00:00
where t1 . comment _doctype = '%(dt)s' and t1 . comment _docname = '%(dn)s' \
2012-03-30 06:59:06 +00:00
and t1 . comment _by = t2 . name order by t1 . creation desc ",{dt:me.dt,dn:me.dn});this.query_max=repl(" select count ( name ) from ` tabComment ` where \
2012-02-14 06:14:13 +00:00
comment _doctype = '%(dt)s' and comment _docname = '%(dn)s' " , { 'dt' : me . dt , 'dn' : me . dn } ) ; }
l . show _cell = function ( cell , ri , ci , d ) { new CommentItem ( cell , ri , ci , d , me ) }
this . lst = l ; this . lst . make ( this . lst _area ) ; } }
CommentItem = function ( cell , ri , ci , d , comment ) { this . comment = comment ; $y ( cell , { padding : '4px 0px' } )
var t = make _table ( cell , 1 , 3 , '100%' , [ '15%' , '65%' , '20%' ] , { padding : '4px' } ) ; this . img = $a ( $td ( t , 0 , 0 ) , 'img' , '' , { width : '40px' } ) ; this . cmt _by = $a ( $td ( t , 0 , 0 ) , 'div' ) ; this . set _picture ( d , ri ) ; this . cmt _dtl = $a ( $td ( t , 0 , 1 ) , 'div' , 'comment' , { fontSize : '11px' } ) ; this . cmt = $a ( $td ( t , 0 , 1 ) , 'div' , '' , { fontSize : '14px' } ) ; this . show _cmt ( $td ( t , 0 , 1 ) , ri , ci , d ) ; this . cmt _delete ( $td ( t , 0 , 2 ) , ri , ci , d ) ; }
2012-03-02 09:26:51 +00:00
CommentItem . prototype . set _picture = function ( d , ri ) { this . user . src = wn . user _info ( d [ ri ] [ 2 ] ) . image ; this . cmt _by . innerHTML = d [ ri ] [ 7 ] ? d [ ri ] [ 7 ] : d [ ri ] [ 2 ] ; }
2012-02-14 06:14:13 +00:00
CommentItem . prototype . show _cmt = function ( cell , ri , ci , d ) { if ( d [ ri ] [ 4 ] ) { hr = d [ ri ] [ 12 ] ; min = d [ ri ] [ 13 ] ; sec = d [ ri ] [ 14 ] ; if ( parseInt ( hr ) > 12 ) { time = ( parseInt ( hr ) - 12 ) + ':' + min + ' PM' }
else { time = hr + ':' + min + ' AM' } }
this . cmt _dtl . innerHTML = 'On ' + d [ ri ] [ 10 ] . substring ( 0 , 3 ) + ' ' + d [ ri ] [ 9 ] + ', ' + d [ ri ] [ 11 ] + ' at ' + time ; this . cmt . innerHTML = replace _newlines ( d [ ri ] [ 1 ] ) ; }
2012-02-24 11:06:58 +00:00
CommentItem . prototype . cmt _delete = function ( cell , ri , ci , d ) { var me = this ; if ( d [ ri ] [ 2 ] == user || d [ ri ] [ 3 ] == user ) { del = $a ( cell , 'i' , 'icon-remove-sign' , { cursor : 'pointer' } ) ; del . cmt _id = d [ ri ] [ 0 ] ; del . onclick = function ( ) { wn . widgets . form . comments . remove ( cur _frm . doctype , cur _frm . docname , this . cmt _id , function ( ) { me . comment . lst . run ( ) ; } ) } } }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / wn / widgets / form / sidebar . js
* /
2012-03-20 13:15:28 +00:00
wn . widgets . form . sidebar = { Sidebar : function ( form ) { var me = this ; this . form = form ; this . opts = { sections : [ { title : 'Actions' , items : [ { type : 'link' , label : 'New' , icon : 'icon-plus' , display : function ( ) { return in _list ( profile . can _create , form . doctype ) } , onclick : function ( ) { new _doc ( me . form . doctype ) } } , { type : 'link' , label : 'List' , icon : 'icon-list' , display : function ( ) { return ! me . form . meta . issingle ; } , onclick : function ( ) { window . location . href = "#!List/" + me . form . doctype } } , { type : 'link' , label : 'Refresh' , icon : 'icon-refresh' , onclick : function ( ) { me . form . reload _doc ( ) } } , { type : 'link' , label : 'Print' , display : function ( ) { return ! ( me . form . doc . _ _islocal || me . form . meta . allow _print ) ; } , icon : 'icon-print' , onclick : function ( ) { me . form . print _doc ( ) } } , { type : 'link' , label : 'Email' , display : function ( ) { return ! ( me . form . doc . _ _islocal || me . form . meta . allow _email ) ; } , icon : 'icon-envelope' , onclick : function ( ) { me . form . email _doc ( ) } } , { type : 'link' , label : 'Copy' , display : function ( ) { return in _list ( profile . can _create , me . form . doctype ) && ! me . form . meta . allow _copy } , icon : 'icon-file' , onclick : function ( ) { me . form . copy _doc ( ) } } , { type : 'link' , label : 'Delete' , display : function ( ) { return me . form . meta . allow _trash && cint ( me . form . doc . docstatus ) != 2 && ( ! me . form . doc . _ _islocal ) && me . form . perm [ 0 ] [ CANCEL ] } , icon : 'icon-remove-sign' , onclick : function ( ) { me . form . savetrash ( ) } } ] } , { title : 'Assign To' , render : function ( wrapper ) { me . form . assign _to = new wn . widgets . form . sidebar . AssignTo ( wrapper , me , me . form . doctype , me . form . docname ) ; } , display : function ( ) { if ( me . form . doc . _ _local ) return false ; else return true ; } } , { title : 'Attachments' , render : function ( wrapper ) { me . form . attachments = new wn . widgets . form . sidebar . Attachments ( wrapper , me , me . form . doctype , me . form . docname ) ; } , display : function ( ) { return me . form . meta . allow _attach } } , { title : 'Comments' , render : function ( wrapper ) { new wn . widgets . form . sidebar . Comments ( wrapper , me , me . form . doctype , me . form . docname ) ; } , display : function ( ) { return ! me . form . doc . _ _islocal } } , { title : 'Tags' , render : function ( wrapper ) { me . form . taglist = new TagList ( wrapper , me . form . doc . _user _tags ? me . form . doc . _user _tags . split ( ',' ) : [ ] , me . form . doctype , me . form . docname , 0 , function ( ) { } ) ; } , display : function ( ) { return ! me . form . doc . _ _islocal } } , { title : 'Users' , render : function ( wrapper ) { var doc = cur _frm . doc ; var scrub _date = function ( d ) { if ( d ) t = d . split ( ' ' ) ; else return '' ; return dateutil . str _to _user ( t [ 0 ] ) + ' ' + t [ 1 ] ; }
2012-03-20 09:07:44 +00:00
$ ( wrapper ) . html ( repl ( ' < p > Created : < br > < span class = "avatar-small" > \
< img title = "%(created_by)s" src = "%(avatar_created)s" / > < / s p a n > \
2012-03-21 06:17:58 +00:00
< span class = "help small" > % ( creation ) s < / s p a n > < / p > \
2012-03-20 09:07:44 +00:00
< p > Modified : < br > < span class = "avatar-small" > \
< img title = "%(modified_by)s" src = "%(avatar_modified)s" / > < / s p a n > \
2012-03-21 07:15:01 +00:00
< span class = "help small" > % ( modified ) s < / s p a n > < / p > ' , { c r e a t e d _ b y : w n . u s e r _ i n f o ( d o c . o w n e r ) . f u l l n a m e , a v a t a r _ c r e a t e d : w n . u s e r _ i n f o ( d o c . o w n e r ) . i m a g e , c r e a t i o n : s c r u b _ d a t e ( d o c . c r e a t i o n ) , m o d i f i e d _ b y : w n . u s e r _ i n f o ( d o c . m o d i f i e d _ b y ) . f u l l n a m e , a v a t a r _ m o d i f i e d : w n . u s e r _ i n f o ( d o c . m o d i f i e d _ b y ) . i m a g e , m o d i f i e d : s c r u b _ d a t e ( d o c . m o d i f i e d ) } ) ) ; } , d i s p l a y : f u n c t i o n ( ) { r e t u r n ! m e . f o r m . d o c . _ _ i s l o c a l } } , { t i t l e : ' H e l p ' , r e n d e r : f u n c t i o n ( w r a p p e r ) { $ ( w r a p p e r ) . h t m l ( ' < d i v c l a s s = " h e l p s m a l l " > '
+ wn . markdown ( me . form . meta . description ) + '</div>' ) } , display : function ( ) { return me . form . meta . description } } ] }
2012-02-20 10:10:29 +00:00
this . refresh = function ( ) { var parent = this . form . page _layout . sidebar _area ; if ( ! this . sidebar ) { this . sidebar = new wn . widgets . PageSidebar ( parent , this . opts ) ; } else { this . sidebar . refresh ( ) ; } } } }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / wn / widgets / form / comments . js
* /
wn . widgets . form . sidebar . Comments = function ( parent , sidebar , doctype , docname ) { var me = this ; this . sidebar = sidebar ; this . doctype = doctype ; this . docname = docname ; this . refresh = function ( ) { $c ( 'webnotes.widgets.form.comments.get_comments' , { dt : me . doctype , dn : me . docname , limit : 5 } , function ( r , rt ) { wn . widgets . form . comments . sync ( me . doctype , me . docname , r ) ; me . make _body ( ) ; } ) ; }
this . make _body = function ( ) { if ( this . wrapper ) this . wrapper . innerHTML = '' ; else this . wrapper = $a ( parent , 'div' , 'sidebar-comment-wrapper' ) ; this . input = $a _input ( this . wrapper , 'text' ) ; this . btn = $btn ( this . wrapper , 'Post' , function ( ) { me . add _comment ( ) } , { marginLeft : '8px' } ) ; this . render _comments ( ) }
this . render _comments = function ( ) { var f = wn . widgets . form . comments ; var cl = f . comment _list [ me . docname ]
2012-03-21 06:17:58 +00:00
this . msg = $a ( this . wrapper , 'div' , 'help small' ) ; if ( cl ) { this . msg . innerHTML = cl . length + ' out of ' + f . n _comments [ me . docname ] + ' comments' ; if ( f . n _comments [ me . docname ] > cl . length ) { this . msg . innerHTML += ' < span class = "link_type" \
onclick = "cur_frm.show_comments()" > Show all < / s p a n > ' }
2012-02-14 06:14:13 +00:00
for ( var i = 0 ; i < cl . length ; i ++ ) { this . render _one _comment ( cl [ i ] ) ; } } else { this . msg . innerHTML = 'Be the first one to comment.' } }
this . render _one _comment = function ( det ) { $a ( this . wrapper , 'div' , 'social sidebar-comment-text' , '' , det . comment ) ; $a ( this . wrapper , 'div' , 'sidebar-comment-info' , '' , comment _when ( det . creation ) + ' by ' + det . comment _by _fullname ) ; }
this . add _comment = function ( ) { if ( ! this . input . value ) return ; this . btn . set _working ( ) ; wn . widgets . form . comments . add ( this . input , me . doctype , me . docname , function ( ) { me . btn . done _working ( ) ; me . make _body ( ) ; } ) ; }
this . refresh ( ) ; }
/ *
* lib / js / legacy / wn / widgets / form / attachments . js
* /
2012-03-12 10:42:09 +00:00
wn . widgets . form . sidebar . Attachments = function ( parent , sidebar , doctype , docname ) { var me = this ; this . frm = sidebar . form ; this . make = function ( ) { if ( this . wrapper ) this . wrapper . innerHTML = '' ; else this . wrapper = $a ( parent , 'div' , 'sidebar-comment-wrapper' ) ; this . attach _wrapper = $a ( this . wrapper , 'div' ) ; if ( this . frm . doc . _ _islocal ) { this . attach _wrapper . innerHTML = ' < div class = "help" > Attachments can be \
uploaded after saving < / d i v > ' ; r e t u r n ; }
2012-02-14 06:14:13 +00:00
var n = this . frm . doc . file _list ? this . frm . doc . file _list . split ( '\n' ) . length : 0 ; if ( n < this . frm . meta . max _attachments || ! this . frm . meta . max _attachments ) { this . btn = $btn ( $a ( this . wrapper , 'div' , 'sidebar-comment-message' ) , 'Add' , function ( ) { me . add _attachment ( ) } ) ; }
this . render ( ) ; }
this . render = function ( ) { this . attach _wrapper . innerHTML = ''
var doc = locals [ me . frm . doctype ] [ me . frm . docname ] ; var fl = doc . file _list ? doc . file _list . split ( '\n' ) : [ ] ; for ( var i = 0 ; i < fl . length ; i ++ ) { new wn . widgets . form . sidebar . Attachment ( this . attach _wrapper , fl [ i ] , me . frm ) } }
this . add _attachment = function ( ) { if ( ! this . dialog ) { this . dialog = new wn . widgets . Dialog ( { title : 'Add Attachment' , width : 400 } )
$y ( this . dialog . body , { margin : '13px' } )
this . dialog . make ( ) ; }
2012-05-10 13:37:53 +00:00
this . dialog . body . innerHTML = '' ; this . dialog . show ( ) ; wn . upload . make ( { parent : this . dialog . body , args : { from _form : 1 , doctype : doctype , docname : docname } , callback : wn . widgets . form . file _upload _done } ) ; }
2012-02-14 06:14:13 +00:00
this . make ( ) ; }
wn . widgets . form . sidebar . Attachment = function ( parent , filedet , frm ) { filedet = filedet . split ( ',' )
this . filename = filedet [ 0 ] ; this . fileid = filedet [ 1 ] ; this . frm = frm ; var me = this ; this . wrapper = $a ( parent , 'div' , 'sidebar-comment-message' ) ; this . remove _fileid = function ( ) { var doc = locals [ me . frm . doctype ] [ me . frm . docname ] ; var fl = doc . file _list . split ( '\n' ) ; new _fl = [ ] ; for ( var i = 0 ; i < fl . length ; i ++ ) { if ( fl [ i ] . split ( ',' ) [ 1 ] != me . fileid ) new _fl . push ( fl [ i ] ) ; }
doc . file _list = new _fl . join ( '\n' ) ; }
2012-06-20 08:16:26 +00:00
var display _name = this . fileid ; if ( this . fileid && this . fileid . substr ( 0 , 8 ) == 'FileData' )
2012-03-21 06:17:58 +00:00
display _name = this . filename ; this . ln = $a ( this . wrapper , 'a' , 'link_type small' , { } , display _name ) ; this . ln . href = 'files/' + this . fileid ; this . ln . target = '_blank' ; this . del = $a ( this . wrapper , 'span' , 'close' , '' , '×' ) ; this . del . onclick = function ( ) { var yn = confirm ( "Are you sure you want to delete the attachment?" )
2012-02-14 06:14:13 +00:00
if ( yn ) { var callback = function ( r , rt ) { locals [ me . frm . doctype ] [ me . frm . docname ] . modified = r . message ; $dh ( me . wrapper ) ; me . remove _fileid ( ) ; frm . refresh ( ) ; }
$c ( 'webnotes.widgets.form.utils.remove_attach' , args = { 'fid' : me . fileid , dt : me . frm . doctype , dn : me . frm . docname } , callback ) ; } } }
2012-05-10 13:37:53 +00:00
wn . widgets . form . file _upload _done = function ( doctype , docname , fileid , filename , at _id , new _timestamp ) { var doc = locals [ doctype ] [ docname ] ; if ( doc . file _list ) { var fl = doc . file _list . split ( '\n' )
2012-02-14 06:14:13 +00:00
fl . push ( filename + ',' + fileid )
doc . file _list = fl . join ( '\n' ) ; }
else
2012-03-20 09:07:44 +00:00
doc . file _list = filename + ',' + fileid ; doc . modified = new _timestamp ; var frm = wn . views . formview [ doctype ] . frm ; frm . attachments . dialog . hide ( ) ; msgprint ( 'File Uploaded Sucessfully.' ) ; frm . refresh ( ) ; }
2012-02-14 06:14:13 +00:00
/ *
* lib / js / legacy / wn / widgets / form / assign _to . js
* /
wn . widgets . form . sidebar . AssignTo = Class . extend ( { init : function ( parent , sidebar , doctype , docname ) { var me = this ; this . doctype = doctype ; this . name = docname ; this . wrapper = $a ( parent , 'div' , 'sidebar-comment-wrapper' ) ; this . body = $a ( this . wrapper , 'div' ) ; this . add _btn = $btn ( $a ( this . wrapper , 'div' , 'sidebar-comment-message' ) , 'Assign' , function ( ) { me . add ( ) ; } )
this . refresh ( ) ; } , refresh : function ( ) { var me = this ; $c ( 'webnotes.widgets.form.assign_to.get' , { doctype : me . doctype , name : me . name } , function ( r , rt ) { me . render ( r . message ) } ) } , render : function ( d ) { var me = this ; $ ( this . body ) . empty ( ) ; if ( this . dialog ) { this . dialog . hide ( ) ; }
for ( var i = 0 ; i < d . length ; i ++ ) { $ ( this . body ) . append ( repl ( ' < div > % ( owner ) s \
< a class = "close" href = "#" data - owner = "%(owner)s" > & # 215 < / a > < / d i v > ' , d [ i ] ) ) }
2012-03-23 06:17:30 +00:00
$ ( this . body ) . find ( 'a.close' ) . click ( function ( ) { $c ( 'webnotes.widgets.form.assign_to.remove' , { doctype : me . doctype , name : me . name , assign _to : $ ( this ) . attr ( 'data-owner' ) } , function ( r , rt ) { me . render ( r . message ) ; } ) ; return false ; } ) ; } , add : function ( ) { var me = this ; if ( ! me . dialog ) { me . dialog = new wn . widgets . Dialog ( { title : 'Add to To Do' , width : 350 , fields : [ { fieldtype : 'Link' , fieldname : 'assign_to' , options : 'Profile' , label : 'Assign To' , description : 'Add to To Do List of' , reqd : true } , { fieldtype : 'Data' , fieldname : 'description' , label : 'Comment' } , { fieldtype : 'Date' , fieldname : 'date' , label : 'Complete By' } , { fieldtype : 'Select' , fieldname : 'priority' , label : 'Priority' , options : 'Low\nMedium\nHigh' , 'default' : 'Medium' } , { fieldtype : 'Check' , fieldname : 'notify' , label : 'Notify By Email' } , { fieldtype : 'Button' , label : 'Add' , fieldname : 'add_btn' } ] } ) ; me . dialog . fields _dict . add _btn . input . onclick = function ( ) { var assign _to = me . dialog . fields _dict . assign _to . get _value ( ) ; if ( assign _to ) { $c ( 'webnotes.widgets.form.assign_to.add' , { doctype : me . doctype , name : me . name , assign _to : assign _to , description : me . dialog . fields _dict . description . get _value ( ) , priority : me . dialog . fields _dict . priority . get _value ( ) , date : me . dialog . fields _dict . date . get _value ( ) , notify : me . dialog . fields _dict . notify . get _value ( ) } , function ( r , rt ) { me . render ( r . message ) ; } ) ; } } }
2012-02-14 06:14:13 +00:00
me . dialog . clear ( ) ; me . dialog . show ( ) ; } } ) ;
/ *
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-05-08 07:28:32 +00:00
$ ( document ) . trigger ( 'app_ready' ) ; } , load _bootinfo : function ( ) { if ( wn . boot ) { LocalDB . sync ( wn . boot . docs ) ; wn . control _panel = wn . boot . control _panel ; if ( wn . boot . error _messages )
2012-02-14 06:14:13 +00:00
console . log ( wn . boot . error _messages )
if ( wn . boot . server _messages )
2012-05-07 12:30:57 +00:00
msgprint ( wn . boot . server _messages ) ; 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 ) ; }
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-02-29 09:41:06 +00:00
* erpnext / startup / js / modules . js
2012-02-14 06:14:13 +00:00
* /
2012-02-22 06:37:42 +00:00
wn . provide ( 'erpnext.module_page' ) ; erpnext . module _page . setup _page = function ( module , wrapper ) { erpnext . module _page . hide _links ( wrapper ) ; erpnext . module _page . make _list ( module , wrapper ) ; $ ( wrapper ) . find ( "a[title]" ) . tooltip ( { delay : { show : 500 , hide : 100 } } ) ; }
2012-03-01 08:28:17 +00:00
erpnext . module _page . hide _links = function ( wrapper ) { $ ( wrapper ) . find ( '[href*="List/"]' ) . each ( function ( ) { var href = $ ( this ) . attr ( 'href' ) ; var dt = href . split ( '/' ) [ 1 ] ; if ( wn . boot . profile . all _read . indexOf ( get _label _doctype ( dt ) ) == - 1 ) { var txt = $ ( this ) . text ( ) ; $ ( this ) . parent ( ) . css ( 'color' , '#999' ) . html ( txt ) ; } } ) ; $ ( wrapper ) . find ( '[data-doctype]' ) . each ( function ( ) { var dt = $ ( this ) . attr ( 'data-doctype' ) ; if ( wn . boot . profile . all _read . indexOf ( dt ) == - 1 ) { var txt = $ ( this ) . text ( ) ; $ ( this ) . parent ( ) . css ( 'color' , '#999' ) . html ( txt ) ; } } ) ; $ ( wrapper ) . find ( '[href*="Form/"]' ) . each ( function ( ) { var href = $ ( this ) . attr ( 'href' ) ; var dt = href . split ( '/' ) [ 1 ] ; if ( wn . boot . profile . all _read . indexOf ( get _label _doctype ( dt ) ) == - 1 ) { var txt = $ ( this ) . text ( ) ; $ ( this ) . parent ( ) . css ( 'color' , '#999' ) . html ( txt ) ; } } ) ; }
2012-05-29 05:23:37 +00:00
erpnext . module _page . make _list = function ( module , wrapper ) { var $w = $ ( wrapper ) . find ( '.reports-list' ) ; var $parent1 = $ ( '<div style="width: 45%; float: left; margin-right: 4.5%"></div>' ) . appendTo ( $w ) ; var $parent2 = $ ( '<div style="width: 45%; float: left;"></div>' ) . appendTo ( $w ) ; wrapper . list1 = new wn . ui . Listing ( { parent : $parent1 , method : 'utilities.get_sc_list' , render _row : function ( row , data ) { if ( ! data . parent _doc _type ) data . parent _doc _type = data . doc _type ; $ ( row ) . html ( repl ( ' < a href = "#!Report/%(doc_type)s/%(criteria_name)s" \
2012-02-21 11:56:50 +00:00
data - doctype = "%(parent_doc_type)s" > \
2012-05-29 05:23:37 +00:00
% ( criteria _name ) s < /a>',data))},args:{module:module},no_refresh:true,callback:function(r){erpnext.module_page.hide_links($parent1)}});wrapper.list1.run();wrapper.list2=new wn.ui.Listing({parent:$parent2,method:'utilities.get_report_list',render_row:function(row,data){$(row).html(repl('<a href="#!Report2/ % ( ref _doctype ) s / % ( name ) s " \
data - doctype = "%(ref_doctype)s" > \
2012-06-13 14:06:55 +00:00
% ( name ) s < / a > ' , d a t a ) ) } , a r g s : { m o d u l e : m o d u l e } , n o _ r e f r e s h : t r u e , c a l l b a c k : f u n c t i o n ( r ) { e r p n e x t . m o d u l e _ p a g e . h i d e _ l i n k s ( $ p a r e n t 2 ) } } ) ; w r a p p e r . l i s t 2 . r u n ( ) ; $ p a r e n t 1 . f i n d ( ' . l i s t - t o o l b a r - w r a p p e r ' ) . p r e p e n d ( " < d i v c l a s s = \ " s h o w - a l l - r e p o r t s \ " > \
2012-06-14 05:35:09 +00:00
< a href = \ "#List/Search Criteria\"> [ List Of All Reports ]</a></div>" ) ; $parent2 . find ( '.list-toolbar-wrapper' ) . prepend ( "<div class=\"show-all-reports\" > \
< a href = \ "#List/Report\"> [ List Of All Reports (New) ]</a></div>" ) ; }
2012-02-14 06:14:13 +00:00
/ *
2012-02-29 09:41:06 +00:00
* erpnext / startup / js / toolbar . js
2012-02-14 06:14:13 +00:00
* /
2012-02-27 12:47:57 +00:00
wn . provide ( 'erpnext.toolbar' ) ; erpnext . toolbar . setup = function ( ) { erpnext . toolbar . add _modules ( ) ; $ ( '#toolbar-user' ) . append ( '<li><a href="#!profile-settings">Profile Settings</a></li>' ) ; $ ( '.navbar .pull-right' ) . append ( ' \
< li > < a href = "#!messages" title = "Unread Messages" > < span class = "navbar-new-comments" > < / s p a n > < / a > < / l i > ' ) ; $ ( ' . n a v b a r . p u l l - r i g h t ' ) . p r e p e n d ( ' < l i c l a s s = " d r o p d o w n " > \
2012-02-21 05:49:24 +00:00
< a class = "dropdown-toggle" data - toggle = "dropdown" href = "#" \
onclick = "return false;" > Help < b class = "caret" > < / b > < / a > \
2012-02-14 06:14:13 +00:00
< ul class = "dropdown-menu" id = "toolbar-help" > \
< / u l > < / l i > ' )
$ ( '#toolbar-help' ) . append ( ' < li > < a href = "http://erpnext.blogspot.com/2011/03/erpnext-help.html" target = "_blank" > \
Documentation < / a > < / l i > ' )
$ ( '#toolbar-help' ) . append ( ' < li > < a href = "http://groups.google.com/group/erpnext-user-forum" target = "_blank" > \
Forum < / a > < / l i > ' )
$ ( '#toolbar-help' ) . append ( ' < li > < a href = "http://www.providesupport.com?messenger=iwebnotes" target = "_blank" > \
Live Chat ( Office Hours ) < / a > < / l i > ' )
2012-04-30 10:13:34 +00:00
erpnext . toolbar . set _new _comments ( ) ; }
2012-02-21 11:56:50 +00:00
erpnext . toolbar . add _modules = function ( ) { $ ( ' < li class = "dropdown" > \
< a class = "dropdown-toggle" data - toggle = "dropdown" href = "#" \
onclick = "return false;" > Modules < b class = "caret" > < / b > < / a > \
2012-02-28 13:26:56 +00:00
< ul class = "dropdown-menu modules" > \
2012-02-21 11:56:50 +00:00
< / u l > \
2012-04-30 10:13:34 +00:00
< / l i > ' ) . p r e p e n d T o ( ' . n a v b a r . n a v : f i r s t ' ) ; i f ( w n . b o o t . m o d u l e s _ l i s t & & t y p e o f ( w n . b o o t . m o d u l e s _ l i s t ) = = ' s t r i n g ' ) { w n . b o o t . m o d u l e s _ l i s t = J S O N . p a r s e ( w n . b o o t . m o d u l e s _ l i s t ) ; }
else
2012-02-29 05:25:43 +00:00
wn . boot . modules _list = keys ( erpnext . modules ) . sort ( ) ; for ( var i in wn . boot . modules _list ) { var m = wn . boot . modules _list [ i ]
2012-03-01 05:54:45 +00:00
if ( m != 'Setup' && wn . boot . profile . allow _modules . indexOf ( m ) != - 1 ) { args = { module : m , module _page : erpnext . modules [ m ] , module _label : m == 'HR' ? 'Human Resources' : m }
2012-02-29 05:25:43 +00:00
$ ( '.navbar .modules' ) . append ( repl ( ' < li > < a href = "#!%(module_page)s" \
data - module = "%(module)s" > % ( module _label ) s < / a > < / l i > ' , a r g s ) ) ; } }
2012-03-01 05:54:45 +00:00
if ( user _roles . indexOf ( "Accounts Manager" ) != - 1 ) { $ ( '.navbar .modules' ) . append ( ' < li > < a href = "#!dashboard" \
data - module = "Dashboard" > Dashboard < / a > < / l i > ' ) ; }
2012-02-28 13:26:56 +00:00
if ( user _roles . indexOf ( "System Manager" ) != - 1 ) { $ ( '.navbar .modules' ) . append ( ' < li class = "divider" > < / l i > \
< li > < a href = "#!Setup" data - module = "Setup" > Setup < / a > < / l i > ' ) ; } }
2012-04-30 10:13:34 +00:00
erpnext . toolbar . set _new _comments = function ( new _comments ) { var navbar _nc = $ ( '.navbar-new-comments' ) ; if ( new _comments && new _comments . length > 0 ) { navbar _nc . text ( new _comments . length ) ; navbar _nc . addClass ( 'navbar-new-comments-true' )
$ . each ( new _comments , function ( i , v ) { var msg = 'New Message: ' + ( v [ 1 ] . length <= 100 ? v [ 1 ] : ( v [ 1 ] . substr ( 0 , 100 ) + "..." ) ) ; var id = v [ 0 ] . replace ( '/' , '-' ) ; if ( ! $ ( '#' + id ) [ 0 ] ) { show _alert ( msg , id ) ; } } ) } else { navbar _nc . removeClass ( 'navbar-new-comments-true' ) ; navbar _nc . text ( 0 ) ; } }
2012-02-14 06:14:13 +00:00
/ *
2012-02-29 09:41:06 +00:00
* erpnext / startup / js / feature _setup . js
2012-02-14 06:14:13 +00:00
* /
2012-06-07 13:39:17 +00:00
pscript . feature _dict = { 'fs_projects' : { 'BOM' : { 'fields' : [ 'project_name' ] } , 'Delivery Note' : { 'fields' : [ 'project_name' ] } , 'Purchase Invoice' : { 'entries' : [ 'project_name' ] } , 'Production Order' : { 'fields' : [ 'project_name' ] } , 'Purchase Order' : { 'po_details' : [ 'project_name' ] } , 'Purchase Receipt' : { 'purchase_receipt_details' : [ 'project_name' ] } , 'Sales Invoice' : { 'fields' : [ 'project_name' ] } , 'Sales Order' : { 'fields' : [ 'project_name' ] } , 'Stock Entry' : { 'fields' : [ 'project_name' ] } , 'Timesheet' : { 'timesheet_details' : [ 'project_name' ] } } , 'fs_packing_details' : { } , 'fs_discounts' : { 'Delivery Note' : { 'delivery_note_details' : [ 'adj_rate' ] } , 'Quotation' : { 'quotation_details' : [ 'adj_rate' ] } , 'Sales Invoice' : { 'entries' : [ 'adj_rate' ] } , 'Sales Order' : { 'sales_order_details' : [ 'adj_rate' , 'ref_rate' ] } } , 'fs_purchase_discounts' : { 'Purchase Order' : { 'po_details' : [ 'purchase_ref_rate' , 'discount_rate' , 'import_ref_rate' ] } , 'Purchase Receipt' : { 'purchase_receipt_details' : [ 'purchase_ref_rate' , 'discount_rate' , 'import_ref_rate' ] } , 'Purchase Invoice' : { 'entries' : [ 'purchase_ref_rate' , 'discount_rate' , 'import_ref_rate' ] } } , 'fs_brands' : { 'Delivery Note' : { 'delivery_note_details' : [ 'brand' ] } , 'Purchase Request' : { 'indent_details' : [ 'brand' ] } , 'Item' : { 'fields' : [ 'brand' ] } , 'Purchase Order' : { 'po_details' : [ 'brand' ] } , 'Purchase Invoice' : { 'entries' : [ 'brand' ] } , 'Quotation' : { 'quotation_details' : [ 'brand' ] } , 'Sales Invoice' : { 'entries' : [ 'brand' ] } , 'Sales BOM' : { 'fields' : [ 'new_item_brand' ] } , 'Sales Order' : { 'sales_order_details' : [ 'brand' ] } , 'Serial No' : { 'fields' : [ 'brand' ] } } , 'fs_after_sales_installations' : { 'Delivery Note' : { 'fields' : [ 'installation_status' , 'per_installed' ] , 'delivery_note_details' : [ 'installed_qty' ] } } , 'fs_item_batch_nos' : { 'Delivery Note' : { 'delivery_note_details' : [ 'batch_no' ] } , 'Item' : { 'fields' : [ 'has_batch_no' ] } , 'Purchase Receipt' : { 'purchase_receipt_details' : [ 'batch_no' ] } , 'Quality Inspection' : { 'fields' : [ 'batch_no' ] } , 'Sales and Pruchase Return Wizard' : { 'return_details' : [ 'batch_no' ] } , 'Sales Invoice' : { 'entries' : [ 'batch_no' ] } , 'Stock Entry' : { 'mtn_details' : [ 'batch_no' ] } , 'Stock Ledger Entry' : { 'fields' : [ 'batch_no' ] } } , 'fs_item_serial_nos' : { 'Customer Issue' : { 'fields' : [ 'serial_no' ] } , 'Delivery Note' : { 'delivery_note_details' : [ 'serial_no' ] , 'packing_details' : [ 'serial_no' ] } , 'Installation Note' : { 'installed_item_details' : [ 'serial_no' ] } , 'Item' : { 'fields' : [ 'has_serial_no' ] } , 'Maintenance Schedule' : { 'item_maintenance_detail' : [ 'serial_no' ] , 'maintenance_schedule_detail' : [ 'serial_no' ] } , 'Maintenance Visit' : { 'maintenance_visit_details' : [ 'serial_no' ] } , 'Purchase Receipt' : { 'purchase_receipt_details' : [ 'serial_no' ] } , 'Quality Inspection' : { 'fields' : [ 'item_serial_no' ] } , 'Sales and Pruchase Return Wizard' : { 'return_details' : [ 'serial_no' ] } , 'Sales Invoice' : { 'entries' : [ 'serial_no' ] } , 'Stock Entry' : { 'mtn_details' : [ 'serial_no' ] } , 'Stock Ledger Entry' : { 'fields' : [ 'serial_no' ] } } , 'fs_item_barcode' : { 'Item' : { 'fields' : [ 'barcode' ] } , 'Delivery Note' : { 'delivery_note_details' : [ 'barcode' ] } , 'Sales Invoice' : { 'entries' : [ 'barcode' ] } } , 'fs_item_group_in_details' : { 'Delivery Note' : { 'delivery_note_details' : [ 'item_group' ] } , 'Opportunity' : { 'enquiry_details' : [ 'item_group' ] } , 'Purchase Request' : { 'indent_details' : [ 'item_group' ] } , 'Item' : { 'fields' : [ 'item_group' ] } , 'Global Defaults' : { 'fields' : [ 'default_item_group' ] } , 'Purchase Order' : { 'po_details' : [ 'item_group' ] } , 'Purchase Receipt' : { 'purchase_receipt_details' : [ 'item_group' ] } , 'Purchase Voucher' : { 'entries' : [ 'item_group' ] } , 'Quotation' : { 'quotation_details' : [ 'item_group' ] } , 'Sales Invoice' : { 'entries' : [ 'item_group' ] } , 'Sales BOM' : { 'fields' : [ 'serial_no' ] } , 'Sales Order' : { 'sales_order_details' : [ 'item_group' ] } , 'Serial No' : { 'fields' : [ 'item_group' ] } , 'Sales Partner' : { 'partner_target_details' : [ 'item_group' ] } , 'Sales Person' : { 'target_details' : [ 'item_group' ] } , 'Territory' : { 'target_details' : [ 'item_group' ] } } , 'fs_page_break' : { 'Delivery Note' : { 'delivery_note_details' : [ 'page_break' ] , 'packing_details' : [ 'page_break' ] } , 'Purchase Request' : { 'indent_details' : [ 'page_break' ] } , 'Purchase Order' : { 'po_details' : [ 'page_break' ] } , 'Purchase Receipt' : { 'purchase_receipt_details' : [ 'page_break' ] } , 'Purchase Voucher' : { 'entries' : [ 'page_break' ] } , 'Quotation' : { 'quotation_details' : [ 'page_break' ] } , ' Sales
2012-02-14 06:14:13 +00:00
$ ( document ) . bind ( 'form_refresh' , function ( ) { for ( sys _feat in sys _defaults )
{ if ( sys _defaults [ sys _feat ] == '0' && ( sys _feat in pscript . feature _dict ) )
{ if ( cur _frm . doc . doctype in pscript . feature _dict [ sys _feat ] )
{ for ( fort in pscript . feature _dict [ sys _feat ] [ cur _frm . doc . doctype ] )
{ if ( fort == 'fields' )
hide _field ( pscript . feature _dict [ sys _feat ] [ cur _frm . doc . doctype ] [ fort ] ) ; else if ( cur _frm . fields _dict [ fort ] )
{ for ( grid _field in pscript . feature _dict [ sys _feat ] [ cur _frm . doc . doctype ] [ fort ] )
cur _frm . fields _dict [ fort ] . grid . set _column _disp ( pscript . feature _dict [ sys _feat ] [ cur _frm . doc . doctype ] [ fort ] [ grid _field ] , false ) ; }
else
2012-05-07 12:30:57 +00:00
msgprint ( 'Grid "' + fort + '" does not exists' ) ; } } } } } )
/ *
* 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' ) ; } ) ; } ) ;