commonScript.js 223 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664
  1. //mootools
  2. var GLOBAL_ITEMS=function(){var t=[];for(var e in this)t.push(e);return t}();!function(){this.MooTools={version:"1.5.0dev",build:"%build%"};var t=this.typeOf=function(t){if(null==t)return"null";if(null!=t.$family)return t.$family();if(t.nodeName){if(1==t.nodeType)return"element";if(3==t.nodeType)return/\S/.test(t.nodeValue)?"textnode":"whitespace"}else if("number"==typeof t.length){if(t.callee)return"arguments";if("item"in t)return"collection"}return typeof t},e=(this.instanceOf=function(t,e){if(null==t)return!1;for(var n=t.$constructor||t.constructor;n;){if(n===e)return!0;n=n.parent}return!!t.hasOwnProperty&&t instanceof e},this.Function),n=!0;for(var r in{toString:1})n=null;n&&(n=["hasOwnProperty","valueOf","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","constructor"]),e.prototype.overloadSetter=function(t){var e=this;return function(r,i){if(null==r)return this;if(t||"string"!=typeof r){for(var a in r)e.call(this,a,r[a]);if(n)for(var o=n.length;o--;)a=n[o],r.hasOwnProperty(a)&&e.call(this,a,r[a])}else e.call(this,r,i);return this}},e.prototype.overloadGetter=function(t){var e=this;return function(n){var r,i;if("string"!=typeof n?r=n:arguments.length>1?r=arguments:t&&(r=[n]),r){i={};for(var a=0;a<r.length;a++)i[r[a]]=e.call(this,r[a])}else i=e.call(this,n);return i}},e.prototype.extend=function(t,e){this[t]=e}.overloadSetter(),e.prototype.implement=function(t,e){this.prototype[t]=e}.overloadSetter();var i=Array.prototype.slice;e.from=function(e){return"function"==t(e)?e:function(){return e}},e.convert=e.from,Array.from=function(e){return null==e?[]:a.isEnumerable(e)&&"string"!=typeof e?"array"==t(e)?e:i.call(e):[e]},Array.convert=Array.from,Number.from=function(t){var e=parseFloat(t);return isFinite(e)?e:null},Number.convert=Number.from,String.from=function(t){return t+""},String.convert=String.from,e.implement({hide:function(){return this.$hidden=!0,this},protect:function(){return this.$protected=!0,this}});var a=this.Type=function(e,n){if(e){var r=e.toLowerCase();a["is"+e]=function(e){return t(e)==r},null!=n&&(n.prototype.$family=function(){return r}.hide())}return null==n?null:(n.extend(this),n.$constructor=a,n.prototype.$constructor=n,n)},o=Object.prototype.toString;a.isEnumerable=function(t){return null!=t&&"number"==typeof t.length&&"[object Function]"!=o.call(t)};var s={},u=function(e){var n=t(e.prototype);return s[n]||(s[n]=[])},c=function(e,n){if(!n||!n.$hidden){for(var r=u(this),a=0;a<r.length;a++){var o=r[a];"type"==t(o)?c.call(o,e,n):o.call(this,e,n)}var s=this.prototype[e];null!=s&&s.$protected||(this.prototype[e]=n),null==this[e]&&"function"==t(n)&&l.call(this,e,(function(t){return n.apply(t,i.call(arguments,1))}))}},l=function(t,e){if(!e||!e.$hidden){var n=this[t];null!=n&&n.$protected||(this[t]=e)}};a.implement({implement:c.overloadSetter(),extend:l.overloadSetter(),alias:function(t,e){c.call(this,t,this.prototype[e])}.overloadSetter(),mirror:function(t){return u(this).push(t),this}}),new a("Type",a);var h=function(t,e,n){var r=e!=Object,i=e.prototype;r&&(e=new a(t,e));for(var o=0,s=n.length;o<s;o++){var u=n[o],c=e[u],l=i[u];c&&c.protect(),r&&l&&e.implement(u,l.protect())}if(r){var f=i.propertyIsEnumerable(n[0]);e.forEachMethod=function(t){if(!f)for(var e=0,r=n.length;e<r;e++)t.call(i,i[n[e]],n[e]);for(var a in i)t.call(i,i[a],a)}}return h};h("String",String,["charAt","charCodeAt","concat","indexOf","lastIndexOf","match","quote","replace","search","slice","split","substr","substring","trim","toLowerCase","toUpperCase"])("Array",Array,["pop","push","reverse","shift","sort","splice","unshift","concat","join","slice","indexOf","lastIndexOf","filter","forEach","every","map","some","reduce","reduceRight"])("Number",Number,["toExponential","toFixed","toLocaleString","toPrecision"])("Function",e,["apply","call","bind"])("RegExp",RegExp,["exec","test"])("Object",Object,["create","defineProperty","defineProperties","keys","getPrototypeOf","getOwnPropertyDescriptor","getOwnPropertyNames","preventExtensions","isExtensible","seal","isSealed","freeze","isFrozen"])("Date",Date,["now"]),Object.extend=l.overloadSetter(),Date.extend("now",(function(){return+new Date})),new a("Boolean",Boolean),Number.prototype.$family=function(){return isFinite(this)?"number":"null"}.hide(),Number.extend("random",(function(t,e){return Math.floor(Math.random()*(e-t+1)+t)}));var f=Object.prototype.hasOwnProperty;Object.extend("forEach",(function(t,e,n){for(var r in t)f.call(t,r)&&e.call(n,t[r],r,t)})),Object.each=Object.forEach,Array.implement({forEach:function(t,e){for(var n=0,r=this.length;n<r;n++)n in this&&t.call(e,this[n],n,this)},each:function(t,e){return Array.forEach(this,t,e),this}});var d=function(e){switch(t(e)){case"array":return e.clone();case"object":return Object.clone(e);default:return e}};Array.implement("clone",(function(){for(var t=this.length,e=new Array(t);t--;)e[t]=d(this[t]);return e}));var g=function(e,n,r){switch(t(r)){case"object":"object"==t(e[n])?Object.merge(e[n],r):e[n]=Object.clone(r);break;case"array":e[n]=r.clone();break;default:e[n]=r}return e};Object.extend({merge:function(e,n,r){if("string"==t(n))return g(e,n,r);for(var i=1,a=arguments.length;i<a;i++){var o=arguments[i];for(var s in o)g(e,s,o[s])}return e},clone:function(t){var e={};for(var n in t)e[n]=d(t[n]);return e},append:function(t){for(var e=1,n=arguments.length;e<n;e++){var r=arguments[e]||{};for(var i in r)t[i]=r[i]}return t}}),["Object","WhiteSpace","TextNode","Collection","Arguments"].each((function(t){new a(t)}));var p=Date.now();String.extend("uniqueID",(function(){return(p++).toString(36)}))}(),Array.implement({every:function(t,e){for(var n=0,r=this.length>>>0;n<r;n++)if(n in this&&!t.call(e,this[n],n,this))return!1;return!0},filter:function(t,e){for(var n,r=[],i=0,a=this.length>>>0;i<a;i++)i in this&&(n=this[i],t.call(e,n,i,this)&&r.push(n));return r},indexOf:function(t,e){for(var n=this.length>>>0,r=e<0?Math.max(0,n+e):e||0;r<n;r++)if(this[r]===t)return r;return-1},map:function(t,e){for(var n=this.length>>>0,r=Array(n),i=0;i<n;i++)i in this&&(r[i]=t.call(e,this[i],i,this));return r},some:function(t,e){for(var n=0,r=this.length>>>0;n<r;n++)if(n in this&&t.call(e,this[n],n,this))return!0;return!1},clean:function(){return this.filter((function(t){return null!=t}))},invoke:function(t){var e=Array.slice(arguments,1);return this.map((function(n){return n[t].apply(n,e)}))},associate:function(t){for(var e={},n=Math.min(this.length,t.length),r=0;r<n;r++)e[t[r]]=this[r];return e},link:function(t){for(var e={},n=0,r=this.length;n<r;n++)for(var i in t)if(t[i](this[n])){e[i]=this[n],delete t[i];break}return e},contains:function(t,e){return-1!=this.indexOf(t,e)},append:function(t){return this.push.apply(this,t),this},getLast:function(){return this.length?this[this.length-1]:null},getRandom:function(){return this.length?this[Number.random(0,this.length-1)]:null},include:function(t){return this.contains(t)||this.push(t),this},combine:function(t){for(var e=0,n=t.length;e<n;e++)this.include(t[e]);return this},erase:function(t){for(var e=this.length;e--;)this[e]===t&&this.splice(e,1);return this},empty:function(){return this.length=0,this},flatten:function(){for(var t=[],e=0,n=this.length;e<n;e++){var r=typeOf(this[e]);"null"!=r&&(t=t.concat("array"==r||"collection"==r||"arguments"==r||instanceOf(this[e],Array)?Array.flatten(this[e]):this[e]))}return t},pick:function(){for(var t=0,e=this.length;t<e;t++)if(null!=this[t])return this[t];return null},hexToRgb:function(t){if(3!=this.length)return null;var e=this.map((function(t){return 1==t.length&&(t+=t),t.toInt(16)}));return t?e:"rgb("+e+")"},rgbToHex:function(t){if(this.length<3)return null;if(4==this.length&&0==this[3]&&!t)return"transparent";for(var e=[],n=0;n<3;n++){var r=(this[n]-0).toString(16);e.push(1==r.length?"0"+r:r)}return t?e:"#"+e.join("")}}),String.implement({test:function(t,e){return("regexp"==typeOf(t)?t:new RegExp(""+t,e)).test(this)},contains:function(t,e){return e?(e+this+e).indexOf(e+t+e)>-1:String(this).indexOf(t)>-1},trim:function(){return String(this).replace(/^\s+|\s+$/g,"")},clean:function(){return String(this).replace(/\s+/g," ").trim()},camelCase:function(){return String(this).replace(/-\D/g,(function(t){return t.charAt(1).toUpperCase()}))},hyphenate:function(){return String(this).replace(/[A-Z]/g,(function(t){return"-"+t.charAt(0).toLowerCase()}))},capitalize:function(){return String(this).replace(/\b[a-z]/g,(function(t){return t.toUpperCase()}))},escapeRegExp:function(){return String(this).replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1")},toInt:function(t){return parseInt(this,t||10)},toFloat:function(){return parseFloat(this)},hexToRgb:function(t){var e=String(this).match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);return e?e.slice(1).hexToRgb(t):null},rgbToHex:function(t){var e=String(this).match(/\d{1,3}/g);return e?e.rgbToHex(t):null},substitute:function(t,e){return String(this).replace(e||/\\?\{([^{}]+)\}/g,(function(e,n){return"\\"==e.charAt(0)?e.slice(1):null!=t[n]?t[n]:""}))}}),Function.extend({attempt:function(){for(var t=0,e=arguments.length;t<e;t++)try{return arguments[t]()}catch(t){}return null}}),Function.implement({attempt:function(t,e){try{return this.apply(e,Array.from(t))}catch(t){}return null},bind:function(t){var e=this,n=arguments.length>1?Array.slice(arguments,1):null,r=function(){},i=function(){var a=t,o=arguments.length;this instanceof i&&(r.prototype=e.prototype,a=new r);var s=n||o?e.apply(a,n&&o?n.concat(Array.slice(arguments)):n||arguments):e.call(a);return a==t?s:a};return i},pass:function(t,e){var n=this;return null!=t&&(t=Array.from(t)),function(){return n.apply(e,t||arguments)}},delay:function(t,e,n){return setTimeout(this.pass(null==n?[]:n,e),t)},periodical:function(t,e,n){return setInterval(this.pass(null==n?[]:n,e),t)}}),Number.implement({limit:function(t,e){return Math.min(e,Math.max(t,this))},round:function(t){return t=Math.pow(10,t||0).toFixed(t<0?-t:0),Math.round(this*t)/t},times:function(t,e){for(var n=0;n<this;n++)t.call(e,n,this)},toFloat:function(){return parseFloat(this)},toInt:function(t){return parseInt(this,t||10)}}),Number.alias("each","times"),function(t){var e={};["abs","acos","asin","atan","atan2","ceil","cos","exp","floor","log","max","min","pow","sin","sqrt","tan"].each((function(t){Number[t]||(e[t]=function(){return Math[t].apply(null,[this].concat(Array.from(arguments)))})})),Number.implement(e)}(),function(){var t=this.Class=new Type("Class",(function(r){instanceOf(r,Function)&&(r={initialize:r});var i=function(){if(n(this),i.$prototyping)return this;this.$caller=null;var t=this.initialize?this.initialize.apply(this,arguments):this;return this.$caller=this.caller=null,t}.extend(this).implement(r);return i.$constructor=t,i.prototype.$constructor=i,i.prototype.parent=e,i})),e=function(){if(!this.$caller)throw new Error('The method "parent" cannot be called.');var t=this.$caller.$name,e=this.$caller.$owner.parent,n=e?e.prototype[t]:null;if(!n)throw new Error('The method "'+t+'" has no parent.');return n.apply(this,arguments)},n=function(t){for(var e in t){var r=t[e];switch(typeOf(r)){case"object":var i=function(){};i.prototype=r,t[e]=n(new i);break;case"array":t[e]=r.clone()}}return t},r=function(e,n,r){if(t.Mutators.hasOwnProperty(e)&&null==(n=t.Mutators[e].call(this,n)))return this;if("function"==typeOf(n)){if(n.$hidden)return this;this.prototype[e]=r?n:function(t,e,n){n.$origin&&(n=n.$origin);var r=function(){if(n.$protected&&null==this.$caller)throw new Error('The method "'+e+'" cannot be called.');var t=this.caller,i=this.$caller;this.caller=i,this.$caller=r;var a=n.apply(this,arguments);return this.$caller=i,this.caller=t,a}.extend({$owner:t,$origin:n,$name:e});return r}(this,e,n)}else Object.merge(this.prototype,e,n);return this};t.implement("implement",r.overloadSetter()),t.Mutators={Extends:function(t){this.parent=t,this.prototype=function(t){t.$prototyping=!0;var e=new t;return delete t.$prototyping,e}(t)},Implements:function(t){Array.from(t).each((function(t){var e=new t;for(var n in e)r.call(this,n,e[n],!0)}),this)}}}(),function(){this.Chain=new Class({$chain:[],chain:function(){return this.$chain.append(Array.flatten(arguments)),this},callChain:function(){return!!this.$chain.length&&this.$chain.shift().apply(this,arguments)},clearChain:function(){return this.$chain.empty(),this}});var t=function(t){return t.replace(/^on([A-Z])/,(function(t,e){return e.toLowerCase()}))};this.Events=new Class({$events:{},addEvent:function(e,n,r){return e=t(e),this.$events[e]=(this.$events[e]||[]).include(n),r&&(n.internal=!0),this},addEvents:function(t){for(var e in t)this.addEvent(e,t[e]);return this},fireEvent:function(e,n,r){e=t(e);var i=this.$events[e];return i?(n=Array.from(n),i.each((function(t){r?t.delay(r,this,n):t.apply(this,n)}),this),this):this},removeEvent:function(e,n){e=t(e);var r=this.$events[e];if(r&&!n.internal){var i=r.indexOf(n);-1!=i&&delete r[i]}return this},removeEvents:function(e){var n;if("object"==typeOf(e)){for(n in e)this.removeEvent(n,e[n]);return this}for(n in e&&(e=t(e)),this.$events)if(!e||e==n)for(var r=this.$events[n],i=r.length;i--;)i in r&&this.removeEvent(n,r[i]);return this}}),this.Options=new Class({setOptions:function(){var t=this.options=Object.merge.apply(null,[{},this.options].append(arguments));if(this.addEvent)for(var e in t)"function"==typeOf(t[e])&&/^on[A-Z]/.test(e)&&(this.addEvent(e,t[e]),delete t[e]);return this}})}(),function(){var t=Object.prototype.hasOwnProperty;Object.extend({subset:function(t,e){for(var n={},r=0,i=e.length;r<i;r++){var a=e[r];a in t&&(n[a]=t[a])}return n},map:function(e,n,r){var i={};for(var a in e)t.call(e,a)&&(i[a]=n.call(r,e[a],a,e));return i},filter:function(e,n,r){var i={};for(var a in e){var o=e[a];t.call(e,a)&&n.call(r,o,a,e)&&(i[a]=o)}return i},every:function(e,n,r){for(var i in e)if(t.call(e,i)&&!n.call(r,e[i],i))return!1;return!0},some:function(e,n,r){for(var i in e)if(t.call(e,i)&&n.call(r,e[i],i))return!0;return!1},keys:function(e){var n=[];for(var r in e)t.call(e,r)&&n.push(r);return n},values:function(e){var n=[];for(var r in e)t.call(e,r)&&n.push(e[r]);return n},getLength:function(t){return Object.keys(t).length},keyOf:function(e,n){for(var r in e)if(t.call(e,r)&&e[r]===n)return r;return null},contains:function(t,e){return null!=Object.keyOf(t,e)},toQueryString:function(t,e){var n=[];return Object.each(t,(function(t,r){var i;switch(e&&(r=e+"["+r+"]"),typeOf(t)){case"object":i=Object.toQueryString(t,r);break;case"array":var a={};t.each((function(t,e){a[e]=t})),i=Object.toQueryString(a,r);break;default:i=r+"="+encodeURIComponent(t)}null!=t&&n.push(i)})),n.join("&")}})}(),"undefined"!=typeof exports&&function(){for(var t in this)GLOBAL_ITEMS.contains(t)||(exports[t]=this[t]);exports.apply=function(t){Object.append(t,exports)}}(),MooTools.More={version:"1.6.1-dev",build:"%build%"},function(){var t=function(t){return null!=t},e=Object.prototype.hasOwnProperty;Object.extend({getFromPath:function(t,n){"string"==typeof n&&(n=n.split("."));for(var r=0,i=n.length;r<i;r++){if(!e.call(t,n[r]))return null;t=t[n[r]]}return t},cleanValues:function(e,n){for(var r in n=n||t,e)n(e[r])||delete e[r];return e},erase:function(t,n){return e.call(t,n)&&delete t[n],t},run:function(t){var e=Array.slice(arguments,1);for(var n in t)t[n].apply&&t[n].apply(t,e);return t}})}(),function(){var t=null,e={},n=function(t){return instanceOf(t,r.Set)?t:e[t]},r=this.Locale={define:function(n,i,a,o){var s;return instanceOf(n,r.Set)?(s=n.name)&&(e[s]=n):(e[s=n]||(e[s]=new r.Set(s)),n=e[s]),i&&n.define(i,a,o),t||(t=n),n},use:function(e){return(e=n(e))&&(t=e,this.fireEvent("change",e)),this},getCurrent:function(){return t},get:function(e,n){return t?t.get(e,n):""},inherit:function(t,e,r){return(t=n(t))&&t.inherit(e,r),this},list:function(){return Object.keys(e)}};Object.append(r,new Events),r.Set=new Class({sets:{},inherits:{locales:[],sets:{}},initialize:function(t){this.name=t||""},define:function(t,e,n){var r=this.sets[t];return r||(r={}),e&&("object"==typeOf(e)?r=Object.merge(r,e):r[e]=n),this.sets[t]=r,this},get:function(t,n,r){var i=Object.getFromPath(this.sets,t);if(null!=i){var a=typeOf(i);return"function"==a?i=i.apply(null,Array.convert(n)):"object"==a&&(i=Object.clone(i)),i}var o=t.indexOf("."),s=o<0?t:t.substr(0,o),u=(this.inherits.sets[s]||[]).combine(this.inherits.locales).include("en-US");r||(r=[]);for(var c=0,l=u.length;c<l;c++)if(!r.contains(u[c])){r.include(u[c]);var h=e[u[c]];if(h&&null!=(i=h.get(t,n,r)))return i}return""},inherit:function(t,e){t=Array.convert(t),e&&!this.inherits.sets[e]&&(this.inherits.sets[e]=[]);for(var n=t.length;n--;)(e?this.inherits.sets[e]:this.inherits.locales).unshift(t[n]);return this}})}(),Locale.define("en-US","Date",{months:["January","February","March","April","May","June","July","August","September","October","November","December"],months_abbr:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],days_abbr:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dateOrder:["month","date","year"],shortDate:"%m/%d/%Y",shortTime:"%I:%M%p",AM:"AM",PM:"PM",firstDayOfWeek:0,ordinal:function(t){return t>3&&t<21?"th":["th","st","nd","rd","th"][Math.min(t%10,4)]},lessThanMinuteAgo:"less than a minute ago",minuteAgo:"about a minute ago",minutesAgo:"{delta} minutes ago",hourAgo:"about an hour ago",hoursAgo:"about {delta} hours ago",dayAgo:"1 day ago",daysAgo:"{delta} days ago",weekAgo:"1 week ago",weeksAgo:"{delta} weeks ago",monthAgo:"1 month ago",monthsAgo:"{delta} months ago",yearAgo:"1 year ago",yearsAgo:"{delta} years ago",lessThanMinuteUntil:"less than a minute from now",minuteUntil:"about a minute from now",minutesUntil:"{delta} minutes from now",hourUntil:"about an hour from now",hoursUntil:"about {delta} hours from now",dayUntil:"1 day from now",daysUntil:"{delta} days from now",weekUntil:"1 week from now",weeksUntil:"{delta} weeks from now",monthUntil:"1 month from now",monthsUntil:"{delta} months from now",yearUntil:"1 year from now",yearsUntil:"{delta} years from now"}),function(){var t=this.Date,e=t.Methods={ms:"Milliseconds",year:"FullYear",min:"Minutes",mo:"Month",sec:"Seconds",hr:"Hours"};["Date","Day","FullYear","Hours","Milliseconds","Minutes","Month","Seconds","Time","TimezoneOffset","Week","Timezone","GMTOffset","DayOfYear","LastMonth","LastDayOfMonth","UTCDate","UTCDay","UTCFullYear","AMPM","Ordinal","UTCHours","UTCMilliseconds","UTCMinutes","UTCMonth","UTCSeconds","UTCMilliseconds"].each((function(e){t.Methods[e.toLowerCase()]=e}));var n=function(t,e,r){return 1==e?t:t<Math.pow(10,e-1)?(r||"0")+n(t,e-1,r):t};t.implement({set:function(t,n){t=t.toLowerCase();var r=e[t]&&"set"+e[t];return r&&this[r]&&this[r](n),this}.overloadSetter(),get:function(t){t=t.toLowerCase();var n=e[t]&&"get"+e[t];return n&&this[n]?this[n]():null}.overloadGetter(),clone:function(){return new t(this.get("time"))},increment:function(e,n){switch(n=null!=n?n:1,e=e||"day"){case"year":return this.increment("month",12*n);case"month":var r=this.get("date");return this.set("date",1).set("mo",this.get("mo")+n),this.set("date",r.min(this.get("lastdayofmonth")));case"week":return this.increment("day",7*n);case"day":return this.set("date",this.get("date")+n)}if(!t.units[e])throw new Error(e+" is not a supported interval");return this.set("time",this.get("time")+n*t.units[e]())},decrement:function(t,e){return this.increment(t,-1*(null!=e?e:1))},isLeapYear:function(){return t.isLeapYear(this.get("year"))},clearTime:function(){return this.set({hr:0,min:0,sec:0,ms:0})},diff:function(e,n){return"string"==typeOf(e)&&(e=t.parse(e)),((e-this)/t.units[n||"day"](3,3)).round()},getLastDayOfMonth:function(){return t.daysInMonth(this.get("mo"),this.get("year"))},getDayOfYear:function(){return(t.UTC(this.get("year"),this.get("mo"),this.get("date")+1)-t.UTC(this.get("year"),0,1))/t.units.day()},setDay:function(e,n){null==n&&""===(n=t.getMsg("firstDayOfWeek"))&&(n=1),e=(7+t.parseDay(e,!0)-n)%7;var r=(7+this.get("day")-n)%7;return this.increment("day",e-r)},getWeek:function(e){null==e&&""===(e=t.getMsg("firstDayOfWeek"))&&(e=1);var n,r=this,i=(7+r.get("day")-e)%7,a=0;if(1==e){var o=r.get("month"),s=r.get("date")-i;if(11==o&&s>28)return 1;0==o&&s<-2&&(r=new t(r).decrement("day",i),i=0),(n=new t(r.get("year"),0,1).get("day")||7)>4&&(a=-7)}else n=new t(r.get("year"),0,1).get("day");return a+=r.get("dayofyear"),a+=6-i,(a+=(7+n-e)%7)/7},getOrdinal:function(e){return t.getMsg("ordinal",e||this.get("date"))},getTimezone:function(){return this.toString().replace(/^.*? ([A-Z]{3}).[0-9]{4}.*$/,"$1").replace(/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/,"$1$2$3")},getGMTOffset:function(){var t=this.get("timezoneOffset");return(t>0?"-":"+")+n((t.abs()/60).floor(),2)+n(t%60,2)},setAMPM:function(t){t=t.toUpperCase();var e=this.get("hr");return e>11&&"AM"==t?this.decrement("hour",12):e<12&&"PM"==t?this.increment("hour",12):this},getAMPM:function(){return this.get("hr")<12?"AM":"PM"},parse:function(e){return this.set("time",t.parse(e)),this},isValid:function(t){return t||(t=this),"date"==typeOf(t)&&!isNaN(t.valueOf())},format:function(e){if(!this.isValid())return"invalid date";if(e||(e="%x %X"),"string"==typeof e&&(e=a[e.toLowerCase()]||e),"function"==typeof e)return e(this);var r=this;return e.replace(/%([a-z%])/gi,(function(e,i){switch(i){case"a":return t.getMsg("days_abbr")[r.get("day")];case"A":return t.getMsg("days")[r.get("day")];case"b":return t.getMsg("months_abbr")[r.get("month")];case"B":return t.getMsg("months")[r.get("month")];case"c":return r.format("%a %b %d %H:%M:%S %Y");case"d":return n(r.get("date"),2);case"e":return n(r.get("date"),2," ");case"H":return n(r.get("hr"),2);case"I":return n(r.get("hr")%12||12,2);case"j":return n(r.get("dayofyear"),3);case"k":return n(r.get("hr"),2," ");case"l":return n(r.get("hr")%12||12,2," ");case"L":return n(r.get("ms"),3);case"m":return n(r.get("mo")+1,2);case"M":return n(r.get("min"),2);case"o":return r.get("ordinal");case"p":return t.getMsg(r.get("ampm"));case"s":return Math.round(r/1e3);case"S":return n(r.get("seconds"),2);case"T":return r.format("%H:%M:%S");case"U":return n(r.get("week"),2);case"w":return r.get("day");case"x":return r.format(t.getMsg("shortDate"));case"X":return r.format(t.getMsg("shortTime"));case"y":return r.get("year").toString().substr(2);case"Y":return r.get("year");case"z":return r.get("GMTOffset");case"Z":return r.get("Timezone")}return i}))},toISOString:function(){return this.format("iso8601")}}).alias({toJSON:"toISOString",compare:"diff",strftime:"format"});var r=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],i=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],a={db:"%Y-%m-%d %H:%M:%S",compact:"%Y%m%dT%H%M%S",short:"%d %b %H:%M",long:"%B %d, %Y %H:%M",rfc822:function(t){return r[t.get("day")]+t.format(", %d ")+i[t.get("month")]+t.format(" %Y %H:%M:%S %Z")},rfc2822:function(t){return r[t.get("day")]+t.format(", %d ")+i[t.get("month")]+t.format(" %Y %H:%M:%S %z")},iso8601:function(t){return t.getUTCFullYear()+"-"+n(t.getUTCMonth()+1,2)+"-"+n(t.getUTCDate(),2)+"T"+n(t.getUTCHours(),2)+":"+n(t.getUTCMinutes(),2)+":"+n(t.getUTCSeconds(),2)+"."+n(t.getUTCMilliseconds(),3)+"Z"}},o=[],s=t.parse,u=function(e,n,r){var i=-1,a=t.getMsg(e+"s");switch(typeOf(n)){case"object":i=a[n.get(e)];break;case"number":if(!(i=a[n]))throw new Error("Invalid "+e+" index: "+n);break;case"string":var o=a.filter((function(t){return this.test(t)}),new RegExp("^"+n,"i"));if(!o.length)throw new Error("Invalid "+e+" string");if(o.length>1)throw new Error("Ambiguous "+e);i=o[0]}return r?a.indexOf(i):i},c=1900,l=70;t.extend({getMsg:function(t,e){return Locale.get("Date."+t,e)},units:{ms:Function.convert(1),second:Function.convert(1e3),minute:Function.convert(6e4),hour:Function.convert(36e5),day:Function.convert(864e5),week:Function.convert(6084e5),month:function(e,n){var r=new t;return 864e5*t.daysInMonth(null!=e?e:r.get("mo"),null!=n?n:r.get("year"))},year:function(e){return e=e||(new t).get("year"),t.isLeapYear(e)?316224e5:31536e6}},daysInMonth:function(e,n){return[31,t.isLeapYear(n)?29:28,31,30,31,30,31,31,30,31,30,31][e]},isLeapYear:function(t){return t%4==0&&t%100!=0||t%400==0},parse:function(e){var n,r=typeOf(e);return"number"==r?new t(e):"string"!=r?e:(e=e.clean()).length?(o.some((function(t){var r=t.re.exec(e);return!!r&&(n=t.handler(r))})),n&&n.isValid()||(n=new t(s(e)))&&n.isValid()||(n=new t(e.toInt())),n):null},parseDay:function(t,e){return u("day",t,e)},parseMonth:function(t,e){return u("month",t,e)},parseUTC:function(e){var n=new t(e),r=t.UTC(n.get("year"),n.get("mo"),n.get("date"),n.get("hr"),n.get("min"),n.get("sec"),n.get("ms"));return new t(r)},orderIndex:function(e){return t.getMsg("dateOrder").indexOf(e)+1},defineFormat:function(t,e){return a[t]=e,this},defineParser:function(t){return o.push(t.re&&t.handler?t:g(t)),this},defineParsers:function(){return Array.flatten(arguments).each(t.defineParser),this},define2DigitYearStart:function(t){return c=t-(l=t%100),this}}).extend({defineFormats:t.defineFormat.overloadSetter()});var h,f=function(e){return new RegExp("(?:"+t.getMsg(e).map((function(t){return t.substr(0,3)})).join("|")+")[a-z]*")},d={d:/[0-2]?[0-9]|3[01]/,H:/[01]?[0-9]|2[0-3]/,I:/0?[1-9]|1[0-2]/,M:/[0-5]?\d/,s:/\d+/,o:/[a-z]*/,p:/[ap]\.?m\.?/,y:/\d{2}|\d{4}/,Y:/\d{4}/,z:/Z|[+-]\d{2}(?::?\d{2})?/};d.m=d.I,d.S=d.M;var g=function(e){if(!h)return{format:e};var n=[],r=(e.source||e).replace(/%([a-z])/gi,(function(e,n){return function(e){switch(e){case"T":return"%H:%M:%S";case"x":return(1==t.orderIndex("month")?"%m[-./]%d":"%d[-./]%m")+"([-./]%y)?";case"X":return"%H([.:]%M)?([.:]%S([.:]%s)?)? ?%p? ?%z?"}return null}(n)||e})).replace(/\((?!\?)/g,"(?:").replace(/ (?!\?|\*)/g,",? ").replace(/%([a-z%])/gi,(function(t,e){var r=d[e];return r?(n.push(e),"("+r.source+")"):e})).replace(/\[a-z\]/gi,"[a-z\\u00c0-\\uffff;&]");return{format:e,re:new RegExp("^"+r+"$","i"),handler:function(e){e=e.slice(1).associate(n);var r=(new t).clearTime(),i=e.y||e.Y;for(var a in null!=i&&p.call(r,"y",i),"d"in e&&p.call(r,"d",1),("m"in e||e.b||e.B)&&p.call(r,"m",1),e)p.call(r,a,e[a]);return r}}},p=function(e,n){if(!n)return this;switch(e){case"a":case"A":return this.set("day",t.parseDay(n,!0));case"b":case"B":return this.set("mo",t.parseMonth(n,!0));case"d":return this.set("date",n);case"H":case"I":return this.set("hr",n);case"m":return this.set("mo",n-1);case"M":return this.set("min",n);case"p":return this.set("ampm",n.replace(/\./g,""));case"S":return this.set("sec",n);case"s":return this.set("ms",1e3*("0."+n));case"w":return this.set("day",n);case"Y":return this.set("year",n);case"y":return(n=+n)<100&&(n+=c+(n<l?100:0)),this.set("year",n);case"z":"Z"==n&&(n="+00");var r=n.match(/([+-])(\d{2}):?(\d{2})?/);return r=(r[1]+"1")*(60*r[2]+(+r[3]||0))+this.getTimezoneOffset(),this.set("time",this-6e4*r)}return this};t.defineParsers("%Y([-./]%m([-./]%d((T| )%X)?)?)?","%Y%m%d(T%H(%M%S?)?)?","%x( %X)?","%d%o( %b( %Y)?)?( %X)?","%b( %d%o)?( %Y)?( %X)?","%Y %b( %d%o( %X)?)?","%o %b %d %X %z %Y","%T","%H:%M( ?%p)?"),Locale.addEvent("change",(function(t){Locale.get("Date")&&function(t){h=t,d.a=d.A=f("days"),d.b=d.B=f("months"),o.each((function(t,e){t.format&&(o[e]=g(t.format))}))}(t)})).fireEvent("change",Locale.getCurrent())}(),Locale.define("zh-CHS","Date",{months:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],months_abbr:["一","二","三","四","五","六","七","八","九","十","十一","十二"],days:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],days_abbr:["日","一","二","三","四","五","六"],dateOrder:["year","month","date"],shortDate:"%Y-%m-%d",shortTime:"%I:%M%p",AM:"AM",PM:"PM",firstDayOfWeek:1,ordinal:"",lessThanMinuteAgo:"不到1分钟前",minuteAgo:"大约1分钟前",minutesAgo:"{delta}分钟之前",hourAgo:"大约1小时前",hoursAgo:"大约{delta}小时前",dayAgo:"1天前",daysAgo:"{delta}天前",weekAgo:"1星期前",weeksAgo:"{delta}星期前",monthAgo:"1个月前",monthsAgo:"{delta}个月前",yearAgo:"1年前",yearsAgo:"{delta}年前",lessThanMinuteUntil:"从现在开始不到1分钟",minuteUntil:"从现在开始約1分钟",minutesUntil:"从现在开始约{delta}分钟",hourUntil:"从现在开始1小时",hoursUntil:"从现在开始约{delta}小时",dayUntil:"从现在开始1天",daysUntil:"从现在开始{delta}天",weekUntil:"从现在开始1星期",weeksUntil:"从现在开始{delta}星期",monthUntil:"从现在开始一个月",monthsUntil:"从现在开始{delta}个月",yearUntil:"从现在开始1年",yearsUntil:"从现在开始{delta}年"}),Locale.define("zh-CHT","Date",{months:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],months_abbr:["一","二","三","四","五","六","七","八","九","十","十一","十二"],days:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],days_abbr:["日","一","二","三","四","五","六"],dateOrder:["year","month","date"],shortDate:"%Y-%m-%d",shortTime:"%I:%M%p",AM:"AM",PM:"PM",firstDayOfWeek:1,ordinal:"",lessThanMinuteAgo:"不到1分鐘前",minuteAgo:"大約1分鐘前",minutesAgo:"{delta}分鐘之前",hourAgo:"大約1小時前",hoursAgo:"大約{delta}小時前",dayAgo:"1天前",daysAgo:"{delta}天前",weekAgo:"1星期前",weeksAgo:"{delta}星期前",monthAgo:"1个月前",monthsAgo:"{delta}个月前",yearAgo:"1年前",yearsAgo:"{delta}年前",lessThanMinuteUntil:"從現在開始不到1分鐘",minuteUntil:"從現在開始約1分鐘",minutesUntil:"從現在開始約{delta}分鐘",hourUntil:"從現在開始1小時",hoursUntil:"從現在開始約{delta}小時",dayUntil:"從現在開始1天",daysUntil:"從現在開始{delta}天",weekUntil:"從現在開始1星期",weeksUntil:"從現在開始{delta}星期",monthUntil:"從現在開始一個月",monthsUntil:"從現在開始{delta}個月",yearUntil:"從現在開始1年",yearsUntil:"從現在開始{delta}年"}),"undefined"==typeof JSON&&(this.JSON={}),function(){var special={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},escape=function(t){return special[t]||"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)};JSON.validate=function(t){return t=t.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""),/^[\],:{}\s]*$/.test(t)},JSON.encode=JSON.stringify?function(t){return JSON.stringify(t)}:function(t){switch(t&&t.toJSON&&(t=t.toJSON()),typeOf(t)){case"string":return'"'+t.replace(/[\x00-\x1f\\"]/g,escape)+'"';case"array":return"["+t.map(JSON.encode).clean()+"]";case"object":case"hash":var e=[];return Object.each(t,(function(t,n){var r=JSON.encode(t);r&&e.push(JSON.encode(n)+":"+r)})),"{"+e+"}";case"number":case"boolean":return""+t;case"null":return"null"}return null},JSON.decode=function(string,secure){if(!string||"string"!=typeOf(string))return null;if(secure||JSON.secure){if(JSON.parse)return JSON.parse(string);if(!JSON.validate(string))throw new Error("JSON could not decode the input; security is enabled and the value is not secure.")}return eval("("+string+")")}}();
  3. //fetch方法
  4. const _getBytes = function(str){
  5. const buffer = new ArrayBuffer(str.length);
  6. const uint8Array = new Uint8Array(buffer);
  7. for (let i = 0; i < str.length; i++) {
  8. uint8Array[i] = str.charCodeAt(i);
  9. }
  10. return uint8Array;
  11. }
  12. /**
  13. * this.fetch是一个方法,用于发起http请求。<br/>
  14. * fetch方法模拟浏览器环境中Fetch API,但要简化一些。fetch方法调用java.net.HttpURLConnection类发起请求。
  15. * @module fetch()
  16. * @o2category server.common
  17. * @o2ordernumber 150
  18. * @o2cn 方法定义
  19. * @param {(String)} url 要获取资源的 URL。
  20. * @param {Object} options 一个配置项对象,包括对请求的设置。可选的参数有:method, headers, body
  21. * @return {Promise} resolve 时回传 Response 对象。
  22. * @o2syntax
  23. * const resPromise = fetch(url, options);
  24. * @example
  25. * <caption>
  26. * <b>样例一:<b> 发起一个GET请求,获取响应文本:
  27. * </caption>
  28. * fetch('http://hostname/resource').then((res)=>{
  29. * return res.text();
  30. * }).then((text)=>{
  31. * console.log(`响应的文本信息是:${text}`);
  32. * });
  33. * @example
  34. * <caption>
  35. * <b>样例二一:<b> 发起get请求。获取json数据,并在header中附带认证信息。
  36. * </caption>
  37. * fetch('http://hostname/resource', {
  38. * headers: {
  39. * "Authorization": "xxxxxxxxxxxxx"
  40. * }
  41. * }).then((res)=>{
  42. * return res.json();
  43. * }).then((json)=>{
  44. * console.log(`响应的json对象是:${JSON.stringify(json, null, '\t')}`);
  45. * });
  46. *
  47. * @example
  48. * <caption>
  49. * <b>样例三:<b> 发起一个POST请求,获取响应json:
  50. * </caption>
  51. * fetch('http://hostname/resource', {
  52. * method: 'post',
  53. * body: '{"postData": "this is post data"}',
  54. * headers: {
  55. * "Content-Type": "application/json; charset=UTF-8"
  56. * }
  57. * }).then((res)=>{
  58. * return res.json();
  59. * }).then((json)=>{
  60. * console.log(`响应的json对象是:${JSON.stringify(json, null, '\t')}`);
  61. * });
  62. *
  63. * @example
  64. * <caption>
  65. * <b>样例四:<b> 使用res.blob()方法获取Response流(java.io.ByteArrayInputStream);或使用res.arrayBuffer()方法获取Response的ArrayBuffer对象
  66. * </caption>
  67. * fetch('http://hostname/resource').then((res)=>{
  68. * return res.blob();
  69. * }).then((blob)=>{
  70. * //获取到 blob,实际上是一个(java.io.ByteArrayInputStream)对象
  71. * });
  72. *
  73. * fetch('http://hostname/resource').then((res)=>{
  74. * return res.arrayBuffer();
  75. * }).then((arrayBuffer)=>{
  76. * //获取到 arrayBuffer对象
  77. * });
  78. *
  79. * @example
  80. * <caption>
  81. * <b>样例五:<b> 错误处理。如果遇到网络错误,fetch将会reject,而如果是服务器响应的错误,如:500, 415等不是一个网络故障,所以想要精确的判断 fetch() 是否成功,需要包含 promise resolved 的情况下,再判断 res.ok 是否为 true。
  82. * </caption>
  83. * fetch('http://hostname/resource').then((res)=>{
  84. * if (!res.ok){
  85. * throw new Error("response was not OK");
  86. * }
  87. * return res.json();
  88. * }).then((json)=>{
  89. * console.log(`响应的json对象是:${JSON.stringify(json, null, '\t')}`);
  90. * }).catch((e)=>{
  91. * //处理请求错误
  92. * });
  93. *
  94. * @example
  95. * <caption>
  96. * <b>样例六:<b> 获取响应的信息。
  97. * </caption>
  98. * fetch('http://hostname/resource').then((res)=>{
  99. * res.ok //请求是否成功
  100. * res.status //请求响应的状态码
  101. * res.statusText //请求响应的状态文本
  102. * res.headers //响应头
  103. * res.error //java.net.HttpURLConnection的错误流
  104. * res.connection //java.net.HttpURLConnection对象
  105. *
  106. * res.text() //响应内容文本
  107. * res.json() //响应内容json对象
  108. * res.blob() //响应内容Response流(java.io.ByteArrayInputStream)
  109. * res.arrayBuffer() //响应内容Response的ArrayBuffer对象
  110. * });
  111. *
  112. * @example
  113. * <caption>
  114. * <b>样例七:<b> 使用await。
  115. * </caption>
  116. * try{
  117. * const res = await fetch('http://hostname/resource');
  118. * if (res.ok){
  119. * const json = await res.json();
  120. * //获取到json对象
  121. * }else{
  122. * log.error(`请求出现错误:${res.statusText}`);
  123. * }
  124. * }catch(e){
  125. * log.error(`请求出现错误:${e.message}`);
  126. * }
  127. */
  128. const fetch = function(url, options = {}) {
  129. const JavaURL = Java.type('java.net.URL');
  130. const urlObj = new JavaURL(url);
  131. return new Promise((resolve, reject) => {
  132. try{
  133. const httpURLConnection = urlObj.openConnection();
  134. // 设置请求方法
  135. httpURLConnection.setRequestMethod(options.method ? options.method.toUpperCase() : 'GET');
  136. // 设置请求头
  137. if (options.headers) {
  138. for (const [header, value] of Object.entries(options.headers)) {
  139. httpURLConnection.setRequestProperty(header, value);
  140. }
  141. }
  142. // 处理请求体
  143. if (options.body) {
  144. httpURLConnection.setDoOutput(true);
  145. const output = httpURLConnection.getOutputStream();
  146. output.write(_getBytes(options.body));
  147. output.flush();
  148. output.close();
  149. }
  150. // 获取响应码
  151. const responseCode = httpURLConnection.getResponseCode();
  152. const getResponseBody = function(inputStream){
  153. const JavaInputStreamReader = Java.type('java.io.InputStreamReader');
  154. const JavaBufferedReader = Java.type('java.io.BufferedReader');
  155. const reader = new JavaBufferedReader(new JavaInputStreamReader(inputStream));
  156. let inputLine;
  157. const responseData = [];
  158. while ((inputLine = reader.readLine()) !== null) {
  159. responseData.push(inputLine);
  160. }
  161. reader.close();
  162. inputStream.close();
  163. httpURLConnection.disconnect();
  164. return responseData.join('\n');
  165. }
  166. if (responseCode >= 200 && responseCode < 300) {};
  167. const isOk = (responseCode >= 200 && responseCode < 300);
  168. const inputStream = (isOk) ? httpURLConnection.getInputStream() : httpURLConnection.getErrorStream();
  169. const responseObject = {
  170. ok: isOk,
  171. status: responseCode,
  172. statusText: httpURLConnection.getResponseMessage(),
  173. headers: httpURLConnection.getHeaderFields(),
  174. error: httpURLConnection.getErrorStream(),
  175. text: async () => getResponseBody(inputStream),
  176. json: async () => JSON.parse(getResponseBody(inputStream)),
  177. blob: async () => {
  178. const byteArray = inputStream.readAllBytes();
  179. const JavaByteArrayInputStream = Java.type('java.io.ByteArrayInputStream');
  180. return new JavaByteArrayInputStream(byteArray);
  181. },
  182. arrayBuffer: async () => {
  183. const byteArray = inputStream.readAllBytes();
  184. return Uint8Array.from(byteArray).buffer;
  185. },
  186. body: {
  187. getReader: () => ({
  188. read: () => {
  189. const value = inputStream.read();
  190. return { value, done: value === -1 };
  191. },
  192. }),
  193. cancel: () => {
  194. httpURLConnection.disconnect();
  195. },
  196. // add other body related properties/methods as needed
  197. },
  198. connection: httpURLConnection
  199. };
  200. resolve(responseObject);
  201. }catch (e){
  202. reject(e);
  203. }
  204. });
  205. }
  206. //执行JS脚本
  207. /**
  208. * 执行代码片段,类似eval。使用Function包装。
  209. * @module exec()
  210. * @o2category server.common
  211. * @o2ordernumber 151
  212. * @o2cn 方法定义
  213. * @param text {String} 需要执行的代码片段
  214. * @param bind {Object} 代码片段中this的指向
  215. * @param arg {Object} 传入参数。如:{x:1, y:'5'},在代码片段中可使用 x 和 y 变量。
  216. * @param throwError {boolean} 当代码片段运行错误时,是否抛出错误
  217. * @returns {any} 返回执行的代码片段的返回值
  218. */
  219. const exec = function(text, bind, arg=null, throwError=true){
  220. const b = bind || globalThis;
  221. const p = (arg) ? Object.values(arg) : [];
  222. const k = (arg) ? Object.keys(arg).join(',') : '';
  223. try {
  224. return Function('return function('+k+'){' + text + '}')().apply(b, p);
  225. }catch(e){
  226. if (throwError) throw e;
  227. console.error(e);
  228. return '';
  229. }
  230. }
  231. //方法定义
  232. /**
  233. * this.define是一个方法,您在脚本中您可以通过this.define()来定义自己的方法。<br/>
  234. * 通过这种方式定义方法,在不同的应用使用相同的方法名称也不会造成冲突。
  235. * @module define()
  236. * @o2category server.common
  237. * @o2ordernumber 160
  238. * @o2cn 方法定义
  239. * @param {(String)} name 定义的方法名称。
  240. * @param {Function} fun 定义的方法
  241. * @param {Boolean} [overwrite] 定义的方法是否能被覆盖重写。默认值为true。
  242. * @o2syntax
  243. * this.define(name, fun, overwrite)
  244. * @example
  245. * <caption>
  246. * <b>样例一:</b>在通用脚本中定义一个通用的方法去获取公文管理所有的文种,在查询语句中根据该方法来拼接JPQL。<br/>
  247. * 1、在内容管理应用中有一个fileRes的应用,在该应用中创建一个脚本,命名为FileSql,并定义方法。
  248. * <img src='img/module/include/server_define1.png' />
  249. * </caption>
  250. * //定义一个方法
  251. * this.define("getFileSQL",function(){
  252. * const application = ["公司发文","部门发文","党委发文"];
  253. * const appSql = " ( ";
  254. * for (let i=0; i<application.length; i++){
  255. * if (i==application.length-1){
  256. * appSql = appSql + " o.applicationName = '"+application[i]+"' "
  257. * }else{
  258. * appSql = appSql + " o.applicationName = '"+application[i]+"' OR "
  259. * }
  260. * }
  261. * appSql = appSql + " ) ";
  262. * return appSql;
  263. *});
  264. * @example
  265. * <caption>
  266. * 2、在查询语句中使用该方法。
  267. * <img src='img/module/include/server_define2.png'/>
  268. * </caption>
  269. * this.include({
  270. * type : "cms",
  271. * application : "fileRes",
  272. * name : "FileSql"
  273. * })
  274. *
  275. * var sql = this.getFileSQL();
  276. *
  277. * return "SELECT o FROM com.x.processplatform.core.entity.content.Task o WHERE "+sql
  278. */
  279. const define = function(name, fun, overwrite){
  280. const over = overwrite===false;
  281. const o = {};
  282. o[name] = {"value": fun, "configurable": over};
  283. Object.defineProperties(globalThis, o);
  284. }
  285. //restful服务Action
  286. const Action = function(root, json){
  287. this.actions = json;
  288. this.root = root;
  289. var invokeFunction = function(service, parameters, name){
  290. var _self = this;
  291. return function(...pars){
  292. let success, failure, async, data, file;
  293. const parameter = {};
  294. const firstType = typeof pars[0];
  295. if (firstType==='function'){
  296. success = pars.shift();
  297. failure = pars.shift();
  298. }
  299. parameters.each((p)=>{
  300. parameter[p] = pars.shift();
  301. });
  302. if (['post', 'put'].includes(service['method']?.toLowerCase())){
  303. data = pars.shift();
  304. }
  305. if (firstType!=='function'){
  306. success = pars.shift();
  307. failure = pars.shift();
  308. }
  309. return _self.invoke({name, data, parameter, success, failure});
  310. };
  311. };
  312. var createMethod = function(service, key){
  313. const jaxrsUri = service.uri;
  314. const re = new RegExp("(?<={).+?(?=})", "g");
  315. const parameters = jaxrsUri.match(re) || [];
  316. this[key] = invokeFunction.call(this, service, parameters, key);
  317. };
  318. this.invoke = function(option){
  319. if (this.actions[option.name]){
  320. let uri = this.actions[option.name].uri;
  321. const method = this.actions[option.name].method || "get";
  322. if (option.parameter){
  323. Object.keys(option.parameter).forEach(function(key){
  324. var v = option.parameter[key];
  325. uri = uri.replace("{"+key+"}", v);
  326. });
  327. }
  328. let res = null;
  329. try{
  330. switch (method.toLowerCase()){
  331. case "get":
  332. res = globalThis.applications.getQuery(this.root, uri);
  333. break;
  334. case "post":
  335. res = globalThis.applications.postQuery(this.root, uri, JSON.stringify(option.data));
  336. break;
  337. case "put":
  338. res = globalThis.applications.putQuery(this.root, uri, JSON.stringify(option.data));
  339. break;
  340. case "delete":
  341. res = globalThis.applications.deleteQuery(this.root, uri);
  342. break;
  343. default:
  344. res = globalThis.applications.getQuery(this.root, uri);
  345. }
  346. if (res && res.getType().toString()==="success"){
  347. const json = JSON.parse(res.toString());
  348. if (option.success) option.success(json);
  349. return json;
  350. }else{
  351. const json = ((res) ? JSON.parse(res.toString()) : null)
  352. if (option.failure) option.failure(json);
  353. return json;
  354. }
  355. }catch(e){
  356. if (option.failure) option.failure(e);
  357. }
  358. return res;
  359. }
  360. };
  361. Object.keys(this.actions).forEach((key)=>{
  362. const service = this.actions[key];
  363. if (service.uri) if (!this[key]) createMethod.call(this, service, key);
  364. });
  365. }
  366. Object.assign(Action, {
  367. get applications(){
  368. return (globalThis.java_resources) ? globalThis.java_resources.getApplications() : null;
  369. }
  370. });
  371. /**
  372. * 本文档说明如何在后台脚本中使用Actions调用平台的RESTful服务。<br/>
  373. * 通过访问以下地址来查询服务列表:http://server/x_program_center/jest/list.html (v7.2之前版本需要加端口20030)
  374. * @module server.Actions
  375. * @o2cn 服务调用
  376. * @o2category server.common
  377. * @o2ordernumber 165
  378. * @o2syntax
  379. * //获取Actions
  380. * this.Actions
  381. */
  382. const Actions = {
  383. "loadedActions": {},
  384. /**
  385. * 平台预置了Actions对象用于调用平台提供的服务,您可以使用this.Actions.load来获取这些方法。由于是运行在服务器端,服务都是同步调用。
  386. * @method load
  387. * @methodOf module:server.Actions
  388. * @instance
  389. * @param {String} root 平台RESTful服务根,具体服务列表参见:http://server/x_program_center/jest/list.html。(v7.2之前版本需要加端口20030)
  390. * 如:
  391. *<pre><code class='language-js'>
  392. * "x_processplatform_assemble_surface" //流程平台相关服务根
  393. * </code></pre>
  394. * @return {Object} 返回action对象,用于后续服务调用
  395. * @o2syntax
  396. * var actions = this.Actions.load( root );
  397. * @o2syntax
  398. * //获取流程平台服务对象。
  399. * var processAction = this.Actions.load("x_processplatform_assemble_surface");
  400. * @o2syntax
  401. * <caption>
  402. * 通过this.Actions.load(root)方法得到action对象,就可以访问此服务下的方法了。<br/>
  403. * 访问方法的规则如下:
  404. * </caption>
  405. * var requestString = this.Actions.load( root )[actionName][methodName]( arguements );
  406. *
  407. * requestString : 服务返回的响应数据,字符串格式,可以通过 requestObjest = JSON.parse(requestString);解析成对象
  408. *
  409. * root : 平台服务根名称,如果 x_processplatform_assemble_surface
  410. *
  411. * actionName : 服务下的Action分类名称,如 TaskAction
  412. *
  413. * methodName : Action分类下的方法名称,如 get
  414. *
  415. * arguements : 需调用的RESTful服务的相关参数。这些参数需要按照先后顺序传入。根据实际情况可以省略某些参数。参数序列分别是:
  416. *
  417. * uri的参数, data(Post, Put方法), success, failure, async。
  418. *
  419. * uri参数:如果有uri有多个参数,需要按先后顺序传入。
  420. *
  421. * data参数:要提交到后台的数据。POST 和 PUT 方法需要传入,GET方法和DELETE方法省略。
  422. *
  423. * success参数:服务执行成功时的回调方法,形如 function(json){
  424. * json为后台服务传回的数据
  425. * }。
  426. *
  427. * failure 参数:服务执行失败时的回调方法,形如 function(xhr){
  428. * xhr XmlHttpRequest对象,服务器请求失败时有值
  429. * }
  430. * 此参数可以省略,如果省略,系统会自动弹出错误信息。
  431. * @o2syntax
  432. * <caption>
  433. * 处理返回的数据有两种方式,二选一即可:<br/>
  434. * 1、该方法返回的结果是响应的 json对象。<br/>
  435. * 2、通过success方法作为第一个参数来处理结果。
  436. * </caption>
  437. * //success:arguements中的第一个function对象
  438. * function(json){
  439. * //json为后台服务传回的数据
  440. * }
  441. * @example
  442. * <caption>
  443. * <b>样例1:</b>
  444. * 根据x_processplatform_assemble_surface服务获取当前用户的待办列表:<br/>
  445. * 可以通过对应服务的查询页面,http://server/x_processplatform_assemble_surface/jest/index.html (v7.2之前版本需要加端口20020)<br/>
  446. * 可以看到以下界面:<img src="img/module/Actions/Actions.png"/>
  447. * 我们可以找到TaskAction的V2ListPaging服务是列式当前用户待办的服务。<br/>
  448. * 该服务有以下信息:<br/>
  449. * 1、actionName是:TaskAction<br/>
  450. * 2、methodName是:V2ListPaging<br/>
  451. * 3、有两个url参数,分别是 page(分页), size(每页数量)<br/>
  452. * 4、有一系列的body参数<br/>
  453. * 5、该服务方法类型是POST<br/>
  454. * 根据这些信息我们可以组织出下面的方法:
  455. * </caption>
  456. * const processAction = this.Actions.load("x_processplatform_assemble_surface"); //获取action
  457. * const method = processAction.TaskAction.V2ListPaging; //获取列式方法
  458. * //执行方法1
  459. * method(
  460. * 1, //uri 第1个参数,如果无uri参数,可以省略
  461. * 20, //uri 第2个参数,如果无uri参数,可以省略,如果还有其他uri参数,可以用逗号, 分隔
  462. * { //body 参数,对POST和PUT请求,该参数必须传,可以为空对象
  463. * processList : [xxx] //具体参数
  464. * },
  465. * function(json){ //正确调用的回调
  466. * //json.data得到服务返回数据
  467. * },
  468. * function(responseJSON){ //可选,错误信息, json格式
  469. * print( JSON.stringify(responseJSON) )
  470. * }
  471. * );
  472. *
  473. * //执行方法2
  474. * const responsJSON = method( 1, 20, {processList : [xxx]} );
  475. * @example
  476. * <caption>出错信息responseJSON的格式</caption>
  477. * {
  478. * "type": "error", //类型为错误
  479. * "message": "标识为:343434 的 Task 对象不存在.", //提示文本
  480. * "date": "2020-12-29 17:02:13", //出错时间
  481. * "prompt": "com.x.base.core.project.exception.ExceptionEntityNotExist" //后台错误类
  482. *}
  483. * @example
  484. * <caption>
  485. * <b>样例2:</b>
  486. * 已知流程实例的workid,在脚本中获取数据,修改后进行保存。
  487. * </caption>
  488. * //查询服务列表找到获取data数据服务为DataAction的getWithWork方法
  489. * //查询服务列表找到更新data数据服务为DataAction的updateWithWork方法
  490. *
  491. * const workid = "cce8bc22-225a-4f85-8132-7374d546886e";
  492. * const json = this.Actions.load("x_processplatform_assemble_surface").DataAction.getWithWork( //平台封装好的方法
  493. * workid, //uri的参数
  494. * );
  495. * const data = json.data;
  496. *
  497. * data.subject = "新标题"; //修改数据
  498. * const result = this.Actions.load("x_processplatform_assemble_surface").DataAction.updateWithWork(
  499. * workid, //uri的参数
  500. * data, //保存的数据
  501. * );
  502. */
  503. "load": function(root){
  504. if (this.loadedActions[root]) return this.loadedActions[root];
  505. const jaxrsString = globalThis.applications.describeApi(root);
  506. const json = JSON.parse(jaxrsString.toString());
  507. if (json && json.jaxrs){
  508. const actionObj = {};
  509. json.jaxrs.forEach((o)=>{
  510. if (o.methods && o.methods.length){
  511. const actions = {};
  512. o.methods.forEach((m)=>{
  513. const o = {"uri": "/"+m.uri};
  514. if (m.method) o.method = m.method;
  515. if (m.enctype) o.enctype = m.enctype;
  516. actions[m.name] = o;
  517. });
  518. actionObj[o.name] = new Action(root, actions);
  519. }
  520. });
  521. this.loadedActions[root] = actionObj;
  522. return actionObj;
  523. }
  524. return null;
  525. }
  526. };
  527. //log输出
  528. const _parsePrint = function(str, ...pars){
  529. if (!str && str!==0 && str!==false) return str;
  530. let text = (typeof str!=="string") ? str.toString() : str;
  531. try{
  532. text = text.replace(/%s/g, ()=>pars.shift()).toString();
  533. text += ' '+pars.map((p)=>p.toString()).join(' ')
  534. }catch(e){}
  535. return text;
  536. }
  537. /**
  538. * this.print是一个方法,在服务器控制台输出信息。<br/>
  539. * @module print()
  540. * @o2cn 控制台输出打印
  541. * @o2category server.common
  542. * @o2ordernumber 152
  543. *
  544. * @param {(String)} text 要输出的文本信息。</b>
  545. * @param {(String)} type 要输出的文本信息的类型,会添加到输出信息的前面,默认为“PRINT”。</b>
  546. * @example
  547. * this.print("这是我要输出的信息");
  548. * //2021-12-20 13:26:24.739 [script] PRINT 这是我要输出的信息
  549. *
  550. * this.print("这是一个自定义类型的信息", "MYTYPE");
  551. * //2021-12-20 13:26:24.765 [script] MYTYPE 这是一个自定义类型的信息
  552. */
  553. const print = function(text, type){
  554. // const d = new Intl.DateTimeFormat(undefined, {
  555. // year: "numeric",
  556. // month: "2-digit",
  557. // day: "2-digit",
  558. // hour: "2-digit",
  559. // minute: "2-digit",
  560. // second: "2-digit",
  561. // fractionalSecondDigits: 3
  562. // }).format(new Date());
  563. var t = (type || "PRINT").toUpperCase();
  564. console[(t==='ERROR') ? 'error' : 'log'](`[script] ${t} ${text}`);
  565. }
  566. /**
  567. * this.log是一个服务器控制台输出方法,可使用log, log.error, log.info, log.warn方法在服务器控制台输入信息。<br/>
  568. * @module log
  569. * @o2category server.common
  570. * @o2ordernumber 155
  571. * @o2cn 分等级控制台输出
  572. * @example
  573. * log("这是我要输出的信息");
  574. * //2021-12-20 13:26:24.739 [script] PRINT 这是我要输出的信息
  575. *
  576. * log.error("这是一个错误信息");
  577. * //2021-12-20 13:26:24.765 [script] ERROR 这是一个错误信息
  578. *
  579. * log.info("这是一个普通信息");
  580. * //2021-12-20 13:26:24.765 [script] INFO 这是一个普通信息
  581. *
  582. * log.warn("这是一个警告信息");
  583. * //2021-12-20 13:26:24.765 [script] WARN 这是一个警告信息
  584. */
  585. const log = function(...arg){
  586. print(_parsePrint(...arg));
  587. }
  588. const keys = ['error', 'info', 'warn'];
  589. keys.forEach((k)=>{
  590. log[k] = function(...arg){
  591. print(_parsePrint(...arg), k);
  592. }
  593. });
  594. //组织相关服务
  595. const _getNameFlag = function(name){
  596. if (Array.isArray(name)){
  597. return name.map(n=>((typeof n)==="object" ? (n.distinguishedName || n.id || n.unique || n.name) : n));
  598. }else{
  599. return [((typeof name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  600. }
  601. }
  602. /**
  603. * 您可以通过this.org获取组织中的人员、人员属性、组织、组织属性、身份、群组和角色。后端调用都是同步的。
  604. * @module server.org
  605. * @o2cn 组织查询
  606. * @o2category server.common
  607. * @o2ordernumber 170
  608. * @since v9.0.4
  609. * @property {GroupFactory} group 后端的GroupFactory实例,可用于获取group群组相关数据
  610. * @property {IdentityFactory} identity 后端的IdentityFactory实例,可用于获取identity身份相关数据
  611. * @property {PersonFactory} person 后端的PersonFactory实例,可用于获取person人员相关数据
  612. * @property {PersonAttributeFactory} personAttribute 后端的GroupFactory实例,可用于获取personAttribute人员属性相关数据
  613. * @property {RoleFactory} role 后端的RoleFactory实例,可用于获取role角色相关数据
  614. * @property {UnitFactory} unit 后端的UnitFactory实例,可用于获取unit相关数据
  615. * @property {UnitAttributeFactory} unitAttribute 后端的UnitAttributeFactory实例,可用于获取unitAttribute组织属性相关数据
  616. * @property {UnitDutyFactory} unitDuty 后端的UnitDutyFactory实例,可用于获取unitDuty组织属性相关数据
  617. * @o2syntax
  618. * //您可以通过以下引用来获取当前实例的org对象,如下:
  619. * this.org;
  620. * globalThis.org;
  621. * org
  622. *
  623. *@example
  624. * //通过后端java类,来获取当前人所在的部门名称
  625. * const unit = org.unit();
  626. * const unitNames = unit.listWithPerson("张三@xxx@P");
  627. */
  628. const org = {}
  629. const _javaOrg = function(){
  630. return globalThis.java_resources.getOrganization();
  631. }
  632. Object.defineProperties(org, {
  633. oGroup: { get: ()=>_javaOrg().group() },
  634. oIdentity: { get: ()=>_javaOrg().identity() },
  635. oPerson: { get: ()=>_javaOrg().person() },
  636. oPersonAttribute: { get: ()=>_javaOrg().personAttribute() },
  637. oRole: { get: ()=>_javaOrg().role() },
  638. oUnit: { get: ()=>_javaOrg().unit() },
  639. oUnitAttribute: { get: ()=>_javaOrg().unitAttribute() },
  640. oUnitDuty: { get: ()=>_javaOrg().unitDuty() }
  641. });
  642. Object.assign(org, {
  643. group: ()=> this.org.oGroup,
  644. identity: ()=> this.org.oIdentity,
  645. person: ()=> this.org.oPerson,
  646. personAttribute: ()=> this.org.oPersonAttribute,
  647. role: ()=> this.org.oRole,
  648. unit: ()=> this.org.oUnit,
  649. unitAttribute: ()=> this.org.oUnitAttribute,
  650. unitDuty: ()=> this.org.oUnitDuty,
  651. getObject(o, v){
  652. if (v && Array.isArray(v)){
  653. return v.map(name=>JSON.parse(o.getObject(name).toString()));
  654. }
  655. return null;
  656. },
  657. //群组***************
  658. //获取群组--返回群组的对象数组
  659. /**
  660. 根据群组标识获取对应的群组对象或数组:group对象或数组
  661. * @method getGroup
  662. * @o2membercategory group
  663. * @methodOf module:server.org
  664. * @static
  665. * @param {GroupFlag|GroupFlag[]} name - 群组的distinguishedName、name、id、unique属性值,群组对象,或上述属性值和对象的数组。
  666. * @return {GroupData|GroupData[]} 返回群组,单个是Object,多个是Array。
  667. * @o2ActionOut x_organization_assemble_express.GroupAction.listObject|example=Group
  668. * @o2syntax
  669. * //返回群组,单个是Object,多个是Array。
  670. * const groupList = this.org.getGroup( name );
  671. */
  672. getGroup: function(name){
  673. const v = this.oGroup.listObject(_getNameFlag(name));
  674. const v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  675. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  676. },
  677. //查询下级群组--返回群组的对象数组
  678. //nested 布尔 true嵌套下级;false直接下级;默认false;
  679. /**
  680. 根据群组标识获取下级群组的对象数组:group对象数组。
  681. * @method listSubGroup
  682. * @o2membercategory group
  683. * @methodOf module:server.org
  684. * @static
  685. * @param {GroupFlag|GroupFlag[]} name - 群组的distinguishedName、name、id、unique属性值,群组对象,或上述属性值和对象的数组。
  686. * @param {Boolean} [nested] true嵌套的所有下级群组;false直接下级群组;默认false。
  687. * @return {GroupData[]} 返回群组数组。
  688. * @o2ActionOut x_organization_assemble_express.GroupAction.listWithGroupSubDirectObject|example=Group
  689. * @o2syntax
  690. * //返回嵌套下级群组数组。
  691. * const groupList = this.org.listSubGroup( name, true );
  692. */
  693. listSubGroup: function(name, nested){
  694. return this.getObject(this.oGroup, this.oGroup[(nested) ? 'listWithGroupSubNested' : 'listWithGroupSubDirect'](_getNameFlag(name)));
  695. },
  696. //查询上级群组--返回群组的对象数组
  697. //nested 布尔 true嵌套上级;false直接上级;默认false;
  698. /**
  699. 根据群组标识获取上级群组的对象数组:group对象数组。
  700. * @method listSupGroup
  701. * @o2membercategory group
  702. * @methodOf module:server.org
  703. * @static
  704. * @param {GroupFlag|GroupFlag[]} name - 群组的distinguishedName、name、id、unique属性值,群组对象,或上述属性值和对象的数组。
  705. * @param {Boolean} [nested] true嵌套的所有上级群组;false直接上级群组;默认false。
  706. * @return {GroupData[]} 返回群组数组。
  707. * @o2ActionOut x_organization_assemble_express.GroupAction.listWithGroupSupDirectObject|example=Group
  708. * @o2syntax
  709. * //返回嵌套上级群组数组。
  710. * const groupList = this.org.listSupGroup( name, true );
  711. */
  712. listSupGroup:function(name, nested){
  713. return this.getObject(this.oGroup, this.oGroup[(nested) ? 'listWithGroupSupNested' : 'listWithGroupSupDirect'](_getNameFlag(name)));
  714. },
  715. //人员所在群组(嵌套)--返回群组的对象数组
  716. /**
  717. * 根据人员标识获取所有的群组对象数组。如果群组具有群组(group)成员,且群组成员中包含该人员,那么该群组也被返回。
  718. * @method listGroupWithPerson
  719. * @o2membercategory group
  720. * @methodOf module:server.org
  721. * @static
  722. * @param {PersonFlag|PersonFlag[]} name - 人员的distinguishedName、id、unique属性值,人员对象,或上述属性值和对象的数组。
  723. * @return {GroupData[]} 返回群组对象数组。
  724. * @o2ActionOut x_organization_assemble_express.GroupAction.listWithPersonObject|example=Group
  725. * @o2syntax
  726. * //返回群组数组。
  727. * const groupList = this.org.listGroupWithPerson( name );
  728. */
  729. listGroupWithPerson:function(name){
  730. return this.getObject(this.oGroup, this.oGroup.listWithPerson(_getNameFlag(name)));
  731. },
  732. //群组是否拥有角色--返回true, false
  733. /**
  734. * 群组是否拥有角色。
  735. * @method groupHasRole
  736. * @o2membercategory role
  737. * @methodOf module:server.org
  738. * @static
  739. * @param {GroupFlag} name - 群组的distinguishedName、name、id、unique属性值,群组对象。
  740. * @param {RoleFlag|RoleFlag[]} roleList - 角色的distinguishedName、name、id、unique属性值,角色对象;或上述属性值和对象的数组。
  741. * @return {Boolean} 如果群组拥有角色返回true, 否则返回false。
  742. * @o2syntax
  743. * //返回判断结果。
  744. * const groupList = this.org.groupHasRole( name, roleList );
  745. */
  746. groupHasRole: function(name, roleList){
  747. const nameFlag = (typeof name==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  748. return this.oGroup.hasRole(nameFlag, _getNameFlag(roleList));
  749. },
  750. //角色***************
  751. //获取角色--返回角色的对象数组
  752. /**
  753. * 根据角色标识获取对应的角色对象或数组。
  754. * @method getRole
  755. * @o2membercategory role
  756. * @methodOf module:server.org
  757. * @static
  758. * @param {RoleFlag|RoleFlag[]} name - 角色的distinguishedName、name、id、unique属性值,角色对象;或上述属性值和对象的数组。
  759. * @return {RoleData|RoleData[]} 返回角色,单个为Object,多个为Array。
  760. * @o2ActionOut x_organization_assemble_express.RoleAction.listObject|example=Role
  761. * @o2syntax
  762. * //返回角色,单个为对象,多个为数组。
  763. * const roleList = this.org.getRole( name );
  764. */
  765. getRole: function(name){
  766. const v = this.oRole.listObject(_getNameFlag(name));
  767. const v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  768. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  769. },
  770. //人员所有角色(嵌套)--返回角色的对象数组
  771. /**
  772. * 根据人员标识获取所有的角色对象数组。如果角色具有群组(group)成员,且群组中包含该人员,那么该角色也被返回。
  773. * @method listRoleWithPerson
  774. * @o2membercategory role
  775. * @methodOf module:server.org
  776. * @static
  777. * @param {PersonFlag|PersonFlag[]} name - 人员的distinguishedName、id、unique属性值,人员对象,或上述属性值和对象的数组。
  778. * @return {RoleData[]} 返回角色对象数组。
  779. * @o2ActionOut x_organization_assemble_express.RoleAction.listWithPersonObject|example=Role
  780. * @o2syntax
  781. * //返回角色数组。
  782. * const roleList = this.org.listRoleWithPerson( name );
  783. */
  784. listRoleWithPerson:function(name){
  785. return this.getObject(this.oRole, this.oRole.listWithPerson(_getNameFlag(name)));
  786. },
  787. //人员***************
  788. //人员是否拥有角色--返回true, false
  789. /**
  790. * 人员是否拥有角色。
  791. * @method personHasRole
  792. * @o2membercategory role
  793. * @methodOf module:server.org
  794. * @static
  795. * @param {PersonFlag} name - 人员的distinguishedName、id、unique属性值,人员对象。
  796. * @param {RoleFlag|RoleFlag[]} roleList - 角色的distinguishedName、name、id、unique属性值,角色对象;或上述属性值和对象的数组。
  797. * @return {Boolean} 如果人员拥有角色返回true, 否则返回false。
  798. * @o2syntax
  799. * //返回判断结果。
  800. * const groupList = this.org.personHasRole( name, roleList );
  801. */
  802. personHasRole: function(name, roleList){
  803. const nameFlag = (typeof name==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  804. return this.oPerson.hasRole(nameFlag, _getNameFlag(roleList));
  805. },
  806. //获取人员,附带身份,身份所在的组织,个人所在群组,个人拥有角色.
  807. /**
  808. 根据人员标识获取对应的人员对象,附带身份,身份所在的组织,个人所在群组,个人拥有角色.
  809. * @method getPersonData
  810. * @o2membercategory person
  811. * @methodOf module:server.org
  812. * @static
  813. * @param {String} name - 人员的distinguishedName、id、unique属性值,人员名称。
  814. * @return {PersonData} 返回人员对象。
  815. * @o2ActionOut x_organization_assemble_express.PersonAction.get|example=PersonData
  816. * @o2syntax
  817. * //返回人员对象。
  818. * const person = this.org.getPersonData( name );
  819. */
  820. getPersonData: function(name){
  821. const v = this.oPerson.getExt((typeof name==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name);
  822. return (!v) ? null : JSON.parse(v.toString());
  823. },
  824. //获取人员--返回人员的对象数组
  825. /**
  826. 根据人员标识获取对应的人员对象或数组:person对象或数组
  827. * @method getPerson
  828. * @o2membercategory person
  829. * @methodOf module:server.org
  830. * @static
  831. * @param {PersonFlag|PersonFlag[]} name - 人员的distinguishedName、id、unique属性值,人员对象,或上述属性值和对象的数组。
  832. * @param {(Boolean)} [findCN] 是否需要额外查找中文名称(如张三),默认false。如果为true,除匹配unique和distingiushedName外,还会在名称的第一段中查找所有匹配到的人(精确匹配)。
  833. * @return {PersonData|PersonData[]} 返回人员,单个是Object,多个是Array。
  834. * @o2ActionOut x_organization_assemble_express.PersonAction.listObject|example=Person
  835. * @o2syntax
  836. * //返回人员,单个是对象,多个是数组。
  837. * const personList = this.org.getPerson( name );
  838. */
  839. getPerson: function(name, findCN){
  840. const v = this.oPerson.listObject(_getNameFlag(name), !!findCN);
  841. const v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  842. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  843. },
  844. //查询下级人员--返回人员的对象数组
  845. //nested 布尔 true嵌套下级;false直接下级;默认false;
  846. /**
  847. 根据人员标识获取下级人员的对象数组:person对象数组。该上下级关系被人员的汇报对象值(superior)决定。
  848. * @method listSubPerson
  849. * @o2membercategory person
  850. * @methodOf module:server.org
  851. * @static
  852. * @param {PersonFlag|PersonFlag[]} name - 人员的distinguishedName、id、unique属性值,人员对象,或上述属性值和对象的数组。
  853. * @param {Boolean} [nested] true嵌套的所有下级人员;false直接下级人员;默认false。
  854. * @return {PersonData[]} 返回人员数组。
  855. * @o2ActionOut x_organization_assemble_express.PersonAction.listWithPersonSubDirectObject|example=Person
  856. * @o2syntax
  857. * //返回嵌套下级人员数组。
  858. * const personList = this.org.listSubPerson( name, true );
  859. */
  860. listSubPerson: function(name, nested){
  861. return this.getObject(this.oPerson, this.oPerson[(nested) ? 'listWithPersonSubNested' : 'listWithPersonSubDirect'](_getNameFlag(name)));
  862. },
  863. //查询上级人员--返回人员的对象数组
  864. //nested 布尔 true嵌套上级;false直接上级;默认false;
  865. /**
  866. *根据人员标识获取上级人员的对象数组:person对象数组。该上下级关系被人员的汇报对象值(superior)决定。
  867. * @method listSupPerson
  868. * @o2membercategory person
  869. * @methodOf module:server.org
  870. * @static
  871. * @param {PersonFlag|PersonFlag[]} name - 人员的distinguishedName、id、unique属性值,人员对象,或上述属性值和对象的数组。
  872. * @param {Boolean} [nested] true嵌套的所有上级人员;false直接上级人员;默认false。
  873. * @return {PersonData[]} 返回人员数组。
  874. * @o2ActionOut x_organization_assemble_express.PersonAction.listWithPersonSupDirectObject|example=Person
  875. * @o2syntax
  876. * //返回嵌套上级人员数组。
  877. * const personList = this.org.listSupPerson( name, true );
  878. */
  879. listSupPerson: function(name, nested){
  880. return this.getObject(this.oPerson, this.oPerson[(nested) ? 'listWithPersonSupNested' : 'listWithPersonSupDirect'](_getNameFlag(name)));
  881. },
  882. //获取群组的所有人员--返回人员的对象数组
  883. /**
  884. * 根据群组标识获取人员对象成员:person对象数组。
  885. * @method listPersonWithGroup
  886. * @o2membercategory person
  887. * @methodOf module:server.org
  888. * @static
  889. * @param {GroupFlag|GroupFlag[]} name - 群组的distinguishedName、name、id、unique属性值,群组对象,或上述属性值和对象的数组。
  890. * @return {PersonData[]} 返回人员对象数组。
  891. * @o2ActionOut x_organization_assemble_express.PersonAction.listWithGroupObject|example=Person
  892. * @o2syntax
  893. * //返回人员数组。
  894. * const personList = this.org.listPersonWithGroup( group );
  895. */
  896. listPersonWithGroup: function(name){
  897. return this.getObject(this.oPerson, this.oPerson.listWithGroup(_getNameFlag(name)));
  898. },
  899. //获取角色的所有人员--返回人员的对象数组
  900. /**
  901. * 根据角色标识获取人员对象数组:person对象数组。
  902. * @method listPersonWithRole
  903. * @o2membercategory person
  904. * @methodOf module:server.org
  905. * @static
  906. * @param {RoleFlag|RoleFlag[]} name - 角色的distinguishedName、name、id、unique属性值,角色对象,或上述属性值和对象的数组。
  907. * @return {PersonData[]} 返回人员对象数组。
  908. * @o2ActionOut x_organization_assemble_express.PersonAction.listWithRoleObject|example=Person
  909. * @o2syntax
  910. * //返回人员数组。
  911. * const personList = this.org.listPersonWithRole( role );
  912. */
  913. listPersonWithRole: function(name){
  914. return this.getObject(this.oPerson, this.oPerson.listWithRole(_getNameFlag(name)));
  915. },
  916. //获取身份的所有人员--返回人员的对象数组
  917. /**
  918. * 根据身份标识获取人员对象成员:person对象数组。
  919. * @method listPersonWithIdentity
  920. * @o2membercategory person
  921. * @methodOf module:server.org
  922. * @static
  923. * @param {IdentityFlag|IdentityFlag[]} name - 身份的distinguishedName、id、unique属性值,身份对象,或上述属性值和对象的数组。
  924. * @return {PersonData[]} 返回人员对象数组。
  925. * @o2ActionOut x_organization_assemble_express.PersonAction.listWithIdentityObject|example=Person
  926. * @o2syntax
  927. * //返回人员数组。
  928. * const personList = this.org.listPersonWithIdentity( identity );
  929. */
  930. listPersonWithIdentity: function(name){
  931. return this.getObject(this.oPerson, this.oPerson.listWithIdentity(_getNameFlag(name)));
  932. },
  933. //获取身份的所有人员--返回人员的对象数组
  934. /**
  935. * 根据身份标识获取人员对象:person对象数组。
  936. * @method getPersonWithIdentity
  937. * @o2membercategory person
  938. * @methodOf module:server.org
  939. * @static
  940. * @param {IdentityFlag|IdentityFlag[]} name - 身份的distinguishedName、id、unique属性值,身份对象,或上述属性值和对象的数组。
  941. * @return {PersonData|PersonData[]} 返回人员对象,单个是Object,多个是Array。
  942. * @o2ActionOut x_organization_assemble_express.PersonAction.listWithIdentityObject|example=Person
  943. * @o2syntax
  944. * //返回人员,单个是Object,多个是Array。
  945. * const personList = this.org.listPersonWithIdentity( identity );
  946. */
  947. getPersonWithIdentity: function(name){
  948. const v = this.oPerson.listWithIdentity(_getNameFlag(name));
  949. const arr = this.getObject(this.oPerson, v);
  950. return (arr && arr.length===1) ? arr[0] : arr;
  951. },
  952. //查询组织成员的人员--返回人员的对象数组
  953. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  954. /**
  955. * 根据组织标识获取人员对象成员:person对象数组。
  956. * @method listPersonWithUnit
  957. * @o2membercategory person
  958. * @methodOf module:server.org
  959. * @static
  960. * @param {UnitFlag|UnitFlag[]} name - 组织的distinguishedName、id、unique属性值,组织对象,或上述属性值和对象的数组。
  961. * @param {Boolean} [nested] 是否嵌套获取组织以及下级组织的人员,true表示嵌套,flase表示获取直接组织。默认为false
  962. * @return {PersonData[]} 返回人员对象数组。
  963. * @o2ActionOut x_organization_assemble_express.PersonAction.listWithUnitSubDirectObject|example=Person
  964. * @o2syntax
  965. * //返回组织的直接人员数组。
  966. * const personList = this.org.listPersonWithUnit( unit );
  967. *
  968. * //返回组织的以及嵌套下级组织所有的人员数组。
  969. * const personList = this.org.listPersonWithUnit( unit, true );
  970. */
  971. listPersonWithUnit: function(name, nested){
  972. return this.getObject(this.oPerson, this.oPerson[(nested) ? 'listWithUnitSubNested' : 'listWithUnitSubDirect'](_getNameFlag(name)));
  973. },
  974. //人员属性************
  975. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  976. /**
  977. * 添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  978. * @method appendPersonAttribute
  979. * @o2membercategory personAttribute
  980. * @methodOf module:server.org
  981. * @static
  982. * @param {PersonFlag} person - 人员的distinguishedName、id、unique属性值,人员对象。
  983. * @param {String} attr 属性名称。
  984. * @param {String[]} values 属性值,必须为数组。
  985. * @o2syntax
  986. * //添加人员属性值
  987. * this.org.appendPersonAttribute( person, attribute, valueArray);
  988. */
  989. appendPersonAttribute: function(person, attr, values){
  990. const personFlag = (typeof person==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  991. return this.oPersonAttribute.appendWithPersonWithName(personFlag, attr, values);
  992. },
  993. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  994. /**
  995. * 设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  996. * @method setPersonAttribute
  997. * @o2membercategory personAttribute
  998. * @methodOf module:server.org
  999. * @static
  1000. * @param {PersonFlag} person - 人员的distinguishedName、id、unique属性值,人员对象。
  1001. * @param {String} attr 属性名称。
  1002. * @param {String[]} values 属性值,必须为数组。
  1003. * @o2syntax
  1004. * //添加人员属性值
  1005. * this.org.setPersonAttribute( person, attribute, valueArray);
  1006. */
  1007. setPersonAttribute: function(person, attr, values){
  1008. const personFlag = (typeof person==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  1009. return this.oPersonAttribute.setWithPersonWithName(personFlag, attr, values);
  1010. },
  1011. //获取人员属性值
  1012. /**
  1013. 根据人员和属性名称获取属性值数组。
  1014. * @method getPersonAttribute
  1015. * @o2membercategory personAttribute
  1016. * @methodOf module:server.org
  1017. * @static
  1018. * @param {PersonFlag} person - 人员的distinguishedName、id、unique属性值,人员对象。
  1019. * @param {String} attr 属性名称。
  1020. * @return {String[]} 返回属性值数组,
  1021. * 如:<pre><code class='language-js'>[ value1, value2 ]</code></pre>
  1022. * @o2syntax
  1023. * //返回该人员的属性值数组。
  1024. * const attributeList = this.org.getPersonAttribute( person, attr );
  1025. */
  1026. getPersonAttribute: function(person, attr){
  1027. const personFlag = (typeof person==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  1028. const v = this.oPersonAttribute.listAttributeWithPersonWithName(personFlag, attr);
  1029. if (v && v.length){
  1030. return v.map(value=>value.toString())
  1031. }
  1032. return [];
  1033. },
  1034. //列出人员所有属性的名称
  1035. /**
  1036. 列出人员所有属性的名称数组。
  1037. * @method listPersonAttributeName
  1038. * @o2membercategory personAttribute
  1039. * @methodOf module:server.org
  1040. * @static
  1041. * @param {PersonFlag|PersonFlag[]} name - 人员的distinguishedName、id、unique属性值,人员对象,或上述属性值和对象的数组。
  1042. * @return {String[]} 返回人员属性名称数组,
  1043. * 如:<pre><code class='language-js'>[ attributeName1, attributeName2 ]</code></pre>
  1044. * @o2syntax
  1045. * //返回人员所有属性的名称数组。
  1046. * const attributeNameList = this.org.listPersonAttributeName( person );
  1047. */
  1048. listPersonAttributeName: function(name){
  1049. const p = _getNameFlag(name);
  1050. const nameList = [];
  1051. for (let i=0; i<p.length; i++){
  1052. const v = this.oPersonAttribute.listNameWithPerson(p[i]);
  1053. if (v && v.length){
  1054. for (let j=0; j<v.length; j++){
  1055. if (nameList.indexOf(v[j])===-1) nameList.push(v[j].toString());
  1056. }
  1057. }
  1058. }
  1059. return nameList;
  1060. },
  1061. //身份**********
  1062. //获取身份
  1063. /**
  1064. 根据身份标识获取对应的身份对象或数组
  1065. * @method getIdentity
  1066. * @o2membercategory identity
  1067. * @methodOf module:server.org
  1068. * @static
  1069. * @param {IdentityFlag|IdentityFlag[]} name - 身份的distinguishedName、id、unique属性值,身份对象,或上述属性值和对象的数组。
  1070. * @return {IdentityData|IdentityData[]} 返回身份,单个是Object,多个是Array。
  1071. * @o2ActionOut x_organization_assemble_express.IdentityAction.listObject|example=Identity|ignoreNoDescr=true|ignoreProps=[woUnitDutyList,woUnit,woGroupList]
  1072. * @o2syntax
  1073. * //返回身份,单个是对象,多个是数组。
  1074. * const identityList = this.org.getIdentity( name );
  1075. */
  1076. getIdentity: function(name){
  1077. const v = this.oIdentity.listObject(_getNameFlag(name));
  1078. const v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  1079. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  1080. },
  1081. //列出人员的身份
  1082. /**
  1083. * 根据人员标识获取对应的身份对象数组。
  1084. * @method listIdentityWithPerson
  1085. * @o2membercategory identity
  1086. * @methodOf module:server.org
  1087. * @static
  1088. * @param {PersonFlag|PersonFlag[]} name - 人员的distinguishedName、id、unique属性值,人员对象,或上述属性值和对象的数组。
  1089. * @return {IdentityData[]} 返回身份对象数组。
  1090. * @o2ActionOut x_organization_assemble_express.IdentityAction.listWithPersonObject|example=Identity
  1091. * @o2syntax
  1092. * //返回身份对象数组。
  1093. * const identityList = this.org.listIdentityWithPerson( person );
  1094. */
  1095. listIdentityWithPerson: function(name){
  1096. return this.getObject(this.oIdentity, this.oIdentity.listWithPerson(_getNameFlag(name)));
  1097. },
  1098. //查询组织成员身份--返回身份的对象数组
  1099. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  1100. /**
  1101. * 根据组织标识获取对应的身份对象数组:identity对象数组。
  1102. * @method listIdentityWithUnit
  1103. * @o2membercategory identity
  1104. * @methodOf module:server.org
  1105. * @static
  1106. * @param {UnitFlag|UnitFlag[]} name - 组织的distinguishedName、id、unique属性值,组织对象,或上述属性值和对象的数组。
  1107. * @param {Boolean} [nested] true嵌套的所有身份成员;false直接身份成员;默认false。
  1108. * @return {IdentityData[]} 返回身份对象数组。
  1109. * @o2ActionOut x_organization_assemble_express.IdentityAction.listWithUnitSubNestedObject|example=Identity
  1110. * @o2syntax
  1111. * //返回直接组织身份对象数组。
  1112. * const identityList = this.org.listIdentityWithUnit( unit );
  1113. *
  1114. * //返回嵌套组织身份对象数组。
  1115. * const identityList = this.org.listIdentityWithUnit( unit, true );
  1116. */
  1117. listIdentityWithUnit: function(name, nested){
  1118. return this.getObject(this.oIdentity, this.oIdentity[(nested) ? 'listWithUnitSubNested' : 'listWithUnitSubDirect'](_getNameFlag(name)));
  1119. },
  1120. //组织**********
  1121. //获取组织
  1122. /**
  1123. 根据组织标识获取对应的组织:unit对象或数组
  1124. * @method getUnit
  1125. * @o2membercategory unit
  1126. * @methodOf module:server.org
  1127. * @static
  1128. * @param {UnitFlag|UnitFlag[]} name - 组织的distinguishedName、id、unique属性值,组织对象,或上述属性值和对象的数组。]
  1129. * @param {(Boolean)} [findCN] 是否需要额外查找中文名称(如综合部),默认false。如果为true,除匹配unique和distingiushedName外,还会在名称的第一段中查找所有匹配到的部门(精确匹配)。
  1130. * @return {UnitData|UnitData[]} 单个是Object,多个是Array。
  1131. * @o2ActionOut x_organization_assemble_express.UnitAction.listObject|example=Unit
  1132. * @o2syntax
  1133. * //返回组织,单个是对象,多个是数组。
  1134. * const unitList = this.org.getUnit( name );
  1135. */
  1136. getUnit: function(name, findCN){
  1137. const v = this.oUnit.listObject(_getNameFlag(name), !!findCN);
  1138. const v_json = (!v || !v.length) ? null: JSON.parse(v.toString());
  1139. return (v_json && v_json.length===1) ? v_json[0] : v_json;
  1140. },
  1141. //查询组织的下级--返回组织的对象数组
  1142. //nested 布尔 true嵌套下级;false直接下级;默认false;
  1143. /**
  1144. 根据组织标识获取下级组织的对象数组:unit对象数组。
  1145. * @method listSubUnit
  1146. * @o2membercategory unit
  1147. * @methodOf module:server.org
  1148. * @static
  1149. * @param {UnitFlag|UnitFlag[]} name - 组织的distinguishedName、id、unique属性值,组织对象,或上述属性值和对象的数组。
  1150. * @param {Boolean} [nested] true嵌套的所有下级组织;false直接下级组织;默认false。
  1151. * @return {UnitData[]} 返回组织数组。
  1152. * @o2ActionOut x_organization_assemble_express.UnitAction.listWithUnitSubNestedObject|example=Unit
  1153. * @o2syntax
  1154. * //返回嵌套下级组织数组。
  1155. * const unitList = this.org.listSubUnit( name, true );
  1156. */
  1157. listSubUnit: function(name, nested){
  1158. return this.getObject(this.oUnit, this.oUnit[(nested) ? 'listWithUnitSubNested' : 'listWithUnitSubDirect'](_getNameFlag(name)));
  1159. },
  1160. //查询组织的上级--返回组织的对象数组
  1161. //nested 布尔 true嵌套上级;false直接上级;默认false;
  1162. /**
  1163. 根据组织标识批量获取上级组织的对象数组:unit对象数组。
  1164. * @method listSupUnit
  1165. * @o2membercategory unit
  1166. * @methodOf module:server.org
  1167. * @static
  1168. * @param {UnitFlag|UnitFlag[]} name - 组织的distinguishedName、id、unique属性值,组织对象,或上述属性值和对象的数组。
  1169. * @param {Boolean} [nested] true嵌套的所有上级组织;false直接上级组织;默认false。
  1170. * @return {UnitData[]} 返回组织数组。
  1171. * @o2ActionOut x_organization_assemble_express.UnitAction.listWithUnitSupNestedObject|example=Unit
  1172. * @o2syntax
  1173. * //返回嵌套上级组织数组。
  1174. * const unitList = this.org.listSupUnit( name, true );
  1175. */
  1176. listSupUnit: function(name, nested){
  1177. return this.getObject(this.oUnit, this.oUnit[(nested) ? 'listWithUnitSupNested' : 'listWithUnitSupDirect'](_getNameFlag(name)));
  1178. },
  1179. listSupUnitWithLevel: function(name, level){
  1180. var supUnitList = this.listSupUnit( name, true);
  1181. var unitList = this.getUnit( name );
  1182. return [].concat(
  1183. supUnitList,
  1184. Array.isArray(unitList) ? unitList : [unitList]
  1185. ).filter(function (u){
  1186. return u.level === level;
  1187. });
  1188. },
  1189. listSupUnitWithType: function(name, type){
  1190. var supUnitList = this.listSupUnit( name, true);
  1191. var unitList = this.getUnit( name );
  1192. return [].concat(
  1193. supUnitList,
  1194. Array.isArray(unitList) ? unitList : [unitList]
  1195. ).filter(function (u){
  1196. return (u.typeList || []).contains( type );
  1197. });
  1198. },
  1199. //根据个人身份获取组织
  1200. //flag 数字 表示获取第几层的组织
  1201. // 字符串 表示获取指定类型的组织
  1202. // 空 表示获取直接所在的组织
  1203. /**
  1204. 根据个人身份获取组织:unit对象或数组。
  1205. * @method getUnitByIdentity
  1206. * @o2membercategory unit
  1207. * @methodOf module:server.org
  1208. * @static
  1209. * @param {IdentityFlag} name - 身份的distinguishedName、id、unique属性值,身份对象。
  1210. * @param {String|Number} [flag] 当值为数字的时候, 表示获取第几层的组织。<br/> 当值为字符串的时候,表示获取指定类型的组织。<br/> 当值为空的时候,表示获取直接所在组织。
  1211. * @return {UnitData} 返回对应的组织对象。
  1212. * @o2ActionOut x_organization_assemble_express.UnitAction.getWithIdentityWithLevelObject|example=Unit
  1213. * @o2syntax
  1214. * //返回直接所在组织。
  1215. * const unit = this.org.getUnitByIdentity( name );
  1216. *
  1217. * //返回第一层组织。
  1218. * const unit = this.org.getUnitByIdentity( name, 1 );
  1219. *
  1220. * * //返回类型为company的最近上级组织。
  1221. * const unit = this.org.getUnitByIdentity( name, "company" );
  1222. */
  1223. getUnitByIdentity: function(name, flag){
  1224. let getUnitMethod = "current";
  1225. let v;
  1226. if (flag){
  1227. if (typeof flag ==="string") getUnitMethod = "type";
  1228. if (typeof flag ==="number") getUnitMethod = "level";
  1229. }
  1230. const n = _getNameFlag(name)[0];
  1231. switch (getUnitMethod){
  1232. case "current":
  1233. v = this.oUnit.getWithIdentity(n);
  1234. break;
  1235. case "type":
  1236. v = this.oUnit.getWithIdentityWithType(n, flag);
  1237. break;
  1238. case "level":
  1239. v = this.oUnit.getWithIdentityWithLevel(n, flag);
  1240. break;
  1241. }
  1242. const o = this.getObject(this.oUnit, [v]);
  1243. return (o && o.length===1) ? o[0] : o;
  1244. },
  1245. //列出身份所在组织的所有上级组织
  1246. /**
  1247. * 批量查询身份所在的组织,并递归查找其上级组织对象.
  1248. * @method listAllSupUnitWithIdentity
  1249. * @o2membercategory unit
  1250. * @methodOf module:server.org
  1251. * @static
  1252. * @param {IdentityFlag|IdentityFlag[]} name - 身份的distinguishedName、id、unique属性值,身份对象,或上述属性值和对象的数组。
  1253. * @return {UnitData[]} 返回组织数组。
  1254. * @o2ActionOut x_organization_assemble_express.UnitAction.listWithIdentitySupNestedObject|example=Unit
  1255. * @o2syntax
  1256. * //返回组织数组。
  1257. * const unitList = this.org.listAllSupUnitWithIdentity( name );
  1258. */
  1259. listAllSupUnitWithIdentity: function(name){
  1260. return this.getObject(this.oUnit, this.oUnit.listWithIdentitySupNested(_getNameFlag(name)));
  1261. },
  1262. //获取人员所在的所有组织(直接所在组织)
  1263. /**
  1264. * 根据个人标识批量获取组织对象成员:Unit对象数组。
  1265. * @method listUnitWithPerson
  1266. * @o2membercategory unit
  1267. * @methodOf module:server.org
  1268. * @static
  1269. * @param {PersonFlag|PersonFlag[]} name - 人员的distinguishedName、id、unique属性值,人员对象,或上述属性值和对象的数组。
  1270. * @return {UnitData[]} 返回组织数组。
  1271. * @o2ActionOut x_organization_assemble_express.UnitAction.listWithPersonObject|example=Unit
  1272. * @o2syntax
  1273. * //返回组织数组。
  1274. * const unitList = this.org.listUnitWithPerson( name );
  1275. */
  1276. listUnitWithPerson: function(name){
  1277. return this.getObject(this.oUnit, this.oUnit.listWithPerson(_getNameFlag(name)));
  1278. },
  1279. //列出人员所在组织的所有上级组织
  1280. /**
  1281. * 根据个人标识批量查询所在组织及所有上级组织:Unit对象数组。
  1282. * @method listAllSupUnitWithPerson
  1283. * @o2membercategory unit
  1284. * @methodOf module:server.org
  1285. * @static
  1286. * @param {PersonFlag|PersonFlag[]} name - 人员的distinguishedName、id、unique属性值,人员对象,或上述属性值和对象的数组。
  1287. * @return {UnitData[]} 返回个人所在组织及所有上级组织。
  1288. * @o2ActionOut x_organization_assemble_express.UnitAction.listWithPersonSupNestedObject|example=Unit
  1289. * @o2syntax
  1290. * //返回组织数组。
  1291. * const unitList = this.org.listAllSupUnitWithPerson( name );
  1292. */
  1293. listAllSupUnitWithPerson: function(name){
  1294. return this.getObject(this.oUnit, this.oUnit.listWithPersonSupNested(_getNameFlag(name)));
  1295. },
  1296. //根据组织属性,获取所有符合的组织
  1297. /**
  1298. * 根据组织属性,获取所有符合的组织。
  1299. * @method listUnitWithAttribute
  1300. * @o2membercategory unit
  1301. * @methodOf module:server.org
  1302. * @static
  1303. * @param {String} name 组织属性名称。
  1304. * @param {String} attribute 组织属性值。
  1305. * @return {UnitData[]} 返回组织数组。
  1306. * @o2ActionOut x_organization_assemble_express.UnitAction.listWithUnitAttributeObject|example=Unit
  1307. * @o2syntax
  1308. * //返回组织数组。
  1309. * const unitList = this.org.listUnitWithAttribute( attributeName, attributeName );
  1310. */
  1311. listUnitWithAttribute: function(name, attribute){
  1312. return this.getObject(this.oUnit, this.oUnit.listWithUnitAttribute(name, attribute));
  1313. },
  1314. //根据组织职务,获取所有符合的组织
  1315. /**
  1316. * 根据组织职务,获取所有符合的组织。
  1317. * @method listUnitWithDuty
  1318. * @o2membercategory unit
  1319. * @methodOf module:server.org
  1320. * @static
  1321. * @param {String} name 组织职务名称。
  1322. * @param {IdentityFlag} id 身份的distinguishedName、id、unique属性值,身份对象。
  1323. * @return {UnitData[]} 返回组织数组。
  1324. * @o2ActionOut x_organization_assemble_express.UnitAction.listWithUnitDutyObject|example=Unit
  1325. * @o2syntax
  1326. * //返回组织数组。
  1327. * const unitList = this.org.listUnitWithDuty( dutyName, identity );
  1328. */
  1329. listUnitWithDuty: function(name, id){
  1330. const idflag = (typeof id==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  1331. return this.getObject(this.oUnit, this.oUnit.listWithUnitDuty(name, idflag));
  1332. },
  1333. /**
  1334. * 列式所有顶层组织。
  1335. * @method listTopUnit
  1336. * @o2membercategory unit
  1337. * @methodOf module:server
  1338. * @static
  1339. * @return {Promise|UnitData[]} 当async为true时,返回
  1340. * @o2ActionOut x_organization_assemble_express.UnitAction.listObject|example=Unit
  1341. * @o2syntax
  1342. * //同步执行,返回顶层组织数组。
  1343. * var unitList = this.org.listTopUnit();
  1344. */
  1345. listTopUnit: function(){
  1346. var action = Actions.load("x_organization_assemble_control").UnitAction;
  1347. return action.listTop().data;
  1348. },
  1349. //组织职务***********
  1350. //获取指定的组织职务的身份
  1351. /**
  1352. * 根据职务名称和组织名称获取身份。
  1353. * @method getDuty
  1354. * @o2membercategory duty
  1355. * @methodOf module:server.org
  1356. * @static
  1357. * @param {String} duty 组织职务名称。
  1358. * @param {UnitFlag} id 组织的distinguishedName、id、unique属性值,组织对象。
  1359. * @return {IdentityData[]} 返回身份数组。
  1360. * @o2ActionOut x_organization_assemble_express.UnitDutyAction.getWithUnitWithName|example=Identity
  1361. * @o2syntax
  1362. * //返回身份数组。
  1363. * const identityList = this.org.getDuty( dutyName, unit );
  1364. */
  1365. getDuty: function(duty, id){
  1366. const unit = (typeof id==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id;
  1367. return this.getObject(this.oIdentity, this.oUnitDuty.listIdentityWithUnitWithName(unit, duty));
  1368. },
  1369. //获取身份的所有职务名称
  1370. /**
  1371. * 批量获取身份的所有职务名称。
  1372. * @method listDutyNameWithIdentity
  1373. * @o2membercategory duty
  1374. * @methodOf module:server.org
  1375. * @static
  1376. * @param {IdentityFlag|IdentityFlag[]} id - 身份的distinguishedName、id、unique属性值,身份对象,或上述属性值和对象的数组。
  1377. * @return {String[]} 返回职务名称数组。
  1378. * @o2syntax
  1379. * //返回职务名称数组。
  1380. * const dutyNameList = this.org.listDutyNameWithIdentity( identity );
  1381. */
  1382. listDutyNameWithIdentity: function(id){
  1383. const ids = _getNameFlag(id);
  1384. const nameList = [];
  1385. for (let i=0; i<ids.length; i++){
  1386. const v = this.oUnitDuty.listNameWithIdentity(ids[i]);
  1387. if (v && v.length){
  1388. for (let j=0; j<v.length; j++){
  1389. if (nameList.indexOf(v[j])===-1) nameList.push(v[j].toString());
  1390. }
  1391. }
  1392. }
  1393. return nameList;
  1394. },
  1395. //获取组织的所有职务名称
  1396. /**
  1397. * 批量获取组织的所有职务名称。
  1398. * @method listDutyNameWithUnit
  1399. * @o2membercategory duty
  1400. * @methodOf module:server.org
  1401. * @static
  1402. * @param {UnitFlag|UnitFlag[]} name - 组织的distinguishedName、id、unique属性值,组织对象,或上述属性值和对象的数组。
  1403. * @return {String[]} 返回职务名称数组。
  1404. * @o2syntax
  1405. * //返回职务名称数组。
  1406. * const dutyNameList = this.org.listDutyNameWithUnit( unit );
  1407. */
  1408. listDutyNameWithUnit: function(name){
  1409. const ids = _getNameFlag(name);
  1410. const nameList = [];
  1411. for (let i=0; i<ids.length; i++){
  1412. const v = this.oUnitDuty.listNameWithUnit(ids[i]);
  1413. if (v && v.length){
  1414. for (let j=0; j<v.length; j++){
  1415. if (nameList.indexOf(v[j])===-1) nameList.push(v[j].toString());
  1416. }
  1417. }
  1418. }
  1419. return nameList;
  1420. },
  1421. //获取组织的所有职务
  1422. /**
  1423. * 批量获取组织的所有职务。
  1424. * @method listUnitAllDuty
  1425. * @o2membercategory duty
  1426. * @methodOf module:server.org
  1427. * @static
  1428. * @param {UnitFlag} name - 组织的distinguishedName、id、unique属性值,组织对象。
  1429. * @return {Object[]} 返回职务数组
  1430. * @o2ActionOut x_organization_assemble_express.UnitDutyAction.listWithUnitObject|example=Duty
  1431. * @o2syntax
  1432. * //返回职务数组。
  1433. * const dutyList = this.org.listUnitAllDuty( unit );
  1434. */
  1435. listUnitAllDuty: function(name){
  1436. const u = _getNameFlag(name)[0];
  1437. const ds = this.oUnitDuty.listNameWithUnit(u);
  1438. const o = []
  1439. for (let i=0; i<ds.length; i++){
  1440. const v = this.oUnitDuty.listIdentityWithUnitWithName(u, ds[i]);
  1441. o.push({"name": ds[i], "identityList": this.getObject(this.oIdentity, v)});
  1442. }
  1443. return o;
  1444. },
  1445. //组织属性**************
  1446. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  1447. /**
  1448. * 添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  1449. * @method appendUnitAttribute
  1450. * @o2membercategory unitAttribute
  1451. * @methodOf module:server.org
  1452. * @static
  1453. * @param {UnitFlag} unit - 组织的distinguishedName、id、unique属性值,组织对象。
  1454. * @param {String} attr 属性名称。
  1455. * @param {String[]} values 属性值,必须为数组。
  1456. * @o2syntax
  1457. * this.org.appendUnitAttribute( unit, attribute, valueArray);
  1458. */
  1459. appendUnitAttribute: function(unit, attr, values){
  1460. const unitFlag = (typeof unit==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1461. return this.oUnitAttribute.appendWithUnitWithName(unitFlag, attr, values);
  1462. },
  1463. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  1464. /**
  1465. * 设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  1466. * @method setUnitAttribute
  1467. * @o2membercategory unitAttribute
  1468. * @methodOf module:server.org
  1469. * @static
  1470. * @param {UnitFlag} unit - 组织的distinguishedName、id、unique属性值,组织对象。
  1471. * @param {String} attr 属性名称。
  1472. * @param {String[]} values 属性值,必须为数组。
  1473. * @o2syntax
  1474. * this.org.setUnitAttribute( unit, attribute, valueArray);
  1475. */
  1476. setUnitAttribute: function(unit, attr, values){
  1477. const unitFlag = (typeof unit==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1478. return this.oUnitAttribute.setWithUnitWithName(unitFlag, attr, values);
  1479. },
  1480. //获取组织属性值
  1481. /**
  1482. 根据组织标识和属性名称获取对应属性值。
  1483. * @method getUnitAttribute
  1484. * @o2membercategory unitAttribute
  1485. * @methodOf module:server.org
  1486. * @static
  1487. * @param {UnitFlag} unit - 组织的distinguishedName、id、unique属性值,组织对象。
  1488. * @param {String} attr 属性名称。
  1489. * @return {String[]} 返回属性值数组,
  1490. * 如:<pre><code class='language-js'>[ value1, value2 ]</code></pre>
  1491. * @o2syntax
  1492. * //返回该组织的属性值数组。
  1493. * const attributeList = this.org.getUnitAttribute( unit, attr );
  1494. */
  1495. getUnitAttribute: function(unit, attr){
  1496. const unitFlag = (typeof unit==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1497. const v = this.oUnitAttribute.listAttributeWithUnitWithName(unitFlag, attr);
  1498. if (v && v.length){
  1499. return v.map(value=>value.toString());
  1500. }
  1501. return [];
  1502. },
  1503. //列出组织所有属性的名称
  1504. /**
  1505. 列出组织所有属性的名称数组。
  1506. * @method listUnitAttributeName
  1507. * @o2membercategory unitAttribute
  1508. * @methodOf module:server.org
  1509. * @static
  1510. * @param {UnitFlag|UnitFlag[]} name - 组织的distinguishedName、id、unique属性值,组织对象,或上述属性值和对象的数组。
  1511. * @return {String[]} 返回组织属性名称数组,
  1512. * 如:<pre><code class='language-js'>[ attributeName1, attributeName2 ]</code></pre>
  1513. * @o2syntax
  1514. * //返回组织所有属性的名称数组。
  1515. * const attributeNameList = this.org.listUnitAttributeName( unit );
  1516. */
  1517. listUnitAttributeName: function(name){
  1518. const p = _getNameFlag(name);
  1519. const nameList = [];
  1520. for (let i=0; i<p.length; i++){
  1521. const v = this.oUnitAttribute.listNameWithUnit(p[i]);
  1522. if (v && v.length){
  1523. for (let j=0; j<v.length; j++){
  1524. if (nameList.indexOf(v[j])===-1) nameList.push(v[j]);
  1525. }
  1526. }
  1527. }
  1528. return nameList;
  1529. },
  1530. //列出组织的所有属性
  1531. /**
  1532. 列出组织的所有属性对象数组。
  1533. * @method listUnitAllAttribute
  1534. * @o2membercategory unitAttribute
  1535. * @methodOf module:server.org
  1536. * @static
  1537. * @param {UnitFlag|UnitFlag[]} name - 组织的distinguishedName、id、unique属性值,组织对象,或上述属性值和对象的数组。
  1538. * @return {Object[]} 返回组织属性对象数组,如:
  1539. * <pre><code class='language-js'>[{
  1540. * "name": "部门类别",
  1541. * "unit": "开发部@kfb@U",
  1542. * "attributeList": [
  1543. * "生产部门",
  1544. * "二级部门"
  1545. * ]
  1546. * }]</code></pre>
  1547. * @o2syntax
  1548. * //返回组织所有属性的对象数组。
  1549. * const attributeObjectList = this.org.listUnitAllAttribute( unit );
  1550. */
  1551. listUnitAllAttribute: function(name){
  1552. const u = _getNameFlag(name)[0];
  1553. const ds = this.oUnitAttribute.listNameWithUnit(u);
  1554. if (ds && ds.length){
  1555. return ds.map( value=>{
  1556. return {name: value, valueList: this.getUnitAttribute(u, value)};
  1557. });
  1558. }
  1559. return [];
  1560. }
  1561. })
  1562. //定义所需的服务
  1563. const processActions = new Action("x_processplatform_assemble_surface", {
  1564. "getDictionary": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{applicationFlag}"},
  1565. "getDictRoot": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/data"},
  1566. "getDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data"},
  1567. "setDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "PUT"},
  1568. "addDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "POST"},
  1569. "deleteDictData": {"uri": "/jaxrs/applicationdict/{applicationDict}/application/{application}/{path}/data", "method": "DELETE"},
  1570. "getScript": {"uri": "/jaxrs/script/{flag}/application/{applicationFlag}", "method": "POST"},
  1571. });
  1572. const cmsActions = new Action("x_cms_assemble_control", {
  1573. "getDictionary": {"uri": "/jaxrs/design/appdict/{appDictId}"},
  1574. "getDictRoot": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  1575. "getDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  1576. "setDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "PUT"},
  1577. "addDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "POST"},
  1578. "deleteDictData": {"uri": "/jaxrs/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data", "method": "DELETE"},
  1579. "getDictRootAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/data"},
  1580. "getDictDataAnonymous" : {"uri": "/jaxrs/anonymous/surface/appdict/{appDictId}/appInfo/{appId}/{path}/data"},
  1581. "getScript": {"uri": "/jaxrs/script/{flag}/appInfo/{appInfoFlag}", "method": "POST"},
  1582. });
  1583. const portalActions = new Action("x_portal_assemble_surface", {
  1584. "getDictionary": {"uri": "/jaxrs/dict/{dictFlag}/portal/{portalFlag}"},
  1585. "getDictRoot": {"uri": "/jaxrs/dict/{dictFlag}/portal/{portalFlag}/data"},
  1586. "getDictData": {"uri": "/jaxrs/dict/{dictFlag}/portal/{portalFlag}/{path}/data"},
  1587. "setDictData": {"uri": "/jaxrs/dict/{dictFlag}/portal/{portalFlag}/{path}/data", "method": "PUT"},
  1588. "addDictData": {"uri": "/jaxrs/dict/{dictFlag}/portal/{portalFlag}/{path}/data", "method": "POST"},
  1589. "deleteDictData": {"uri": "/jaxrs/dict/{dictFlag}/portal/{portalFlag}/{path}/data", "method": "DELETE"},
  1590. "getScript": {"uri": "/jaxrs/script/portal/{portal}/name/{name}","method": "POST"}
  1591. });
  1592. const serviceActions = new Action("x_program_center", {
  1593. "getDictionary": {"uri": "/jaxrs/dict/{id}"},
  1594. "getDictRoot": {"uri": "/jaxrs/dict/{dictFlag}/data"},
  1595. "getDictData": {"uri": "/jaxrs/dict/{dictFlag}/{path}/data"},
  1596. "setDictData": {"uri": "/jaxrs/dict/{dictFlag}/{path}/data", "method": "PUT"},
  1597. "addDictData": {"uri": "/jaxrs/dict/{dictFlag}/{path}/data", "method": "POST"},
  1598. "deleteDictData": {"uri": "/jaxrs/dict/{dictFlag}/{path}/data", "method": "DELETE"},
  1599. "getScript": {"uri": "/jaxrs/script/name/{name}/imported","method": "GET"}
  1600. });
  1601. //include 引用脚本
  1602. //optionsOrName : {
  1603. // type : "", 默认为process, 可以为 portal process cms
  1604. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  1605. // name : "" // 脚本名称/别名/id
  1606. //}
  1607. //或者name: "" // 脚本名称/别名/id
  1608. const includedScripts = {};
  1609. /**
  1610. * 在流程、门户、内容管理或服务管理中可以创建了脚本配置。</br>
  1611. * 默认情况下系统以javascript格式进行编辑。
  1612. * 这个时候可以使用<code class='language-js'>this.include()</code>引用脚本配置。</br>
  1613. * 在v9.2以后,如果脚本配置名称以.json 、 .html 或 .css结束,系统会加载相应的编辑器。
  1614. * 这种情况您可以使用如下方法获取内容。
  1615. * <pre><code class='language-js'>this.includeHmtl();
  1616. * this.includeCss();
  1617. * this.includeJson();
  1618. * </code></pre>
  1619. * @module server.common.include
  1620. * @o2cn 脚本配置相应api
  1621. * @o2category server.common
  1622. * @o2ordernumber 175
  1623. */
  1624. /**
  1625. * this.include是一个方法,当您在流程、门户、内容管理或服务管理中创建了脚本配置,可以使用this.include()用来引用脚本配置。<br/>
  1626. * v8.0及以后版本中增加了服务管理的脚本配置。<br/>
  1627. * @method include
  1628. * @methodOf module:server.common.
  1629. * @o2cn 脚本引用
  1630. * @param {(String|Object)} optionsOrName 可以是脚本标识字符串或者是对象。
  1631. * <pre><code class='language-js'>
  1632. *
  1633. * //如果需要引用其他应用的脚本配置,将options设置为Object;
  1634. * this.include({
  1635. * //type: 应用类型。可以为 portal process cms service。流程脚本默认为process,服务管理中默认为service
  1636. * type : "portal",
  1637. * application : "首页", // 门户、流程、CMS的名称、别名、id。 引用服务管理的脚本则忽略该参数。
  1638. * name : "initScript" // 脚本配置的名称、别名或id
  1639. * });
  1640. *
  1641. * //引用服务管理中的脚本
  1642. * this.include({
  1643. * "type": "service",
  1644. * "name": "scriptName"
  1645. * });
  1646. *
  1647. * //引用流程管理中的脚本
  1648. * this.include({
  1649. * "type": "process",
  1650. * "application": "appName",
  1651. * "name": "scriptName"
  1652. * });
  1653. *
  1654. * //引用内容管理中的脚本
  1655. * this.include({
  1656. * "type": "cms",
  1657. * "application": "appName",
  1658. * "name": "scriptName"
  1659. * });
  1660. *
  1661. * //引用门户管理中的脚本
  1662. * this.include({
  1663. * "type": "portal",
  1664. * "application": "appName",
  1665. * "name": "scriptName"
  1666. * });
  1667. * </code></pre>
  1668. * @param {Function} [callback] 加载后执行的回调方法。
  1669. *
  1670. * @o2syntax
  1671. * //您可以在表单、流程、视图和查询视图的各个嵌入脚本中,通过this.include()来引用本应用或其他应用的脚本配置,如下:
  1672. * this.include( optionsOrName, callback )
  1673. * @example
  1674. * <caption>
  1675. * <b>样例一:</b>在通用脚本中定义一个通用的方法去获取公文管理所有的文种,在查询语句中根据该方法来拼接JPQL。<br/>
  1676. * 1、在内容管理应用中有一个fileRes的应用,在该应用中创建一个脚本,命名为FileSql,并定义方法。
  1677. * <img src='img/module/include/server_define1.png' />
  1678. * </caption>
  1679. * //定义一个方法
  1680. * this.define('getFileSQL',function(){
  1681. * const application = ['公司发文','部门发文','党委发文'];
  1682. * const apps = application.map((app)=>{
  1683. * return `o.applicationName = '${app}'`
  1684. * });
  1685. * return `(${apps.join(' OR ')})`;
  1686. *});
  1687. * @example
  1688. * <caption>
  1689. * 2、在查询语句中使用该方法。
  1690. * <img src='img/module/include/server_define2.png'/>
  1691. * </caption>
  1692. * this.include({
  1693. * type : 'cms',
  1694. * application : 'fileRes',
  1695. * name : 'FileSql'
  1696. * });
  1697. * const sql = this.getFileSQL();
  1698. * return `SELECT o FROM com.x.processplatform.core.entity.content.Task o WHERE ${sql}`;
  1699. */
  1700. /**
  1701. * 当脚本配置保存的是html文件(名称以.html结束),this.includeHtml可以以获取html内容。
  1702. * @method includeHtml
  1703. * @since v9.2
  1704. * @methodOf module:server.common.include
  1705. * @param {(String|Object)} optionsOrName 可以是脚本标识字符串或者是对象。
  1706. * <pre><code class='language-js'>
  1707. * //如果需要获取本应用的html(在脚本配置中),将options设置为String。
  1708. * this.includeHtml("test.html") //脚本配置的名称、别名或id
  1709. *
  1710. * //如果需要获取其他应用的html,将options设置为Object;
  1711. * this.includeHtml({
  1712. * //type: 应用类型。可以为 portal process cms service。
  1713. * //如果没有该选项或者值为空字符串,则表示应用脚本和被应用的脚本配置类型相同。
  1714. * //比如在门户的A应用脚本中引用门户B应用的脚本配置,则type可以省略。
  1715. * type : "portal",
  1716. * application : "首页", // 门户、流程、CMS的名称、别名、id。 默认为当前应用,如果脚本在服务管理中忽略该参数
  1717. * name : "test.html" // 脚本配置的名称、别名或id
  1718. * })
  1719. *
  1720. * //获取服务管理中的html
  1721. * this.includeHtml({
  1722. * "type": "service",
  1723. * "name": "scriptName"
  1724. * });
  1725. *
  1726. * //获取流程管理中的html
  1727. * this.includeHtml({
  1728. * "type": "process",
  1729. * "application": "appName",
  1730. * "name": "scriptName"
  1731. * });
  1732. *
  1733. * //获取内容管理中的html
  1734. * this.includeHtml({
  1735. * "type": "cms",
  1736. * "application": "appName",
  1737. * "name": "scriptName"
  1738. * });
  1739. *
  1740. * //获取门户管理中的html
  1741. * this.includeHtml({
  1742. * "type": "portal",
  1743. * "application": "appName",
  1744. * "name": "scriptName"
  1745. * });
  1746. * </code></pre>
  1747. * @param {Function} [callback] 加载后执行的回调方法
  1748. * @param {Boolean} [async] 是否异步加载,默认为true
  1749. * @o2syntax
  1750. * this.includeHtml( optionsOrName, callback, async )
  1751. * @example
  1752. * //同步获取html(不推荐)
  1753. * //在门户的脚本库里配置了html,名称为test.html
  1754. * var html = this.includeHtml({
  1755. * "type": "portal",
  1756. * "application": "appName", //门户的标识
  1757. * "name": "test.html"
  1758. * });
  1759. */
  1760. /**
  1761. * 当脚本配置保存的是css文件(名称以.css结束),this.includeCss可以以获取html内容。
  1762. * @method includeCss
  1763. * @since v9.2
  1764. * @methodOf module:server.common.include
  1765. * @param {(String|Object)} optionsOrName 可以是脚本标识字符串或者是对象。
  1766. * <pre><code class='language-js'>
  1767. * //如果需要获取本应用的css(在脚本配置中),将options设置为String。
  1768. * this.includeCss("test.css") //脚本配置的名称、别名或id
  1769. *
  1770. * //如果需要获取其他应用的html,将options设置为Object;
  1771. * this.includeCss({
  1772. * //type: 应用类型。可以为 portal process cms service。
  1773. * //如果没有该选项或者值为空字符串,则表示应用脚本和被应用的脚本配置类型相同。
  1774. * //比如在门户的A应用脚本中引用门户B应用的脚本配置,则type可以省略。
  1775. * type : "portal",
  1776. * application : "首页", // 门户、流程、CMS的名称、别名、id。 默认为当前应用,如果脚本在服务管理中忽略该参数
  1777. * name : "initScript" // 脚本配置的名称、别名或id
  1778. * })
  1779. *
  1780. * //获取服务管理中的html
  1781. * this.includeCss({
  1782. * "type": "service",
  1783. * "name": "scriptName"
  1784. * });
  1785. *
  1786. * //获取流程管理中的html
  1787. * this.includeCss({
  1788. * "type": "process",
  1789. * "application": "appName",
  1790. * "name": "scriptName"
  1791. * });
  1792. *
  1793. * //获取内容管理中的html
  1794. * this.includeCss({
  1795. * "type": "cms",
  1796. * "application": "appName",
  1797. * "name": "scriptName"
  1798. * });
  1799. *
  1800. * //获取门户管理中的html
  1801. * this.includeCss({
  1802. * "type": "portal",
  1803. * "application": "appName",
  1804. * "name": "scriptName"
  1805. * });
  1806. * </code></pre>
  1807. * @param {Function} [callback] 加载后执行的回调方法
  1808. * @param {Boolean} [async] 是否异步加载,默认为true
  1809. * @o2syntax
  1810. * this.includeCss( optionsOrName, callback, async )
  1811. * @example
  1812. * //同步获取css文本(不推荐)
  1813. * //在门户的脚本库里配置了css,名称为test.css
  1814. * var cssText = this.includeCss({
  1815. * "type": "portal",
  1816. * "application": "appName", //门户的标识
  1817. * "name": "test.css"
  1818. * });
  1819. */
  1820. /**
  1821. * 当脚本配置保存的是json文件(名称以.json结束),this.includeJson可以以获取json内容。
  1822. * @method includeJson
  1823. * @since v9.2
  1824. * @methodOf module:server.common.include
  1825. * @param {(String|Object)} optionsOrName 可以是脚本标识字符串或者是对象。
  1826. * <pre><code class='language-js'>
  1827. * //如果需要获取本应用的json(在脚本配置中),将options设置为String。
  1828. * this.includeJson("test.json") //脚本配置的名称、别名或id
  1829. *
  1830. * //如果需要获取其他应用的html,将options设置为Object;
  1831. * this.includeJson({
  1832. * //type: 应用类型。可以为 portal process cms service。
  1833. * //如果没有该选项或者值为空字符串,则表示应用脚本和被应用的脚本配置类型相同。
  1834. * //比如在门户的A应用脚本中引用门户B应用的脚本配置,则type可以省略。
  1835. * type : "portal",
  1836. * application : "首页", // 门户、流程、CMS的名称、别名、id。 默认为当前应用,如果脚本在服务管理中忽略该参数
  1837. * name : "initScript" // 脚本配置的名称、别名或id
  1838. * })
  1839. *
  1840. * //获取服务管理中的json对象
  1841. * this.includeJson({
  1842. * "type": "service",
  1843. * "name": "scriptName"
  1844. * });
  1845. *
  1846. * //获取流程管理中的json对象
  1847. * this.includeJson({
  1848. * "type": "process",
  1849. * "application": "appName",
  1850. * "name": "scriptName"
  1851. * });
  1852. *
  1853. * //获取内容管理中的json对象
  1854. * this.includeJson({
  1855. * "type": "cms",
  1856. * "application": "appName",
  1857. * "name": "scriptName"
  1858. * });
  1859. *
  1860. * //获取门户管理中的json对象
  1861. * this.includeJson({
  1862. * "type": "portal",
  1863. * "application": "appName",
  1864. * "name": "scriptName"
  1865. * });
  1866. * </code></pre>
  1867. * @param {Function} [callback] 加载后执行的回调方法
  1868. * @param {Boolean} [async] 是否异步加载,默认为true
  1869. * @o2syntax
  1870. * this.includeJson( optionsOrName, callback, async )
  1871. * @example
  1872. * //同步获取json数据(不推荐)
  1873. * //在门户的脚本库里配置了css,名称为test.json
  1874. * var json = this.includeJson({
  1875. * "type": "portal",
  1876. * "application": "appName", //门户的标识
  1877. * "name": "test.json"
  1878. * });
  1879. */
  1880. const include = function( optionsOrName , callback ){
  1881. const options = (typeof optionsOrName) == "string" ? { name : optionsOrName } : optionsOrName;
  1882. const name = options.name;
  1883. const type = (!options.type) ? 'process' : options.type;
  1884. const application = type === "service" ? "service" : options.application;
  1885. if (!name || !type || !application){
  1886. log.error("can not find script. missing script name or application");
  1887. return false;
  1888. }
  1889. if (!includedScripts[application]) includedScripts[application] = [];
  1890. if (includedScripts[application].indexOf( name )> -1){
  1891. if (callback) callback.apply(globalThis);
  1892. return;
  1893. }
  1894. const actionsMap = {
  1895. portal: portalActions,
  1896. process: processActions,
  1897. cms: cmsActions,
  1898. service: serviceActions,
  1899. }
  1900. const arg1 = (type==='portal') ? application : name;
  1901. const arg2 = (type==='portal') ? name : application;
  1902. const json = (type==='service') ? actionsMap[type].getScript(name) : actionsMap[type].getScript(arg1, arg2, {"importedList":includedScripts[application]});
  1903. includedScripts[application] = includedScripts[application].concat(json.data.importedList);
  1904. includedScripts[application].push(name);
  1905. if (json.data && json.data.text){
  1906. exec(json.data.text, globalThis);
  1907. if (callback) callback.apply(globalThis);
  1908. }
  1909. }
  1910. const _includeSource = function (optionsOrName, callback, fileType) {
  1911. const options = (typeof optionsOrName) == "string" ? { name : optionsOrName } : optionsOrName;
  1912. const name = options.name;
  1913. const type = (!options.type) ? 'process' : options.type;
  1914. const application = type === "service" ? "service" : options.application;
  1915. if (!name || !type || !application){
  1916. log.error("can not find script. missing script name or application");
  1917. return false;
  1918. }
  1919. const actionsMap = {
  1920. portal: portalActions,
  1921. process: processActions,
  1922. cms: cmsActions,
  1923. service: serviceActions,
  1924. }
  1925. const arg1 = (type==='portal') ? application : name;
  1926. const arg2 = (type==='portal') ? name : application;
  1927. const json = (type==='service') ? actionsMap[type].getScript(name) : actionsMap[type].getScript(arg1, arg2, {"importedList":includedScripts[application]});
  1928. let result;
  1929. if (json.data && json.data.text){
  1930. result = json.data.text;
  1931. if( fileType === 'json' ){
  1932. result = JSON.parse(result);
  1933. }
  1934. if (callback) callback.call(globalThis, result);
  1935. }
  1936. return result;
  1937. };
  1938. const includeHtml = function (optionsOrName, callback){
  1939. return _includeSource.apply(this, [optionsOrName, callback, 'html'])
  1940. };
  1941. const includeJson = function (optionsOrName, callback){
  1942. return _includeSource.apply(this, [optionsOrName, callback, 'json'])
  1943. };
  1944. const includeCss = function (optionsOrName, callback){
  1945. return _includeSource.apply(this, [optionsOrName, callback, 'css']);
  1946. };
  1947. //Dict数据字典
  1948. /**
  1949. * this.Dict是一个工具类,如果您在流程、内容管理、门户和服务管理中创建了数据字典,可以使用this.Dict类对数据字典进行增删改查操作。<br/>
  1950. * 从v8.0版本开始,支持在门户和服务管理中创建数据字典。
  1951. * @module server.Dict
  1952. * @o2cn 数据字典
  1953. * @o2category server.common
  1954. * @o2ordernumber 180
  1955. * @o2syntax
  1956. * //您可以通过this.Dict()对本应用或其他应用的数据字典中的数据进行增删改查,如下:
  1957. * const dict = new this.Dict( options )
  1958. * @example
  1959. * const dict = new this.Dict({
  1960. * //type: 应用类型。可以为process cms portal service。流程脚本默认为process,服务管理中默认为service。
  1961. * type : "cms",
  1962. * application : "bulletin", //流程、CMS、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
  1963. * name : "bulletinDictionary", // 数据字典的名称、别名、id
  1964. * });
  1965. *
  1966. * //引用服务管理中的数据字典
  1967. * const dict = new this.Dict({
  1968. * "type": "service",
  1969. * "name": "dictName"
  1970. * });
  1971. *
  1972. * //引用流程管理中的数据字典
  1973. * const dict = new this.Dict({
  1974. * "type": "process",
  1975. * "application": "appName",
  1976. * "name": "dictName"
  1977. * });
  1978. *
  1979. * //引用内容管理中的数据字典
  1980. * const dict = new this.Dict({
  1981. * "type": "cms",
  1982. * "application": "appName",
  1983. * "name": "dictName"
  1984. * });
  1985. *
  1986. * //引用门户管理中的数据字典
  1987. * const dict = new this.Dict({
  1988. * "type": "portal",
  1989. * "application": "appName",
  1990. * "name": "dictName"
  1991. * });
  1992. */
  1993. const Dict = function(optionsOrName){
  1994. const options = (typeof optionsOrName) == "string" ? { name : optionsOrName } : optionsOrName;
  1995. const name = this.name = options.name;
  1996. const type = (!options.type) ? 'process' : options.type;
  1997. const applicationId = options.application || ((globalThis.java_workContext) ? globalThis.java_workContext.getWork().application : "");
  1998. const enableAnonymous = options.enableAnonymous || false;
  1999. const actionMap = {
  2000. cms: cmsActions,
  2001. service: serviceActions,
  2002. portal: portalActions,
  2003. process: processActions
  2004. }
  2005. const action = actionMap[type]
  2006. const encodePath = function( path ){
  2007. const arr = path.split(/\./g);
  2008. const ar = arr.map(function(v){
  2009. return encodeURIComponent(v);
  2010. });
  2011. return ( type === "portal" || type === "service" ) ? ar.join(".") : ar.join("/");
  2012. };
  2013. /**
  2014. * 根据路径获取数据字典中的数据。
  2015. * @method get
  2016. * @methodOf module:server.Dict
  2017. * @static
  2018. * @param {String} [path] 数据字典中的数据路径,允许使用中文。当路径为多级时,用点号(.)分隔。当值为空的时候,表示获取数据字典中的所有数据。
  2019. * @param {Function} [success] 获取数据成功时的回调函数。<b>流程设计后台脚本中无此参数。</b>
  2020. * @param {Function} [failure] 获取数据失败时的回调。<b>流程设计后台脚本中无此参数。</b>
  2021. * @return {(Object|Array|String|Number|Boolean)}
  2022. * 返回数据字典的数据,类型和配置数据字典时候指定的一致。
  2023. * @o2syntax
  2024. * const data = dict.get( path, success, failure )
  2025. * @example
  2026. * <caption>
  2027. * 已经配置好了如下图所示的数据字典
  2028. * <img src='img/module/Dict/dict.png' />
  2029. * </caption>
  2030. * const dict = new this.Dict({
  2031. * //type: 应用类型。可以为process cms portal service。默认为process。
  2032. * type : "cms",
  2033. * application : "bulletin", //流程、CMS、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
  2034. * name : "bulletinDictionary", // 数据字典的名称、别名、id
  2035. * });
  2036. *
  2037. * const data = dict.get();
  2038. * //data的值为
  2039. * {
  2040. * "category": [
  2041. * {
  2042. * "enable": true,
  2043. * "sequence": 1.0,
  2044. * "text": "公司公告",
  2045. * "value": "company"
  2046. * },
  2047. * {
  2048. * "enable": "false",
  2049. * "sequence": 2.0,
  2050. * "text": "部门公告",
  2051. * "value": "department"
  2052. * }
  2053. * ]
  2054. * }
  2055. *
  2056. * const category = dict.get("category");
  2057. * //category的值为
  2058. * [
  2059. * {
  2060. * "enable": true,
  2061. * "sequence": 1.0,
  2062. * "text": "公司公告",
  2063. * "value": "company"
  2064. * },
  2065. * {
  2066. * "enable": "false",
  2067. * "sequence": 2.0,
  2068. * "text": "部门公告",
  2069. * "value": "department"
  2070. * }
  2071. * ]
  2072. *
  2073. * const array0 = dict.get("category.0");
  2074. * //array0 的值为
  2075. * {
  2076. * "enable": true,
  2077. * "sequence": 1.0,
  2078. * "text": "公司公告",
  2079. * "value": "company"
  2080. * }
  2081. *
  2082. * const enable = dict.get("category.0.eanble");
  2083. * //enable 的值为 true
  2084. */
  2085. this.get = function(path, success, failure){
  2086. const getDataMethodName = (enableAnonymous && type === 'cms') ? 'getDictDataAnonymous' : 'getDictData';
  2087. const getRootMethodName = (enableAnonymous && type === 'cms') ? 'getDictRootAnonymous' : 'getDictRoot';
  2088. const methodName = (path) ? getDataMethodName : getRootMethodName;
  2089. const successFun = json=>{if (success) success(json.data);}
  2090. const failureFun = json=>{if (failure) failure(json.data);}
  2091. const par = [encodeURIComponent(this.name)];
  2092. if (type !== "service") par.push(applicationId);
  2093. if (path) par.push(encodePath(path));
  2094. const json = action[methodName](...par, successFun, failureFun);
  2095. return json.data;
  2096. };
  2097. /**
  2098. * 根据路径修改数据字典的数据。
  2099. * @method set
  2100. * @methodOf module:Dict
  2101. * @instance
  2102. * @param {String} path 数据字典中的数据路径,允许使用中文。当路径为多级时,用点号(.)分隔。如果数据路径不存在,则报错。
  2103. * @param {(Object|Array|String|Number|Boolean)} value 修改后的数据
  2104. * @param {Function} [success] 设置数据成功时的回调函数。<b>流程设计后台脚本中无此参数。</b>
  2105. * @param {Function} [failure] 设置数据错误时的回调函数。<b>流程设计后台脚本中无此参数。</b>
  2106. * @o2syntax
  2107. * dict.set( path, data, success, failure )
  2108. * @example
  2109. * const dict = new this.Dict({
  2110. * //type: 应用类型。可以为process cms portal service。默认为process。
  2111. * type : "cms",
  2112. * application : "bulletin", //流程、CMS、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
  2113. * name : "bulletinDictionary", // 数据字典的名称、别名、id
  2114. * });
  2115. *
  2116. * dict.set( "category", { text : "系统公告", value : "system" }, function(data){
  2117. * //data 形如
  2118. * //{
  2119. * // "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典ID
  2120. * //}
  2121. * }, function(xhr){
  2122. * //xhr 为 xmlHttpRequest
  2123. * });
  2124. * @example
  2125. * <caption>
  2126. * 对Example add的数据字典进行赋值,如下:
  2127. * </caption>
  2128. * const dict = new this.Dict({
  2129. * //type: 应用类型。可以为process cms portal service。默认为process。
  2130. * type : "cms",
  2131. * application : "bulletin", //流程、CMS、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
  2132. * name : "bulletinDictionary", // 数据字典的名称、别名、id
  2133. * });
  2134. *
  2135. * dict.set( "archiveOptions", [ { text : "是" }, { text : "否" } ]);
  2136. * //数据字典的值变为
  2137. * {
  2138. * "category": [
  2139. * {
  2140. * "enable": true,
  2141. * "sequence": 1.0,
  2142. * "text": "公司公告",
  2143. * "value": "company"
  2144. * },
  2145. * {
  2146. * "enable": "false",
  2147. * "sequence": 2.0,
  2148. * "text": "部门公告",
  2149. * "value": "department"
  2150. * },
  2151. * {
  2152. * "sequence" : 3.0,
  2153. * "text": "系统公告",
  2154. * "value": "system"
  2155. * }
  2156. *
  2157. * ],
  2158. * "archiveOptions" : [ { text : "是" }, { text : "否" } ]
  2159. * }
  2160. *
  2161. * dict.set( "category.2", { text : "县级公告", value : "county" }, function(data){
  2162. * //data 形如
  2163. * //{
  2164. * // "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典ID
  2165. * //}
  2166. * }, function(xhr){
  2167. * //xhr 为 xmlHttpRequest
  2168. * });
  2169. *
  2170. * /数据字典的值变为
  2171. * {
  2172. * "category": [
  2173. * {
  2174. * "enable": true,
  2175. * "sequence": 1.0,
  2176. * "text": "公司公告",
  2177. * "value": "company"
  2178. * },
  2179. * {
  2180. * "enable": "false",
  2181. * "sequence": 2.0,
  2182. * "text": "部门公告",
  2183. * "value": "department"
  2184. * },
  2185. * {
  2186. * "text": "县级公告",
  2187. * "value": "county"
  2188. * }
  2189. * ],
  2190. * "archiveOptions" : [ { text : "是" }, { text : "否" } ]
  2191. * }
  2192. *
  2193. * dict.set( "category.1.sequence", 3 );
  2194. * dict.set( "category.2.sequence", 2 );
  2195. * //数据字典的值变为
  2196. * {
  2197. * "category": [
  2198. * {
  2199. * "enable": true,
  2200. * "sequence": 1.0,
  2201. * "text": "公司公告",
  2202. * "value": "company"
  2203. * },
  2204. * {
  2205. * "enable": "false",
  2206. * "sequence": 3.0,
  2207. * "text": "部门公告",
  2208. * "value": "department"
  2209. * },
  2210. * {
  2211. * "sequence": 2.0,
  2212. * "text": "县级公告",
  2213. * "value": "county"
  2214. * }
  2215. * ],
  2216. * "archiveOptions" : [ { text : "是" }, { text : "否" } ]
  2217. * }
  2218. * @example
  2219. * <caption>
  2220. * 下面是错误的赋值:
  2221. * </caption>
  2222. * dict.set( "category_1", { text : "公司公告" } ); //出错,因为category_1在数据字典中不存在
  2223. */
  2224. this.set = function(path, value, success, failure){
  2225. const successFun = json=>{if (success) success(json.data);}
  2226. const failureFun = json=>{if (failure) failure(json.data);}
  2227. const par = [encodeURIComponent(this.name)];
  2228. if (type !== "service") par.push(applicationId);
  2229. const json = action.setDictData(...par, encodePath(path), value, successFun, failureFun);
  2230. return json.data;
  2231. };
  2232. /**
  2233. * 根据路径新增数据字典的数据。
  2234. * @method add
  2235. * @methodOf module:Dict
  2236. * @instance
  2237. * @param {String} path 数据字典中的数据路径,允许使用中文。当路径为多级时,用点号(.)分隔。如果path在数据字典中已有数据,且原有数据是数组,则数组添加一项;如果原有数据不是数组,则报错。
  2238. * @param {(Object|Array|String|Number|Boolean)} data 需要新增的数据
  2239. * @param {Function} [success] 增加数据成功时的回调函数。<b>流程设计后台脚本中无此参数。</b>
  2240. * @param {Function} [failure] 增加数据错误时的回调函数。<b>流程设计后台脚本中无此参数。</b>
  2241. * @o2syntax
  2242. * dict.add( path, data, success, failure )
  2243. * @example
  2244. * const dict = new this.Dict({
  2245. * //type: 应用类型。可以为process cms portal service。默认为process。
  2246. * type : "cms",
  2247. * application : "bulletin", //流程、CMS、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
  2248. * name : "bulletinDictionary", // 数据字典的名称、别名、id
  2249. * });
  2250. *
  2251. * dict.add( "category", { text : "系统公告", value : "system" }, function(data){
  2252. * //data 形如
  2253. * //{
  2254. * // "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典ID
  2255. * //}
  2256. * }, function(xhr){
  2257. * //xhr 为 xmlHttpRequest
  2258. * });
  2259. * @example
  2260. * <caption>
  2261. * 对get方法样例的数据字典进行赋值,如下:
  2262. * </caption>
  2263. * const dict = new this.Dict({
  2264. * //type: 应用类型。可以为process cms portal service。默认为process。
  2265. * type : "cms",
  2266. * application : "bulletin", //流程、CMS、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
  2267. * name : "bulletinDictionary", // 数据字典的名称、别名、id
  2268. * });
  2269. *
  2270. * dict.add( "category", { text : "系统公告", value : "system" }, function(data){
  2271. * //data 形如
  2272. * //{
  2273. * // "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典ID
  2274. * //}
  2275. * }, function(xhr, text, error){
  2276. * //xhr 为 xmlHttpRequest, text 为错误文本, error为Error对象
  2277. * });
  2278. * //数据字典的值变为
  2279. * {
  2280. * "category": [
  2281. * {
  2282. * "enable": true,
  2283. * "sequence": 1.0,
  2284. * "text": "公司公告",
  2285. * "value": "company"
  2286. * },
  2287. * {
  2288. * "enable": "false",
  2289. * "sequence": 2.0,
  2290. * "text": "部门公告",
  2291. * "value": "department"
  2292. * },
  2293. * {
  2294. * "text": "系统公告",
  2295. * "value": "system"
  2296. * }
  2297. * ]
  2298. * }
  2299. *
  2300. * dict.add( "category.2.sequence", 3 );
  2301. * //数据字典的值变为
  2302. * {
  2303. * "category": [
  2304. * {
  2305. * "enable": true,
  2306. * "sequence": 1.0,
  2307. * "text": "公司公告",
  2308. * "value": "company"
  2309. * },
  2310. * {
  2311. * "enable": "false",
  2312. * "sequence": 2.0,
  2313. * "text": "部门公告",
  2314. * "value": "department"
  2315. * },
  2316. * {
  2317. * "sequence" : 3.0,
  2318. * "text": "系统公告",
  2319. * "value": "system"
  2320. * }
  2321. * ]
  2322. * }
  2323. * dict.add( "archiveOptions", {
  2324. * "yes" : "是",
  2325. * "no" : "否"
  2326. * });
  2327. * //数据字典的值变为
  2328. * {
  2329. * "category": [
  2330. * {
  2331. * "enable": true,
  2332. * "sequence": 1.0,
  2333. * "text": "公司公告",
  2334. * "value": "company"
  2335. * },
  2336. * {
  2337. * "enable": "false",
  2338. * "sequence": 2.0,
  2339. * "text": "部门公告",
  2340. * "value": "department"
  2341. * },
  2342. * {
  2343. * "sequence" : 3.0,
  2344. * "text": "系统公告",
  2345. * "value": "system"
  2346. * }
  2347. *
  2348. * ],
  2349. * "archiveOptions" : {
  2350. * "yes" : "是",
  2351. * "no" : "否"
  2352. * }
  2353. * }
  2354. * @example
  2355. * <caption>下面是错误的赋值,如下:</caption>
  2356. * dict.add( "category.3", { text : "系统公告", value : "system" }); //出错,因为不能对数组下标直接赋值
  2357. *
  2358. * dict.add( "category.1.value", { text : "系统公告" } ); //出错,因为不能对已经存在的非数组路径赋值
  2359. */
  2360. this.add = function(path, value, success, failure){
  2361. const successFun = json=>{if (success) success(json.data);}
  2362. const failureFun = json=>{if (failure) failure(json.data);}
  2363. const par = [encodeURIComponent(this.name)];
  2364. if (type !== "service") par.push(applicationId);
  2365. const json = action.addDictData(...par, encodePath(path), value, successFun, failureFun);
  2366. return json.data;
  2367. };
  2368. /**
  2369. * 根据路径删除数据字典的数据。<b>流程设计后台脚本中无此方法。</b>
  2370. * @method delete
  2371. * @methodOf module:Dict
  2372. * @instance
  2373. * @param {String} path 数据字典中的数据路径,允许使用中文。当路径为多级时,用点号(.)分隔。如果数据路径不存在,则报错。
  2374. * @param {Function} [success] 删除数据成功时的回调函数。
  2375. * @param {Function} [failure] 删除数据错误时的回调函数。
  2376. * @o2syntax
  2377. * dict.delete( path, success, failure )
  2378. * @example
  2379. * const dict = new this.Dict({
  2380. * //type: 应用类型。可以为process cms portal service。默认为process。
  2381. * type : "cms",
  2382. * application : "bulletin", //流程、CMS的名称、别名、id, 默认为当前应用
  2383. * name : "bulletinDictionary", //流程、CMS、门户管理的名称、别名、id。引用服务管理的数组字典则忽略该参数。
  2384. * });
  2385. *
  2386. * dict.delete( "category", function(){
  2387. * }, function(xhr){
  2388. * //xhr 为 xmlHttpRequest
  2389. * });
  2390. * @example
  2391. * <caption>
  2392. * 对Example set的数据字典进行赋值,如下:
  2393. * </caption>
  2394. * const dict = new this.Dict("bulletinDictionary");
  2395. *
  2396. * dict.delete( "archiveOptions");
  2397. * //数据字典的值变为
  2398. * {
  2399. * "category": [
  2400. * {
  2401. * "enable": true,
  2402. * "sequence": 1.0,
  2403. * "text": "公司公告",
  2404. * * "value": "company"
  2405. * },
  2406. * {
  2407. * "enable": "false",
  2408. * "sequence": 3.0,
  2409. * "text": "部门公告",
  2410. * "value": "department"
  2411. * },
  2412. * {
  2413. * "sequence": 2.0,
  2414. * "text": "县级公告",
  2415. * "value": "county"
  2416. * }
  2417. * ]
  2418. * }
  2419. *
  2420. * dict.delete( "category.2.sequence", function(data){
  2421. * //data 形如
  2422. * //{
  2423. * // "id": "80ed5f60-500f-4358-8bbc-b7e81f77aa39" //id为数据字典ID
  2424. * //}
  2425. * }, function(xhr){
  2426. * //xhr 为 xmlHttpRequest
  2427. * });
  2428. * //数据字典的值变为
  2429. * {
  2430. * "category": [
  2431. * {
  2432. * "enable": true,
  2433. * "sequence": 1.0,
  2434. * "text": "公司公告",
  2435. * "value": "company"
  2436. * },
  2437. * {
  2438. * "enable": "false",
  2439. * "sequence": 3.0,
  2440. * "text": "部门公告",
  2441. * "value": "department"
  2442. * },
  2443. * {
  2444. * "text": "县级公告",
  2445. * "value": "county"
  2446. * }
  2447. * ]
  2448. * }
  2449. *
  2450. * dict.delete( "category.2");
  2451. * //数据字典的值变为
  2452. * {
  2453. * "category": [
  2454. * {
  2455. * "enable": true,
  2456. * "sequence": 1.0,
  2457. * "text": "公司公告",
  2458. * "value": "company"
  2459. * },
  2460. * {
  2461. * "enable": "false",
  2462. * "sequence": 3.0,
  2463. * "text": "部门公告",
  2464. * "value": "department"
  2465. * }
  2466. * ]
  2467. * }
  2468. * @example
  2469. * <caption>
  2470. * 下面是错误的删除:
  2471. * </caption>
  2472. * dict.delete( "category_1" ); //出错,因为category_1在数据字典中不存在
  2473. */
  2474. this["delete"] = function(path, success, failure){
  2475. const successFun = json=>{if (success) success(json.data);}
  2476. const failureFun = json=>{if (failure) failure(json.data);}
  2477. const par = [encodeURIComponent(this.name)];
  2478. if (type !== "service") par.push(applicationId);
  2479. const json = action.deleteDictData(...par, encodePath(path), successFun, failureFun);
  2480. return json.data;
  2481. };
  2482. this.destory = this["delete"];
  2483. }
  2484. /**
  2485. * this.Table是一个工具类,您可以使用这个类对数据中心的数据表进行增删改查操作。
  2486. * @module server.Table
  2487. * @o2cn 数据表执行
  2488. * @o2category server.common
  2489. * @o2ordernumber 185
  2490. * @param {String} name 数据表的id、名称或别名。
  2491. * @return {Object} table对象
  2492. * @o2syntax
  2493. * //您可以在脚本中,通过this.Table()来返回Table的对象,如下:
  2494. * const table = new this.Table( tableName )
  2495. */
  2496. const Table = function(name){
  2497. this.name = name;
  2498. this.action = Actions.load("x_query_assemble_surface").TableAction;
  2499. /**
  2500. * 列示表中的行对象,下一页。
  2501. * @method listRowNext
  2502. * @methodOf module:server.Table
  2503. * @instance
  2504. * @param {String} id 当前页最后一条数据的Id,如果是第一页使用"(0)"或 "0"。
  2505. * @param {String|Number} count 下一页的行数
  2506. * @param {Function} [success] 调用成功时的回调函数。
  2507. * @param {Function} [failure] 调用错误时的回调函数。
  2508. * @o2syntax
  2509. * table.listRowNext( id, count, success, failure )
  2510. * @example
  2511. * const table = new this.Table("table1");
  2512. *
  2513. * table.listRowNext( "0", 20, function(data){
  2514. * //data 形如
  2515. * //{
  2516. * // "type": "success",
  2517. * // "data":[
  2518. * // {
  2519. * // "id": "5584e6d1-8088-4694-a948-8968ac8d4923", //数据的id
  2520. * // "createTime": "2021-11-01 16:23:41", //数据创建时间
  2521. * // "updateTime": "2021-11-01 16:23:41", //数据更新时间
  2522. * // ... //定义的字段(列)和值
  2523. * // }
  2524. * // ],
  2525. * // "message": "",
  2526. * // "date": "2021-11-01 18:34:19",
  2527. * // "spent": 13,
  2528. * //}
  2529. * }, function(xhr){
  2530. * //xhr 为 xmlHttpRequest
  2531. * });
  2532. */
  2533. this.listRowNext = function(id, count, success, failure){
  2534. return this.action.listRowNext(this.name, id, count, success, failure);
  2535. };
  2536. /**
  2537. * 列示表中的行对象,上一页。
  2538. * @method listRowPrev
  2539. * @methodOf module:server.Table
  2540. * @instance
  2541. * @param {String} id 当前页第一条数据的Id,如果是最后一页使用"(0)"或 "0"。
  2542. * @param {String|Number} count 上一页的行数
  2543. * @param {Function} [success] 调用成功时的回调函数。
  2544. * @param {Function} [failure] 调用错误时的回调函数。
  2545. * @o2syntax
  2546. * table.listRowPrev( id, count, success, failure )
  2547. * @example
  2548. * const table = new this.Table("table1");
  2549. *
  2550. * table.listRowPrev( "0", 20, function(data){
  2551. * //data 形如
  2552. * //{
  2553. * // "type": "success",
  2554. * // "data":[
  2555. * // {
  2556. * // "id": "5584e6d1-8088-4694-a948-8968ac8d4923", //数据的id
  2557. * // "createTime": "2021-11-01 16:23:41", //数据创建时间
  2558. * // "updateTime": "2021-11-01 16:23:41", //数据更新时间
  2559. * // ... //定义的字段(列)和值
  2560. * // }
  2561. * // ],
  2562. * // "message": "",
  2563. * // "date": "2021-11-01 18:34:19",
  2564. * // "spent": 13,
  2565. * //}
  2566. * }, function(xhr){
  2567. * //xhr 为 xmlHttpRequest
  2568. * });
  2569. */
  2570. this.listRowPrev = function(id, count, success, failure){
  2571. return this.action.listRowPrev(this.name, id, count, success, failure);
  2572. };
  2573. /**
  2574. * 根据条件获取表中的数据。
  2575. * @method listRowSelect
  2576. * @methodOf module:server.Table
  2577. * @instance
  2578. * @param {String} [where] 查询条件,格式为jpql语法,o.name='zhangsan',允许为空。
  2579. * @param {String} [orderBy] 排序条件,格式为:o.updateTime desc,允许为空
  2580. * @param {String|Number} [size] 返回结果集数量,允许为空。
  2581. * @param {Function} [success] 调用成功时的回调函数。
  2582. * @param {Function} [failure] 调用错误时的回调函数。
  2583. * @o2syntax
  2584. * table.listRowSelect( where, orderBy, size, success, failure )
  2585. * @example
  2586. * const table = new this.Table("table1");
  2587. *
  2588. * //查询字段name等于zhangsan的数据,结果按updateTime倒序
  2589. * table.listRowSelect( "o.name='zhangsan'", "o.updateTime desc", 20, function(data){
  2590. * //data 形如
  2591. * //{
  2592. * // "type": "success",
  2593. * // "data":[
  2594. * // {
  2595. * // "id": "5584e6d1-8088-4694-a948-8968ac8d4923", //数据的id
  2596. * // "createTime": "2021-11-01 16:23:41", //数据创建时间
  2597. * // "updateTime": "2021-11-01 16:23:41", //数据更新时间
  2598. * // ... //定义的字段(列)和值
  2599. * // }
  2600. * // ],
  2601. * // "message": "",
  2602. * // "date": "2021-11-01 18:34:19",
  2603. * // "spent": 13,
  2604. * //}
  2605. * }, function(xhr){
  2606. * //xhr 为 xmlHttpRequest
  2607. * });
  2608. */
  2609. this.listRowSelect = function(where, orderBy, size, success, failure){
  2610. return this.action.listRowSelect(this.name, {"where": where, "orderBy": orderBy, "size": size || ""}, success, failure);
  2611. };
  2612. this.listRowSelectWhere = function(where, success, failure){
  2613. return this.action.listRowSelectWhere(this.name, where, success, failure);
  2614. };
  2615. /**
  2616. * 通过where 统计数量。
  2617. * @method rowCountWhere
  2618. * @methodOf module:server.Table
  2619. * @instance
  2620. * @param {String} where 查询条件,格式为jpql语法,o.name='zhangsan',允许为空。
  2621. * @param {Function} [success] 调用成功时的回调函数。
  2622. * @param {Function} [failure] 调用错误时的回调函数。
  2623. * @o2syntax
  2624. * table.rowCountWhere( where, success, failure )
  2625. * @example
  2626. * const table = new this.Table("table1");
  2627. *
  2628. * //查询字段name等于zhangsan的数据,结果按updateTime倒序
  2629. * table.rowCountWhere( "o.name='zhangsan'", function(data){
  2630. * //data 形如
  2631. * //{
  2632. * // "type": "success",
  2633. * // "data": {
  2634. * // "value": 5 //符合条件数据的总条数
  2635. * // },
  2636. * // "message": "",
  2637. * // "date": "2021-11-01 18:32:27"
  2638. * //}
  2639. * }, function(xhr){
  2640. * //xhr 为 xmlHttpRequest
  2641. * });
  2642. */
  2643. this.rowCountWhere = function(where, success, failure){
  2644. return this.action.rowCountWhere(this.name, where, success, failure);
  2645. };
  2646. /**
  2647. * 删除数据表中指定id的记录。
  2648. * @method deleteRow
  2649. * @methodOf module:server.Table
  2650. * @instance
  2651. * @param {id} [id] 需要删除记录的id。
  2652. * @param {Function} [success] 调用成功时的回调函数。
  2653. * @param {Function} [failure] 调用错误时的回调函数。
  2654. * @o2syntax
  2655. * table.deleteRow( id, success, failure )
  2656. * @example
  2657. * const table = new this.Table("table1");
  2658. *
  2659. * table.deleteRow( "e1f89185-d8b0-4b66-9e34-aed3323d0d79", function(data){
  2660. * //data 形如
  2661. * //{
  2662. * // "type": "success",
  2663. * // "data": {
  2664. * // "value": true //true表示删除成功,false表示无此数据
  2665. * // },
  2666. * // "message": "",
  2667. * // "date": "2021-11-01 18:32:27"
  2668. * //}
  2669. * }, function(xhr){
  2670. * //xhr 为 xmlHttpRequest
  2671. * });
  2672. */
  2673. this.deleteRow = function(id, success, failure){
  2674. return this.action.rowDelete(this.name, id, success, failure);
  2675. };
  2676. /**
  2677. * 删除指定表中所有行的数据。
  2678. * @method deleteAllRow
  2679. * @methodOf module:server.Table
  2680. * @instance
  2681. * @param {Function} [success] 调用成功时的回调函数。
  2682. * @param {Function} [failure] 调用错误时的回调函数。
  2683. * @o2syntax
  2684. * table.deleteAllRow( success, failure, async )
  2685. * @example
  2686. * const table = new this.Table("table1");
  2687. *
  2688. * table.deleteAllRow( function(data){
  2689. * //data 形如
  2690. * //{
  2691. * // "type": "success",
  2692. * // "data": {
  2693. * // "value": 1 //表示删除的条数,0表示无数据
  2694. * // },
  2695. * // "message": "",
  2696. * // "date": "2021-11-01 18:32:27"
  2697. * //}
  2698. * }, function(xhr){
  2699. * //xhr 为 xmlHttpRequest
  2700. * });
  2701. */
  2702. this.deleteAllRow = function(success, failure){
  2703. return this.action.rowDeleteAll(this.name, success, failure);
  2704. };
  2705. /**
  2706. * 获取数据表中指定id的记录。
  2707. * @method getRow
  2708. * @methodOf module:server.Table
  2709. * @instance
  2710. * @param {id} [id] 需要获取记录的id。
  2711. * @param {Function} [success] 调用成功时的回调函数。
  2712. * @param {Function} [failure] 调用错误时的回调函数。
  2713. * @o2syntax
  2714. * table.getRow( id, success, failure )
  2715. * @example
  2716. * const table = new this.Table("table1");
  2717. *
  2718. * table.getRow( "e1f89185-d8b0-4b66-9e34-aed3323d0d79", function(data){
  2719. * //data 形如
  2720. * //{
  2721. * // "type": "success",
  2722. * // "data":{
  2723. * // "id": "5584e6d1-8088-4694-a948-8968ac8d4923", //数据的id
  2724. * // "createTime": "2021-11-01 16:23:41", //数据创建时间
  2725. * // "updateTime": "2021-11-01 16:23:41", //数据更新时间
  2726. * // ... //定义的字段(列)和值
  2727. * // },
  2728. * // "message": "",
  2729. * // "date": "2021-11-01 18:34:19",
  2730. * // "spent": 13,
  2731. * //}
  2732. * }, function(xhr){
  2733. * //xhr 为 xmlHttpRequest
  2734. * });
  2735. */
  2736. this.getRow = function(id, success, failure){
  2737. return this.action.rowGet(this.name, id, success, failure);
  2738. };
  2739. /**
  2740. * 往数据表中批量插入数据。
  2741. * @method insertRow
  2742. * @methodOf module:server.Table
  2743. * @instance
  2744. * @param {Object[]} data 需要插入的数据。
  2745. * @param {Function} [success] 调用成功时的回调函数。
  2746. * @param {Function} [failure] 调用错误时的回调函数。
  2747. * @o2syntax
  2748. * table.insertRow( data, success, failure )
  2749. * @example
  2750. * const table = new this.Table("table1");
  2751. * const data = [
  2752. * {
  2753. * "subject": "标题一",
  2754. * ... //其他字段
  2755. * },
  2756. * ...
  2757. * ];
  2758. * table.insertRow( data, function(data){
  2759. * //data 形如
  2760. * //{
  2761. * // "type": "success",
  2762. * // "data": {
  2763. * // "value": true //true表示插入成功
  2764. * // },
  2765. * // "message": "",
  2766. * // "date": "2021-11-01 18:32:27"
  2767. * //}
  2768. * }, function(xhr){
  2769. * //xhr 为 xmlHttpRequest
  2770. * });
  2771. */
  2772. this.insertRow = function(data, success, failure){
  2773. return this.action.rowInsert(this.name, data, success, failure);
  2774. };
  2775. /**
  2776. * 往数据表中插入单条数据。
  2777. * @method addRow
  2778. * @methodOf module:Table
  2779. * @instance
  2780. * @param {Object} data 需要插入的数据。
  2781. * @param {Function} [success] 调用成功时的回调函数。
  2782. * @param {Function} [failure] 调用错误时的回调函数。
  2783. * @o2syntax
  2784. * table.addRow( data, success, failure, async )
  2785. * @example
  2786. * const table = new this.Table("table1");
  2787. * const data = {
  2788. * "subject": "标题一",
  2789. * ... //其他字段
  2790. * };
  2791. * table.addRow( data, function(data){
  2792. * //data 形如
  2793. * //{
  2794. * // "type": "success",
  2795. * // "data": {
  2796. * // "id": 2cf3a20d-b166-490b-8d29-05544db3d79b //true表示修改成功
  2797. * // },
  2798. * // "message": "",
  2799. * // "date": "2021-11-01 18:32:27"
  2800. * //}
  2801. * }, function(xhr){
  2802. * //xhr 为 xmlHttpRequest
  2803. * });
  2804. */
  2805. this.addRow = function(data, success, failure){
  2806. return this.action.rowInsertOne(this.name, data, success, failure);
  2807. };
  2808. /**
  2809. * 往数据表中修改单条数据。
  2810. * @method updateRow
  2811. * @methodOf module:server.Table
  2812. * @instance
  2813. * @param {String} id 需要修改的数据id。
  2814. * @param {Object} data 需要修改的数据。
  2815. * @param {Function} [success] 调用成功时的回调函数。
  2816. * @param {Function} [failure] 调用错误时的回调函数。
  2817. * @o2syntax
  2818. * table.updateRow( id, data, success, failure )
  2819. * @example
  2820. * const table = new this.Table("table1");
  2821. * const data = {
  2822. * "id" : "2cf3a20d-b166-490b-8d29-05544db3d79b",
  2823. * "subject": "标题一",
  2824. * ... //其他字段
  2825. * };
  2826. * table.updateRow( "2cf3a20d-b166-490b-8d29-05544db3d79b", data, function(data){
  2827. * //data 形如
  2828. * //{
  2829. * // "type": "success",
  2830. * // "data": {
  2831. * // "value": true //true表示修改成功
  2832. * // },
  2833. * // "message": "",
  2834. * // "date": "2021-11-01 18:32:27"
  2835. * //}
  2836. * }, function(xhr){
  2837. * //xhr 为 xmlHttpRequest
  2838. * });
  2839. */
  2840. this.updateRow = function(id, data, success, failure){
  2841. return this.action.rowUpdate(this.name, id, data, success, failure);
  2842. };
  2843. /**
  2844. * 往数据表中部分修改单条数据。
  2845. * @method updateRow
  2846. * @methodOf module:server.Table
  2847. * @instance
  2848. * @param {String} id 需要修改的数据id。
  2849. * @param {Object} data 需要修改的部分数据,其他数据不变。
  2850. * @param {Function} [success] 调用成功时的回调函数。
  2851. * @param {Function} [failure] 调用错误时的回调函数。
  2852. * @o2syntax
  2853. * table.updateRow( id, data, success, failure )
  2854. * @example
  2855. * const table = new this.Table("table1");
  2856. * const data = {
  2857. * "id" : "2cf3a20d-b166-490b-8d29-05544db3d79b",
  2858. * "subject": "标题一",
  2859. * ... //其他字段
  2860. * };
  2861. * table.updateRow( "2cf3a20d-b166-490b-8d29-05544db3d79b", data, function(data){
  2862. * //data 形如
  2863. * //{
  2864. * // "type": "success",
  2865. * // "data": {
  2866. * // "value": true //true表示修改成功
  2867. * // },
  2868. * // "message": "",
  2869. * // "date": "2021-11-01 18:32:27"
  2870. * //}
  2871. * }, function(xhr){
  2872. * //xhr 为 xmlHttpRequest
  2873. * });
  2874. */
  2875. this.partUpdateRow = function(id, data, success, failure){
  2876. return this.action.rowPartUpdate(this.name, id, data, success, failure);
  2877. };
  2878. }
  2879. /**
  2880. * 您可以通过statement对象,获取执行查询语句或者对查询结果进行选择。<br/>
  2881. * @module server.statement
  2882. * @o2cn 查询视图执行
  2883. * @o2category server.common
  2884. * @o2ordernumber 190
  2885. * @o2syntax
  2886. * //您可以在流程表单、内容管理表单、门户页面或视图中,通过this来获取statement对象,如下:
  2887. * const statement = this.statement;
  2888. */
  2889. const statement = {
  2890. _parseParameter: function(obj, format){
  2891. if(typeof obj !== 'object')return {};
  2892. const parameter = {};
  2893. //传入的参数
  2894. for (const [key, value] of Object.entries(obj)) {
  2895. parameter[key] = (typeOf(value) === 'date') ? (['sql', 'sqlScript'].includes(format) ? value.format('db') : `{ts '${value.format('db')}'}`) : value;
  2896. }
  2897. return parameter;
  2898. },
  2899. _parseFilter: function(filter=[], parameter={}, format){
  2900. return filter.map((d)=>{
  2901. let pName = d.path.replace(/\./g, '_');
  2902. pName = (parameter[pName]) ?
  2903. (function unique(name, i){
  2904. return (parameter[name+'_'+i]) ? unique(name, ++i) : name+'_'+i;
  2905. })(pName, 1) :
  2906. pName;
  2907. parameter[pName] = (d.comparison === 'like' || d.comparison === 'notLike') ?
  2908. `%${d.value.replace(/^%|%$/g, '')}%` :
  2909. (() => {
  2910. if (d.formatType === "numberValue") {
  2911. return parseFloat(d.value);
  2912. } else if ( ["dateTimeValue","dateValue","timeValue"].includes( d.formatType ) && !["sql", "sqlScript"].includes(format)) {
  2913. const prefix = {dateTimeValue: 'ts', datetimeValue: 'ts', dateValue: 'd', timeValue: 't'}[d.formatType];
  2914. return `{${prefix} '${d.value}'}`;
  2915. }
  2916. return d.value;
  2917. })();
  2918. d.value = pName;
  2919. return d;
  2920. });
  2921. },
  2922. _execute: function (statement, callback, format) {
  2923. const parameter = this._parseParameter(statement.parameter, format);
  2924. const filterList = this._parseFilter(statement.filter, parameter, format);
  2925. const obj = {
  2926. "filterList": filterList,
  2927. "parameter" : parameter
  2928. };
  2929. return Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  2930. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  2931. callback
  2932. );
  2933. },
  2934. _needCheckFormat: function(s){
  2935. if (s.format) return false;
  2936. if (typeof s.parameter === "object"){
  2937. if (Object.values(s.parameter).findIndex(p=>typeOf(p)==='date')!==-1){
  2938. return true;
  2939. }
  2940. }
  2941. if( Array.isArray(s.filter)){
  2942. if (s.filter.findIndex(f=>["dateTimeValue", "datetimeValue", "dateValue", "timeValue"].includes(f))!==-1){
  2943. return true;
  2944. }
  2945. }
  2946. return false;
  2947. },
  2948. /**
  2949. * 执行指定的查询语句。
  2950. * @method execute
  2951. * @static
  2952. * @param {Object} statement - 要执行的查询语句的信息。数据格式如下:
  2953. * <div>以下的filter参数参考<a href='global.html#StatementFilter'>StatementFilter</a>,
  2954. * parameter参数参考<a href='global.html#StatementParameter'>StatementParameter</a></div>
  2955. * <pre><code class='language-js'>
  2956. * {
  2957. * "name" : "tesStatement", //(String)必选,查询配置的名称、别名或ID
  2958. * "mode" : "all", //(String)必选,“all”、“data”或者“count”,all表示同时执行查询语句和总数语句,data表示执行查询语句,count表示执行总数语句
  2959. * "page" : 1, //(number)可选,当前页码,默认为1
  2960. * "pageSize" : 20, //(number)可选,每页的数据条数,默认为20
  2961. * "filter": [ //(Array)可选,对查询进行过滤的条件。json数组格式,每个数组元素描述一个过滤条件,每个元素数据格式如下:
  2962. * {
  2963. * "path":"o.title", //查询语句格式为jpql使用o.title,为原生sql中使用xtitle
  2964. * "comparison":"like",
  2965. * "value":"关于",
  2966. * "formatType":"textValue"
  2967. * }
  2968. * ],
  2969. * parameter : {
  2970. * "person" : "", //参数名称为下列值时,后台默认赋值,person(当前人),identityList(当前人身份列表),unitList(当前人所在直接组织), unitAllList(当前人所在所有组织), groupList(当前人所在群组)
  2971. * "startTime" : (new Date("2020-01-01")), //如果对比的是日期,需要传入 Date 类型
  2972. * "applicationName" : "%test%", //如果运算符用的是 like, noLike,模糊查询
  2973. * "processName" : "test流程", //其他写确定的值
  2974. * "?1": "关于" //v8.0后查询语句支持问号加数字的传参
  2975. * }
  2976. * }
  2977. * </code></pre>
  2978. * @param {Function} callback - 访问成功后的回调函数
  2979. * @o2syntax
  2980. * this.statement.execute(statement, callback, async);
  2981. * @example
  2982. * //获取“task”查询中的数据
  2983. * //查询语句为 select o from Task o where (o.person = :person) and (o.startTime > :startTime) and (o.applicationName like :applicationName) and (o.processName = :processName)
  2984. * //总数语句为 select count(o.id) from Task o where (o.person = :person) and (o.startTime > :startTime) and (o.applicationName like :applicationName) and (o.processName = :processName)
  2985. * //过滤条件为标题o.title包含包含(like))“7月”。
  2986. * this.statement.execute({
  2987. * "name": "task",
  2988. * "mode" : "all",
  2989. * "filter": [
  2990. * {
  2991. * "path":"o.title", //查询语句格式为jpql使用o.title,为原生sql中使用xtitle
  2992. * "comparison":"like",
  2993. * "value":"7月",
  2994. * "formatType":"textValue"
  2995. * }
  2996. * ],
  2997. * "parameter" : {
  2998. * "person" : "", //参数名称为下列值时,后台默认赋值,person(当前人),identityList(当前人身份列表),unitList(当前人所在直接组织), unitAllList(当前人所在所有组织), groupList(当前人所在群组)
  2999. * "startTime" : (new Date("2020-01-01")), //如果对比的是日期,需要传入 Date 类型
  3000. * "applicationName" : "%test%", //如果运算符用的是 like, noLike,模糊查询
  3001. * "processName" : "test流程", //其他写确定的值
  3002. * "?1": "关于" //v8.0后查询语句支持问号加数字的传参
  3003. * }
  3004. * }, function(json){
  3005. * const count = json.count; //总数语句执行后返回的数字
  3006. * const list = json.data; //查询语句后返回的数组
  3007. * //......
  3008. * });
  3009. */
  3010. execute: function (statement, callback) {
  3011. const jsonFormat = (!statement.format && this._needCheckFormat(statement)) ? Actions.load("x_query_assemble_surface").StatementAction.getFormat(statement.name).data : statement;
  3012. return this._execute(statement, callback, (jsonFormat?.format || ""));
  3013. },
  3014. select: function () {}
  3015. };
  3016. /**
  3017. * 您可以通过view对象,获取视图数据或选择视图数据。<br/>
  3018. * @module server.view
  3019. * @o2cn 视图执行
  3020. * @o2category server.common
  3021. * @o2ordernumber 195
  3022. * @o2syntax
  3023. * //您可以在流程表单、内容管理表单或门户页面中,通过this来获取view对象,如下:
  3024. * const view = this.view;
  3025. */
  3026. const view = {
  3027. /**
  3028. * 获取指定视图的数据。
  3029. * @method lookup
  3030. * @static
  3031. * @param {Object} view - 要访问的视图信息。数据格式如下:<br/>
  3032. * <caption>以下的filter参数参考<a href='global.html#ViewFilter'>ViewFilter</a></caption>
  3033. * <pre><code class='language-js'>
  3034. * {
  3035. * "view" : "testView", //(String)必选,视图的名称、别名或ID
  3036. * "application" : "test数据中心应用", //(String)必选,视图所在数据应用的名称、别名或ID
  3037. * "filter": [ //(Array of Object)可选,对视图进行过滤的条件。json数组格式,每个数组元素描述一个过滤条件。
  3038. * {
  3039. * "logic":"and",
  3040. * "path":"$work.title",
  3041. * "comparison":"like",
  3042. * "value":"7月",
  3043. * "formatType":"textValue"
  3044. * }
  3045. * ]
  3046. * }
  3047. * </code></pre>
  3048. * @param {Function} callback - 访问成功后的回调函数
  3049. * @param {Boolean} [async] - 同步或异步调用。true:异步;false:同步。默认为true。
  3050. * @o2syntax
  3051. * this.view.lookup(view, callback, async);
  3052. * @example
  3053. * //获取“财务管理”应用中“报销审批数据”视图中的数据
  3054. * //过滤条件为标题($work.title)包含包含(like))“7月”。
  3055. * this.view.lookup({
  3056. * "view": "报销审批数据",
  3057. * "application": "财务管理",
  3058. * "filter": [
  3059. * {
  3060. * "logic":"and",
  3061. * "path":"$work.title",
  3062. * "comparison":"like",
  3063. * "value":"7月",
  3064. * "formatType":"textValue"
  3065. * }
  3066. * ]
  3067. *}, function(data){
  3068. * const grid = data.grid; //得到过滤后的数据
  3069. * const groupGrid = data.groupGrid; //如果有分类,得到带分类的数据
  3070. * //......
  3071. *});
  3072. * @example
  3073. * //获取“财务管理”应用中“报销审批数据”视图中的数据
  3074. * //过滤条件为标题($work.title)包含包含(like))“7月”,并且总金额大于500小于5000
  3075. * this.view.lookup({
  3076. * "view": "报销审批数据",
  3077. * "application": "财务管理",
  3078. * "filter": [
  3079. * {
  3080. * "logic":"and",
  3081. * "path":"$work.title",
  3082. * "comparison":"like",
  3083. * "value":"7月",
  3084. * "formatType":"textValue"
  3085. * },
  3086. * {
  3087. * "logic":"and",
  3088. * "path":"amount",
  3089. * "comparison":"range",
  3090. * "value":500,
  3091. * "otherValue":5000,
  3092. * "formatType":"numberValue"
  3093. * },
  3094. * ]
  3095. *}, function(data){
  3096. * const grid = data.grid; //得到过滤后的数据
  3097. * const groupGrid = data.groupGrid; //如果有分类,得到带分类的数据
  3098. * //......
  3099. *});
  3100. */
  3101. "lookup": function(view, callback){
  3102. const filterList = {"filterList": (view.filter || null)};
  3103. const json = Actions.load("x_query_assemble_surface").ViewAction.executeWithQuery(view.view, view.application, filterList);
  3104. const data = {
  3105. "grid": json.data.grid || json.data.groupGrid,
  3106. "groupGrid": json.data.groupGrid
  3107. };
  3108. if (callback) callback(data);
  3109. return data;
  3110. },
  3111. "select": function(view, callback, options){}
  3112. };
  3113. /**
  3114. * 可以通过service对象发起restful请求,或soap协议的webservice调用。
  3115. * @module service
  3116. * @o2cn 通用service调用
  3117. * @o2category server.common
  3118. * @o2syntax
  3119. * const service = this.service;
  3120. * @example
  3121. * //通过get方法发起restful请求,获取json数据
  3122. * const res = this.service.restful("get", "config/myjson.json");
  3123. * if (res.responseCode>=200 && responseCode<300){
  3124. * const jsonData = res.json;
  3125. * }
  3126. */
  3127. const service = {
  3128. /**
  3129. * 发起restful请求。
  3130. * @method restful
  3131. * @o2category server.common
  3132. * @param {String} [method] - restful请求方法:get、post、put、delete ...
  3133. * @param {String} [url] - restful请求地址
  3134. * @param {Object} [headers] - 可选,json对象,请求的header,默认content-type为:“application/json charset=utf-8”
  3135. * @param {String|Object} [body] - 可选,post、put请求的消息体,传入文本或json对象
  3136. * @param {Number} [connectTimeout] - 可选,连接超时时间(毫秒),默认是2000。
  3137. * @param {Number} [readTimeout] - 可选,传输超时时间(毫秒),默认是300000。
  3138. * @return {Object} 返回json格式的请求结果对象,格式如下:
  3139. * <pre><code class='language-js'>
  3140. * {
  3141. * "responseCode" : 200, //请求返回的code
  3142. * "headers" : {}, //响应头
  3143. * "body": "", //响应的body文本内容
  3144. * "json": {} //响应的body的json格式内容
  3145. * }
  3146. * </code></pre>
  3147. * @o2syntax
  3148. * var res = this.service.restful(method, url, headers, body, connectTimeout, readTimeout);
  3149. * @example
  3150. * //通过get方法发起restful请求,获取json数据
  3151. * var res = this.service.restful("get", "config/myjson.json");
  3152. * if (res.responseCode>=200 && res.responseCode<300){
  3153. * var jsonData = res.json;
  3154. * }
  3155. */
  3156. restful: function(method, url, headers, body, connectTimeout=2000, readTimeout=300000){
  3157. const service = globalThis.java_resources.getWebservicesClient();
  3158. const bodyData = ((typeof body)==="object") ? JSON.stringify(body) : (body||"");
  3159. const res = service.restful(method, url, (headers||null), bodyData, (connectTimeout||2000), (readTimeout||300000));
  3160. const o = {
  3161. "responseCode" : res.getResponseCode(),
  3162. "headers" : res.getHeaders(),
  3163. "body": res.getBody()
  3164. }
  3165. try {
  3166. o.json = JSON.parse(o.body);
  3167. }catch(e){}
  3168. return o;
  3169. },
  3170. /**
  3171. * 通过get方法发起restful请求。
  3172. * @method get
  3173. * @methodOf restful
  3174. * @static
  3175. * @param {String} [url] - restful请求地址
  3176. * @param {Object} [headers] - 可选,json对象,请求的header,默认content-type为:“application/json charset=utf-8”
  3177. * @param {Number} [connectTimeout] - 可选,连接超时时间(毫秒),默认是2000。
  3178. * @param {Number} [readTimeout] - 可选,传输超时时间(毫秒),默认是300000。
  3179. * @return {Object} 返回json格式的请求结果对象,格式如下:
  3180. * <pre><code class='language-js'>
  3181. * {
  3182. * "responseCode" : 200, //请求返回的code
  3183. * "headers" : {}, //响应头
  3184. * "body": "", //响应的body文本内容
  3185. * "json": {} //响应的body的json格式内容
  3186. * }
  3187. * </code></pre>
  3188. * @o2syntax
  3189. * var res = this.service.get(url, headers, connectTimeout, readTimeout);
  3190. */
  3191. "get": function(url, headers, connectTimeout, readTimeout){
  3192. return this.restful("get", url, headers, "", connectTimeout, readTimeout);
  3193. },
  3194. /**
  3195. * 通过post方法发起restful请求。
  3196. * @method post
  3197. * @static
  3198. * @param {String} [url] - restful请求地址
  3199. * @param {Object} [headers] - 可选,json对象,请求的header,默认content-type为:“application/json charset=utf-8”
  3200. * @param {String|Object} [body] - 可选,post、put请求的消息体,传入文本或json对象
  3201. * @param {Number} [connectTimeout] - 可选,连接超时时间(毫秒),默认是2000。
  3202. * @param {Number} [readTimeout] - 可选,传输超时时间(毫秒),默认是300000。
  3203. * @return {Object} 返回json格式的请求结果对象,格式如下:
  3204. * <pre><code class='language-js'>
  3205. * {
  3206. * "responseCode" : 200, //请求返回的code
  3207. * "headers" : {}, //响应头
  3208. * "body": "", //响应的body文本内容
  3209. * "json": {} //响应的body的json格式内容
  3210. * }
  3211. * </code></pre>
  3212. * @o2syntax
  3213. * var res = this.service.post(url, headers, body, connectTimeout, readTimeout);
  3214. */
  3215. "post": function(url, headers, body, connectTimeout, readTimeout){
  3216. return this.restful("post", url, headers, body, connectTimeout, readTimeout);
  3217. },
  3218. /**
  3219. * 发起soap协议的webservice请求。
  3220. * @method soap
  3221. * @o2category server.common
  3222. * @param {String} [wsdl] - wsdl文件地址
  3223. * @param {String} [method] - 要调用的方法名称
  3224. * @param {Array} [pars] - 方法所需要的参数
  3225. * @return {Object} 与服务返回的类型有关:
  3226. * @o2syntax
  3227. * var res = this.service.soap(wsdl, method, pars);
  3228. * @example
  3229. * //模拟通过webservice获取用户
  3230. * var res = this.service.soap("wsdl/mywsdl.wsdl", "getPerson", ["张三", "李四"]);
  3231. */
  3232. soap: function(wsdl, method, pars){
  3233. const service = globalThis.java_resources.getWebservicesClient();
  3234. return service.soap(wsdl, method, pars);
  3235. },
  3236. soapXml: function(wsdl, xml){
  3237. const service = globalThis.java_resources.getWebservicesClient();
  3238. return service.jaxwsXml(wsdl, xml);
  3239. }
  3240. }
  3241. //=========================================================================================/
  3242. //====以上为公共对象和方法,在服务端脚本中通用================================================/
  3243. //=========================================================================================/
  3244. /*****************************************************************/
  3245. /* response - 服务调用活动,响应脚本,获取响应内容 ******************/
  3246. /* 服务管理 invoke,用于设置响应内容 *******************/
  3247. /* - 接口响应对象,服务端注入对象 java_customResponse **********/
  3248. /* - java_jaxrsResponse, type() ******************************/
  3249. /* java_jaxrsResponse, get() 字符串 ************************/
  3250. /* java_jaxwsResponse 直接返回不做处理 *********************/
  3251. /*****************************************************************/
  3252. const responseDescriptor = {
  3253. get: function(){
  3254. if (globalThis.java_customResponse){ //注入 java_customResponse 对象,表示脚本运行于 服务管理 invoke 中
  3255. /**
  3256. * 用于服务管理的接口脚本,描述服务的响应对象。<br>
  3257. * @o2range 服务管理-接口
  3258. * @o2cn 服务的响应对象
  3259. * @module server.service.response
  3260. * @o2category server.service
  3261. * @o2ordernumber 245
  3262. * @o2syntax
  3263. * const res = this.response;
  3264. */
  3265. return {
  3266. /**
  3267. * @summary 服务返回一个303跳转。
  3268. * @method seeOther
  3269. * @methodOf service.service.module:response
  3270. * @static
  3271. * @param {String} [url] 跳转的url。
  3272. * @o2syntax
  3273. * this.response.seeOther(url);
  3274. */
  3275. seeOther: function(url){
  3276. globalThis.java_customResponse.seeOther(url);
  3277. },
  3278. /**
  3279. * @summary 服务返回一个301跳转。
  3280. * @method redirect
  3281. * @methodOf service.service.module:response
  3282. * @static
  3283. * @param {String} [url] 跳转的url。
  3284. * @o2syntax
  3285. * this.response.redirect(url);
  3286. */
  3287. redirect: function(url){
  3288. globalThis.java_customResponse.temporaryRedirect(url);
  3289. },
  3290. /**
  3291. * @summary 服务正常返回数据(200)。
  3292. * @method setBody
  3293. * @methodOf service.service.module:response
  3294. * @static
  3295. * @param {String|Object} [body] 响应内容,文本或json对象。
  3296. * @param {String} [contentType] 响应头的Content-Type。
  3297. * @o2syntax
  3298. * this.response.setBody(body, contentType);
  3299. * @example
  3300. * //设置json格式的响应内容
  3301. * this.response.setBody({
  3302. * "key1": "value1",
  3303. * "key2": "value2"
  3304. * }, "application/json");
  3305. */
  3306. setBody: function(body, contentType=''){
  3307. const o = (typeof body==='object') ? JSON.stringify(body) : body;
  3308. globalThis.java_customResponse.setBody(o, contentType);
  3309. },
  3310. customResponse: globalThis.java_customResponse
  3311. }
  3312. }
  3313. if (globalThis.java_jaxrsResponse) { //注入 java_jaxrsResponse 对象,表示脚本运行于 服务调用活动,响应脚本 中,并且调用类型为 jaxrs
  3314. /**
  3315. * 用于流程配置的服务调用活动中的“响应脚本”,描述调用服务后得到的响应。(注意:调用方式为异步时,“响应脚本”不会执行)<br>
  3316. * @o2range 流程配置-服务调用活动中的“响应脚本”
  3317. * @module server.response
  3318. * @o2cn 服务调用的响应
  3319. * @o2category server.process
  3320. * @o2ordernumber 230
  3321. * @o2syntax
  3322. * const res = this.response;
  3323. */
  3324. return {
  3325. /**
  3326. * @summary jaxrs方式的服务调用活动,请求返回的状态。有四个可能的值:
  3327. * <pre><code class="language-js">success : 表示请求成功
  3328. * warn : 当调用的是平台内部服务时,虽然请求成功,但产生了警告
  3329. * error : 请求调用错误
  3330. * connectFatal : 网络连接错误</code></pre>
  3331. * @member {String} status
  3332. * @memberOf server.module:response
  3333. * @o2syntax
  3334. * const status = this.response.status;
  3335. */
  3336. get status(){
  3337. return globalThis.java_jaxrsResponse.type() || '';
  3338. },
  3339. /**
  3340. * @summary 请求返回的值,如果是jaxrs服务,得到的是响应的文本,如果是jaxws服务,响应类型取决于服务的返回。
  3341. * @member {String|Any} value
  3342. * @memberOf server.module:response
  3343. * @o2syntax
  3344. * const value = this.response.value;
  3345. * @example
  3346. * //处理json对象的返回信息
  3347. * const value = this.response.value;
  3348. * const resData = JSON.parse(value);
  3349. */
  3350. get value(){
  3351. return globalThis.java_jaxrsResponse.get();
  3352. },
  3353. /**
  3354. * @summary 获取请求返回的值,如果是jaxrs服务,会尽可能将响应数据转换为json对象,如果不能解析为json对象的,则返回文本,如果是jaxws服务,响应类型取决于服务的返回。
  3355. * @method get
  3356. * @methodOf server.module:response
  3357. * @static
  3358. * @return {Object|String|Any} 响应的内容.
  3359. * @o2syntax
  3360. * const res = this.response.get();
  3361. */
  3362. get(){
  3363. const value = globalThis.java_jaxrsResponse.get();
  3364. if (JSON.validate(value)){
  3365. return JSON.decode(value);
  3366. }
  3367. return value;
  3368. }
  3369. }
  3370. }
  3371. if (globalThis.java_jaxwsResponse) { //注入 java_jaxwsResponse 对象,表示脚本运行于 服务调用活动,响应脚本 中,并且调用类型为 jaxws
  3372. return {
  3373. value: globalThis.java_jaxwsResponse,
  3374. get(){
  3375. return globalThis.java_jaxwsResponse || null;
  3376. }
  3377. }
  3378. }
  3379. return null;
  3380. }
  3381. }
  3382. /***************************************************************/
  3383. /* workContext -流程脚本中的 workcontext 对象,用于获取流程实例的相关数据 *****/
  3384. /**************************************************************/
  3385. /**
  3386. * 您可以在流程事件、流程路由事件、流程活动事件中通过workContext获取和流程相关的流程实例对象数据。
  3387. * @module server.workContext
  3388. * @o2cn 流程实例
  3389. * @o2category server.process
  3390. * @o2range {Process} 所有流程配置中的脚本可以使用此对象
  3391. * @o2ordernumber 200
  3392. * @o2syntax
  3393. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前流程实例数据,如下:
  3394. * var context = this.workContext;
  3395. */
  3396. const workContext = {
  3397. /**
  3398. * 当前流程实例正在流转中,并且当前用户有待办,则返回当前用户的待办对象。
  3399. * 事实上在后端的活动事件中,大部分的情况下,此方法获取到的是taskCompleted对象,因为在人工活动的事件中,除了“待办处理前”事件,其他事件处理时,当前用户的待办都已经转为已办了。
  3400. * @summary 获取当前流程与当前用户相关的待办或已办对象:task对象或taskCompleted对象。
  3401. * @methodOf module:server.workContext
  3402. * @o2ActionOut x_processplatform_assemble_surface.TaskAction.get|example=Task|Task对象:
  3403. * @method getTask
  3404. * @static
  3405. * @return {(Task|TaskCompleted|Null)} 当前用户的待办任务对象:task。当前用户没有对此流程实例的待办时,或流程实例已经流转结束,返回null。
  3406. * @o2syntax
  3407. * const task = this.workContext.getTask();
  3408. */
  3409. getTask: function(){ //根据work获取当前处理的的task或者TaskCompleted json字符串 只能在流转的过程中获取到
  3410. var taskString = globalThis.java_workContext.getTaskOrTaskCompleted();
  3411. var task = (taskString) ? JSON.parse(taskString) : null;
  3412. if (task){
  3413. task.personDn = task.person || "";
  3414. task.unitDn = task.unit || "";
  3415. task.unitDnList = task.unitList || "";
  3416. task.identityDn = task.identity || "";
  3417. task.creatorPersonDn = task.creatorPerson ||"";
  3418. task.creatorUnitDn = task.creatorUnit ||"";
  3419. task.creatorUnitDnList = task.creatorUnitList ||"";
  3420. task.creatorIdentityDn = task.creatorIdentity ||"";
  3421. }
  3422. return task;
  3423. },
  3424. /**
  3425. * 获取当前流程实例对象:work对象或workCompleted对象。
  3426. * @method getWork
  3427. * @methodOf module:server.workContext
  3428. * @static
  3429. * @return {(Work|WorkCompleted)} 流程实例对象;如果流程已结束,返回已结束的流程实例对象。
  3430. * @o2ActionOut x_processplatform_assemble_surface.WorkAction.manageGet|example=Work|ignoreNoDescr=true|ignoreProps=[properties,manualTaskIdentityMatrix]|Work对象:
  3431. * @o2ActionOut x_processplatform_assemble_surface.WorkCompletedAction.get|example=WorkCompleted|ignoreProps=[properties,data,taskCompletedList,readCompletedList,reviewList,recordList,workLogList,storeForm,mobileStoreForm]|WorkCompleted对象:
  3432. * @o2syntax
  3433. * const work = this.workContext.getWork();
  3434. */
  3435. "getWork": function(){ //work的字符串
  3436. var work = JSON.parse(globalThis.java_workContext.getWork());
  3437. work.creatorPersonDn = work.creatorPerson ||"";
  3438. work.creatorUnitDn = work.creatorUnit ||"";
  3439. work.creatorUnitDnList = work.creatorUnitList ||"";
  3440. work.creatorIdentityDn = work.creatorIdentity ||"";
  3441. return work;
  3442. },
  3443. /**
  3444. * 获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  3445. * @method getTaskList
  3446. * @methodOf module:server.workContext
  3447. * @o2ActionOut x_processplatform_assemble_surface.TaskAction.listWithWork|example=Task
  3448. * @static
  3449. * @return {(Task[])} 待办任务列表.
  3450. * @o2syntax
  3451. * const taskList = this.workContext.getTaskList();
  3452. */
  3453. "getTaskList": function(){return JSON.parse(globalThis.java_workContext.getTaskList());}, //根据work获取所有的task数组 json字符串
  3454. /**
  3455. * 获取当前流程实例的所有已办对象。如果流程实例没有任何人处理过,则返回一个空数组。
  3456. * @method getTaskCompletedList
  3457. * @methodOf module:server.workContext
  3458. * @static
  3459. * @return {(TaskCompleted[])} 已办任务列表.
  3460. * @o2ActionOut x_processplatform_assemble_surface.TaskCompletedAction.listWithWork|example=Task
  3461. * @o2syntax
  3462. * const taskCompletedList = this.workContext.getTaskCompletedList();
  3463. */
  3464. "getTaskCompletedList": function(){return JSON.parse(globalThis.java_workContext.getTaskCompletedList());}, //根据work获取所有的TaskCompleted数组 json字符串
  3465. /**
  3466. * @summary 获取当前流程实例的所有待阅对象数组。如果流程实例无待阅,则返回一个空数组。
  3467. * @method getReadList
  3468. * @methodOf module:server.workContext
  3469. * @static
  3470. * @return {(Read[])} 当前流程实例的所有待阅对象数组.
  3471. * @o2ActionOut x_processplatform_assemble_surface.ReadAction.get|example=Read
  3472. * @o2syntax
  3473. * const readList = this.workContext.getReadList();
  3474. */
  3475. "getReadList": function(){return JSON.parse(globalThis.java_workContext.getReadList());}, //根据work获取所有的read数组 json字符串
  3476. /**
  3477. * @summary 获取当前流程实例的所有已阅对象。如果流程实例没有已阅,则返回一个空数组。
  3478. * @method getReadCompletedList
  3479. * @methodOf module:server.workContext
  3480. * @static
  3481. * @return {(ReadCompleted[])} 当前流程实例的所有已阅对象数组.
  3482. * @o2ActionOut x_processplatform_assemble_surface.ReadCompletedAction.listWithWork|example=Read
  3483. * @o2syntax
  3484. * const readCompletedList = this.workContext.getReadCompletedList();
  3485. */
  3486. "getReadCompletedList": function(){return JSON.parse(globalThis.java_workContext.getReadCompletedList());}, //根据work获取所有的ReadCompleted数组 json字符串
  3487. /**
  3488. * @summary 获取当前流程实例的所有review对象。如果流程实例没有review,则返回一个空数组。
  3489. * @method getReviewList
  3490. * @alias getReviewListByJob
  3491. * @methodOf module:server.workContext
  3492. * @static
  3493. * @return {(Review[])} 当前流程实例的所有review对象数组.
  3494. * @o2ActionOut x_processplatform_assemble_surface.ReviewAction.listWithJob|example=Review
  3495. * @o2syntax
  3496. * const reviewList = this.workContext.getReviewList();
  3497. */
  3498. "getReviewList": function(){return JSON.parse(globalThis.java_workContext.getJobReviewList());},
  3499. /**
  3500. * @summary getTaskListByJob方法的别名。
  3501. * @method getJobTaskList
  3502. * @static
  3503. * @see server.module:workContext.getTaskListByJob
  3504. */
  3505. "getJobTaskList": function(){return JSON.parse(globalThis.java_workContext.getJobTaskList());}, //根据jobid获取所有的task数组 json字符串
  3506. /**
  3507. * @summary getTaskCompletedListByJob方法的别名。
  3508. * @method getJobTaskCompletedList
  3509. * @static
  3510. * @see server.module:workContext.getTaskCompletedListByJob
  3511. */
  3512. "getJobTaskCompletedList": function(){return JSON.parse(globalThis.java_workContext.getJobTaskCompletedList());}, //根据jobid获取所有的TaskCompleted数组 json字符串
  3513. /**
  3514. * @summary getReadListByJob方法的别名。
  3515. * @method getJobReadList
  3516. * @static
  3517. * @see server.module:workContext.getReadListByJob
  3518. */
  3519. "getJobReadList": function(){return JSON.parse(globalThis.java_workContext.getJobReadList());}, //根据jobid获取所有的read数组 json字符串
  3520. /**
  3521. * @summary getReadCompletedListByJob方法的别名。
  3522. * @method getJobReadCompletedList
  3523. * @static
  3524. * @see server.module:workContext.getReadCompletedListByJob
  3525. */
  3526. "getJobReadCompletedList": function(){return JSON.parse(globalThis.java_workContext.getJobReadCompletedList());}, //根据jobid获取所有的ReadCompleted数组 json字符串
  3527. /**
  3528. * @summary getReviewList方法的别名。
  3529. * @method getJobReviewList
  3530. * @static
  3531. * @see server.module:workContext.getReviewList
  3532. */
  3533. "getJobReviewList": function (){return this.getReviewList();}, //根据jobid获取所有的Review数组 json字符串
  3534. /**
  3535. * 根据当前工作的job获取当前流程实例的所有待办对象。如果流程实例已流转完成,则返回一个空数组。
  3536. * @method getTaskListByJob
  3537. * @methodOf module:server.workContext
  3538. * @o2ActionOut x_processplatform_assemble_surface.TaskAction.listWithJob|example=Task
  3539. * @static
  3540. * @return {(Task[])} 待办任务列表.
  3541. * @o2syntax
  3542. * const taskList = this.workContext.getTaskListByJob();
  3543. */
  3544. "getTaskListByJob": function(){return this.getJobTaskList();},
  3545. /**
  3546. * 根据当前工作的job获取当前流程实例的所有已办对象。如果流程实例没有任何人处理过,则返回一个空数组。
  3547. * @method getTaskCompletedListByJob
  3548. * @methodOf module:server.workContext
  3549. * @static
  3550. * @return {(TaskCompleted[])} 已办任务列表.
  3551. * @o2ActionOut x_processplatform_assemble_surface.TaskCompletedAction.listWithJob|example=Task
  3552. * @o2syntax
  3553. * const taskCompletedList = this.workContext.getTaskCompletedListByJob();
  3554. */
  3555. "getTaskCompletedListByJob": function(){return this.getJobTaskCompletedList();},
  3556. /**
  3557. * @summary 根据当前工作的job获取当前流程实例的所有待阅对象。如果流程实例无待阅,则返回一个空数组。
  3558. * @method getReadListByJob
  3559. * @methodOf module:server.workContext
  3560. * @static
  3561. * @return {(Read[])} 当前流程实例的所有待阅对象数组.
  3562. * @o2ActionOut x_processplatform_assemble_surface.ReadAction.listWithJob|example=Read
  3563. * @o2syntax
  3564. * const readList = this.workContext.getReadListByJob();
  3565. */
  3566. "getReadListByJob": function(){return this.getJobReadList();},
  3567. /**
  3568. * @summary 根据当前工作的job获取当前流程实例的所有已阅对象。如果流程实例没有已阅,则返回一个空数组。
  3569. * @method getReadCompletedListByJob
  3570. * @methodOf module:server.workContext
  3571. * @static
  3572. * @return {(ReadCompleted[])} 当前流程实例的所有已阅对象数组.
  3573. * @o2ActionOut x_processplatform_assemble_surface.ReadCompletedAction.listWithJob|example=Read
  3574. * @o2syntax
  3575. * const readCompletedList = this.workContext.getReadCompletedListByJob();
  3576. */
  3577. "getReadCompletedListByJob": function(){return this.getJobReadCompletedList();},
  3578. /**
  3579. * @summary getReviewList方法的别名。
  3580. * @method getReviewListByJob
  3581. * @static
  3582. * @see server.module:workContext.getReviewList
  3583. */
  3584. "getReviewListByJob": function(){return this.getJobReviewList();},
  3585. /**
  3586. * 获取当前流程实例所在的活动节点对象:activity对象。
  3587. * @method getActivity
  3588. * @static
  3589. * @return {(Activity|Null)} 当前流程实例所在的活动节点对象,如果当前流程实例已流转完成,则返回null.
  3590. * <pre><code class='language-js'>{
  3591. * "id": "801087c5-a4e6-4b91-bf4d-a81cdaa04471", //节点ID
  3592. * "name": "办理", //节点名称
  3593. * "description": "", //节点描述
  3594. * "alias": "", //节点别名
  3595. * "resetRange": "department", //重置处理人范围
  3596. * "resetCount": 0, //重置处理人数字
  3597. * "allowReset": true, //是否允许重置
  3598. * "manualMode": "single", //处理方式 单人single, 并行parallel, 串行queue, grab抢办
  3599. * "customData": { //节点上的自定义属性,如果没有设置,不输出该值
  3600. *
  3601. * }
  3602. * }</code></pre>
  3603. * @o2syntax
  3604. * const activity = this.workContext.getActivity();
  3605. */
  3606. "getActivity": function(){return JSON.parse(globalThis.java_workContext.getActivity());}, //活动对象字符串
  3607. /**
  3608. * @summary 获取当前流程实例的所有流程记录(WorkLog)。
  3609. * @method getWorkLogList
  3610. * @static
  3611. * @return {WorkLog[]} 流程记录对象.
  3612. * @o2ActionOut x_processplatform_assemble_surface.WorkLogAction.listWithJob|example=WorkLog|ignoreProps=[properties,goBackFromActivityType]
  3613. * @o2syntax
  3614. * const workLogList = this.workContext.getWorkLogList();
  3615. */
  3616. "getWorkLogList": function(){return JSON.parse(globalThis.java_workContext.getWorkLogList());}, //WorkLogList对象数组的字符串
  3617. /**
  3618. * @summary 获取当前流程实例的所有流程记录(Record)。
  3619. * @method getRecordList
  3620. * @o2ActionOut x_processplatform_assemble_surface.RecordAction.listWithJob|example=Record
  3621. * @static
  3622. * @return {Record[]} 流程记录(Record)对象.
  3623. * @o2syntax
  3624. * const recordList = this.workContext.getRecordList();
  3625. */
  3626. "getRecordList": function(){return JSON.parse(globalThis.java_workContext.getRecordList());}, //RecordList对象数组的字符串,需要新增
  3627. /**
  3628. * @summary 最后一条Record对象,在活动流转完成事件中,获取本次流转的record;在其它事件中获取的是整个job的最后一条record,并不是本次流转的record。
  3629. * @method getRecord
  3630. * @o2ActionOut x_processplatform_assemble_surface.RecordAction.listWithJob|example=Record
  3631. * @static
  3632. * @return {Record[]} 流程记录(Record)对象.
  3633. * @o2syntax
  3634. * const record = this.workContext.getRecord();
  3635. */
  3636. "getRecord": function(){return JSON.parse(globalThis.java_workContext.getRecord());}, //最后一条Record对象,(在活动流转完成事件中,获取本次流转的record;在其它事件中获取的是整个job的最后一条record,并不是本次流转的record)
  3637. /**
  3638. * @summary 获取当前流程实例的附件对象列表。
  3639. * @method getAttachmentList
  3640. * @static
  3641. * @return {WorkAttachmentData[]} 附件数据.
  3642. * @o2ActionOut x_processplatform_assemble_surface.AttachmentAction.getWithWorkOrWorkCompleted|example=Attachment|ignoreProps=[properties]
  3643. * @o2syntax
  3644. * //获取附件列表
  3645. * const attachmentList = this.workContext.getAttachmentList();
  3646. */
  3647. "getAttachmentList": function(){return JSON.parse(globalThis.java_workContext.getAttachmentList());}, //附件对象数组的字符串
  3648. /**
  3649. * @summary 获取可选路由对象数组的字符串(流转事件中,获取到流转中的可选路由列表,根据当前work状态获取)。
  3650. * @method getRouteList
  3651. * @static
  3652. * @return {Route[]} 路由字符串数组.
  3653. * @o2syntax
  3654. * const routeList = this.workContext.getRouteList();
  3655. */
  3656. "getRouteList": function(){return JSON.parse(globalThis.java_workContext.getRouteList());}, //可选路由对象数组的字符串(流转事件中,获取到流转中的可选路由列表,根据当前work状态获取)
  3657. /**
  3658. * @summary 重新设置流程实例标题
  3659. * @method setTitle
  3660. * @static
  3661. * @param {String} title - 标题字符串.
  3662. * @o2syntax
  3663. * this.workContext.setTitle(title);
  3664. * @example
  3665. * this.workContext.setTitle("标题");
  3666. */
  3667. "setTitle": function(title){globalThis.java_workContext.setTitle(title);}, //设置title
  3668. "getControl": function(){return null;},
  3669. "getInquiredRouteList": function(){return null;}
  3670. };
  3671. const workContent = workContext;
  3672. /***************************************************************/
  3673. /* assignData - 流程调用脚本,数据脚本
  3674. {
  3675. data:{},
  3676. application:"",
  3677. process:"",
  3678. identity: "",
  3679. attachmentList: [],
  3680. title: "",
  3681. processing: true
  3682. }
  3683. 可通过return 返回assignData, **********************************/
  3684. /**************************************************************/
  3685. /**
  3686. * 用于流程配置的流程调用活动中的“数据脚本”和“标题脚本”,可以通过assignData对象获取要调用的流程的相关信息,以及要传递给被调用流程实例的业务数据。<br>
  3687. * 也可以修改业务数据,并通过assignData的set方法,将业务数据传递到被调用的流程实例。<br/>
  3688. * @o2range 流程配置-流程调用活动中的“数据脚本”中可用
  3689. * @module server.assignData
  3690. * @o2cn 流程实例业务数据
  3691. * @o2category server.process
  3692. * @o2ordernumber 210
  3693. * @example
  3694. * //在流程调用活动中的“数据脚本”,通过下面的代码修改业务数据,并传递给被调用流程的实例:
  3695. * const data = this.assignData.get();
  3696. * data.data.parentProcessData = "父流程实例的信息";
  3697. * this.assignData.set(data);
  3698. * @example
  3699. * <caption>
  3700. * assignData.set方法是为了兼容以前的版本。<br>
  3701. * <b>建议通过return一个json对象的方式来设置data内容</b>
  3702. * </caption>
  3703. * //也可以通过return一个json对象的方式来代替assignData.set方法
  3704. * const data = this.assignData.get();
  3705. * data.data.parentProcessData = "父流程实例的信息";
  3706. * return data;
  3707. */
  3708. const assignData = { //java_assignData 应用调用活动的创建的流程实例的业务数据处理对象,get set 方法
  3709. _data: null,
  3710. /**
  3711. * @summary 获取要调用的流程的相关信息,以及要传递给被调用流程实例的业务数据。
  3712. * @method get
  3713. * @methodOf module:server.assignData
  3714. * @static
  3715. * @return {Object} 描述被调用的流程的信息,及要传递的业务数据.
  3716. * <pre><code class='language-js'>{
  3717. * "application": "application id", //被调用的应用id
  3718. * "process": "process id", //被调用的流程id
  3719. * "identity": "xxx@xxx@I", //被调用流程的启动这身份
  3720. * "title": "title", //被调用流程实例的标题
  3721. * "attachmentList": [], //要传递到被调用的流程实例的附件对象
  3722. * "data": {}, //要传递到被调用的流程实例的业务数据
  3723. * "attachmentSoftCopy" //如果为true,不拷贝附件文件。默认false @todo
  3724. * }</code></pre>
  3725. * @o2syntax
  3726. * const data = this.assignData.get();
  3727. */
  3728. "get": function(){
  3729. this.data = JSON.parse(globalThis.java_assignData.get());
  3730. return this.data;
  3731. },
  3732. /**
  3733. * @summary 设置修改后的assignData对象。(set方法为了兼容早期的版本。建议使用 return data; 方式直接返回json对象)
  3734. * @method set
  3735. * @methodOf module:server.assignData
  3736. * @static
  3737. * @param {Object} [data] 要设置的assignData对象,一般情况都是通过assignData.get()获取并做必要修改的对象。
  3738. * @o2syntax
  3739. * this.assignData.set(data);
  3740. * @deprecated set方法已不建议使用了。建议return一个json对象或数组的方式来设置data。
  3741. * @example
  3742. * const data = this.assignData.get();
  3743. * data.data.parentProcessData = "父流程实例的信息";
  3744. * return data;
  3745. */
  3746. "set": function(data){
  3747. globalThis.java_assignData.set(JSON.stringify(data || this.data));
  3748. }
  3749. };
  3750. Object.defineProperties(assignData, {"data": {
  3751. "get": function(){
  3752. if (this._data) return this._data;
  3753. return JSON.parse(globalThis.java_assignData.get());
  3754. },
  3755. "set": function(v){this._data = v;}
  3756. }}
  3757. );
  3758. /***************************************************************/
  3759. /* parameters - 服务调用活动,参数脚本,要传入的参数 ******************/
  3760. /* 数据中心查询语句的脚本中,获取语句参数。***************/
  3761. /* - 调用活动中,如果是webservice调用,则注入 java_jaxwsParameters 对象,parameters 返回一个对象,包含 add 和 remove方法;***************/
  3762. /* - 调用活动中,如果是restfyl调用,则注入 java_jaxrsParameters 对象,parameters 返回一个对象,包含 put 和 remove方法;******************/
  3763. /* - 数据中心查询语句的脚本中,则注入 java_parameters json文本,parameters 返回一个json对象,用于获取调用查询语句的参数******************/
  3764. /***************************************************************/
  3765. /**
  3766. * 用于流程配置的服务调用活动中的“参数脚本”,为jaxrs和jaxws两种服务调用方式传递参数。<br>
  3767. * 当调用类型为jaxrs时:可使用parameters.put和parameters.remove方法<br/>
  3768. * 当调用类型为jaxws时:可使用parameters.add和parameters.remove方法<br/>
  3769. * @o2range 流程配置-服务调用活动中的“参数脚本”中可用
  3770. * @module server.parameters
  3771. * @o2cn 服务调用参数
  3772. * @o2category server.process
  3773. * @o2ordernumber 215
  3774. * @deprecated parameters对象已经不建议使用了。建议return一个json对象或数组的方式来设置参数。
  3775. * @example
  3776. * //使用jaxrs方式的服务调用活动的参数脚本中
  3777. * //如果rest服务地址为:xxx/{id}/xx/{name},则需要传入两个参数:id和name,可使用如下代码:
  3778. * this.parameters.put("id", "id value");
  3779. * this.parameters.put("name", "name value");
  3780. *
  3781. * //或者
  3782. * this.parameters.put({
  3783. * "id": "id value",
  3784. * "name": "name value"
  3785. * });
  3786. *
  3787. * @example
  3788. * //使用jaxws方式的服务调用活动的参数脚本中
  3789. * //如果需要传入三个参数,可使用如下代码:
  3790. * this.parameters.add("参数1");
  3791. * this.parameters.add("参数2");
  3792. * this.parameters.add("参数3");
  3793. *
  3794. * //或者
  3795. * this.parameters.add(["参数1", "参数2", "参数3"]);
  3796. *
  3797. * @example
  3798. * <caption>
  3799. * 以上两个例子中使用了parameters对象来收集参数,这主要是为了兼容以前的版本。<br>
  3800. * <b>我们更建议通过return一个json对象或数组的方式来设置参数</b>
  3801. * </caption>
  3802. * //以上两个例子中使用了parameters对象来收集参数
  3803. * //更好的方式是:通过return一个json对象或数组的方式来设置参数
  3804. * //对于jaxrs方式:
  3805. * return {
  3806. * "id": "id value",
  3807. * "name": "name value"
  3808. * }
  3809. *
  3810. * //对于jaxws方式:
  3811. * return ["参数1", "参数2", "参数3"];
  3812. */
  3813. /**
  3814. * 用于数据中心查询语句的脚本中,可获取语句参数。json对象,在调用此语句的时候传入<br>
  3815. * @o2range 数据中心-查询配置-通过脚本创建查询语句
  3816. * @o2cn 数据中心查询语句参数
  3817. * @module server.service.parameters
  3818. * @o2category server.service
  3819. * @o2ordernumber 255
  3820. * @o2syntax
  3821. * var pars = this.parameters;
  3822. * @example
  3823. * <caption>
  3824. * 通过this.statement.execute调用一个名为“task”的查询配置,并传入parameters,代码如下:
  3825. * <pre><code class='language-js'>//用一个名为“task”的查询配置,并传入parameters
  3826. * this.statement.execute({
  3827. * "name": "task",
  3828. * "mode" : "all",
  3829. * "parameter" : {
  3830. * "person" : "xxx@xxx@p", //传入人员参数
  3831. * "startTime" : (new Date("2020-01-01")) //传入时间参数
  3832. * }
  3833. * }, function(json){
  3834. * var count = json.count; //总数语句执行后返回的数字
  3835. * var list = json.data; //查询语句后返回的数组
  3836. * //......
  3837. * });
  3838. * </code></pre>
  3839. *
  3840. * 在task查询配置的脚本中,parameters对象就可获取到执行查询时传入的parameters对象,以便于动态创建查询语句
  3841. * </caption>
  3842. * //动态生成查询指定用户,在指定时间之后的所有待办数据
  3843. * var user = this.parameters.person;
  3844. * var startTime = (new Date(this.parameters.startTime)).format("db"); //格式化为yyyy-mm-dd hh:mm:ss
  3845. * return "SELECT o FROM Task o WHERE o.person='"+user+"' AND o.startTime>{ts '"+startTime+"'}"
  3846. */
  3847. const parametersDescriptor = {
  3848. get: function(){
  3849. if (globalThis.java_jaxwsParameters){ //注入 java_jaxwsParameters 对象,表示脚本运行于 服务调用活动,参数脚本 中,并且调用类型为 jaxws
  3850. return {
  3851. /**
  3852. * @summary jaxws方式的服务调用活动,“参数脚本”中,使用parameters.add设置参数。
  3853. * @method add
  3854. * @methodOf module:server.parameters
  3855. * @static
  3856. * @param {Any|Array} [value] 要设置的参数值。
  3857. * @o2syntax
  3858. * this.parameters.add(value);
  3859. * @deprecated 不建议使用,建议return一个数组的方式来设置参数。如:
  3860. * <pre><code class='language-js'>return ["参数1", "参数2", "参数3"];</code></pre>
  3861. */
  3862. add(value){
  3863. if (Array.isArray(value)){
  3864. value.forEach(function(v){
  3865. globalThis.java_jaxwsParameters.add(v);
  3866. });
  3867. }else{
  3868. globalThis.java_jaxwsParameters.add(value);
  3869. }
  3870. },
  3871. /**
  3872. * @summary 服务调用活动,“参数脚本”中,删除已设置参数。
  3873. * @method remove
  3874. * @methodOf module:server.parameters
  3875. * @static
  3876. * @param {String|Number} [name] jaxrs方式的服务调用活动,传入要删除参数的key;jaxws方式的服务调用活动,传入要删除的参数的索引。
  3877. * @o2syntax
  3878. * this.parameters.remove(name);
  3879. * @deprecated 不建议使用
  3880. */
  3881. remove(name){
  3882. globalThis.java_jaxwsParameters.remove(name);
  3883. }
  3884. }
  3885. }
  3886. if (globalThis.java_jaxrsParameters){ //注入 java_jaxrsParameters 对象,表示脚本运行于 服务调用活动,参数脚本 中,并且调用类型为 jaxrs
  3887. return {
  3888. /**
  3889. * @summary jaxrs方式的服务调用活动,“参数脚本”中,使用parameters.put设置参数。
  3890. * @method put
  3891. * @methodOf module:server.parameters
  3892. * @static
  3893. * @param {String|Object} [name] 要设置的参数key,或参数json对象。
  3894. * @param {String|Number|boolean} [value] 要设置的参数值。
  3895. * @o2syntax
  3896. * this.parameters.put(name, value);
  3897. * this.parameters.put(obj);
  3898. * @deprecated 不建议使用,建议return一个json对象的方式来设置参数。如:
  3899. * <pre><code class='language-js'>return {
  3900. * "id": "id value",
  3901. * "name": "name value"
  3902. * };</code></pre>
  3903. */
  3904. put(name, value){
  3905. if ((typeof name)==="object"){
  3906. var _keys = Object.keys(name);
  3907. for (var i=0; i<_keys.length; i++){
  3908. globalThis.java_jaxrsParameters.put(_keys[i], name[_keys[i]]);
  3909. }
  3910. }else{
  3911. globalThis.java_jaxrsParameters.put(name, value);
  3912. }
  3913. },
  3914. remove(name){
  3915. globalThis.java_jaxrsParameters.remove(name);
  3916. }
  3917. }
  3918. }
  3919. if (globalThis.java_parameters){ //注入 java_parameters 对象,表示脚本运行于 数据中心查询语句的脚本 中
  3920. return JSON.parse(globalThis.java_parameters)
  3921. }
  3922. return null;
  3923. }
  3924. }
  3925. /***************************************************************/
  3926. /* body - 服务调用活动,消息体脚本,设置调用消息体 ******************/
  3927. /***************************************************************/
  3928. /**
  3929. * 用于流程配置的服务调用活动中的“消息体脚本”,仅在jaxrs方式的服务调用活动中可用。<br>
  3930. * @o2range 流程配置-服务调用活动中的“消息体脚本”,服务协议为jaxrs
  3931. * @module server.body
  3932. * @o2cn 服务调用消息体
  3933. * @o2category server.process
  3934. * @o2ordernumber 220
  3935. * @deprecated body对象已经不建议使用了。建议return一个json对象的方式来设置body。如:
  3936. * <pre><code class='language-js'>return {
  3937. * "key1": "value1",
  3938. * "key2": "value2",
  3939. * "key3": "value3"
  3940. * };</code></pre>
  3941. * @example
  3942. * //设置jaxrs服务调用的消息体
  3943. * this.body.set({
  3944. * "key1": "value1",
  3945. * "key2": "value2",
  3946. * "key3": "value3"
  3947. * })
  3948. *
  3949. * //或者设置
  3950. * this.body.set("this is body data");
  3951. *
  3952. * @example
  3953. * <caption>
  3954. * body.set方法是为了兼容以前的版本。<br>
  3955. * <b>建议通过return一个json对象的方式来设置消息体内容</b>
  3956. * </caption>
  3957. * return {
  3958. * "key1": "value1",
  3959. * "key2": "value2",
  3960. * "key3": "value3"
  3961. * };
  3962. *
  3963. * //或
  3964. * return "this is body data";
  3965. */
  3966. const body = {
  3967. /**
  3968. * @summary 服务调用活动中的“消息体脚本”,用于设置消息体内容。
  3969. * @method set
  3970. * @methodOf module:server.body
  3971. * @static
  3972. * @param {String|Object} [data] 消息体内容。
  3973. * @o2syntax
  3974. * this.body.set(data);
  3975. * @deprecated 不建议使用,建议return一个json对象或数组的方式来设置body。
  3976. */
  3977. set(data){
  3978. if ((typeof data)==="string"){
  3979. globalThis.java_jaxrsBody.set(data);
  3980. }
  3981. if ((typeof data)==="object"){
  3982. globalThis.java_jaxrsBody.set(JSON.stringify(data));
  3983. }
  3984. }
  3985. };
  3986. /***************************************************************/
  3987. /* headers - 服务调用活动,消息头脚本,设置调用消息头 ******************/
  3988. /***************************************************************/
  3989. /**
  3990. * 用于流程配置的服务调用活动中的“消息头脚本”,仅在jaxrs方式的服务调用活动中可用。<br>
  3991. * @o2range 流程配置-服务调用活动中的“消息头脚本”,服务协议为jaxrs
  3992. * @module server.headers
  3993. * @o2cn 服务调用消息头
  3994. * @o2category server.process
  3995. * @o2ordernumber 225
  3996. * @deprecated headers对象已经不建议使用了,建议return一个json对象的方式来设置headers。如:
  3997. * <pre><code class='language-js'>return {
  3998. * "Content-Type": "application/x-www-form-urlencoded",
  3999. * "Accept-Language": "en"
  4000. * };</code></pre>
  4001. * @example
  4002. * //设置jaxrs服务调用的消息头
  4003. * this.headers.put("Content-Type", "application/x-www-form-urlencoded");
  4004. *
  4005. * //或者
  4006. * this.headers.put({
  4007. * "Content-Type": "application/x-www-form-urlencoded",
  4008. * "Accept-Language": "en"
  4009. * });
  4010. *
  4011. * @example
  4012. * <caption>
  4013. * headers.put方法是为了兼容以前的版本。<br>
  4014. * <b>建议通过return一个json对象的方式来设置消息头内容</b>
  4015. * </caption>
  4016. * return {
  4017. * "Content-Type": "application/x-www-form-urlencoded",
  4018. * "Accept-Language": "en"
  4019. * };
  4020. */
  4021. const headers = {
  4022. /**
  4023. * @summary jaxrs方式的服务调用活动,“消息头脚本”中,headers.put设置消息头。
  4024. * @method add
  4025. * @methodOf module:server.headers
  4026. * @static
  4027. * @param {String|Object} [name] 要设置的消息头名称,或消息头json对象。
  4028. * @param {String} [value] 要设置的消息头值。
  4029. * @o2syntax
  4030. * this.headers.put(name, value);
  4031. * this.headers.put(obj);
  4032. * @deprecated 不建议使用,建议return一个json对象的方式来设置headers。如:
  4033. * <pre><code class='language-js'>return {
  4034. * "Content-Type": "application/x-www-form-urlencoded",
  4035. * "Accept-Language": "en"
  4036. * };</code></pre>
  4037. */
  4038. put(name, value){
  4039. try{
  4040. if ((typeof name)==="object"){
  4041. var _keys = Object.keys(name);
  4042. for (var i=0; i<_keys.length; i++){
  4043. if (globalThis.java_jaxrsHeaders) globalThis.java_jaxrsHeaders.put(_keys[i], name[_keys[i]]);
  4044. }
  4045. }else{
  4046. if (globalThis.java_jaxrsHeaders) globalThis.java_jaxrsHeaders.put(name, value);
  4047. }
  4048. }catch(e){}
  4049. },
  4050. /**
  4051. * @summary jaxrs方式的服务调用活动,“消息头脚本”中,删除已经设置消息头。
  4052. * @method remove
  4053. * @methodOf module:server.headers
  4054. * @static
  4055. * @param {String} [name] 要删除的消息头名称。
  4056. * @o2syntax
  4057. * this.headers.remove(name);
  4058. * @deprecated 不建议使用
  4059. */
  4060. remove(name){
  4061. try{
  4062. if (globalThis.java_jaxrsHeaders) globalThis.java_jaxrsHeaders.remove(name);
  4063. }catch(e){}
  4064. }
  4065. };
  4066. /***************************************************************/
  4067. /* requestText - 服务活动,服务响应脚本,获取请求的文本内容 ******/
  4068. /* 服务管理 invoke 请求消息体的文本内容 * ******/
  4069. /***************************************************************/
  4070. /**
  4071. * 调用接口时传入的请求消息体的文本内容。
  4072. * @o2range 服务管理-接口
  4073. * @module server.requestText
  4074. * @o2cn 传入的服务消息体文本
  4075. * @o2category server.service
  4076. * @o2ordernumber 250
  4077. * @o2syntax
  4078. * const text = this.requestText;
  4079. * @example
  4080. * const text = this.requestText; //传入的服务消息体文本
  4081. * const object = JSON.parse(text); //转成对象
  4082. */
  4083. /**
  4084. * 用于流程配置的服务活动中的“服务响应脚本”,获取请求的文本内容。<br>
  4085. * @o2range 流程配置-服务活动中的“响应脚本”
  4086. * @module server.requestText
  4087. * @o2cn 服务调用请求对象
  4088. * @o2category server.process
  4089. * @o2ordernumber 235
  4090. * @o2syntax
  4091. * const text = this.requestText;
  4092. * const object = JSON.parse(text); //转成对象
  4093. */
  4094. const requestTextDescriptor = {
  4095. get: function(){
  4096. return globalThis.java_requestText || '';
  4097. }
  4098. }
  4099. /***************************************************************/
  4100. /* request - 服务活动,服务响应脚本,获取请求内容 ****************/
  4101. /* 服务管理 invoke 请求的java对象 java_request *********/
  4102. /***************************************************************/
  4103. const requestDescriptor = {
  4104. get: function(){
  4105. if (globalThis.java_request){ //注入java_request对象,表示脚本运行在 服务管理 invoke 中。直接返回 java_request 对象。
  4106. /**
  4107. * 调用接口时传入的请求对象。java的 request(java.net.http.HttpRequest)对象。
  4108. * @o2range 服务管理-接口
  4109. * @module server.request
  4110. * @o2cn 传入的服务消息体文本
  4111. * @o2category server.service
  4112. * @o2ordernumber 250
  4113. * @o2syntax
  4114. * const req = this.request;
  4115. */
  4116. globalThis.java_request.getBody = function(){
  4117. try{
  4118. return JSON.parse(globalThis.java_requestText);
  4119. }catch(e){
  4120. return globalThis.java_requestText;
  4121. }
  4122. }
  4123. return globalThis.java_request;
  4124. }
  4125. if (globalThis.java_requestText) { //注入java_requestText对象,表示脚本运行在 服务活动,服务响应脚本 中。
  4126. /**
  4127. * 用于流程配置的服务活动中的“服务响应脚本”,描述发起服务的请求对象。<br>
  4128. * @o2range 流程配置-服务活动中的“响应脚本”
  4129. * @module server.request
  4130. * @o2cn 服务调用请求对象
  4131. * @o2category server.process
  4132. * @o2ordernumber 235
  4133. * @o2syntax
  4134. * const res = this.request;
  4135. */
  4136. return {
  4137. /**
  4138. * @summary 获取请求的body内容。
  4139. * @method getBody
  4140. * @methodOf server.module:request
  4141. * @static
  4142. * @return {Object|String} 请求的body内容,如果能转换为json,则返回json对象,否则返回请求的内容的文本.
  4143. * @o2syntax
  4144. * const req = this.request.getBody();
  4145. */
  4146. getBody(){
  4147. try{
  4148. return JSON.parse(globalThis.java_requestText);
  4149. }catch(e){
  4150. return globalThis.java_requestText;
  4151. }
  4152. },
  4153. /**
  4154. * @summary 获取请求的body的原始内容。
  4155. * @member {String} text
  4156. * @memberOf server.module:request
  4157. * @o2syntax
  4158. * var req = this.request.text;
  4159. */
  4160. get text(){
  4161. return globalThis.java_requestText;
  4162. }
  4163. }
  4164. }
  4165. return null;
  4166. }
  4167. }
  4168. /***************************************************************/
  4169. /* expire - 活动时效计算对象,用于设置活动时效 ********************/
  4170. /***************************************************************/
  4171. //活动时效计算对象,流程时效得去掉
  4172. //java_expire,
  4173. //脚本返回JSON数据:
  4174. //{
  4175. // hour: 3 //几小时后超时
  4176. // workHour: 5 //几个工作小时后超时
  4177. // date: '2016-08-01' //到达指定时间后超时
  4178. //}
  4179. //设置指定的超时时间:
  4180. //this.expire.setDate([Date or String] date)
  4181. //设置几小时后超时:
  4182. //this.expire.setHour([Int] hour)
  4183. //设置几个工作小时后超时:
  4184. //this.expire.setWorkHour([Int] hour)
  4185. /**
  4186. * 用于流程配置的人工活动的“时效脚本”中,用于设置超时时间。可以通过设置小时数,工作小时数,和指定时间点来设置超时,如果全部设置,则优先级为:工作小时>小时>时间<br>
  4187. * @o2range 流程配置-人工活动中的“时效脚本”
  4188. * @module server.expire
  4189. * @o2cn 超时时间设置
  4190. * @o2category server.process
  4191. * @o2ordernumber 240
  4192. * @deprecated expire对象已经不建议使用了。建议return一个json对象的方式来设置超时时间。
  4193. * @example
  4194. * //设置超时时限为待办产生后5小时
  4195. * this.expire.setHour(5);
  4196. *
  4197. * //设置超时时限为待办产生后5个工作小时(只计算工作时间)
  4198. * this.expire.setWorkHour(5);
  4199. *
  4200. * //设置超时时限为指定时间,如业务数据中的设定的办理期限(processingTime)
  4201. * this.expire.setDate(this.data.processingTime);
  4202. *
  4203. * @example
  4204. * <caption>
  4205. * expire对象是为了兼容以前的版本。<br>
  4206. * <b>建议可以直接返回一个json对象来设置超时时间</b>
  4207. * </caption>
  4208. * //设置超时时限为待办产生后5小时
  4209. * return {"hour": 5};
  4210. *
  4211. * //设置超时时限为待办产生后5个工作小时(只计算工作时间)
  4212. * return {"workHour": 5};
  4213. *
  4214. * //设置超时时限为指定时间,如业务数据中的设定的办理期限(processingTime)
  4215. * return {"date": this.data.processingTime};
  4216. */
  4217. const expire = {
  4218. /**
  4219. * @summary 设置超时小时数。
  4220. * @method setHour
  4221. * @methodOf server.module:expire
  4222. * @static
  4223. * @param {Number} [hour] 超时的小时数。
  4224. * @deprecated 不建议使用,建议return一个json对象的方式来设置超时时间。如:
  4225. * <pre><code class='language-js'>return {"hour": 5}</code></pre>
  4226. */
  4227. "setHour": function(hour){
  4228. try{globalThis.java_expire.setHour(hour);}catch(e){}
  4229. },
  4230. /**
  4231. * @summary 设置超时工作小时数。
  4232. * @method setWorkHour
  4233. * @methodOf server.module:expire
  4234. * @static
  4235. * @param {Number} [hour] 超时的工作小时数。
  4236. * @deprecated 不建议使用,建议return一个json对象的方式来设置超时时间。如:
  4237. * <pre><code class='language-js'>return {"workHour": 5}</code></pre>
  4238. */
  4239. "setWorkHour": function(hour){
  4240. try{globalThis.java_expire.setWorkHour(hour);}catch(e){}
  4241. },
  4242. /**
  4243. * @summary 设置超时时间。
  4244. * @method setDate
  4245. * @methodOf server.module:expire
  4246. * @static
  4247. * YYYY-MM-DD HH:mm:SS
  4248. * @param {String} [date] 一个表示日期时间的字符串,按以下格式:
  4249. * <pre><code class="language-js">yyyy-MM-dd HH:mm:ss //如2021-09-12 18:26:51</code></pre>
  4250. * @deprecated 不建议使用,建议return一个json对象的方式来设置超时时间。如:
  4251. * <pre><code class='language-js'>return {"date": "2021-09-12 18:26:51"}</code></pre>
  4252. */
  4253. "setDate": function(date){
  4254. try{globalThis.java_expire.setDate(date);}catch(e){}
  4255. }
  4256. };
  4257. /******************************************/
  4258. /******************************************/
  4259. /* data 和 embedData 处理 **************/
  4260. /******************************************/
  4261. /******************************************/
  4262. /**
  4263. * 在流程调用活动中。当启用流程等待的情况下,在"子流程成功后"、"子流程取消后"、"子流程完成后",三个事件脚本中,可以访问到embedData对象<br/>
  4264. * embedData对象就是被调用的子流程的业务数据,它是一个类似JSON的对象,您可以用访问JSON对象的方法访问embedData对象的所有数据。<br/>
  4265. * 如果您需要获取embedData的json文本,请使用embedData.toString()方法。<b>注意:JSON.stringify()方法不能用于embedData对象</b><br>
  4266. * 您可以通过work对象的embedCompleted值来判断被调用的子流程是否正常完成。 cancel end terminate
  4267. * <pre><code class='language-js'>
  4268. * var embedStatus = this.workContext.getWork().embedCompleted;
  4269. * if (embedStatus=="end"){
  4270. * //被调用的子流程正常流转到了结束活动
  4271. * }
  4272. * if (embedStatus=="cancel"){
  4273. * //被调用的子流程流转到了取消活动
  4274. * }
  4275. * if (embedStatus=="terminate"){
  4276. * //被调用的子流程被终止了
  4277. * }
  4278. * </code></pre>
  4279. * @o2range 流程配置-流程调用活动中,当启用流程等待的情况下,在"子流程成功后"、"子流程取消后"、"子流程完成后",三个事件中可用
  4280. * @module server.embedData
  4281. * @o2cn 调用活动的子流程业务数据
  4282. * @o2category server.process
  4283. * @o2ordernumber 205
  4284. * @example
  4285. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前实例的业务数据,如下:
  4286. * var embedData = this.embedData;
  4287. */
  4288. /**
  4289. * 在流程事件、流程路由事件、流程活动事件中通过this.data获取流程实例的业务数据。(内容管理无后台脚本)。<br/>
  4290. * 这些数据一般情况下是通过您创建的表单收集而来的,也可以通过脚本进行创建和增删改查操作。<br/>
  4291. * data对象基本上是一个JSON对象,您可以用访问JSON对象的方法访问data对象的所有数据。
  4292. * @module server.data
  4293. * @o2cn 流程数据
  4294. * @o2category server.process
  4295. * @o2ordernumber 205
  4296. * @example
  4297. * //您可以在表单或流程的各个嵌入脚本中,通过this来获取当前实例的业务数据,如下:
  4298. * var data = this.data;
  4299. * @borrows module:data#[property] as [property]
  4300. */
  4301. const ArrayList = Java.type('java.util.ArrayList');
  4302. const createProxy = function(target, j_data){
  4303. target.$Jdata ?? Object.defineProperty(target, '$Jdata', {
  4304. value: j_data
  4305. });
  4306. return new Proxy(target, {
  4307. get(target, property){
  4308. if (property==='add'){
  4309. return function(key, value){
  4310. if (key==="length" && (target.$Jdata instanceof ArrayList)){
  4311. while (target.$Jdata.size()>value){
  4312. target.$Jdata.remove(target.$Jdata.size()-1);
  4313. }
  4314. }else{
  4315. target.$Jdata[key] = value;
  4316. }
  4317. return Reflect.set(target, key, value);
  4318. }
  4319. }
  4320. if (property==='del'){
  4321. return function (key) {
  4322. delete target.$Jdata[key];
  4323. delete target[key];
  4324. }
  4325. }
  4326. return (property!=='$Jdata' && target[property] && (typeof target[property]==='object' || Array.isArray(target[property]))) ? createProxy(target[property], target.$Jdata[property]) : target[property];
  4327. },
  4328. set(target, property, value){
  4329. if (property==="length" && (target.$Jdata instanceof ArrayList)){
  4330. while (target.$Jdata.size()>value){
  4331. target.$Jdata.remove(target.$Jdata.size()-1);
  4332. }
  4333. }else{
  4334. target.$Jdata[property] = value;
  4335. }
  4336. return Reflect.set(...arguments);
  4337. }
  4338. });
  4339. }
  4340. const _javaDataToJson = (javaData)=>{
  4341. try{
  4342. // const Gson = Java.type('com.google.gson.Gson');
  4343. // const gson = new Gson();
  4344. // return JSON.parse(gson.toJson(javaData));
  4345. return JSON.parse(javaData.toString());
  4346. }catch(e) {
  4347. return null;
  4348. }
  4349. }
  4350. let _data = null;
  4351. const dataDescriptor = {
  4352. get(){
  4353. return _data ?? (()=>{
  4354. if (!globalThis.java_data) return null;
  4355. const data = _javaDataToJson(globalThis.java_data);
  4356. return _data = createProxy(data, globalThis.java_data);
  4357. })();
  4358. }
  4359. }
  4360. let _embedData = null;
  4361. const embedDataDescriptor = {
  4362. get(){
  4363. return _embedData ?? (()=>{
  4364. if (!globalThis.java_embedData) return null;
  4365. // const Gson = Java.type('com.google.gson.Gson');
  4366. // const gson = new Gson();
  4367. const data = _javaDataToJson(globalThis.java_embedData);
  4368. return _embedData = createProxy(data, globalThis.java_embedData);
  4369. })();
  4370. }
  4371. }
  4372. /************************************************************/
  4373. /* person text直接注入,oauth配置和默认生成口令脚本中使用 *****/
  4374. /************************************************************/
  4375. /************************************************************/
  4376. /* value直接注入,视图显示值中使用 ***************************/
  4377. /************************************************************/
  4378. const _get = function(key, java_data){
  4379. if (!globalThis[`o${key}`]) globalThis[`o${key}`] = JSON.parse(java_data);
  4380. return globalThis[`o${key}`];
  4381. }
  4382. const o= {
  4383. entityManager: { get: function(){return null;} },
  4384. context: { get: function(){return ((globalThis.java_resources) ? globalThis.java_resources.getContext() : null)} },
  4385. applications: { get: function(){return ((globalThis.java_resources) ? globalThis.java_resources.getApplications() : null)} },
  4386. organization: { get: function(){return ((globalThis.java_resources) ? globalThis.java_resources.getOrganization() : null)} },
  4387. /**
  4388. * 获取当前用户对象。
  4389. * @module server.currentPerson
  4390. * @o2cn 当前用户全称对象
  4391. * @o2category server.common
  4392. * @o2ordernumber 250
  4393. * @o2syntax
  4394. * var user = this.currentPerson;
  4395. */
  4396. currentPerson: { get: function(){return (globalThis.java_effectivePerson) ? _get('currentPerson', globalThis.java_effectivePerson) : null;} },
  4397. effectivePerson: { get: function(){return (globalThis.java_effectivePerson) ? _get('effectivePerson', globalThis.java_effectivePerson) : null;} },
  4398. resources: { get: function(){return (globalThis.java_resources || null)} },
  4399. customResponse: { get: function(){return (globalThis.java_customResponse || null)} },
  4400. message: { get: function(){return (globalThis.java_message) ? _get('message', globalThis.java_message) : null;} },
  4401. //===========================================================================
  4402. // 将要导出的对象和方法绑定到 globalThis。(以后将通过 export 和 import 来引入)
  4403. //===========================================================================
  4404. fetch: { value: fetch },
  4405. exec: { value: exec },
  4406. define: { value: define },
  4407. Action: { value: Action },
  4408. log: { value: log },
  4409. Actions: { value: Actions },
  4410. print: { value: print },
  4411. org: { value: org },
  4412. processActions: { value: processActions },
  4413. cmsActions: { value: cmsActions },
  4414. portalActions: { value: portalActions },
  4415. serviceActions: { value: serviceActions },
  4416. includedScripts: { value: includedScripts },
  4417. include: { value: include },
  4418. includeHtml: { value: includeHtml },
  4419. includeCss: { value: includeCss },
  4420. includeJson: { value: includeJson },
  4421. Dict: { value: Dict },
  4422. Table: { value: Table },
  4423. statement: { value: statement },
  4424. view: { value: view },
  4425. service: { value: service },
  4426. response: responseDescriptor,
  4427. parameters: parametersDescriptor,
  4428. requestText: requestTextDescriptor,
  4429. request: requestDescriptor,
  4430. workContext: { value: workContext },
  4431. workContent: { value: workContext },
  4432. assignData: { value: assignData },
  4433. body: { value: body },
  4434. headers: { value: headers },
  4435. expire: { value: expire },
  4436. // @todo 需要包装为javascript对象
  4437. data: dataDescriptor,
  4438. embedData: embedDataDescriptor
  4439. // embedData: { value: globalThis.embedData }
  4440. };
  4441. Object.defineProperties(globalThis, o);
  4442. /* 清除 engine */
  4443. globalThis.engine = null;
  4444. //=== java_resources: =============
  4445. //所有服务段脚本中都有 java对象
  4446. // Context getContext() 应用上下文对象,无用
  4447. // Applications getApplications() 与服务端交互的请求方法
  4448. // describeApi()
  4449. // getQuery()
  4450. // postQuery()
  4451. // putQuery()
  4452. // deleteQuery()
  4453. // Organization getOrganization() 组织相关的服务
  4454. // WebservicesClient getWebservicesClient() 发起HTTP请求和Webservice请求的工具
  4455. // EntityManagerContainer getEntityManagerContainer() jpa管理对象,不暴露
  4456. //=== java_customResponse: =========================================
  4457. // 只在服务管理 invoke 中使用,主要用于设置 invoke 的请求响应 java对象
  4458. // seeOther() 设置 303 跳转
  4459. // temporaryRedirect() 设置 301 跳转
  4460. // setBody() 设置 响应数据 和 响应 content-type 200
  4461. //=== java_effectivePerson: =========================================
  4462. //当前用户的对象 java对象 -- 改为 json字符串 todo
  4463. // toJson() 转json字符串
  4464. //=== java_parameters: ==============================================
  4465. //只查询语句中使用,用于参数传递 json字符串
  4466. //=== java_requestText: ==============================================
  4467. // 只在服务管理 invoke 中使用,获取请求消息体的文本内容 json字符串
  4468. //=== java_request: ==================================================
  4469. // 只在服务管理 invoke 中使用,请求的 request对象 java对象
  4470. //=== java_message: ==================================================
  4471. // 只在消息过滤器和加载器中使用,描述消息的 json字符串
  4472. // 主要信息有:title、person、body、type
  4473. //=== person: ========================================================
  4474. // 只在系统配置中,默认用户密码设置脚本中使用,获取当前执行到的,即将生成密码的用户。 java对象
  4475. // getName()、getMobile()、getEmployee() 等获取个人信息的方法