12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269 |
- MWF.xScript = MWF.xScript || {};
- MWF.xScript.CMSEnvironment = function(ev){
- var _data = ev.data;
- var _form = ev.form;
- var _forms = ev.forms;
- this.appType = "cms";
- this.library = COMMON;
- //this.library.version = "4.0";
- //data
- var getJSONData = function(jData){
- return new MWF.xScript.CMSJSONData(jData, function(data, key, _self){
- var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
- while (p && !_forms[p.getKey()]) p = p.getParent();
- var k = (p) ? p.getKey() : "";
- if (k) if(_forms[k]) if(_forms[k].resetData) _forms[k].resetData();
- }, "", null, _form);
- };
- this.setData = function(data){
- this.data = getJSONData(data);
- this.data.save = function(callback){
- _form.documentAction.saveData(function(json){if (callback) callback();}.bind(this), null, ev.document.id, data);
- }
- };
- this.setData(_data);
- //task
- //this.task = ev.task;
- //this.task.process = function(routeName, opinion, callback){
- // _form.submitWork(routeName, opinion, callback);
- //};
- //inquiredRouteList
- //this.inquiredRouteList = null;
- //workContext
- /**
- * 您可以通过documentContext获取内容管理实例相关的对象数据。
- * @module documentContext
- * @o2cn 内容管理实例
- * @o2category web
- * @o2range {CMS}
- * @o2ordernumber 30
- * @example
- * //您可以在内容管理表单中,通过this来获取当前实例的documentContext对象,如下:
- * var context = this.documentContext;
- */
- this.documentContext = {
- // * @o2ActionOut x_cms_assemble_control.WoDocument|ignoreNoDescr=true|example=Document
- /**
- * 获取当前内容管理实例的文档对象:document对象。
- * @method getDocument
- * @static
- * @return {Document} 文档对象.
- * <pre><code class='language-js'>{
- * "id": "3359aedd-c2d8-4d8c-b8b0-02507da1b3f4", //数据库主键,自动生成.
- * "summary": " ", //文档摘要
- * "title": "航天科工外部董事调研组到培训中心调研", //文档标题
- * "documentType": "信息", //文档类型,跟随分类类型,信息 | 数据
- * "appId": "c295f34c-9ce1-4122-b795-820267e32b68", //栏目ID
- * "appName": "通知公告", //栏目名称
- * "appAlias": " ", //栏目别名
- * "categoryId": "33fb19f0-0670-464d-875c-32fb86148f7a", //分类ID
- * "categoryName": "通知公告", //分类名称
- * "categoryAlias": "通知公告-通知公告", //分类别名
- * "form": "dddefed4-4411-4e4e-b982-cdd4cd083443", //绑定的表单模板ID
- * "formName": "通知公告编辑表单", //绑定的表单模板名称
- * "importBatchName": " ", //文件导入的批次号:一般是分类ID+时间缀
- * "readFormId": "d6f1f596-fcb7-4a87-baaf-7f6cdafe3cec", //绑定的阅读表单模板ID
- * "readFormName": "通知公告阅读表单", //绑定的阅读表单模板名称
- * "creatorPerson": "李义@liyi@P", //创建人,可能为空,如果由系统创建。
- * "creatorIdentity": "李义@469d1601-c4a5-46ae-b7bf-4da9af07b6fa@I", //创建人Identity,可能为空,如果由系统创建。
- * "creatorUnitName": "浙江兰德纵横@a706f5f0-4a3b-4785-8e1d-0a944bfad4eb@U", //创建人组织,可能为空,如果由系统创建。
- * "creatorTopUnitName": "浙江兰德纵横@a706f5f0-4a3b-4785-8e1d-0a944bfad4eb@U", //创建人顶层组织,可能为空,如果由系统创建。
- * "docStatus": "published", //文档状态: waitPublished | published | draft | checking | error
- * "description": " ", //说明备注,可以填写说明信息,如导入信息检验失败原因等
- * "viewCount": 1, //文档被查看次数
- * "commendCount": 1, //文档被赞次数
- * "commentCount": 1, //文档评论次数
- * "publishTime": "2018-01-04 14:17:16", //文档发布时间
- * "modifyTime": "2022-09-01 17:05:47", //文档修改时间
- * "isTop": true, //是否置顶
- * "hasIndexPic": true, //是否含有首页图片
- * "reviewed": true, //是否已经更新review信息.
- * "sequenceTitle": " ", //用于标题排序的sequence
- * "sequenceAppAlias": " ", //用于栏目别名排序的sequence
- * "sequenceCategoryAlias": " ", //用于分类别名排序的sequence
- * "sequenceCreatorPerson": " ", //用于创建者排序的sequence
- * "sequenceCreatorUnitName": " ", //用于创建者组织排序的sequence
- * "readPersonList": [
- * "张三@zhangsan@P"
- * "所有人"
- * ], //阅读人员
- * "readUnitList": [
- * ], //阅读组织
- * "readGroupList": [
- * ], //阅读群组
- * "authorPersonList": [
- * "张三@zhangsan@P"
- * ], //作者人员
- * "authorUnitList": [
- * ], //作者组织
- * "authorGroupList": [
- * ], //作者群组
- * "remindPersonList": [
- * " "
- * ], //发布提醒人员
- * "remindUnitList": [
- * " "
- * ], //发布提醒组织
- * "remindGroupList": [
- * " "
- * ], //发布提醒群组
- * "managerList": [
- * "张三@zhangsan@P"
- * ], //管理者
- * "pictureList": [
- * ], //首页图片列表
- * "distributeFactor": 1, //分布式存储标识位.
- * "createTime": "2022-09-01 17:05:47", //创建时间,自动生成,索引创建在约束中.
- * "updateTime": "2022-09-01 17:05:47", //修改时间,自动生成,索引创建在约束中.
- * "sequence": " ", //列表序号,由创建时间以及ID组成.在保存时自动生成,索引创建在约束中.
- * "stringValue01": "", //业务数据String值01.
- * "stringValue02": "", //业务数据String值02.
- * "stringValue03": "", //业务数据String值03.
- * "stringValue04": "", //业务数据String值04.
- * "stringValue05": "", //业务数据String值05.
- * "stringValue06": "", //业务数据String值06.
- * "stringValue07": "", //业务数据String值07.
- * "stringValue08": "", //业务数据String值08.
- * "stringValue09": "", //业务数据String值09.
- * "stringValue10": "", //业务数据String值10.
- * "longValue01": "", //业务数据Long值01.
- * "longValue02": "", //业务数据Long值02.
- * "doubleValue01": "", //业务数据double值01.
- * "doubleValue02": "", //业务数据double值02.
- * "dateTimeValue01": "", //业务数据dateTime值01.
- * "dateTimeValue02": "", //业务数据dateTime值02.
- * "dateTimeValue03": "", //业务数据dateTime值03.
- * }
- *</code></pre>
- * @o2syntax
- * var doc = this.documentContext.getDocument();
- */
- "getDocument": function(){return ev.document },
- /**
- * 获取当前人对文档的权限。
- * @method getControl
- * @static
- * @return {DocumentControl} 当前人对文档所拥有的权限.
- * <pre><code class='language-js'>{
- * "allowRead": true, //是否允许阅读文档
- * "allowPublishDocument": true, //是否允许发布文档
- * "allowSave": true, //是否允许保存文档
- * "allowPopularDocument": true, //是否允许设置为热点
- * "allowEditDocument": true, //是否允许编辑文档
- * "allowDeleteDocument": true //是否允许删除文档
- * }</code></pre>
- * @o2syntax
- * var control = this.documentContext.getControl();
- */
- "getControl": function(){return ev.control;},
- /**
- * 获取当前文档的附件对象列表。
- * @method getAttachmentList
- * @static
- * @return {DocumentFileInfo[]} 当前文档的附件对象列表.
- * @o2ActionOut x_cms_assemble_control.FileInfoAction.get|example=Attachment|ignoreProps=[properties]
- * @o2syntax
- * var attachmentList = this.documentContext.getAttachmentList();
- */
- "getAttachmentList": function(){return ev.attachmentList;}
- //"setTitle": function(title){
- // if (!this.workAction){
- // MWF.require("MWF.xScript.Actions.WorkActions", null, false);
- // this.workAction = new MWF.xScript.Actions.WorkActions();
- // }
- // this.workAction.setTitle(ev.work.id, {"title": title});
- //}
- };
- //dict
- this.Dict = MWF.xScript.createCMSDict(_form.json.application, "cms");
- //org
- var orgActions = null;
- var getOrgActions = function(){
- // if (!orgActions){
- // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
- // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
- // }
- if (!orgActions){
- MWF.require("MWF.xScript.Actions.UnitActions", null, false);
- orgActions = new MWF.xScript.Actions.UnitActions();
- }
- };
- var getNameFlag = function(name){
- var t = typeOf(name);
- if (t==="array"){
- var v = [];
- name.each(function(id){
- v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
- });
- return v;
- }else{
- return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
- }
- };
- this.org = {
- //群组***************
- //获取群组--返回群组的对象数组
- getGroup: function(name, async){
- getOrgActions();
- var data = {"groupList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- v = (v && v.length===1) ? v[0] : v
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listGroup(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var v = null;
- // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
- // return (v && v.length===1) ? v[0] : v;
- },
- //查询下级群组--返回群组的对象数组
- //nested 布尔 true嵌套下级;false直接下级;默认false;
- listSubGroup: function(name, nested, async){
- getOrgActions();
- var data = {"groupList": getNameFlag(name)};
- var v = null;
- // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
- // v = json.data;
- // return v;
- // }.ag().catch(function(json){ return json; });
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise;
- if (nested){
- promise = orgActions.listSubGroupNested(data, cb, null, !!async);
- }else{
- promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
- }
- return (!!async) ? promise : v;
- // var v = null;
- // if (nested){
- // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
- // }else{
- // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
- // }
- // return v;
- },
- //查询上级群组--返回群组的对象数组
- //nested 布尔 true嵌套上级;false直接上级;默认false;
- listSupGroup:function(name, nested, async){
- getOrgActions();
- var data = {"groupList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise
- if (nested){
- var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
- }else{
- var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
- }
- return (!!async) ? promise : v;
- // var v = null;
- // if (nested){
- // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
- // }else{
- // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
- // }
- // return v;
- },
- //人员所在群组(嵌套)--返回群组的对象数组
- listGroupWithPerson:function(name, async){
- getOrgActions();
- var data = {"personList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var v = null;
- // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
- // return v;
- },
- //身份所在群组(嵌套)--返回群组的对象数组
- listGroupWithIdentity:function(identity, async){
- getOrgActions();
- var data = {"identityList": getNameFlag(identity)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listGroupWithIdentity(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //群组是否拥有角色--返回true, false
- groupHasRole: function(name, role, async){
- getOrgActions();
- nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
- var data = {"group":nameFlag,"roleList":getNameFlag(role)};
- var v = false;
- var cb = function(json){
- v = json.data.value;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.groupHasRole(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var v = false;
- // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
- // return v;
- },
- //角色***************
- //获取角色--返回角色的对象数组
- getRole: function(name, async){
- getOrgActions();
- var data = {"roleList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- v = (v && v.length===1) ? v[0] : v;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listRole(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var v = null;
- // orgActions.listRole(data, function(json){v = json.data;}, null, false);
- // return (v && v.length===1) ? v[0] : v;
- },
- //人员所有角色(嵌套)--返回角色的对象数组
- listRoleWithPerson:function(name, async){
- getOrgActions();
- var data = {"personList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var v = null;
- // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
- // return v;
- },
- //人员***************
- //人员是否拥有角色--返回true, false
- personHasRole: function(name, role, async){
- getOrgActions();
- nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
- var data = {"person":nameFlag,"roleList":getNameFlag(role)};
- var v = false;
- var cb = function(json){
- v = json.data.value;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.personHasRole(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var v = false;
- // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
- // return v;
- },
- //获取人员,附带身份,身份所在的组织,个人所在群组,个人拥有角色.
- getPersonData: function(name, async){
- getOrgActions();
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.getPerson(null, cb, null, !!async, {"flag": name});
- return (!!async) ? promise : v;
- },
- //获取人员--返回人员的对象数组
- getPerson: function(name, async, findCN){
- getOrgActions();
- var data = {"personList": getNameFlag(name)};
- if( o2.typeOf(findCN) === "boolean"){
- data.useNameFind = findCN;
- }
- var v = null;
- var cb = function(json){
- v = json.data;
- v = (v && v.length===1) ? v[0] : v;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listPerson(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var v = null;
- // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
- // return (v && v.length===1) ? v[0] : v;
- },
- //查询下级人员--返回人员的对象数组
- //nested 布尔 true嵌套下级;false直接下级;默认false;
- listSubPerson: function(name, nested, async){
- getOrgActions();
- var data = {"personList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise;
- if (nested){
- promise = orgActions.listPersonSubNested(data, cb, null, !!async);
- }else{
- promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
- }
- return (!!async) ? promise : v;
- },
- //查询上级人员--返回人员的对象数组
- //nested 布尔 true嵌套上级;false直接上级;默认false;
- listSupPerson: function(name, nested, async){
- getOrgActions();
- var data = {"personList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise;
- if (nested){
- promise = orgActions.listPersonSupNested(data, cb, null, !!async);
- }else{
- promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
- }
- return (!!async) ? promise : v;
- },
- //获取群组的所有人员--返回人员的对象数组
- listPersonWithGroup: function(name, async){
- getOrgActions();
- var data = {"groupList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //获取角色的所有人员--返回人员的对象数组
- listPersonWithRole: function(name, async){
- getOrgActions();
- var data = {"roleList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise
- promise = orgActions.listPersonWithRole(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //获取身份的所有人员--返回人员的对象数组
- listPersonWithIdentity: function(name, async){
- getOrgActions();
- var data = {"identityList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //获取身份的所有人员--返回人员的对象数组或人员对象
- getPersonWithIdentity: function(name, async){
- getOrgActions();
- var data = {"identityList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- v = (v && v.length===1) ? v[0] : v;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //查询组织成员的人员--返回人员的对象数组
- //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
- listPersonWithUnit: function(name, nested, async){
- getOrgActions();
- var data = {"unitList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise;
- if (nested){
- promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
- }else{
- promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
- }
- return (!!async) ? promise : v;
- },
- //根据属性查询人员--返回人员的对象数组
- //name string 属性名
- //value string 属性值
- listPersonWithAttribute: function(name, value, async){
- getOrgActions();
- var data = {"name": name, "attribute": value};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //根据属性查询人员--返回人员的全称数组
- //name string 属性名
- //value string 属性值
- listPersonNameWithAttribute: function(name, value, async){
- getOrgActions();
- var data = {"name": name, "attribute": value};
- var v = null;
- var cb = function(json){
- v = json.data.personList;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //人员属性************
- //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
- appendPersonAttribute: function(person, attr, values, success, failure, async){
- getOrgActions();
- var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
- var data = {"attributeList":values,"name":attr,"person":personFlag};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.appendPersonAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var cb = function(json){
- // if (success) return success(json);
- // }.ag().catch(function(xhr, text, error){
- // if (failure) return failure(xhr, text, error);
- // });
- //
- // orgActions.appendPersonAttribute(data, cb, null, !!async);
- },
- //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
- setPersonAttribute: function(person, attr, values, success, failure, async){
- getOrgActions();
- var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
- var data = {"attributeList":values,"name":attr,"person":personFlag};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.setPersonAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var cb = function(json){
- // if (success) return success(json);
- // }.ag().catch(function(xhr, text, error){
- // if (failure) return failure(xhr, text, error);
- // });
- //
- // orgActions.setPersonAttribute(data, cb, null, !!async);
- },
- //获取人员属性值
- getPersonAttribute: function(person, attr, async){
- getOrgActions();
- var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
- var data = {"name":attr,"person":personFlag};
- var v = null;
- var cb = function(json){
- v = json.data.attributeList;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //列出人员所有属性的名称
- listPersonAttributeName: function(name, async){
- getOrgActions();
- var data = {"personList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data.nameList;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //列出人员的所有属性
- listPersonAllAttribute: function(name, async){
- getOrgActions();
- var data = {"personList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //身份**********
- //获取身份
- getIdentity: function(name, async){
- getOrgActions();
- var data = {"identityList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- v = (v && v.length===1) ? v[0] : v;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listIdentity(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //列出人员的身份
- listIdentityWithPerson: function(name, async, findCN){
- getOrgActions();
- var data = {"personList":getNameFlag(name)};
- if( o2.typeOf(findCN) === "boolean"){
- data.useNameFind = findCN;
- }
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //查询组织成员身份--返回身份的对象数组
- //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
- listIdentityWithUnit: function(name, nested, async){
- getOrgActions();
- var data = {"unitList": getNameFlag(name)};
- var v = null;
- // var cb = function(json){
- // v = json.data;
- // if (async && o2.typeOf(async)=="function") return async(v);
- // return v;
- // }.ag().catch(function(json){ return json; });
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
- var promise = orgActions[method](data, cb, null, !!async);
- promise.name = "org";
- //
- // if (nested){
- // orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
- // }else{
- // orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
- // }
- return (!!async) ? promise : v;
- },
- //组织**********
- //获取组织
- getUnit: function(name, async, findCN){
- getOrgActions();
- var data = {"unitList":getNameFlag(name)};
- if( o2.typeOf(findCN) === "boolean"){
- data.useNameFind = findCN;
- }
- var v = null;
- var cb = function(json){
- v = json.data;
- v = (v && v.length===1) ? v[0] : v;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listUnit(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //查询组织的下级--返回组织的对象数组
- //nested 布尔 true嵌套下级;false直接下级;默认false;
- listSubUnit: function(name, nested, async){
- getOrgActions();
- var data = {"unitList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise;
- if (nested){
- promise = orgActions.listUnitSubNested(data, cb, null, !!async);
- }else{
- promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
- }
- return (!!async) ? promise : v;
- },
- //查询组织的上级--返回组织的对象数组
- //nested 布尔 true嵌套上级;false直接上级;默认false;
- //async 布尔 true异步请求
- listSupUnit: function(name, nested, async){
- getOrgActions();
- var data = {"unitList": getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise;
- if (nested){
- promise = orgActions.listUnitSupNested(data, cb, null, !!async);
- }else{
- promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
- }
- return (!!async) ? promise : v;
- // if (callback){
- // if (nested){
- // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
- // }else{
- // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
- // }
- // }else{
- // var v = null;
- // if (nested){
- // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
- // }else{
- // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
- // }
- // return v;
- // }
- },
- listSupUnitWithLevel: function(name, level, async){
- var v;
- var supUnitList = this.listSupUnit( name, true, !!async);
- var unitList = this.getUnit( name, false, !!async );
- var cb = function(sups, units){
- v = [].concat(
- sups,
- typeOf( units ) === "object" ? [units] : units
- ).filter(function (u){
- return u.level === level;
- });
- if (async && o2.typeOf(async)==="function") return async(v);
- return v;
- };
- if( typeof supUnitList.then === 'function' ){
- return Promise.all([supUnitList, unitList]).then(function( result){
- return cb(result[0], result[1]);
- });
- }else{
- return cb(supUnitList, unitList);
- }
- },
- listSupUnitWithType: function(name, type, async){
- var v;
- var supUnitList = this.listSupUnit( name, true, !!async);
- var unitList = this.getUnit( name, false, !!async );
- var cb = function(sups, units){
- v = [].concat(
- sups,
- typeOf( units ) === "object" ? [units] : units
- ).filter(function (u){
- return (u.typeList || []).contains( type );
- });
- if (async && o2.typeOf(async)==="function") return async(v);
- return v;
- };
- if( typeof supUnitList.then === 'function' ){
- return Promise.all([supUnitList, unitList]).then(function( result){
- return cb(result[0], result[1]);
- });
- }else{
- return cb(supUnitList, unitList);
- }
- },
- //根据个人身份获取组织
- //flag 数字 表示获取第几层的组织
- // 字符串 表示获取指定类型的组织
- // 空 表示获取直接所在的组织
- getUnitByIdentity: function(name, flag, async){
- getOrgActions();
- var getUnitMethod = "current";
- var v;
- if (flag){
- if (typeOf(flag)==="string") getUnitMethod = "type";
- if (typeOf(flag)==="number") getUnitMethod = "level";
- }
- var cb;
- var promise;
- switch (getUnitMethod){
- case "current":
- var data = {"identityList":getNameFlag(name)};
- // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
- // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
- // }.ag().catch(function(json){ return json; });
- cb = function(json){
- v = json.data; v=(v&&v.length===1) ? v[0] : v;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
- break;
- case "type":
- var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
- cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
- // v = json.data; return v;
- // }.ag().catch(function(json){ return json; });
- promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
- break;
- case "level":
- var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
- cb = function(json){
- v = json.data; v=(v&&v.length===1) ? v[0] : v;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
- // v = json.data; return v;
- // }.ag().catch(function(json){ return json; });
- promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
- break;
- }
- return (!!async) ? promise : v;
- },
- //列出身份所在组织的所有上级组织
- listAllSupUnitWithIdentity: function(name, async){
- getOrgActions();
- var data = {"identityList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //获取人员所在的所有组织
- listUnitWithPerson: function(name, async){
- getOrgActions();
- var data = {"personList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //列出人员所在组织的所有上级组织
- listAllSupUnitWithPerson: function(name, async){
- getOrgActions();
- var data = {"personList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //根据组织属性,获取所有符合的组织
- listUnitWithAttribute: function(name, attribute, async){
- getOrgActions();
- var data = {"name":name,"attribute":attribute};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //根据组织职务,获取所有符合的组织
- listUnitWithDuty: function(name, id, async){
- getOrgActions();
- var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //组织职务***********
- //获取指定的组织职务的身份
- getDuty: function(duty, id, async){
- getOrgActions();
- var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.getDuty(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //获取身份的所有职务名称
- listDutyNameWithIdentity: function(name, async){
- getOrgActions();
- var data = {"identityList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data.nameList;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //获取组织的所有职务名称
- listDutyNameWithUnit: function(name, async){
- getOrgActions();
- var data = {"unitList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data.nameList;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //获取组织的所有职务
- listUnitAllDuty: function(name, async){
- getOrgActions();
- var data = {"unitList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //列出顶层组织
- listTopUnit: function(async){
- var action = MWF.Actions.get("x_organization_assemble_control");
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = action.listTopUnit(cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //组织属性**************
- //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
- appendUnitAttribute: function(unit, attr, values, success, failure, async){
- getOrgActions();
- var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
- var data = {"attributeList":values,"name":attr,"unit":unitFlag};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.appendUnitAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var cb = function(json){
- // if (success) return success(json);
- // }.ag().catch(function(xhr, text, error){
- // if (failure) return failure(xhr, text, error);
- // });
- //
- // orgActions.appendPersonAttribute(data, cb, null, !!async);
- // orgActions.appendUnitAttribute(data, function(json){
- // if (json.data.value){
- // if (success) success();
- // }else{
- // if (failure) failure(null, "", "append values failed");
- // }
- // }, function(xhr, text, error){
- // if (failure) failure(xhr, text, error);
- // }, false);
- },
- //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
- setUnitAttribute: function(unit, attr, values, success, failure, async){
- getOrgActions();
- var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
- var data = {"attributeList":values,"name":attr,"unit":unitFlag};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.setUnitAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- // var cb = function(json){
- // if (success) return success(json);
- // }.ag().catch(function(xhr, text, error){
- // if (failure) return failure(xhr, text, error);
- // });
- // orgActions.setUnitAttribute(data, cb, null, !!async);
- // orgActions.setUnitAttribute(data, function(json){
- // if (json.data.value){
- // if (success) success();
- // }else{
- // if (failure) failure(null, "", "append values failed");
- // }
- // }, function(xhr, text, error){
- // if (failure) failure(xhr, text, error);
- // }, false);
- },
- //获取组织属性值
- getUnitAttribute: function(unit, attr, async){
- getOrgActions();
- var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
- var data = {"name":attr,"unit":unitFlag};
- var v = null;
- var cb = function(json){
- v = json.data.attributeList;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //列出组织所有属性的名称
- listUnitAttributeName: function(name, async){
- getOrgActions();
- var data = {"unitList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data.nameList;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
- return (!!async) ? promise : v;
- },
- //列出组织的所有属性
- listUnitAllAttribute: function(name, async){
- getOrgActions();
- var data = {"unitList":getNameFlag(name)};
- var v = null;
- var cb = function(json){
- v = json.data;
- if (async && o2.typeOf(async)=="function") return async(v);
- return v;
- };
- var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
- return (!!async) ? promise : v;
- }
- };
- this.Action = (function(){
- var actions = [];
- return function(root, json){
- var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
- action.getActions = function(callback){
- if (!this.actions) this.actions = {};
- Object.merge(this.actions, json);
- if (callback) callback();
- };
- this.invoke = function(option){
- action.invoke(option)
- }
- }
- })();
- // this.service = {
- // "jaxwsClient": {},
- // "jaxrsClient":{}
- // };
- var lookupAction = null;
- var getLookupAction = function(callback){
- if (!lookupAction){
- MWF.require("MWF.xDesktop.Actions.RestActions", function(){
- lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
- lookupAction.getActions = function(actionCallback){
- this.actions = {
- "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
- "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
- };
- if (actionCallback) actionCallback();
- }
- if (callback) callback();
- }.bind(this));
- }else{
- if (callback) callback();
- }
- };
- this.view = {
- "lookup": function(view, callback, async){
- var filterList = {"filterList": (view.filter || null)};
- return MWF.Actions.load("x_query_assemble_surface").ViewAction.executeWithQuery(view.view, view.application, filterList, function(json){
- var data = {
- "grid": json.data.grid || json.data.groupGrid,
- "groupGrid": json.data.groupGrid
- };
- if (callback) callback(data);
- return data;
- }, null, async);
- },
- "lookupV1": function(view, callback){
- getLookupAction(function(){
- lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
- var data = {
- "grid": json.data.grid,
- "groupGrid": json.data.groupGrid
- };
- if (callback) callback(data);
- }.bind(this)});
- }.bind(this));
- },
- "select": function(view, callback, options){
- if (view.view){
- var viewJson = {
- "application": view.application || _form.json.application,
- "viewName": view.view || "",
- "isTitle": (view.isTitle===false) ? "no" : "yes",
- "select": (view.isMulti===false) ? "single" : "multi",
- "filter": view.filter
- };
- if (!options) options = {};
- options.width = view.width;
- options.height = view.height;
- options.title = view.caption;
- var width = options.width || "700";
- var height = options.height || "400";
- if (layout.mobile){
- var size = document.body.getSize();
- width = size.x;
- height = size.y;
- options.style = "viewmobile";
- }
- width = width.toInt();
- height = height.toInt();
- var size = _form.app.content.getSize();
- var x = (size.x-width)/2;
- var y = (size.y-height)/2;
- if (x<0) x = 0;
- if (y<0) y = 0;
- if (layout.mobile){
- x = 20;
- y = 0;
- }
- var _self = this;
- MWF.require("MWF.xDesktop.Dialog", function(){
- var dlg = new MWF.xDesktop.Dialog({
- "title": options.title || "select view",
- "style": options.style || "view",
- "top": y,
- "left": x-20,
- "fromTop":y,
- "fromLeft": x-20,
- "width": width,
- "height": height,
- "html": "<div style='height: 100%;'></div>",
- "maskNode": _form.app.content,
- "container": _form.app.content,
- "buttonList": [
- {
- "text": MWF.LP.process.button.ok,
- "action": function(){
- //if (callback) callback(_self.view.selectedItems);
- if (callback) callback(_self.view.getData());
- this.close();
- }
- },
- {
- "text": MWF.LP.process.button.cancel,
- "action": function(){this.close();}
- }
- ]
- });
- dlg.show();
- if (layout.mobile){
- var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
- var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
- if (backAction) backAction.addEvent("click", function(e){
- dlg.close();
- }.bind(this));
- if (okAction) okAction.addEvent("click", function(e){
- //if (callback) callback(this.view.selectedItems);
- if (callback) callback(this.view.getData());
- dlg.close();
- }.bind(this));
- }
- MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
- this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
- }.bind(this));
- }.bind(this));
- }
- }
- };
- this.statement = {
- execute: function (obj, callback, async) {
- if( obj.format ){
- return this._execute(obj, callback, async, obj.format);
- }else{
- if( this.needCheckFormat(obj) ){
- var result;
- var p = MWF.Actions.load("x_query_assemble_surface").StatementAction.getFormat(obj.name, function(json){
- result = this._execute(obj, callback, async, json.data.format);
- return result;
- }.bind(this), null, async);
- return result || p;
- }else{
- return this._execute(obj, callback, async, "");
- }
- }
- },
- needCheckFormat: function(s){
- if( s.format )return false;
- if( typeOf(s.parameter) === "object" ){
- for( var p in s.parameter ){
- if( typeOf( s.parameter[p] ) === "date" )return true;
- }
- }
- if( typeOf(s.filter) === "array" ){
- for( var i=0; i< s.filter.length; i++){
- var fType = s.filter[i].formatType;
- if( ["dateTimeValue", "datetimeValue", "dateValue", "timeValue"].contains( fType ) )return true;
- }
- }
- return false;
- },
- _execute: function(statement, callback, async, format){
- var parameter = this.parseParameter(statement.parameter, format);
- var filterList = this.parseFilter(statement.filter, parameter, format);
- var obj = {
- "filterList": filterList,
- "parameter" : parameter
- };
- return MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
- statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
- function (json) {
- if (callback) callback(json);
- return json;
- }, null, async);
- },
- parseFilter : function( filter, parameter, format){
- if( typeOf(filter) !== "array" )return [];
- if( !parameter )parameter = {};
- var filterList = [];
- ( filter || [] ).each( function (d) {
- if( !d.logic )d.logic = "and";
- //var parameterName = d.path.replace(/\./g, "_");
- var pName = d.path.replace(/\./g, "_");
- var parameterName = pName;
- var suffix = 1;
- while( parameter[parameterName] ){
- parameterName = pName + "_" + suffix;
- suffix++;
- }
- var value = d.value;
- if( d.comparison === "like" || d.comparison === "notLike" ){
- if( value.substr(0, 1) !== "%" )value = "%"+value;
- if( value.substr(value.length-1,1) !== "%" )value = value+"%";
- parameter[ parameterName ] = value; //"%"+value+"%";
- }else{
- if( ["sql", "sqlScript"].contains(format) ) {
- if (d.formatType === "numberValue") {
- value = parseFloat(value);
- }
- }else{
- if (d.formatType === "dateTimeValue" || d.formatType === "datetimeValue") {
- value = "{ts '" + value + "'}"
- } else if (d.formatType === "dateValue") {
- value = "{d '" + value + "'}"
- } else if (d.formatType === "timeValue") {
- value = "{t '" + value + "'}"
- } else if (d.formatType === "numberValue") {
- value = parseFloat(value);
- }
- }
- parameter[ parameterName ] = value;
- }
- d.value = parameterName;
- filterList.push( d );
- }.bind(this));
- return filterList;
- },
- parseParameter : function( obj, format ){
- if( typeOf(obj) !== "object" )return {};
- var parameter = {};
- //传入的参数
- for( var p in obj ){
- var value = obj[p];
- if( typeOf( value ) === "date" ){
- if( ["sql", "sqlScript"].contains(format) ){
- value = value.format("db");
- }else{
- value = "{ts '"+value.format("db")+"'}"
- }
- }
- parameter[ p ] = value;
- }
- return parameter;
- },
- "select": function (statement, callback, options) {
- if (statement.name) {
- // var parameter = this.parseParameter(statement.parameter);
- // var filterList = this.parseFilter(statement.filter, parameter);
- var statementJson = {
- "statementId": statement.name || "",
- "isTitle": (statement.isTitle === false) ? "no" : "yes",
- "select": (statement.isMulti === false) ? "single" : "multi",
- "filter": statement.filter,
- "parameter": statement.parameter
- };
- if (!options) options = {};
- options.width = statement.width;
- options.height = statement.height;
- options.title = statement.caption;
- var width = options.width || "700";
- var height = options.height || "400";
- if (layout.mobile) {
- var size = document.body.getSize();
- width = size.x;
- height = size.y;
- options.style = "viewmobile";
- }
- width = width.toInt();
- height = height.toInt();
- var size = _form.app.content.getSize();
- var x = (size.x - width) / 2;
- var y = (size.y - height) / 2;
- if (x < 0) x = 0;
- if (y < 0) y = 0;
- if (layout.mobile) {
- x = 20;
- y = 0;
- }
- var _self = this;
- MWF.require("MWF.xDesktop.Dialog", function () {
- var dlg = new MWF.xDesktop.Dialog({
- "title": options.title || "select statement view",
- "style": options.style || "view",
- "top": y,
- "left": x - 20,
- "fromTop": y,
- "fromLeft": x - 20,
- "width": width,
- "height": height,
- "html": "<div style='height: 100%;'></div>",
- "maskNode": _form.app.content,
- "container": _form.app.content,
- "buttonList": [
- {
- "text": MWF.LP.process.button.ok,
- "action": function () {
- //if (callback) callback(_self.view.selectedItems);
- if (callback) callback(_self.statement.getData());
- this.close();
- }
- },
- {
- "text": MWF.LP.process.button.cancel,
- "action": function () { this.close(); }
- }
- ]
- });
- dlg.show();
- if (layout.mobile) {
- var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
- var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
- if (backAction) backAction.addEvent("click", function (e) {
- dlg.close();
- }.bind(this));
- if (okAction) okAction.addEvent("click", function (e) {
- //if (callback) callback(this.view.selectedItems);
- if (callback) callback(this.statement.getData());
- dlg.close();
- }.bind(this));
- }
- MWF.xDesktop.requireApp("query.Query", "Statement", function () {
- this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
- }.bind(this));
- }.bind(this));
- }
- }
- };
- this.importer = {
- "upload": function (options, callback, async) {
- MWF.xDesktop.requireApp("query.Query", "Importer", function () {
- var importer = new MWF.xApplication.query.Query.Importer(_form.app.content, options, {}, _form.app, _form.Macro);
- importer.addEvent("afterImport", function (data) {
- if(callback)callback(data);
- });
- importer.load();
- }.bind(this));
- },
- "downloadTemplate": function(options, fileName, callback){
- MWF.xDesktop.requireApp("query.Query", "Importer", function () {
- var importer = new MWF.xApplication.query.Query.Importer(_form.app.content, options, {}, _form.app, _form.Macro);
- importer.downloadTemplate(fileName, callback);
- }.bind(this));
- }
- };
- //var lookupAction = null;
- //var getLookupAction = function(callback){
- // if (!lookupAction){
- // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
- // lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
- // lookupAction.getActions = function(actionCallback){
- // this.actions = {
- // "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
- // "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
- // };
- // if (actionCallback) actionCallback();
- // }
- // if (callback) callback();
- // }.bind(this));
- // }else{
- // if (callback) callback();
- // }
- //};
- //
- //this.view = {
- // "lookup": function(view, callback){
- // getLookupAction(function(){
- // lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
- // var data = {
- // "grid": json.data.grid,
- // "groupGrid": json.data.groupGrid
- // };
- // if (callback) callback(data);
- // }.bind(this)});
- // }.bind(this));
- // },
- // "select": function(view, callback, options){
- // if (view.view){
- // var viewJson = {
- // "application": view.application || "",
- // "viewName": view.view || "",
- // "isTitle": view.isTitle || "yes",
- // "select": view.select || "multi",
- // "title": view.title || "Select View"
- // };
- // if (!options) options = {};
- // var width = options.width || "700";
- // var height = options.height || "400";
- //
- // if (layout.mobile){
- // var size = document.body.getSize();
- // width = size.x;
- // height = size.y;
- // options.style = "viewmobile";
- // }
- // width = width.toInt();
- // height = height.toInt();
- //
- // var size = _form.app.content.getSize();
- // var x = (size.x-width)/2;
- // var y = (size.y-height)/2;
- // if (x<0) x = 0;
- // if (y<0) y = 0;
- // if (layout.mobile){
- // x = 20;
- // y = 0;
- // }
- //
- // var _self = this;
- // MWF.require("MWF.xDesktop.Dialog", function(){
- // var dlg = new MWF.xDesktop.Dialog({
- // "title": options.title || "select View",
- // "style": options.style || "view",
- // "top": y,
- // "left": x-20,
- // "fromTop":y,
- // "fromLeft": x-20,
- // "width": width,
- // "height": height,
- // "html": "<div style='height: 100%;'></div>",
- // "maskNode": _form.app.content,
- // "container": _form.app.content,
- // "buttonList": [
- // {
- // "text": MWF.LP.process.button.ok,
- // "action": function(){
- // //if (callback) callback(_self.view.selectedItems);
- // if (callback) callback(_self.view.getData());
- // this.close();
- // }
- // },
- // {
- // "text": MWF.LP.process.button.cancel,
- // "action": function(){this.close();}
- // }
- // ]
- // });
- // dlg.show();
- // if (layout.mobile){
- // var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
- // var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
- // if (backAction) backAction.addEvent("click", function(e){
- // dlg.close();
- // }.bind(this));
- // if (okAction) okAction.addEvent("click", function(e){
- // //if (callback) callback(this.view.selectedItems);
- // if (callback) callback(this.view.getData());
- // dlg.close();
- // }.bind(this));
- // }
- //
- // // MWF.xDesktop.requireApp("cms.Xform", "widget.View", function(){
- // // this.view = new MWF.xApplication.cms.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
- // // }.bind(this));
- // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
- // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
- // }.bind(this));
- // }.bind(this));
- // }
- // }
- //};
- //include 引用脚本
- //optionsOrName : {
- // type : "", 默认为cms, 可以为 portal process cms
- // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
- // name : "" // 脚本名称/别名/id
- //}
- //或者name: "" // 脚本名称/别名/id
- // if( !window.includedScripts ){
- // var includedScripts = window.includedScripts = [];
- // }else{
- // var includedScripts = window.includedScripts;
- // }
- var _getScriptAction = function ( type ){
- var scriptAction;
- switch (type) {
- case "portal" :
- if (this.scriptActionPortal) {
- scriptAction = this.scriptActionPortal;
- } else {
- MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
- scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
- }
- break;
- case "process" :
- if (this.scriptActionProcess) {
- scriptAction = this.scriptActionProcess;
- } else {
- MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
- scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
- }
- break;
- case "cms" :
- if (this.scriptActionCMS) {
- scriptAction = this.scriptActionCMS;
- } else {
- MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
- scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
- }
- break;
- case "service" :
- if (this.scriptActionService) {
- scriptAction = this.scriptActionService;
- } else {
- MWF.require("MWF.xScript.Actions.ServiceScriptActions", null, false);
- scriptAction = this.scriptActionService = new MWF.xScript.Actions.ServiceScriptActions();
- }
- break;
- }
- return scriptAction;
- }
- //缓存名称、别名、id
- var _parseScriptImportList = function (json, type){
- var includedScripts = [];
- var importedList = json.data.importedList || [];
- importedList.each(function (flag) {
- if (type === "portal") {
- includedScripts.push(type + "-" + json.data.portal + "-" + flag);
- if (json.data.portalName) includedScripts.push(type + "-" + json.data.portalName + "-" + flag);
- if (json.data.portalAlias) includedScripts.push(type + "-" + json.data.portalAlias + "-" + flag);
- } else if (type === "cms") {
- includedScripts.push(type + "-" + json.data.appId + "-" + flag);
- if (json.data.appName) includedScripts.push(type + "-" + json.data.appName + "-" + flag);
- if (json.data.appAlias) includedScripts.push(type + "-" + json.data.appAlias + "-" + flag);
- } else if (type === "process") {
- includedScripts.push(type + "-" + json.data.application + "-" + flag);
- if (json.data.appName) includedScripts.push(type + "-" + json.data.appName + "-" + flag);
- if (json.data.appAlias) includedScripts.push(type + "-" + json.data.appAlias + "-" + flag);
- }else if (type === "service") {
- includedScripts.push(type + "-" + flag);
- }
- });
- return includedScripts.concat(importedList);
- }
- var includedScripts = [];
- var _includeSingle = function( optionsOrName , callback , async){
- var options = optionsOrName;
- if( typeOf( options ) === "string" ){
- options = { name : options };
- }
- var name = options.name;
- var type;
- if( options.type === "service" ){
- type = options.type;
- }else{
- type = ( options.type && options.application ) ? options.type : "cms";
- }
- var application = options.application || _form.json.application;
- var key = type +"-" + application + "-" + name;
- if( type === "service" ){
- key = type + "-" + name;
- }
- //js 加载过就不重新加载了
- if (includedScripts.indexOf( key )> -1){
- if (callback) callback.apply(this);
- return;
- }
- var successCallback = function(json){
- if (json.data){
- includedScripts.push( key );
- includedScripts = includedScripts.concat( _parseScriptImportList(json, type) );
- MWF.CMSMacro.exec(json.data.text, this);
- if (callback) callback.apply(this);
- }else{
- if (callback) callback.apply(this);
- }
- }.bind(this);
- if (( options.enableAnonymous || options.anonymous ) && type === "cms") {
- o2.Actions.load("x_cms_assemble_control").ScriptAnonymousAction.getWithAppWithName(application, name, successCallback, null, !!async);
- } else {
- var scriptAction = _getScriptAction.call(this, type);
- if( type === "service" ){
- scriptAction.getScriptByName(name, includedScripts, successCallback, null, !!async);
- }else{
- scriptAction.getScriptByName(application, name, includedScripts, successCallback, null, !!async);
- }
- }
- };
- this.include = function( optionsOrName , callback, async){
- if (o2.typeOf(optionsOrName)==="array"){
- if (!!async){
- var count = optionsOrName.length;
- var loaded = 0;
- optionsOrName.each(function(option){
- _includeSingle.apply(this, [option, function(){
- loaded++;
- if (loaded>=count) if (callback) callback.apply(this);
- }.bind(this), true]);
- }.bind(this));
- }else{
- optionsOrName.each(function(option){
- _includeSingle.apply(this, [option]);
- }.bind(this));
- if (callback) callback.apply(this);
- }
- }else{
- _includeSingle.apply(this, [optionsOrName , callback, async])
- }
- };
- var includedSourceMap = {};
- var _includeSource = function (optionsOrName, callback, async, fileType) {
- var options = typeOf(optionsOrName) === "string" ? {name: optionsOrName} : optionsOrName;
- var name = options.name;
- var type = options.type === "service" ? options.type : ((options.type && options.application) ? options.type : "cms");
- var application = options.application || _form.json.application;
- var key = type === "service" ? (type + "-" + name) : (type + "-" + application + "-" + name);
- var data, result;
- if( includedSourceMap[key] ){
- data = includedSourceMap[key];
- if(callback)callback( data.text );
- return !!async ? Promise.resolve( data.text ) : data.text;
- }
- var successCallback = function (json) {
- if (json.data) {
- var includeds = [key];
- includeds = includeds.concat( _parseScriptImportList(json, type) );
- includeds.each(function(k){
- includedSourceMap[k] = json.data;
- })
- result = json.data.text;
- if( fileType === 'json' ){
- result = JSON.parse(result);
- }
- if (callback) callback.call(this, result);
- } else {
- result = '';
- if (callback) callback.call(this, '');
- }
- return result;
- }.bind(this);
- var p;
- if (( options.enableAnonymous || options.anonymous ) && type === "cms") {
- p = o2.Actions.load("x_cms_assemble_control").ScriptAnonymousAction.getWithAppWithName(application, name, !!async ? null : successCallback, null, !!async);
- } else {
- var scriptAction = _getScriptAction.call(this, type);
- if( type === "service" ){
- p = scriptAction.getScriptByName(name, includedScripts, successCallback, !!async ? null : successCallback, null, !!async);
- }else{
- p = scriptAction.getScriptByName(application, name, includedScripts, !!async ? null : successCallback, null, !!async);
- }
- }
- return !!async ? p.then( successCallback ) : result;
- };
- this.includeHtml = function (optionsOrName, callback, async){
- return _includeSource.apply(this, [optionsOrName, callback, async!==false, 'html'])
- };
- this.includeJson = function (optionsOrName, callback, async){
- return _includeSource.apply(this, [optionsOrName, callback, async!==false, 'json'])
- };
- this.includeCss = function (optionsOrName, callback, async){
- return _includeSource.apply(this, [optionsOrName, callback, async!==false, 'css']);
- };
- //var includedScripts = [];
- //this.include = function(name, callback){
- // if (includedScripts.indexOf(name)==-1){
- // if (!this.scriptAction){
- // MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
- // this.scriptAction = new MWF.xScript.Actions.CMSScriptActions();
- // }
- // this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
- // includedScripts = includedScripts.concat(json.data.importedList);
- // MWF.CMSMacro.exec(json.data.text, this);
- // if (callback) callback.apply(this);
- // }.bind(this), null, false);
- // }else{
- // if (callback) callback.apply(this);
- // }
- //}.bind(this);
- this.define = function(name, fun, overwrite){
- var over = true;
- if (overwrite===false) over = false;
- var o = {};
- o[name] = {"value": fun, "configurable": over};
- MWF.defineProperties(this, o);
- }.bind(this);
- this.exec = function(text, bind, arg=null, throwError=true){
- const b = bind || globalThis;
- const p = (arg) ? Object.values(arg) : [];
- const k = (arg) ? Object.keys(arg).join(',') : '';
- try {
- return Function('return function('+k+'){' + text + '}')().apply(b, p);
- }catch(e){
- if (throwError) throw e;
- console.error(e);
- return '';
- }
- }
- //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
- //可在调用前执行 var resolve = this.wait();
- //在异步调用结束后 执行 resolve.cb();
- //目前只有表单的queryload事件支持此方法。
- this.wait = function(){
- resolve = {};
- var setResolve = function(callback){
- resolve.cb = callback;
- }.bind(this);
- this.target.event_resolve = setResolve;
- return resolve;
- };
- //和this.wait配合使用,
- //如果没有异步,则resolve.cb方法不存在,
- //所以在回调中中使用this.goon();使表单继续加载
- this.goon = function(){
- this.target.event_resolve = null;
- };
- //仅前台对象-----------------------------------------
- //form
- this.form = {
- "getInfor": function(){return ev.formInfor;},
- "infor": ev.formInfor,
- "getApp": function(){return _form.app;},
- "app": _form.app,
- "node": function(){return _form.node;},
- // "readonly": _form.options.readonly,
- "get": function(name,subformName ){
- if( !_form.all )return null;
- if( subformName ){
- if( _form.all[subformName +"_"+ name] )return _form.all[subformName +"_"+ name];
- return _form.all[name];
- }else{
- return _form.all[name];
- }
- // return (_form.all) ? _form.all[name] : null;
- },
- "getField": function(name){return _forms[name];},
- "getAction": function(){return _form.documentAction},
- "getData": function(){return new MWF.xScript.CMSJSONData(_form.getData());},
- "save": function(callback){
- _form.saveDocument(callback);
- },
- "close": function(){_form.closeDocument();},
- /**
- * @summary 根据表单中所有组件的校验设置和表单的“发布校验”脚本进行校验。<b>(仅内容管理表单中可用)</b>
- * @method verifyPublish
- * @static
- * @o2syntax
- * this.form.verifyPublish()
- * @example
- * if( !this.form.verifyPublish() ){
- * return false;
- * }
- * @return {Boolean} 是否通过校验
- */
- "verifyPublish": function(isSave){
- return !(!_form.formValidation("publish") || !_form[isSave ? 'formSaveValidation' : 'formPublishValidation']());
- },
- /**发布当前文档。<b>(仅内容管理表单中可用)</b>
- * @method publish
- * @memberOf module:form
- * @param {Function} callback - 发布后的回调方法,如果接收的参数<b>为空</b>表示校验未通过,如果参数<b>不为空</b>为发布后的回调
- * @o2syntax
- * this.form.publish( callback );
- * @sample
- * this.form.publish( function(json){
- * if( !json ){
- * //校验未通过
- * }else{
- * //校验通过,json.data.id 为文档id
- * }
- * });
- */
- "publish": function(callback){
- _form.publishDocument(callback)
- },
- //"archive": function(option){
- // _form.archiveDocument()
- //},
- //"redraft": function(option){
- // _form.redraftDocument()
- //},
- "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
- // var p = MWF.getCenter({"x": width, "y": height});
- // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
- // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
- if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
- var p = MWF.getCenter({"x": width, "y": height});
- e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
- _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
- }else{
- e = (arguments.length>1) ? arguments[1] : null;
- title = (arguments.length>2) ? arguments[2] : null;
- text = (arguments.length>3) ? arguments[3] : null;
- width = (arguments.length>4) ? arguments[4] : null;
- height = (arguments.length>5) ? arguments[5] : null;
- ok = (arguments.length>6) ? arguments[6] : null;
- cancel = (arguments.length>7) ? arguments[7] : null;
- callback = (arguments.length>8) ? arguments[8] : null;
- mask = (arguments.length>9) ? arguments[9] : null;
- style = (arguments.length>10) ? arguments[10] : null;
- _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
- }
- },
- //"confirm": function(type, e, title, text, width, height, ok, cancel, callback){
- // _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
- //},
- "alert": function(type, title, text, width, height){
- _form.alert(type, title, text, width, height);
- },
- "notice": function(content, type, target, where, offset, option){
- _form.notice(content, type, target, where, offset, option);
- },
- "dialog": function ( options ) {
- return _form.dialog( options );
- },
- "selectOrg": function ( container, options, delayLoad) {
- if( !container )container = _form.app.content;
- return new MWF.O2Selector(container, options, delayLoad);
- },
- "addEvent": function(e, f){_form.addEvent(e, f);},
- "openWork": function(id, completedId, title, options){
- var op = options || {};
- op.workId = id;
- op.workCompletedId = completedId;
- op.docTitle = title;
- op.appId = "process.Work"+(op.workId || op.workCompletedId);
- return layout.desktop.openApplication(this.event, "process.Work", op);
- },
- "openJob": function(id, choice, options, callback){
- var workData = null, handel;
- o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
- if (json.data) workData = json.data;
- }.bind(this), null, false);
- if( !layout.inBrowser && o2.typeOf(callback) === "function" ){
- if( !options )options = {};
- var queryLoad = options.onQueryLoad;
- options.onQueryLoad = function () {
- if( o2.typeOf(queryLoad) === "function" )queryLoad.call(this);
- callback(this);
- }
- }
- runCallback = function ( handel ) {
- if( o2.typeOf(callback) === "function" ) {
- if (layout.inBrowser) {
- callback(handel);
- } else if (options && options.appId) {
- if (layout.desktop && layout.desktop.apps && layout.desktop.apps[options.appId]) {
- callback(layout.desktop.apps[options.appId], true);
- }else{
- callback(handel, false);
- }
- }else{
- callback(handel, false);
- }
- }
- };
- if (workData){
- var len = workData.workList.length + workData.workCompletedList.length;
- if (len){
- if (len>1 && choice){
- var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
- workData.workList.each(function(work){
- var workNode = new Element("div", {
- "styles": {
- "background": "#ffffff",
- "border-radius": "10px",
- "clear": "both",
- "margin-bottom": "10px",
- "height": "40px",
- "padding": "10px 10px"
- }
- }).inject(node);
- var html = "<div style='height: 40px; width: 40px; float: left; background: url(../x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
- "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
- "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
- "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
- "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
- "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
- workNode.set("html", html);
- var action = workNode.getElement(".MWFAction");
- action.store("work", work);
- action.addEvent("click", function(e){
- var work = e.target.retrieve("work");
- if (work){
- handel = this.openWork(work.id, null, work.title, options);
- runCallback( handel );
- }
- dlg.close();
- }.bind(this));
- }.bind(this));
- workData.workCompletedList.each(function(work){
- var workNode = new Element("div", {
- "styles": {
- "background": "#ffffff",
- "border-radius": "10px",
- "clear": "both",
- "margin-bottom": "10px",
- "height": "40px",
- "padding": "10px 10px"
- }
- }).inject(node);
- var html = "<div style='height: 40px; width: 40px; float: left; background: url(../x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
- "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
- "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
- "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
- "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
- workNode.set("html", html);
- var action = workNode.getElement(".MWFAction");
- action.store("work", work);
- action.addEvent("click", function(e){
- var work = e.target.retrieve("work");
- if (work){
- handel = this.openWork(null, work.id, work.title, options);
- runCallback( handel );
- }
- dlg.close();
- }.bind(this));
- }.bind(this));
- var height = node.getSize().y+20;
- if (height>600) height = 600;
- var dlg = o2.DL.open({
- "title": o2.LP.widget.choiceWork,
- "style" : "user",
- "isResize": false,
- "content": node,
- "buttonList": [
- {
- "type" : "cancel",
- "text": o2.LP.widget.close,
- "action": function(){dlg.close();}
- }
- ]
- });
- }else{
- if (workData.workList.length){
- var work = workData.workList[0];
- handel = this.openWork(work.id, null, work.title, options);
- runCallback( handel );
- return handel;
- }else{
- var work = workData.workCompletedList[0];
- handel = this.openWork(null, work.id, work.title, options);
- runCallback( handel );
- return handel;
- }
- }
- }else{
- runCallback(new Error("Can't open this Job", {
- cause: workData
- }));
- }
- }else{
- runCallback(new Error("Can't open this Job", {
- cause: workData
- }));
- }
- },
- "openDocument": function(id, title, options){
- var op = options || {};
- op.documentId = id;
- op.docTitle = title || "";
- op.appId = (op.appId) || ("cms.Document"+id);
- if( op.onPostPublish ){
- op.postPublish = op.onPostPublish;
- delete op.onPostPublish;
- }
- if( op.onAfterPublish ){
- op.afterPublish = op.onAfterPublish;
- delete op.onAfterPublish;
- }
- if( op.onAfterSave ){
- op.afterSave = op.onAfterSave;
- delete op.onAfterSave;
- }
- if( op.onBeforeClose ){
- op.beforeClose = op.onBeforeClose;
- delete op.onBeforeClose;
- }
- if( op.onPostDelete ){
- op.postDelete = op.onPostDelete;
- delete op.onPostDelete;
- }
- return layout.desktop.openApplication(this.event, "cms.Document", op);
- },
- "openPortal": function (name, page, par) {
- var action = MWF.Actions.get("x_portal_assemble_surface");
- action.getApplication(name, function (json) {
- if (json.data) {
- if (page) {
- action.getPageByName(page, json.data.id, function (pageJson) {
- var pageId = (pageJson.data) ? pageJson.data.id : "";
- layout.desktop.openApplication(null, "portal.Portal", {
- "portalId": json.data.id,
- "pageId": pageId,
- "parameters": par,
- "appId": (par && par.appId) || ("portal.Portal" + json.data.id + pageId)
- })
- });
- } else {
- layout.desktop.openApplication(null, "portal.Portal", {
- "portalId": json.data.id,
- "parameters": par,
- "appId": (par && par.appId) || ("portal.Portal" + json.data.id)
- })
- }
- }
- });
- },
- "openCMS": function(name){
- var action = MWF.Actions.get("x_cms_assemble_control");
- action.getColumn(name, function(json){
- if (json.data){
- layout.desktop.openApplication(null, "cms.Module", {
- "columnId": json.data.id,
- "appId": "cms.Module"+json.data.id
- });
- }
- });
- },
- "openProcess": function(name){
- var action = MWF.Actions.get("x_processplatform_assemble_surface");
- action.getApplication(name, function(json){
- if (json.data){
- layout.desktop.openApplication(null, "process.Application", {
- "id": json.data.id,
- "appId": "process.Application"+json.data.id
- });
- }
- });
- },
- "openApplication":function(name, options, status){
- return layout.desktop.openApplication(null, name, options, status);
- },
- "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle, restrictToColumn) {
- var column = columnOrOptions;
- var onAfterPublish, onPostPublish;
- if (typeOf(columnOrOptions) == "object") {
- column = columnOrOptions.column;
- category = columnOrOptions.category;
- data = columnOrOptions.data;
- identity = columnOrOptions.identity;
- callback = columnOrOptions.callback;
- target = columnOrOptions.target;
- latest = columnOrOptions.latest;
- selectColumnEnable = columnOrOptions.selectColumnEnable;
- ignoreTitle = columnOrOptions.ignoreTitle;
- restrictToColumn = columnOrOptions.restrictToColumn;
- onAfterPublish = columnOrOptions.onAfterPublish;
- onPostPublish = columnOrOptions.onPostPublish;
- }
- if (target) {
- if (layout.app && layout.app.inBrowser) {
- layout.app.content.empty();
- layout.app = null;
- }
- }
- MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
- var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
- "documentData": data,
- "identity": identity,
- "ignoreTitle": ignoreTitle === true,
- "ignoreDrafted": latest === false,
- "selectColumnEnable": !category || selectColumnEnable === true,
- "restrictToColumn": restrictToColumn === true || (!!category && selectColumnEnable !== true),
- "categoryFlag": category, //category id or name
- "columnFlag": column, //column id or name,
- "onStarted": function (documentId, data, windowHandle) {
- if (callback) callback(documentId, data, windowHandle);
- },
- "onPostPublish": function () {
- if(onPostPublish)onPostPublish();
- },
- "onAfterPublish": function () {
- if(onAfterPublish)onAfterPublish();
- }
- });
- starter.load();
- })
- },
- "startProcess": function(app, process, data, identity, callback, target, latest, afterCreated, skipDraftCheck){
- if (arguments.length>2){
- for (var i=2; i<arguments.length; i++){
- if (typeOf(arguments[i])=="boolean"){
- target = arguments[i];
- break;
- }
- }
- }
- if (target){
- if (layout.app && layout.app.inBrowser){
- //layout.app.content.empty();
- layout.app.$openWithSelf = true;
- }
- }
- if (!app || !process){
- var cmpt = this.getApp();
- o2.requireApp([["process.TaskCenter", "lp."+o2.language], ["process.TaskCenter", ""]],"", function(){
- var obj = {
- "lp": o2.xApplication.process.TaskCenter.LP,
- "content": cmpt.content,
- "addEvent": function(type, fun){
- cmpt.addEvent(type, fun);
- },
- "getAction": function (callback) {
- if (!this.action) {
- this.action = o2.Actions.get("x_processplatform_assemble_surface");
- if (callback) callback();
- } else {
- if (callback) callback();
- }
- },
- "desktop": layout.desktop,
- "refreshAll": function(){},
- "notice": cmpt.notice,
- }
- o2.JSON.get("../x_component_process_TaskCenter/$Main/default/css.wcss", function(data){
- obj.css = data;
- }, false);
- if (!cmpt.processStarter) cmpt.processStarter = new o2.xApplication.process.TaskCenter.Starter(obj);
- cmpt.processStarter.load({
- "appFlag": app
- });
- }, true, true);
- return "";
- }
- MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", null, false);
- var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
- if (json.data){
- var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
- "workData": data,
- "identity": identity,
- "latest": latest,
- "skipDraftCheck": skipDraftCheck,
- "onStarted": function(data, title, processName){
- var application;
- if (data.work){
- var work = data.work;
- var options = {
- "draft": work,
- "draftData":data.data||{},
- "appId": "process.Work"+(new o2.widget.UUID).toString(),
- "desktopReload": false
- };
- if( !layout.inBrowser && afterCreated )options.onPostLoadForm = afterCreated;
- application = layout.desktop.openApplication(null, "process.Work", options);
- }else{
- var currentTask = [];
- data.each(function(work){
- if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
- }.bind(this));
- if (currentTask.length==1){
- var options = {"workId": currentTask[0], "appId": currentTask[0]};
- if( !layout.inBrowser && afterCreated )options.onPostLoadForm = afterCreated;
- application =layout.desktop.openApplication(null, "process.Work", options);
- }else{}
- }
- // var currentTask = [];
- // data.each(function(work){
- // if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
- // }.bind(this));
- //
- // if (currentTask.length==1){
- // var options = {"workId": currentTask[0], "appId": currentTask[0]};
- // layout.desktop.openApplication(null, "process.Work", options);
- // }else{}
- if (callback) callback(data);
- if(layout.inBrowser && afterCreated){
- afterCreated(application)
- }
- }.bind(this)
- });
- starter.load();
- }
- });
- }
- };
- Object.defineProperty(this.form, "readonly", {
- get: function(){ return !!_form.options.readonly; }
- });
- this.target = ev.target;
- this.event = ev.event;
- this.status = ev.status;
- this.session = layout.desktop.session;
- this.Actions = o2.Actions;
- this.query = function(option){
- // options = {
- // "name": "statementName",
- // "data": "json data",
- // "firstResult": 1,
- // "maxResults": 100,
- // "success": function(){},
- // "error": function(){},
- // "async": true or false, default is true
- // }
- if (option){
- var json = (option.data) || {};
- if (option.firstResult) json.firstResult = option.firstResult.toInt();
- if (option.maxResults) json.maxResults = option.maxResults.toInt();
- o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
- }
- };
- this.Table = MWF.xScript.createTable();
- //兼容流程拷贝过来的表单
- var _fitWorkContextList = function(callback, error){
- var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
- var list = [];
- if (cb) cb(list);
- return [];
- };
- this.workContext = {
- "getWork": function(){
- return (ev.data || {}).$work || {} ;
- },
- "getActivity": function(){return {}},
- "getTask": function(){return {}},
- "getTaskList": function(callback, error){
- return _fitWorkContextList(callback, error)
- },
- "getTaskListByJob": function(callback, error){
- return _fitWorkContextList(callback, error)
- },
- "getTaskCompletedList": function(callback, error){
- return _fitWorkContextList(callback, error)
- },
- "getTaskCompletedListByJob": function(callback, error){
- return _fitWorkContextList(callback, error)
- },
- "getReadList": function(callback, error){
- return _fitWorkContextList(callback, error)
- },
- "getReadListByJob": function(callback, error){
- return _fitWorkContextList(callback, error)
- },
- "getReadCompletedList": function(callback, error){
- return _fitWorkContextList(callback, error)
- },
- "getReadCompletedListByJob": function(callback, error){
- return _fitWorkContextList(callback, error)
- },
- "getReviewList": function(callback, error){
- return _fitWorkContextList(callback, error)
- },
- "getReviewListByJob": this.getReviewList,
- "getJobTaskList": this.getTaskListByJob,
- "getJobReadList": this.getReadListByJob,
- "getJobTaskCompletedList": this.getTaskCompletedListByJob,
- "getJobReadCompletedList": this.getReadCompletedListByJob,
- "getJobReviewList": this.getReviewList,
- "getControl": function(){return ev.control;},
- "getWorkLogList": function(){return [];},
- "getRecordList": function(){return [];},
- "getAttachmentList": function(callback, error){
- var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
- if(cb)cb( ev.attachmentList );
- return ev.attachmentList;
- },
- "getRouteList": function(){return [];},
- "getInquiredRouteList": function(){return null;}
- };
- this.workContent = this.workContext;
- };
- if( !MWF.xScript.createTable )MWF.xScript.createTable = function(){
- return function(name){
- this.name = name;
- this.action = o2.Actions.load("x_query_assemble_surface").TableAction;
- this.listRowNext = function(id, count, success, error, async){
- return this.action.listRowNext(this.name, id, count, success, error, async);
- };
- this.listRowPrev = function(id, count, success, error, async){
- return this.action.listRowPrev(this.name, id, count, success, error, async);
- };
- this.listRowSelect = function(where, orderBy, size, success, error, async){
- return this.action.listRowSelect(this.name, {"where": where, "orderBy": orderBy, "size": size || ""}, success, error, async);
- };
- this.listRowSelectWhere = function(where, success, error, async){
- return this.action.listRowSelectWhere(this.name, where, success, error, async);
- };
- this.rowCountWhere = function(where, success, error, async){
- return this.action.rowCountWhere(this.name, where, success, error, async);
- };
- this.deleteRow = function(id, success, error, async){
- return this.action.rowDelete(this.name, id, success, error, async);
- };
- this.deleteAllRow = function(success, error, async){
- return this.action.rowDeleteAll(this.name, success, error, async);
- };
- this.getRow = function(id, success, error, async){
- return this.action.rowGet(this.name, id, success, error, async);
- };
- this.insertRow = function(data, success, error, async){
- return this.action.rowInsert(this.name, data, success, error, async);
- };
- this.addRow = function(data, success, error, async){
- return this.action.rowInsertOne(this.name, data, success, error, async);
- };
- this.updateRow = function(id, data, success, error, async){
- return this.action.rowUpdate(this.name, id, data, success, error, async);
- };
- this.partUpdateRow = function(id, data, success, error, async){
- return this.action.rowPartUpdate(this.name, id, data, success, error, async);
- };
- }
- };
- var getArrayJSONData = function(jData, p, _form){
- return new MWF.xScript.CMSJSONData(jData, function(data, key, _self){
- var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
- while (p && !_form.forms[p.getKey()]) p = p.getParent();
- //if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
- var k = (p) ? p.getKey() : "";
- if (k) if(_form.forms[k]) if(_form.forms[k].resetData) _form.forms[k].resetData();
- //if(p) if(p.getKey()) if(_forms[p.getKey()]) if(_forms[p.getKey()].render) _forms[p.getKey()].render();
- }, "", p, _form);
- };
- MWF.xScript.CMSJSONData = function(data, callback, key, parent, _form){
- var getter = function(data, callback, k, _self){
- return function(){
- var t = typeOf(data[k]);
- if (["array","object"].indexOf(t)===-1){
- return data[k]
- }else{
- if (t==="array"){
- if (window.Proxy){
- var arr = new Proxy(data[k], {
- get: function(o, k){
- return (o2.typeOf(o[k])==="object") ? getArrayJSONData(o[k], _self, _form) : o[k];
- },
- set: function(o, k, v){
- o[k] = v;
- if (callback) callback(o, k, _self);
- return true;
- }
- });
- return arr;
- }else{
- var arr =[];
- data[k].forEach(function(d, i){
- arr.push((o2.typeOf(d)==="object") ? getArrayJSONData(d, _self, _form) : d);
- });
- return arr;
- }
- // var arr =[];
- // data[k].forEach(function(d, i){
- // arr.push((o2.typeOf(d)==="object") ? getArrayJSONData(d, _self, _form) : d);
- // });
- // return arr;
- //return data[k];
- }else{
- return new MWF.xScript.CMSJSONData(data[k], callback, k, _self, _form);
- }
- }
- };
- };
- var setter = function(data, callback, k, _self){
- return function(v){
- data[k] = v;
- //debugger;
- //this.add(k, v, true);
- if (callback) callback(data, k, _self);
- }
- };
- var define = function(){
- var o = {};
- for (var k in data) o[k] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, k, this]),"set": setter.apply(this, [data, callback, k, this])};
- o["length"] = {"get": function(){return Object.keys(data).length;}};
- o["some"] = {"get": function(){return data.some;}};
- MWF.defineProperties(this, o);
- var methods = {
- "getKey": {"value": function(){ return key; }},
- "getParent": {"value": function(){ return parent; }},
- "toString": {"value": function() { return data.toString();}},
- "setSection": {"value": function(newKey, newValue){
- this.add(newKey, newValue, true);
- try {
- var path = [this.getKey()];
- p = this.getParent();
- while (p && p.getKey()){
- path.unshift(p.getKey());
- p = p.getParent();
- }
- if (path.length) _form.sectionListObj[path.join(".")] = newKey;
- }catch(e){
- }
- }},
- "add": {"value": function(newKey, newValue, overwrite, noreset){
- if( newKey.test(/^\d+$/) ){
- throw new Error("Field name '"+newKey+"' cannot contain only numbers" );
- }
- if (arguments.length<2 || newKey.indexOf("..")===-1){
- var flag = true;
- var type = typeOf(data);
- if (type==="array"){
- if (arguments.length<2){
- data.push(newKey);
- newValue = newKey;
- newKey = data.length-1;
- }else{
- if (!newKey && newKey!==0){
- data.push(newValue);
- newKey = data.length-1;
- }else{
- if (newKey>=data.length){
- data.push(newValue);
- newKey = data.length-1;
- }else{
- if (overwrite) data[newKey] = newValue;
- newValue = data[newKey];
- flag = false;
- }
- }
- }
- if (flag){
- var o = {};
- o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
- MWF.defineProperties(this, o);
- }
- if (!noreset) this[newKey] = newValue;
- }else if (type==="object"){
- if (!this.hasOwnProperty(newKey)){
- if (!data[newKey] || overwrite){
- data[newKey] = newValue;
- }
- newValue = data[newKey];
- if (flag){
- var o = {};
- o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
- MWF.defineProperties(this, o);
- }
- if (!noreset) this[newKey] = newValue;
- }else{
- if (!Object.getOwnPropertyDescriptor(this, newKey).get){
- var o = {};
- o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
- MWF.defineProperties(this, o);
- }
- if (overwrite){
- data[newKey] = newValue;
- if (!noreset) this[newKey] = newValue;
- }
- }
- }
- return this[newKey];
- }else{
- var keys = newKey.split("..");
- var kk = keys.shift();
- var d = this.add(kk, {}, false, true);
- if (keys.length) return d.add(keys.join(".."), newValue, overwrite, noreset);
- return d;
- }
- }},
- "check": {
- "value": function(kk, v){
- var value = typeOf( v ) === "null" ? "" : v;
- this.add(kk, value, false, true);
- }
- },
- "del": {"value": function(delKey){
- if (!this.hasOwnProperty(delKey)) return null;
- // delete data[delKey];
- // delete this[delKey];
- data[delKey] = "";
- this[delKey] = "";
- return this;
- }}
- };
- MWF.defineProperties(this, methods);
- };
- var type = typeOf(data);
- if (type==="object" || type==="array") define.apply(this);
- };
- // MWF.xScript.CMSJSONData = function(data, callback, key, parent){
- // var getter = function(data, callback, k, _self){
- // return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
- // };
- // var setter = function(data, callback, k, _self){
- // return function(v){
- // data[k] = v;
- // //debugger;
- // //this.add(k, v, true);
- // if (callback) callback(data, k, _self);
- // }
- // };
- // var define = function(){
- // var o = {};
- // for (var k in data) o[k] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, k, this]),"set": setter.apply(this, [data, callback, k, this])};
- // o["length"] = {"get": function(){return Object.keys(data).length;}};
- // o["some"] = {"get": function(){return data.some;}};
- // MWF.defineProperties(this, o);
- //
- // var methods = {
- // "getKey": {"value": function(){ return key; }},
- // "getParent": {"value": function(){ return parent; }},
- // "toString": {"value": function() { return data.toString();}},
- // "add": {"value": function(newKey, newValue, overwrite){
- // var flag = true;
- // var type = typeOf(data);
- // if (type==="array"){
- // if (arguments.length<2){
- // data.push(newKey);
- // newValue = newKey;
- // newKey = data.length-1;
- // }else{
- // if (!newKey && newKey!==0){
- // data.push(newValue);
- // newKey = data.length-1;
- // }else{
- // flag = false;
- // }
- // }
- // if (flag){
- // var o = {};
- // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
- // MWF.defineProperties(this, o);
- // }
- // this[newKey] = newValue;
- // }else if (type==="object"){
- // if (!this.hasOwnProperty(newKey)){
- // data[newKey] = newValue;
- //
- // if (flag){
- // var o = {};
- // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
- // MWF.defineProperties(this, o);
- // }
- // this[newKey] = newValue;
- // }else{
- // if (overwrite) this[newKey] = newValue;
- // }
- // }
- //
- // return this[newKey];
- // }},
- // "del": {"value": function(delKey){
- // if (!this.hasOwnProperty(delKey)) return null;
- // delete data[delKey];
- // delete this[delKey];
- // return this;
- // }}
- // };
- // MWF.defineProperties(this, methods);
- // };
- // var type = typeOf(data);
- // if (type==="object" || type==="array") define.apply(this);
- // };
- //MWF.xScript.CMSJSONData = function(data, callback, key, parent){
- // var getter = function(data, callback, k, _self){
- // return function(){return (["array","object"].indexOf(typeOf(data[k]))==-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
- // }
- // var setter = function(data, callback, k, _self){
- // return function(v){
- // data[k] = v;
- // if (callback) callback(data, k, _self);
- // }
- // }
- // var define = function(){
- // var o = {};
- // for (var k in data) o[k] = {
- // "configurable": true,
- // "get": getter.apply(this, [data, callback, k, this]),
- // "set": setter.apply(this, [data, callback, k, this])
- // };
- // o["length"] = {"get": function(){return Object.keys(data).length;}};
- // MWF.defineProperties(this, o);
- // this.getKey = function(){ return key; };
- // this.getParent = function(){ return parent; };
- // this.toString = function() { return data.toString();};
- // this.add = function(newKey, newValue){
- // var type = typeOf(data);
- // if (!this.hasOwnProperty(newKey)){
- // if (type=="array"){
- // data.push(newValue || {});
- // newKey = data.length-1;
- // }else{
- // data[newKey] = newValue || {};
- // }
- // var o = {};
- // o[newKey] = {"configurable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
- // MWF.defineProperties(this, o);
- // }
- // this[newKey] = newValue;
- // return this;
- // };
- // this.del = function(delKey){
- // if (!this.hasOwnProperty(delKey)) return null;
- // delete data[newKey];
- // delete this[newKey];
- // return this;
- // };
- // }
- // var type = typeOf(data);
- // if (type=="object" || type=="array") define.apply(this);
- //};
- //MWF.xScript.createCMSDict = function(application){
- // return function(name){
- // var applicationId = application;
- // this.name = name;
- // MWF.require("MWF.xScript.Actions.CMSDictActions", null, false);
- // var action = new MWF.xScript.Actions.CMSDictActions();
- //
- // this.get = function(path, success, failure){
- // var value = null;
- // if( path ){
- // var arr = path.split(/\./g);
- // var ar = arr.map(function(v){
- // return encodeURIComponent(v);
- // });
- // //var p = path.replace(/\./g, "/");
- // var p = ar.join("/");
- // action.getDict(applicationId, encodeURIComponent(this.name), p, function(json){
- // value = json.data;
- // if (success) success(json.data);
- // }, function(xhr, text, error){
- // if (failure) failure(xhr, text, error);
- // }, false);
- // }else{
- // action.getDictWhole(applicationId, encodeURIComponent(this.name), function(json){
- // value = json.data;
- // if (success) success(json.data);
- // }, function(xhr, text, error){
- // if (failure) failure(xhr, text, error);
- // }, false);
- // }
- // return value;
- // };
- //
- // this.set = function(path, value, success, failure){
- // var p = path.replace(/\./g, "/");
- // action.setDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
- // if (success) success(json.data);
- // }, function(xhr, text, error){
- // if (failure) failure(xhr, text, error);
- // });
- // };
- // this.add = function(path, value, success, failure){
- // var p = path.replace(/\./g, "/");
- // action.addDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
- // if (success) success(json.data);
- // }, function(xhr, text, error){
- // if (failure) failure(xhr, text, error);
- // });
- // };
- // this["delete"] = function(path, success, failure){
- // var p = path.replace(/\./g, "/");
- // action.deleteDict(applicationId, encodeURIComponent(this.name), p, function(json){
- // if (success) success(json.data);
- // }, function(xhr, text, error){
- // if (failure) failure(xhr, text, error);
- // });
- // };
- // this.destory = this["delete"];
- // }
- //};
- if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
- if( !MWF.xScript.addDictToCache )MWF.xScript.addDictToCache = function ( options, path, json ) {
- if( !path )path = "root";
- if( path.indexOf("root") !== 0 )path = "root." + path ;
- var type = options.appType || "process";
- var enableAnonymous = (options.enableAnonymous || options.anonymous) || false;
- var appFlagList = [];
- if( options.application )appFlagList.push( options.application );
- if( options.appId )appFlagList.push( options.appId );
- if( options.appName )appFlagList.push( options.appName );
- if( options.appAlias )appFlagList.push( options.appAlias );
- var dictFlagList = [];
- if( options.id )dictFlagList.push( options.id );
- if( options.name )dictFlagList.push( options.name );
- if( options.alias )dictFlagList.push( options.alias );
- var cache = {};
- cache[path] = json;
- for( var i=0; i<appFlagList.length; i++ ){
- for( var j=0; j<dictFlagList.length; j++ ){
- var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
- if( !MWF.xScript.dictLoaded[k] ){
- MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
- // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
- }else if( i===0 && j===0 ){
- MWF.xScript.setDictToCache( k, path ,json );
- var arr = path.split(/\./g);
- var p;
- var cache = MWF.xScript.dictLoaded[k];
- for( var l=0 ; l<arr.length; l++ ){
- p = l === 0 ? arr[0] : ( p + "." + arr[l] );
- if( cache[ p ] )break;
- }
- if( p ){
- var mathP = p+".";
- Object.keys( cache ).each( function( path, idx){
- if( path.indexOf( mathP ) === 0 )delete cache[path];
- })
- }
- }
- }
- }
- };
- if( !MWF.xScript.getMatchedDict )MWF.xScript.getMatchedDict = function(key, path){
- if( !path )path = "root";
- if( path.indexOf("root") !== 0 )path = "root." + path ;
- var arr = path.split(/\./g);
- if( MWF.xScript.dictLoaded[key] ){
- var dicts = MWF.xScript.dictLoaded[key];
- var list = Array.clone(arr);
- var p;
- var dict;
- for( var i=0 ; i<arr.length; i++ ){
- p = i === 0 ? arr[0] : ( p + "." + arr[i] );
- list.shift();
- if( dicts[ p ] ){
- dict = dicts[ p ];
- break;
- }
- }
- return {
- dict : dict,
- unmatchedPathList : list
- }
- }
- return {
- dict : null,
- unmatchedPathList : list
- }
- };
- if( !MWF.xScript.insertDictToCache )MWF.xScript.insertDictToCache = function(key, path, json){
- var p = path;
- if( !p )p = "root";
- if( p.indexOf("root") !== 0 )p = "root." + p ;
- if( MWF.xScript.dictLoaded[key] ){
- var matchedDict = MWF.xScript.getMatchedDict( key, path );
- var dict = matchedDict.dict;
- var list = matchedDict.unmatchedPathList;
- if( !dict ){
- MWF.xScript.dictLoaded[key][p] = json;
- }else if( !list || list.length === 0 ){
- MWF.xScript.dictLoaded[key][p] = json;
- }else{
- for( var j=0; j<list.length-1; j++ ){
- if( !dict[ list[j] ] ){
- dict[ list[j] ] = {};
- }
- dict = dict[ list[j] ];
- }
- var lastPath = list[list.length-1];
- if( !dict[lastPath] ){
- dict[lastPath] = json;
- }else if( typeOf( dict[lastPath] ) === "array" ){
- dict[lastPath].push( json );
- }
- }
- }else{
- MWF.xScript.dictLoaded[key] = {};
- MWF.xScript.dictLoaded[key][p] = json;
- }
- };
- if( !MWF.xScript.setDictToCache )MWF.xScript.setDictToCache = function(key, path, json){
- var p = path;
- if( !p )p = "root";
- if( p.indexOf("root") !== 0 )p = "root." + p ;
- if( MWF.xScript.dictLoaded[key] ){
- var matchedDict = MWF.xScript.getMatchedDict( key, path );
- var dict = matchedDict.dict;
- var list = matchedDict.unmatchedPathList;
- if( !dict ){
- MWF.xScript.dictLoaded[key][p] = json;
- }else if( !list || list.length === 0 ){
- MWF.xScript.dictLoaded[key][p] = json;
- }else{
- for( var j=0; j<list.length-1; j++ ){
- if( !dict[ list[j] ] ){
- dict[ list[j] ] = {};
- }
- dict = dict[ list[j] ];
- }
- dict[list[list.length-1]] = json;
- }
- }else{
- MWF.xScript.dictLoaded[key] = {};
- MWF.xScript.dictLoaded[key][p] = json;
- }
- };
- if( !MWF.xScript.getDictFromCache )MWF.xScript.getDictFromCache = function( key, path ){
- var matchedDict = MWF.xScript.getMatchedDict( key, path );
- var dict = matchedDict.dict;
- var list = matchedDict.unmatchedPathList;
- if( dict ){
- for( var j=0; j<list.length; j++ ){
- dict = dict[ list[j] ];
- if( !dict )return null;
- }
- return dict;
- }
- return null;
- };
- if( !MWF.xScript.deleteDictToCache )MWF.xScript.deleteDictToCache = function(key, path){
- var matchedDict = MWF.xScript.getMatchedDict( key, path );
- var dict = matchedDict.dict;
- var list = matchedDict.unmatchedPathList;
- if( dict){
- for( var j=0; j<list.length-1; j++ ){
- dict = dict[ list[j] ];
- if( !dict )return;
- }
- if( list.length ){
- delete dict[list[list.length-1]];
- }
- }
- };
- if( !MWF.xScript.createCMSDict )MWF.xScript.createCMSDict = function(application, appType){
- //optionsOrName : {
- // type : "", //默认为process, 可以为 process cms
- // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
- // name : "", // 数据字典名称/别名/id
- // anonymous : false //允许在未登录的情况下读取CMS的数据字典, 该参数名也可以是 enableAnonymous
- //}
- //或者name: "" // 数据字典名称/别名/id
- return function(optionsOrName){
- var options = optionsOrName;
- if( typeOf( options ) == "string" ){
- options = {
- name : options,
- type: appType,
- application: application
- };
- }
- var name = this.name = options.name;
- var type;
- if( options.type === "service"){
- type = options.type;
- }else{
- type = ( options.type && options.application ) ? options.type : "cms";
- }
- var applicationId = options.application || application;
- var enableAnonymous = ( options.enableAnonymous || options.anonymous ) || false;
- var opt = {
- "appType" : type,
- "name" : name,
- "appId" : applicationId,
- "enableAnonymous" : enableAnonymous
- };
- var key = name+type+applicationId+enableAnonymous;
- // if (!dictLoaded[key]) dictLoaded[key] = {};
- // this.dictData = dictLoaded[key];
- //MWF.require("MWF.xScript.Actions.DictActions", null, false);
- var action;
- if (type === "cms") {
- action = MWF.Actions.get("x_cms_assemble_control");
- } else if( type === "portal" ){
- action = MWF.Actions.get("x_portal_assemble_surface");
- }else if( type === "service" ){
- key = name+type+enableAnonymous;
- action = MWF.Actions.get("x_program_center");
- } else {
- action = MWF.Actions.get("x_processplatform_assemble_surface");
- }
- var encodePath = function( path ){
- var arr = path.split(/\./g);
- var ar = arr.map(function(v){
- return encodeURIComponent(v);
- });
- return ( type === "portal" || type === "service" ) ? ar.join(".") : ar.join("/");
- };
- this.get = function(path, success, failure, async, refresh){
- var value = null;
- if (success===true) async=true;
- if (failure===true) async=true;
- if (!refresh ){
- var data = MWF.xScript.getDictFromCache( key, path );
- if( data ){
- if (success && o2.typeOf(success)=="function") success( data );
- if( !!async ){
- return Promise.resolve( data );
- }else{
- return data;
- }
- }
- }
- // var cb = function(json){
- // value = json.data;
- // MWF.xScript.addDictToCache(opt, path, value);
- // if (success && o2.typeOf(success)=="function") value = success(json.data);
- // return value;
- // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
- var cb = function(json){
- value = json.data;
- MWF.xScript.addDictToCache(opt, path, value);
- if (success && o2.typeOf(success)=="function") value = success(json.data);
- return value;
- };
- var promise;
- if( type === "service" ){
- if (path){
- var p = encodePath( path );
- promise = action.getDictData(encodeURIComponent(this.name), p, cb, null, !!async, false);
- }else{
- promise = action.getDictRoot(this.name, cb, null, !!async, false);
- }
- }else{
- if (path){
- var p = encodePath( path );
- promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async, false);
- }else{
- promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async, false);
- }
- }
- return (!!async) ? promise : value;
- // if (path){
- // var p = encodePath( path );
- // //var p = path.replace(/\./g, "/");
- // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
- // value = json.data;
- // // this.dictData[path] = value;
- // MWF.xScript.addDictToCache(opt, path, value);
- // if (success) success(json.data);
- // }.bind(this), function(xhr, text, error){
- // if (failure) failure(xhr, text, error);
- // }, !!async);
- // }else{
- // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
- // value = json.data;
- // // this.dictData["root"] = value;
- // MWF.xScript.addDictToCache(opt, path, value);
- // if (success) success(json.data);
- // }.bind(this), function(xhr, text, error){
- // if (failure) failure(xhr, text, error);
- // }, !!async);
- // }
- //return value;
- };
- this.set = function(path, value, success, failure){
- var p = encodePath( path );
- //var p = path.replace(/\./g, "/");
- var successCallback = function(json){
- MWF.xScript.setDictToCache(key, path, value);
- if (success) return success(json.data);
- };
- var failureCallback = function(xhr, text, error){
- if (failure) return failure(xhr, text, error);
- };
- if( type === "service" ){
- return action.setDictData(encodeURIComponent(this.name), p, value, successCallback, failureCallback, false, false);
- }else{
- return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, successCallback, failureCallback, false, false);
- }
- };
- this.add = function(path, value, success, failure){
- var p = encodePath( path );
- //var p = path.replace(/\./g, "/");
- var successCallback = function(json){
- MWF.xScript.insertDictToCache(key, path, value);
- if (success) return success(json.data);
- };
- var failureCallback = function(xhr, text, error){
- if (failure) return failure(xhr, text, error);
- };
- if( type === "service" ) {
- return action.addDictData(encodeURIComponent(this.name), p, value, successCallback, failureCallback, false, false);
- }else{
- return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, successCallback, failureCallback, false, false);
- }
- };
- this["delete"] = function(path, success, failure){
- var p = encodePath( path );
- //var p = path.replace(/\./g, "/");
- var successCallback = function(json){
- MWF.xScript.deleteDictToCache(key, path);
- if (success) return success(json.data);
- };
- var failureCallback = function(xhr, text, error){
- if (failure) return failure(xhr, text, error);
- };
- if( type === "service" ) {
- return action.deleteDictData(encodeURIComponent(this.name), p, successCallback, failureCallback, false, false);
- }else{
- return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, successCallback, failureCallback, false, false);
- }
- };
- this.destory = this["delete"];
- }
- };
|