CMSEnvironment.js 140 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.CMSEnvironment = function(ev){
  3. var _data = ev.data;
  4. var _form = ev.form;
  5. var _forms = ev.forms;
  6. this.appType = "cms";
  7. this.library = COMMON;
  8. //this.library.version = "4.0";
  9. //data
  10. var getJSONData = function(jData){
  11. return new MWF.xScript.CMSJSONData(jData, function(data, key, _self){
  12. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  13. while (p && !_forms[p.getKey()]) p = p.getParent();
  14. var k = (p) ? p.getKey() : "";
  15. if (k) if(_forms[k]) if(_forms[k].resetData) _forms[k].resetData();
  16. }, "", null, _form);
  17. };
  18. this.setData = function(data){
  19. this.data = getJSONData(data);
  20. this.data.save = function(callback){
  21. _form.documentAction.saveData(function(json){if (callback) callback();}.bind(this), null, ev.document.id, data);
  22. }
  23. };
  24. this.setData(_data);
  25. //task
  26. //this.task = ev.task;
  27. //this.task.process = function(routeName, opinion, callback){
  28. // _form.submitWork(routeName, opinion, callback);
  29. //};
  30. //inquiredRouteList
  31. //this.inquiredRouteList = null;
  32. //workContext
  33. /**
  34. * 您可以通过documentContext获取内容管理实例相关的对象数据。
  35. * @module documentContext
  36. * @o2cn 内容管理实例
  37. * @o2category web
  38. * @o2range {CMS}
  39. * @o2ordernumber 30
  40. * @example
  41. * //您可以在内容管理表单中,通过this来获取当前实例的documentContext对象,如下:
  42. * var context = this.documentContext;
  43. */
  44. this.documentContext = {
  45. // * @o2ActionOut x_cms_assemble_control.WoDocument|ignoreNoDescr=true|example=Document
  46. /**
  47. * 获取当前内容管理实例的文档对象:document对象。
  48. * @method getDocument
  49. * @static
  50. * @return {Document} 文档对象.
  51. * <pre><code class='language-js'>{
  52. * "id": "3359aedd-c2d8-4d8c-b8b0-02507da1b3f4", //数据库主键,自动生成.
  53. * "summary": " ", //文档摘要
  54. * "title": "航天科工外部董事调研组到培训中心调研", //文档标题
  55. * "documentType": "信息", //文档类型,跟随分类类型,信息 | 数据
  56. * "appId": "c295f34c-9ce1-4122-b795-820267e32b68", //栏目ID
  57. * "appName": "通知公告", //栏目名称
  58. * "appAlias": " ", //栏目别名
  59. * "categoryId": "33fb19f0-0670-464d-875c-32fb86148f7a", //分类ID
  60. * "categoryName": "通知公告", //分类名称
  61. * "categoryAlias": "通知公告-通知公告", //分类别名
  62. * "form": "dddefed4-4411-4e4e-b982-cdd4cd083443", //绑定的表单模板ID
  63. * "formName": "通知公告编辑表单", //绑定的表单模板名称
  64. * "importBatchName": " ", //文件导入的批次号:一般是分类ID+时间缀
  65. * "readFormId": "d6f1f596-fcb7-4a87-baaf-7f6cdafe3cec", //绑定的阅读表单模板ID
  66. * "readFormName": "通知公告阅读表单", //绑定的阅读表单模板名称
  67. * "creatorPerson": "李义@liyi@P", //创建人,可能为空,如果由系统创建。
  68. * "creatorIdentity": "李义@469d1601-c4a5-46ae-b7bf-4da9af07b6fa@I", //创建人Identity,可能为空,如果由系统创建。
  69. * "creatorUnitName": "浙江兰德纵横@a706f5f0-4a3b-4785-8e1d-0a944bfad4eb@U", //创建人组织,可能为空,如果由系统创建。
  70. * "creatorTopUnitName": "浙江兰德纵横@a706f5f0-4a3b-4785-8e1d-0a944bfad4eb@U", //创建人顶层组织,可能为空,如果由系统创建。
  71. * "docStatus": "published", //文档状态: waitPublished | published | draft | checking | error
  72. * "description": " ", //说明备注,可以填写说明信息,如导入信息检验失败原因等
  73. * "viewCount": 1, //文档被查看次数
  74. * "commendCount": 1, //文档被赞次数
  75. * "commentCount": 1, //文档评论次数
  76. * "publishTime": "2018-01-04 14:17:16", //文档发布时间
  77. * "modifyTime": "2022-09-01 17:05:47", //文档修改时间
  78. * "isTop": true, //是否置顶
  79. * "hasIndexPic": true, //是否含有首页图片
  80. * "reviewed": true, //是否已经更新review信息.
  81. * "sequenceTitle": " ", //用于标题排序的sequence
  82. * "sequenceAppAlias": " ", //用于栏目别名排序的sequence
  83. * "sequenceCategoryAlias": " ", //用于分类别名排序的sequence
  84. * "sequenceCreatorPerson": " ", //用于创建者排序的sequence
  85. * "sequenceCreatorUnitName": " ", //用于创建者组织排序的sequence
  86. * "readPersonList": [
  87. * "张三@zhangsan@P"
  88. * "所有人"
  89. * ], //阅读人员
  90. * "readUnitList": [
  91. * ], //阅读组织
  92. * "readGroupList": [
  93. * ], //阅读群组
  94. * "authorPersonList": [
  95. * "张三@zhangsan@P"
  96. * ], //作者人员
  97. * "authorUnitList": [
  98. * ], //作者组织
  99. * "authorGroupList": [
  100. * ], //作者群组
  101. * "remindPersonList": [
  102. * " "
  103. * ], //发布提醒人员
  104. * "remindUnitList": [
  105. * " "
  106. * ], //发布提醒组织
  107. * "remindGroupList": [
  108. * " "
  109. * ], //发布提醒群组
  110. * "managerList": [
  111. * "张三@zhangsan@P"
  112. * ], //管理者
  113. * "pictureList": [
  114. * ], //首页图片列表
  115. * "distributeFactor": 1, //分布式存储标识位.
  116. * "createTime": "2022-09-01 17:05:47", //创建时间,自动生成,索引创建在约束中.
  117. * "updateTime": "2022-09-01 17:05:47", //修改时间,自动生成,索引创建在约束中.
  118. * "sequence": " ", //列表序号,由创建时间以及ID组成.在保存时自动生成,索引创建在约束中.
  119. * "stringValue01": "", //业务数据String值01.
  120. * "stringValue02": "", //业务数据String值02.
  121. * "stringValue03": "", //业务数据String值03.
  122. * "stringValue04": "", //业务数据String值04.
  123. * "stringValue05": "", //业务数据String值05.
  124. * "stringValue06": "", //业务数据String值06.
  125. * "stringValue07": "", //业务数据String值07.
  126. * "stringValue08": "", //业务数据String值08.
  127. * "stringValue09": "", //业务数据String值09.
  128. * "stringValue10": "", //业务数据String值10.
  129. * "longValue01": "", //业务数据Long值01.
  130. * "longValue02": "", //业务数据Long值02.
  131. * "doubleValue01": "", //业务数据double值01.
  132. * "doubleValue02": "", //业务数据double值02.
  133. * "dateTimeValue01": "", //业务数据dateTime值01.
  134. * "dateTimeValue02": "", //业务数据dateTime值02.
  135. * "dateTimeValue03": "", //业务数据dateTime值03.
  136. * }
  137. *</code></pre>
  138. * @o2syntax
  139. * var doc = this.documentContext.getDocument();
  140. */
  141. "getDocument": function(){return ev.document },
  142. /**
  143. * 获取当前人对文档的权限。
  144. * @method getControl
  145. * @static
  146. * @return {DocumentControl} 当前人对文档所拥有的权限.
  147. * <pre><code class='language-js'>{
  148. * "allowRead": true, //是否允许阅读文档
  149. * "allowPublishDocument": true, //是否允许发布文档
  150. * "allowSave": true, //是否允许保存文档
  151. * "allowPopularDocument": true, //是否允许设置为热点
  152. * "allowEditDocument": true, //是否允许编辑文档
  153. * "allowDeleteDocument": true //是否允许删除文档
  154. * }</code></pre>
  155. * @o2syntax
  156. * var control = this.documentContext.getControl();
  157. */
  158. "getControl": function(){return ev.control;},
  159. /**
  160. * 获取当前文档的附件对象列表。
  161. * @method getAttachmentList
  162. * @static
  163. * @return {DocumentFileInfo[]} 当前文档的附件对象列表.
  164. * @o2ActionOut x_cms_assemble_control.FileInfoAction.get|example=Attachment|ignoreProps=[properties]
  165. * @o2syntax
  166. * var attachmentList = this.documentContext.getAttachmentList();
  167. */
  168. "getAttachmentList": function(){return ev.attachmentList;}
  169. //"setTitle": function(title){
  170. // if (!this.workAction){
  171. // MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  172. // this.workAction = new MWF.xScript.Actions.WorkActions();
  173. // }
  174. // this.workAction.setTitle(ev.work.id, {"title": title});
  175. //}
  176. };
  177. //dict
  178. this.Dict = MWF.xScript.createCMSDict(_form.json.application, "cms");
  179. //org
  180. var orgActions = null;
  181. var getOrgActions = function(){
  182. // if (!orgActions){
  183. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  184. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  185. // }
  186. if (!orgActions){
  187. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  188. orgActions = new MWF.xScript.Actions.UnitActions();
  189. }
  190. };
  191. var getNameFlag = function(name){
  192. var t = typeOf(name);
  193. if (t==="array"){
  194. var v = [];
  195. name.each(function(id){
  196. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  197. });
  198. return v;
  199. }else{
  200. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  201. }
  202. };
  203. this.org = {
  204. //群组***************
  205. //获取群组--返回群组的对象数组
  206. getGroup: function(name, async){
  207. getOrgActions();
  208. var data = {"groupList": getNameFlag(name)};
  209. var v = null;
  210. var cb = function(json){
  211. v = json.data;
  212. v = (v && v.length===1) ? v[0] : v
  213. if (async && o2.typeOf(async)=="function") return async(v);
  214. return v;
  215. };
  216. var promise = orgActions.listGroup(data, cb, null, !!async);
  217. return (!!async) ? promise : v;
  218. // var v = null;
  219. // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  220. // return (v && v.length===1) ? v[0] : v;
  221. },
  222. //查询下级群组--返回群组的对象数组
  223. //nested 布尔 true嵌套下级;false直接下级;默认false;
  224. listSubGroup: function(name, nested, async){
  225. getOrgActions();
  226. var data = {"groupList": getNameFlag(name)};
  227. var v = null;
  228. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  229. // v = json.data;
  230. // return v;
  231. // }.ag().catch(function(json){ return json; });
  232. var cb = function(json){
  233. v = json.data;
  234. if (async && o2.typeOf(async)=="function") return async(v);
  235. return v;
  236. };
  237. var promise;
  238. if (nested){
  239. promise = orgActions.listSubGroupNested(data, cb, null, !!async);
  240. }else{
  241. promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
  242. }
  243. return (!!async) ? promise : v;
  244. // var v = null;
  245. // if (nested){
  246. // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  247. // }else{
  248. // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  249. // }
  250. // return v;
  251. },
  252. //查询上级群组--返回群组的对象数组
  253. //nested 布尔 true嵌套上级;false直接上级;默认false;
  254. listSupGroup:function(name, nested, async){
  255. getOrgActions();
  256. var data = {"groupList": getNameFlag(name)};
  257. var v = null;
  258. var cb = function(json){
  259. v = json.data;
  260. if (async && o2.typeOf(async)=="function") return async(v);
  261. return v;
  262. };
  263. var promise
  264. if (nested){
  265. var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
  266. }else{
  267. var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
  268. }
  269. return (!!async) ? promise : v;
  270. // var v = null;
  271. // if (nested){
  272. // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  273. // }else{
  274. // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  275. // }
  276. // return v;
  277. },
  278. //人员所在群组(嵌套)--返回群组的对象数组
  279. listGroupWithPerson:function(name, async){
  280. getOrgActions();
  281. var data = {"personList": getNameFlag(name)};
  282. var v = null;
  283. var cb = function(json){
  284. v = json.data;
  285. if (async && o2.typeOf(async)=="function") return async(v);
  286. return v;
  287. };
  288. var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
  289. return (!!async) ? promise : v;
  290. // var v = null;
  291. // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  292. // return v;
  293. },
  294. //身份所在群组(嵌套)--返回群组的对象数组
  295. listGroupWithIdentity:function(identity, async){
  296. getOrgActions();
  297. var data = {"identityList": getNameFlag(identity)};
  298. var v = null;
  299. var cb = function(json){
  300. v = json.data;
  301. if (async && o2.typeOf(async)=="function") return async(v);
  302. return v;
  303. };
  304. var promise = orgActions.listGroupWithIdentity(data, cb, null, !!async);
  305. return (!!async) ? promise : v;
  306. },
  307. //群组是否拥有角色--返回true, false
  308. groupHasRole: function(name, role, async){
  309. getOrgActions();
  310. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  311. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  312. var v = false;
  313. var cb = function(json){
  314. v = json.data.value;
  315. if (async && o2.typeOf(async)=="function") return async(v);
  316. return v;
  317. };
  318. var promise = orgActions.groupHasRole(data, cb, null, !!async);
  319. return (!!async) ? promise : v;
  320. // var v = false;
  321. // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  322. // return v;
  323. },
  324. //角色***************
  325. //获取角色--返回角色的对象数组
  326. getRole: function(name, async){
  327. getOrgActions();
  328. var data = {"roleList": getNameFlag(name)};
  329. var v = null;
  330. var cb = function(json){
  331. v = json.data;
  332. v = (v && v.length===1) ? v[0] : v;
  333. if (async && o2.typeOf(async)=="function") return async(v);
  334. return v;
  335. };
  336. var promise = orgActions.listRole(data, cb, null, !!async);
  337. return (!!async) ? promise : v;
  338. // var v = null;
  339. // orgActions.listRole(data, function(json){v = json.data;}, null, false);
  340. // return (v && v.length===1) ? v[0] : v;
  341. },
  342. //人员所有角色(嵌套)--返回角色的对象数组
  343. listRoleWithPerson:function(name, async){
  344. getOrgActions();
  345. var data = {"personList": getNameFlag(name)};
  346. var v = null;
  347. var cb = function(json){
  348. v = json.data;
  349. if (async && o2.typeOf(async)=="function") return async(v);
  350. return v;
  351. };
  352. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  353. return (!!async) ? promise : v;
  354. // var v = null;
  355. // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  356. // return v;
  357. },
  358. //人员***************
  359. //人员是否拥有角色--返回true, false
  360. personHasRole: function(name, role, async){
  361. getOrgActions();
  362. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  363. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  364. var v = false;
  365. var cb = function(json){
  366. v = json.data.value;
  367. if (async && o2.typeOf(async)=="function") return async(v);
  368. return v;
  369. };
  370. var promise = orgActions.personHasRole(data, cb, null, !!async);
  371. return (!!async) ? promise : v;
  372. // var v = false;
  373. // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  374. // return v;
  375. },
  376. //获取人员,附带身份,身份所在的组织,个人所在群组,个人拥有角色.
  377. getPersonData: function(name, async){
  378. getOrgActions();
  379. var v = null;
  380. var cb = function(json){
  381. v = json.data;
  382. if (async && o2.typeOf(async)=="function") return async(v);
  383. return v;
  384. };
  385. var promise = orgActions.getPerson(null, cb, null, !!async, {"flag": name});
  386. return (!!async) ? promise : v;
  387. },
  388. //获取人员--返回人员的对象数组
  389. getPerson: function(name, async, findCN){
  390. getOrgActions();
  391. var data = {"personList": getNameFlag(name)};
  392. if( o2.typeOf(findCN) === "boolean"){
  393. data.useNameFind = findCN;
  394. }
  395. var v = null;
  396. var cb = function(json){
  397. v = json.data;
  398. v = (v && v.length===1) ? v[0] : v;
  399. if (async && o2.typeOf(async)=="function") return async(v);
  400. return v;
  401. };
  402. var promise = orgActions.listPerson(data, cb, null, !!async);
  403. return (!!async) ? promise : v;
  404. // var v = null;
  405. // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  406. // return (v && v.length===1) ? v[0] : v;
  407. },
  408. //查询下级人员--返回人员的对象数组
  409. //nested 布尔 true嵌套下级;false直接下级;默认false;
  410. listSubPerson: function(name, nested, async){
  411. getOrgActions();
  412. var data = {"personList": getNameFlag(name)};
  413. var v = null;
  414. var cb = function(json){
  415. v = json.data;
  416. if (async && o2.typeOf(async)=="function") return async(v);
  417. return v;
  418. };
  419. var promise;
  420. if (nested){
  421. promise = orgActions.listPersonSubNested(data, cb, null, !!async);
  422. }else{
  423. promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
  424. }
  425. return (!!async) ? promise : v;
  426. },
  427. //查询上级人员--返回人员的对象数组
  428. //nested 布尔 true嵌套上级;false直接上级;默认false;
  429. listSupPerson: function(name, nested, async){
  430. getOrgActions();
  431. var data = {"personList": getNameFlag(name)};
  432. var v = null;
  433. var cb = function(json){
  434. v = json.data;
  435. if (async && o2.typeOf(async)=="function") return async(v);
  436. return v;
  437. };
  438. var promise;
  439. if (nested){
  440. promise = orgActions.listPersonSupNested(data, cb, null, !!async);
  441. }else{
  442. promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
  443. }
  444. return (!!async) ? promise : v;
  445. },
  446. //获取群组的所有人员--返回人员的对象数组
  447. listPersonWithGroup: function(name, async){
  448. getOrgActions();
  449. var data = {"groupList": getNameFlag(name)};
  450. var v = null;
  451. var cb = function(json){
  452. v = json.data;
  453. if (async && o2.typeOf(async)=="function") return async(v);
  454. return v;
  455. };
  456. var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
  457. return (!!async) ? promise : v;
  458. },
  459. //获取角色的所有人员--返回人员的对象数组
  460. listPersonWithRole: function(name, async){
  461. getOrgActions();
  462. var data = {"roleList": getNameFlag(name)};
  463. var v = null;
  464. var cb = function(json){
  465. v = json.data;
  466. if (async && o2.typeOf(async)=="function") return async(v);
  467. return v;
  468. };
  469. var promise
  470. promise = orgActions.listPersonWithRole(data, cb, null, !!async);
  471. return (!!async) ? promise : v;
  472. },
  473. //获取身份的所有人员--返回人员的对象数组
  474. listPersonWithIdentity: function(name, async){
  475. getOrgActions();
  476. var data = {"identityList": getNameFlag(name)};
  477. var v = null;
  478. var cb = function(json){
  479. v = json.data;
  480. if (async && o2.typeOf(async)=="function") return async(v);
  481. return v;
  482. };
  483. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  484. return (!!async) ? promise : v;
  485. },
  486. //获取身份的所有人员--返回人员的对象数组或人员对象
  487. getPersonWithIdentity: function(name, async){
  488. getOrgActions();
  489. var data = {"identityList": getNameFlag(name)};
  490. var v = null;
  491. var cb = function(json){
  492. v = json.data;
  493. v = (v && v.length===1) ? v[0] : v;
  494. if (async && o2.typeOf(async)=="function") return async(v);
  495. return v;
  496. };
  497. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  498. return (!!async) ? promise : v;
  499. },
  500. //查询组织成员的人员--返回人员的对象数组
  501. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  502. listPersonWithUnit: function(name, nested, async){
  503. getOrgActions();
  504. var data = {"unitList": getNameFlag(name)};
  505. var v = null;
  506. var cb = function(json){
  507. v = json.data;
  508. if (async && o2.typeOf(async)=="function") return async(v);
  509. return v;
  510. };
  511. var promise;
  512. if (nested){
  513. promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
  514. }else{
  515. promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
  516. }
  517. return (!!async) ? promise : v;
  518. },
  519. //根据属性查询人员--返回人员的对象数组
  520. //name string 属性名
  521. //value string 属性值
  522. listPersonWithAttribute: function(name, value, async){
  523. getOrgActions();
  524. var data = {"name": name, "attribute": value};
  525. var v = null;
  526. var cb = function(json){
  527. v = json.data;
  528. if (async && o2.typeOf(async)=="function") return async(v);
  529. return v;
  530. };
  531. var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
  532. return (!!async) ? promise : v;
  533. },
  534. //根据属性查询人员--返回人员的全称数组
  535. //name string 属性名
  536. //value string 属性值
  537. listPersonNameWithAttribute: function(name, value, async){
  538. getOrgActions();
  539. var data = {"name": name, "attribute": value};
  540. var v = null;
  541. var cb = function(json){
  542. v = json.data.personList;
  543. if (async && o2.typeOf(async)=="function") return async(v);
  544. return v;
  545. };
  546. var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
  547. return (!!async) ? promise : v;
  548. },
  549. //人员属性************
  550. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  551. appendPersonAttribute: function(person, attr, values, success, failure, async){
  552. getOrgActions();
  553. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  554. var data = {"attributeList":values,"name":attr,"person":personFlag};
  555. var v = null;
  556. var cb = function(json){
  557. v = json.data;
  558. if (async && o2.typeOf(async)=="function") return async(v);
  559. return v;
  560. };
  561. var promise = orgActions.appendPersonAttribute(data, cb, null, !!async);
  562. return (!!async) ? promise : v;
  563. // var cb = function(json){
  564. // if (success) return success(json);
  565. // }.ag().catch(function(xhr, text, error){
  566. // if (failure) return failure(xhr, text, error);
  567. // });
  568. //
  569. // orgActions.appendPersonAttribute(data, cb, null, !!async);
  570. },
  571. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  572. setPersonAttribute: function(person, attr, values, success, failure, async){
  573. getOrgActions();
  574. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  575. var data = {"attributeList":values,"name":attr,"person":personFlag};
  576. var v = null;
  577. var cb = function(json){
  578. v = json.data;
  579. if (async && o2.typeOf(async)=="function") return async(v);
  580. return v;
  581. };
  582. var promise = orgActions.setPersonAttribute(data, cb, null, !!async);
  583. return (!!async) ? promise : v;
  584. // var cb = function(json){
  585. // if (success) return success(json);
  586. // }.ag().catch(function(xhr, text, error){
  587. // if (failure) return failure(xhr, text, error);
  588. // });
  589. //
  590. // orgActions.setPersonAttribute(data, cb, null, !!async);
  591. },
  592. //获取人员属性值
  593. getPersonAttribute: function(person, attr, async){
  594. getOrgActions();
  595. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  596. var data = {"name":attr,"person":personFlag};
  597. var v = null;
  598. var cb = function(json){
  599. v = json.data.attributeList;
  600. if (async && o2.typeOf(async)=="function") return async(v);
  601. return v;
  602. };
  603. var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
  604. return (!!async) ? promise : v;
  605. },
  606. //列出人员所有属性的名称
  607. listPersonAttributeName: function(name, async){
  608. getOrgActions();
  609. var data = {"personList":getNameFlag(name)};
  610. var v = null;
  611. var cb = function(json){
  612. v = json.data.nameList;
  613. if (async && o2.typeOf(async)=="function") return async(v);
  614. return v;
  615. };
  616. var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
  617. return (!!async) ? promise : v;
  618. },
  619. //列出人员的所有属性
  620. listPersonAllAttribute: function(name, async){
  621. getOrgActions();
  622. var data = {"personList":getNameFlag(name)};
  623. var v = null;
  624. var cb = function(json){
  625. v = json.data;
  626. if (async && o2.typeOf(async)=="function") return async(v);
  627. return v;
  628. };
  629. var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
  630. return (!!async) ? promise : v;
  631. },
  632. //身份**********
  633. //获取身份
  634. getIdentity: function(name, async){
  635. getOrgActions();
  636. var data = {"identityList":getNameFlag(name)};
  637. var v = null;
  638. var cb = function(json){
  639. v = json.data;
  640. v = (v && v.length===1) ? v[0] : v;
  641. if (async && o2.typeOf(async)=="function") return async(v);
  642. return v;
  643. };
  644. var promise = orgActions.listIdentity(data, cb, null, !!async);
  645. return (!!async) ? promise : v;
  646. },
  647. //列出人员的身份
  648. listIdentityWithPerson: function(name, async, findCN){
  649. getOrgActions();
  650. var data = {"personList":getNameFlag(name)};
  651. if( o2.typeOf(findCN) === "boolean"){
  652. data.useNameFind = findCN;
  653. }
  654. var v = null;
  655. var cb = function(json){
  656. v = json.data;
  657. if (async && o2.typeOf(async)=="function") return async(v);
  658. return v;
  659. };
  660. var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
  661. return (!!async) ? promise : v;
  662. },
  663. //查询组织成员身份--返回身份的对象数组
  664. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  665. listIdentityWithUnit: function(name, nested, async){
  666. getOrgActions();
  667. var data = {"unitList": getNameFlag(name)};
  668. var v = null;
  669. // var cb = function(json){
  670. // v = json.data;
  671. // if (async && o2.typeOf(async)=="function") return async(v);
  672. // return v;
  673. // }.ag().catch(function(json){ return json; });
  674. var cb = function(json){
  675. v = json.data;
  676. if (async && o2.typeOf(async)=="function") return async(v);
  677. return v;
  678. };
  679. var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
  680. var promise = orgActions[method](data, cb, null, !!async);
  681. promise.name = "org";
  682. //
  683. // if (nested){
  684. // orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
  685. // }else{
  686. // orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
  687. // }
  688. return (!!async) ? promise : v;
  689. },
  690. //组织**********
  691. //获取组织
  692. getUnit: function(name, async, findCN){
  693. getOrgActions();
  694. var data = {"unitList":getNameFlag(name)};
  695. if( o2.typeOf(findCN) === "boolean"){
  696. data.useNameFind = findCN;
  697. }
  698. var v = null;
  699. var cb = function(json){
  700. v = json.data;
  701. v = (v && v.length===1) ? v[0] : v;
  702. if (async && o2.typeOf(async)=="function") return async(v);
  703. return v;
  704. };
  705. var promise = orgActions.listUnit(data, cb, null, !!async);
  706. return (!!async) ? promise : v;
  707. },
  708. //查询组织的下级--返回组织的对象数组
  709. //nested 布尔 true嵌套下级;false直接下级;默认false;
  710. listSubUnit: function(name, nested, async){
  711. getOrgActions();
  712. var data = {"unitList": getNameFlag(name)};
  713. var v = null;
  714. var cb = function(json){
  715. v = json.data;
  716. if (async && o2.typeOf(async)=="function") return async(v);
  717. return v;
  718. };
  719. var promise;
  720. if (nested){
  721. promise = orgActions.listUnitSubNested(data, cb, null, !!async);
  722. }else{
  723. promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
  724. }
  725. return (!!async) ? promise : v;
  726. },
  727. //查询组织的上级--返回组织的对象数组
  728. //nested 布尔 true嵌套上级;false直接上级;默认false;
  729. //async 布尔 true异步请求
  730. listSupUnit: function(name, nested, async){
  731. getOrgActions();
  732. var data = {"unitList": getNameFlag(name)};
  733. var v = null;
  734. var cb = function(json){
  735. v = json.data;
  736. if (async && o2.typeOf(async)=="function") return async(v);
  737. return v;
  738. };
  739. var promise;
  740. if (nested){
  741. promise = orgActions.listUnitSupNested(data, cb, null, !!async);
  742. }else{
  743. promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
  744. }
  745. return (!!async) ? promise : v;
  746. // if (callback){
  747. // if (nested){
  748. // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  749. // }else{
  750. // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  751. // }
  752. // }else{
  753. // var v = null;
  754. // if (nested){
  755. // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  756. // }else{
  757. // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  758. // }
  759. // return v;
  760. // }
  761. },
  762. listSupUnitWithLevel: function(name, level, async){
  763. var v;
  764. var supUnitList = this.listSupUnit( name, true, !!async);
  765. var unitList = this.getUnit( name, false, !!async );
  766. var cb = function(sups, units){
  767. v = [].concat(
  768. sups,
  769. typeOf( units ) === "object" ? [units] : units
  770. ).filter(function (u){
  771. return u.level === level;
  772. });
  773. if (async && o2.typeOf(async)==="function") return async(v);
  774. return v;
  775. };
  776. if( typeof supUnitList.then === 'function' ){
  777. return Promise.all([supUnitList, unitList]).then(function( result){
  778. return cb(result[0], result[1]);
  779. });
  780. }else{
  781. return cb(supUnitList, unitList);
  782. }
  783. },
  784. listSupUnitWithType: function(name, type, async){
  785. var v;
  786. var supUnitList = this.listSupUnit( name, true, !!async);
  787. var unitList = this.getUnit( name, false, !!async );
  788. var cb = function(sups, units){
  789. v = [].concat(
  790. sups,
  791. typeOf( units ) === "object" ? [units] : units
  792. ).filter(function (u){
  793. return (u.typeList || []).contains( type );
  794. });
  795. if (async && o2.typeOf(async)==="function") return async(v);
  796. return v;
  797. };
  798. if( typeof supUnitList.then === 'function' ){
  799. return Promise.all([supUnitList, unitList]).then(function( result){
  800. return cb(result[0], result[1]);
  801. });
  802. }else{
  803. return cb(supUnitList, unitList);
  804. }
  805. },
  806. //根据个人身份获取组织
  807. //flag 数字 表示获取第几层的组织
  808. // 字符串 表示获取指定类型的组织
  809. // 空 表示获取直接所在的组织
  810. getUnitByIdentity: function(name, flag, async){
  811. getOrgActions();
  812. var getUnitMethod = "current";
  813. var v;
  814. if (flag){
  815. if (typeOf(flag)==="string") getUnitMethod = "type";
  816. if (typeOf(flag)==="number") getUnitMethod = "level";
  817. }
  818. var cb;
  819. var promise;
  820. switch (getUnitMethod){
  821. case "current":
  822. var data = {"identityList":getNameFlag(name)};
  823. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  824. // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
  825. // }.ag().catch(function(json){ return json; });
  826. cb = function(json){
  827. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  828. if (async && o2.typeOf(async)=="function") return async(v);
  829. return v;
  830. };
  831. promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
  832. break;
  833. case "type":
  834. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  835. cb = function(json){
  836. v = json.data;
  837. if (async && o2.typeOf(async)=="function") return async(v);
  838. return v;
  839. };
  840. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  841. // v = json.data; return v;
  842. // }.ag().catch(function(json){ return json; });
  843. promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  844. break;
  845. case "level":
  846. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  847. cb = function(json){
  848. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  849. if (async && o2.typeOf(async)=="function") return async(v);
  850. return v;
  851. };
  852. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  853. // v = json.data; return v;
  854. // }.ag().catch(function(json){ return json; });
  855. promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  856. break;
  857. }
  858. return (!!async) ? promise : v;
  859. },
  860. //列出身份所在组织的所有上级组织
  861. listAllSupUnitWithIdentity: function(name, async){
  862. getOrgActions();
  863. var data = {"identityList":getNameFlag(name)};
  864. var v = null;
  865. var cb = function(json){
  866. v = json.data;
  867. if (async && o2.typeOf(async)=="function") return async(v);
  868. return v;
  869. };
  870. var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  871. return (!!async) ? promise : v;
  872. },
  873. //获取人员所在的所有组织
  874. listUnitWithPerson: function(name, async){
  875. getOrgActions();
  876. var data = {"personList":getNameFlag(name)};
  877. var v = null;
  878. var cb = function(json){
  879. v = json.data;
  880. if (async && o2.typeOf(async)=="function") return async(v);
  881. return v;
  882. };
  883. var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
  884. return (!!async) ? promise : v;
  885. },
  886. //列出人员所在组织的所有上级组织
  887. listAllSupUnitWithPerson: function(name, async){
  888. getOrgActions();
  889. var data = {"personList":getNameFlag(name)};
  890. var v = null;
  891. var cb = function(json){
  892. v = json.data;
  893. if (async && o2.typeOf(async)=="function") return async(v);
  894. return v;
  895. };
  896. var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  897. return (!!async) ? promise : v;
  898. },
  899. //根据组织属性,获取所有符合的组织
  900. listUnitWithAttribute: function(name, attribute, async){
  901. getOrgActions();
  902. var data = {"name":name,"attribute":attribute};
  903. var v = null;
  904. var cb = function(json){
  905. v = json.data;
  906. if (async && o2.typeOf(async)=="function") return async(v);
  907. return v;
  908. };
  909. promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
  910. return (!!async) ? promise : v;
  911. },
  912. //根据组织职务,获取所有符合的组织
  913. listUnitWithDuty: function(name, id, async){
  914. getOrgActions();
  915. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  916. var v = null;
  917. var cb = function(json){
  918. v = json.data;
  919. if (async && o2.typeOf(async)=="function") return async(v);
  920. return v;
  921. };
  922. var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
  923. return (!!async) ? promise : v;
  924. },
  925. //组织职务***********
  926. //获取指定的组织职务的身份
  927. getDuty: function(duty, id, async){
  928. getOrgActions();
  929. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  930. var v = null;
  931. var cb = function(json){
  932. v = json.data;
  933. if (async && o2.typeOf(async)=="function") return async(v);
  934. return v;
  935. };
  936. var promise = orgActions.getDuty(data, cb, null, !!async);
  937. return (!!async) ? promise : v;
  938. },
  939. //获取身份的所有职务名称
  940. listDutyNameWithIdentity: function(name, async){
  941. getOrgActions();
  942. var data = {"identityList":getNameFlag(name)};
  943. var v = null;
  944. var cb = function(json){
  945. v = json.data.nameList;
  946. if (async && o2.typeOf(async)=="function") return async(v);
  947. return v;
  948. };
  949. var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  950. return (!!async) ? promise : v;
  951. },
  952. //获取组织的所有职务名称
  953. listDutyNameWithUnit: function(name, async){
  954. getOrgActions();
  955. var data = {"unitList":getNameFlag(name)};
  956. var v = null;
  957. var cb = function(json){
  958. v = json.data.nameList;
  959. if (async && o2.typeOf(async)=="function") return async(v);
  960. return v;
  961. };
  962. var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  963. return (!!async) ? promise : v;
  964. },
  965. //获取组织的所有职务
  966. listUnitAllDuty: function(name, async){
  967. getOrgActions();
  968. var data = {"unitList":getNameFlag(name)};
  969. var v = null;
  970. var cb = function(json){
  971. v = json.data;
  972. if (async && o2.typeOf(async)=="function") return async(v);
  973. return v;
  974. };
  975. var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
  976. return (!!async) ? promise : v;
  977. },
  978. //列出顶层组织
  979. listTopUnit: function(async){
  980. var action = MWF.Actions.get("x_organization_assemble_control");
  981. var v = null;
  982. var cb = function(json){
  983. v = json.data;
  984. if (async && o2.typeOf(async)=="function") return async(v);
  985. return v;
  986. };
  987. var promise = action.listTopUnit(cb, null, !!async);
  988. return (!!async) ? promise : v;
  989. },
  990. //组织属性**************
  991. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  992. appendUnitAttribute: function(unit, attr, values, success, failure, async){
  993. getOrgActions();
  994. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  995. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  996. var v = null;
  997. var cb = function(json){
  998. v = json.data;
  999. if (async && o2.typeOf(async)=="function") return async(v);
  1000. return v;
  1001. };
  1002. var promise = orgActions.appendUnitAttribute(data, cb, null, !!async);
  1003. return (!!async) ? promise : v;
  1004. // var cb = function(json){
  1005. // if (success) return success(json);
  1006. // }.ag().catch(function(xhr, text, error){
  1007. // if (failure) return failure(xhr, text, error);
  1008. // });
  1009. //
  1010. // orgActions.appendPersonAttribute(data, cb, null, !!async);
  1011. // orgActions.appendUnitAttribute(data, function(json){
  1012. // if (json.data.value){
  1013. // if (success) success();
  1014. // }else{
  1015. // if (failure) failure(null, "", "append values failed");
  1016. // }
  1017. // }, function(xhr, text, error){
  1018. // if (failure) failure(xhr, text, error);
  1019. // }, false);
  1020. },
  1021. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  1022. setUnitAttribute: function(unit, attr, values, success, failure, async){
  1023. getOrgActions();
  1024. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1025. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  1026. var v = null;
  1027. var cb = function(json){
  1028. v = json.data;
  1029. if (async && o2.typeOf(async)=="function") return async(v);
  1030. return v;
  1031. };
  1032. var promise = orgActions.setUnitAttribute(data, cb, null, !!async);
  1033. return (!!async) ? promise : v;
  1034. // var cb = function(json){
  1035. // if (success) return success(json);
  1036. // }.ag().catch(function(xhr, text, error){
  1037. // if (failure) return failure(xhr, text, error);
  1038. // });
  1039. // orgActions.setUnitAttribute(data, cb, null, !!async);
  1040. // orgActions.setUnitAttribute(data, function(json){
  1041. // if (json.data.value){
  1042. // if (success) success();
  1043. // }else{
  1044. // if (failure) failure(null, "", "append values failed");
  1045. // }
  1046. // }, function(xhr, text, error){
  1047. // if (failure) failure(xhr, text, error);
  1048. // }, false);
  1049. },
  1050. //获取组织属性值
  1051. getUnitAttribute: function(unit, attr, async){
  1052. getOrgActions();
  1053. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  1054. var data = {"name":attr,"unit":unitFlag};
  1055. var v = null;
  1056. var cb = function(json){
  1057. v = json.data.attributeList;
  1058. if (async && o2.typeOf(async)=="function") return async(v);
  1059. return v;
  1060. };
  1061. var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
  1062. return (!!async) ? promise : v;
  1063. },
  1064. //列出组织所有属性的名称
  1065. listUnitAttributeName: function(name, async){
  1066. getOrgActions();
  1067. var data = {"unitList":getNameFlag(name)};
  1068. var v = null;
  1069. var cb = function(json){
  1070. v = json.data.nameList;
  1071. if (async && o2.typeOf(async)=="function") return async(v);
  1072. return v;
  1073. };
  1074. var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
  1075. return (!!async) ? promise : v;
  1076. },
  1077. //列出组织的所有属性
  1078. listUnitAllAttribute: function(name, async){
  1079. getOrgActions();
  1080. var data = {"unitList":getNameFlag(name)};
  1081. var v = null;
  1082. var cb = function(json){
  1083. v = json.data;
  1084. if (async && o2.typeOf(async)=="function") return async(v);
  1085. return v;
  1086. };
  1087. var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
  1088. return (!!async) ? promise : v;
  1089. }
  1090. };
  1091. this.Action = (function(){
  1092. var actions = [];
  1093. return function(root, json){
  1094. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  1095. action.getActions = function(callback){
  1096. if (!this.actions) this.actions = {};
  1097. Object.merge(this.actions, json);
  1098. if (callback) callback();
  1099. };
  1100. this.invoke = function(option){
  1101. action.invoke(option)
  1102. }
  1103. }
  1104. })();
  1105. // this.service = {
  1106. // "jaxwsClient": {},
  1107. // "jaxrsClient":{}
  1108. // };
  1109. var lookupAction = null;
  1110. var getLookupAction = function(callback){
  1111. if (!lookupAction){
  1112. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  1113. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  1114. lookupAction.getActions = function(actionCallback){
  1115. this.actions = {
  1116. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  1117. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  1118. };
  1119. if (actionCallback) actionCallback();
  1120. }
  1121. if (callback) callback();
  1122. }.bind(this));
  1123. }else{
  1124. if (callback) callback();
  1125. }
  1126. };
  1127. this.view = {
  1128. "lookup": function(view, callback, async){
  1129. var filterList = {"filterList": (view.filter || null)};
  1130. return MWF.Actions.load("x_query_assemble_surface").ViewAction.executeWithQuery(view.view, view.application, filterList, function(json){
  1131. var data = {
  1132. "grid": json.data.grid || json.data.groupGrid,
  1133. "groupGrid": json.data.groupGrid
  1134. };
  1135. if (callback) callback(data);
  1136. return data;
  1137. }, null, async);
  1138. },
  1139. "lookupV1": function(view, callback){
  1140. getLookupAction(function(){
  1141. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  1142. var data = {
  1143. "grid": json.data.grid,
  1144. "groupGrid": json.data.groupGrid
  1145. };
  1146. if (callback) callback(data);
  1147. }.bind(this)});
  1148. }.bind(this));
  1149. },
  1150. "select": function(view, callback, options){
  1151. if (view.view){
  1152. var viewJson = {
  1153. "application": view.application || _form.json.application,
  1154. "viewName": view.view || "",
  1155. "isTitle": (view.isTitle===false) ? "no" : "yes",
  1156. "select": (view.isMulti===false) ? "single" : "multi",
  1157. "filter": view.filter
  1158. };
  1159. if (!options) options = {};
  1160. options.width = view.width;
  1161. options.height = view.height;
  1162. options.title = view.caption;
  1163. var width = options.width || "700";
  1164. var height = options.height || "400";
  1165. if (layout.mobile){
  1166. var size = document.body.getSize();
  1167. width = size.x;
  1168. height = size.y;
  1169. options.style = "viewmobile";
  1170. }
  1171. width = width.toInt();
  1172. height = height.toInt();
  1173. var size = _form.app.content.getSize();
  1174. var x = (size.x-width)/2;
  1175. var y = (size.y-height)/2;
  1176. if (x<0) x = 0;
  1177. if (y<0) y = 0;
  1178. if (layout.mobile){
  1179. x = 20;
  1180. y = 0;
  1181. }
  1182. var _self = this;
  1183. MWF.require("MWF.xDesktop.Dialog", function(){
  1184. var dlg = new MWF.xDesktop.Dialog({
  1185. "title": options.title || "select view",
  1186. "style": options.style || "view",
  1187. "top": y,
  1188. "left": x-20,
  1189. "fromTop":y,
  1190. "fromLeft": x-20,
  1191. "width": width,
  1192. "height": height,
  1193. "html": "<div style='height: 100%;'></div>",
  1194. "maskNode": _form.app.content,
  1195. "container": _form.app.content,
  1196. "buttonList": [
  1197. {
  1198. "text": MWF.LP.process.button.ok,
  1199. "action": function(){
  1200. //if (callback) callback(_self.view.selectedItems);
  1201. if (callback) callback(_self.view.getData());
  1202. this.close();
  1203. }
  1204. },
  1205. {
  1206. "text": MWF.LP.process.button.cancel,
  1207. "action": function(){this.close();}
  1208. }
  1209. ]
  1210. });
  1211. dlg.show();
  1212. if (layout.mobile){
  1213. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1214. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1215. if (backAction) backAction.addEvent("click", function(e){
  1216. dlg.close();
  1217. }.bind(this));
  1218. if (okAction) okAction.addEvent("click", function(e){
  1219. //if (callback) callback(this.view.selectedItems);
  1220. if (callback) callback(this.view.getData());
  1221. dlg.close();
  1222. }.bind(this));
  1223. }
  1224. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  1225. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  1226. }.bind(this));
  1227. }.bind(this));
  1228. }
  1229. }
  1230. };
  1231. this.statement = {
  1232. execute: function (obj, callback, async) {
  1233. if( obj.format ){
  1234. return this._execute(obj, callback, async, obj.format);
  1235. }else{
  1236. if( this.needCheckFormat(obj) ){
  1237. var result;
  1238. var p = MWF.Actions.load("x_query_assemble_surface").StatementAction.getFormat(obj.name, function(json){
  1239. result = this._execute(obj, callback, async, json.data.format);
  1240. return result;
  1241. }.bind(this), null, async);
  1242. return result || p;
  1243. }else{
  1244. return this._execute(obj, callback, async, "");
  1245. }
  1246. }
  1247. },
  1248. needCheckFormat: function(s){
  1249. if( s.format )return false;
  1250. if( typeOf(s.parameter) === "object" ){
  1251. for( var p in s.parameter ){
  1252. if( typeOf( s.parameter[p] ) === "date" )return true;
  1253. }
  1254. }
  1255. if( typeOf(s.filter) === "array" ){
  1256. for( var i=0; i< s.filter.length; i++){
  1257. var fType = s.filter[i].formatType;
  1258. if( ["dateTimeValue", "datetimeValue", "dateValue", "timeValue"].contains( fType ) )return true;
  1259. }
  1260. }
  1261. return false;
  1262. },
  1263. _execute: function(statement, callback, async, format){
  1264. var parameter = this.parseParameter(statement.parameter, format);
  1265. var filterList = this.parseFilter(statement.filter, parameter, format);
  1266. var obj = {
  1267. "filterList": filterList,
  1268. "parameter" : parameter
  1269. };
  1270. return MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  1271. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  1272. function (json) {
  1273. if (callback) callback(json);
  1274. return json;
  1275. }, null, async);
  1276. },
  1277. parseFilter : function( filter, parameter, format){
  1278. if( typeOf(filter) !== "array" )return [];
  1279. if( !parameter )parameter = {};
  1280. var filterList = [];
  1281. ( filter || [] ).each( function (d) {
  1282. if( !d.logic )d.logic = "and";
  1283. //var parameterName = d.path.replace(/\./g, "_");
  1284. var pName = d.path.replace(/\./g, "_");
  1285. var parameterName = pName;
  1286. var suffix = 1;
  1287. while( parameter[parameterName] ){
  1288. parameterName = pName + "_" + suffix;
  1289. suffix++;
  1290. }
  1291. var value = d.value;
  1292. if( d.comparison === "like" || d.comparison === "notLike" ){
  1293. if( value.substr(0, 1) !== "%" )value = "%"+value;
  1294. if( value.substr(value.length-1,1) !== "%" )value = value+"%";
  1295. parameter[ parameterName ] = value; //"%"+value+"%";
  1296. }else{
  1297. if( ["sql", "sqlScript"].contains(format) ) {
  1298. if (d.formatType === "numberValue") {
  1299. value = parseFloat(value);
  1300. }
  1301. }else{
  1302. if (d.formatType === "dateTimeValue" || d.formatType === "datetimeValue") {
  1303. value = "{ts '" + value + "'}"
  1304. } else if (d.formatType === "dateValue") {
  1305. value = "{d '" + value + "'}"
  1306. } else if (d.formatType === "timeValue") {
  1307. value = "{t '" + value + "'}"
  1308. } else if (d.formatType === "numberValue") {
  1309. value = parseFloat(value);
  1310. }
  1311. }
  1312. parameter[ parameterName ] = value;
  1313. }
  1314. d.value = parameterName;
  1315. filterList.push( d );
  1316. }.bind(this));
  1317. return filterList;
  1318. },
  1319. parseParameter : function( obj, format ){
  1320. if( typeOf(obj) !== "object" )return {};
  1321. var parameter = {};
  1322. //传入的参数
  1323. for( var p in obj ){
  1324. var value = obj[p];
  1325. if( typeOf( value ) === "date" ){
  1326. if( ["sql", "sqlScript"].contains(format) ){
  1327. value = value.format("db");
  1328. }else{
  1329. value = "{ts '"+value.format("db")+"'}"
  1330. }
  1331. }
  1332. parameter[ p ] = value;
  1333. }
  1334. return parameter;
  1335. },
  1336. "select": function (statement, callback, options) {
  1337. if (statement.name) {
  1338. // var parameter = this.parseParameter(statement.parameter);
  1339. // var filterList = this.parseFilter(statement.filter, parameter);
  1340. var statementJson = {
  1341. "statementId": statement.name || "",
  1342. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  1343. "select": (statement.isMulti === false) ? "single" : "multi",
  1344. "filter": statement.filter,
  1345. "parameter": statement.parameter
  1346. };
  1347. if (!options) options = {};
  1348. options.width = statement.width;
  1349. options.height = statement.height;
  1350. options.title = statement.caption;
  1351. var width = options.width || "700";
  1352. var height = options.height || "400";
  1353. if (layout.mobile) {
  1354. var size = document.body.getSize();
  1355. width = size.x;
  1356. height = size.y;
  1357. options.style = "viewmobile";
  1358. }
  1359. width = width.toInt();
  1360. height = height.toInt();
  1361. var size = _form.app.content.getSize();
  1362. var x = (size.x - width) / 2;
  1363. var y = (size.y - height) / 2;
  1364. if (x < 0) x = 0;
  1365. if (y < 0) y = 0;
  1366. if (layout.mobile) {
  1367. x = 20;
  1368. y = 0;
  1369. }
  1370. var _self = this;
  1371. MWF.require("MWF.xDesktop.Dialog", function () {
  1372. var dlg = new MWF.xDesktop.Dialog({
  1373. "title": options.title || "select statement view",
  1374. "style": options.style || "view",
  1375. "top": y,
  1376. "left": x - 20,
  1377. "fromTop": y,
  1378. "fromLeft": x - 20,
  1379. "width": width,
  1380. "height": height,
  1381. "html": "<div style='height: 100%;'></div>",
  1382. "maskNode": _form.app.content,
  1383. "container": _form.app.content,
  1384. "buttonList": [
  1385. {
  1386. "text": MWF.LP.process.button.ok,
  1387. "action": function () {
  1388. //if (callback) callback(_self.view.selectedItems);
  1389. if (callback) callback(_self.statement.getData());
  1390. this.close();
  1391. }
  1392. },
  1393. {
  1394. "text": MWF.LP.process.button.cancel,
  1395. "action": function () { this.close(); }
  1396. }
  1397. ]
  1398. });
  1399. dlg.show();
  1400. if (layout.mobile) {
  1401. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1402. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1403. if (backAction) backAction.addEvent("click", function (e) {
  1404. dlg.close();
  1405. }.bind(this));
  1406. if (okAction) okAction.addEvent("click", function (e) {
  1407. //if (callback) callback(this.view.selectedItems);
  1408. if (callback) callback(this.statement.getData());
  1409. dlg.close();
  1410. }.bind(this));
  1411. }
  1412. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  1413. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
  1414. }.bind(this));
  1415. }.bind(this));
  1416. }
  1417. }
  1418. };
  1419. this.importer = {
  1420. "upload": function (options, callback, async) {
  1421. MWF.xDesktop.requireApp("query.Query", "Importer", function () {
  1422. var importer = new MWF.xApplication.query.Query.Importer(_form.app.content, options, {}, _form.app, _form.Macro);
  1423. importer.addEvent("afterImport", function (data) {
  1424. if(callback)callback(data);
  1425. });
  1426. importer.load();
  1427. }.bind(this));
  1428. },
  1429. "downloadTemplate": function(options, fileName, callback){
  1430. MWF.xDesktop.requireApp("query.Query", "Importer", function () {
  1431. var importer = new MWF.xApplication.query.Query.Importer(_form.app.content, options, {}, _form.app, _form.Macro);
  1432. importer.downloadTemplate(fileName, callback);
  1433. }.bind(this));
  1434. }
  1435. };
  1436. //var lookupAction = null;
  1437. //var getLookupAction = function(callback){
  1438. // if (!lookupAction){
  1439. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  1440. // lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  1441. // lookupAction.getActions = function(actionCallback){
  1442. // this.actions = {
  1443. // "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  1444. // "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  1445. // };
  1446. // if (actionCallback) actionCallback();
  1447. // }
  1448. // if (callback) callback();
  1449. // }.bind(this));
  1450. // }else{
  1451. // if (callback) callback();
  1452. // }
  1453. //};
  1454. //
  1455. //this.view = {
  1456. // "lookup": function(view, callback){
  1457. // getLookupAction(function(){
  1458. // lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  1459. // var data = {
  1460. // "grid": json.data.grid,
  1461. // "groupGrid": json.data.groupGrid
  1462. // };
  1463. // if (callback) callback(data);
  1464. // }.bind(this)});
  1465. // }.bind(this));
  1466. // },
  1467. // "select": function(view, callback, options){
  1468. // if (view.view){
  1469. // var viewJson = {
  1470. // "application": view.application || "",
  1471. // "viewName": view.view || "",
  1472. // "isTitle": view.isTitle || "yes",
  1473. // "select": view.select || "multi",
  1474. // "title": view.title || "Select View"
  1475. // };
  1476. // if (!options) options = {};
  1477. // var width = options.width || "700";
  1478. // var height = options.height || "400";
  1479. //
  1480. // if (layout.mobile){
  1481. // var size = document.body.getSize();
  1482. // width = size.x;
  1483. // height = size.y;
  1484. // options.style = "viewmobile";
  1485. // }
  1486. // width = width.toInt();
  1487. // height = height.toInt();
  1488. //
  1489. // var size = _form.app.content.getSize();
  1490. // var x = (size.x-width)/2;
  1491. // var y = (size.y-height)/2;
  1492. // if (x<0) x = 0;
  1493. // if (y<0) y = 0;
  1494. // if (layout.mobile){
  1495. // x = 20;
  1496. // y = 0;
  1497. // }
  1498. //
  1499. // var _self = this;
  1500. // MWF.require("MWF.xDesktop.Dialog", function(){
  1501. // var dlg = new MWF.xDesktop.Dialog({
  1502. // "title": options.title || "select View",
  1503. // "style": options.style || "view",
  1504. // "top": y,
  1505. // "left": x-20,
  1506. // "fromTop":y,
  1507. // "fromLeft": x-20,
  1508. // "width": width,
  1509. // "height": height,
  1510. // "html": "<div style='height: 100%;'></div>",
  1511. // "maskNode": _form.app.content,
  1512. // "container": _form.app.content,
  1513. // "buttonList": [
  1514. // {
  1515. // "text": MWF.LP.process.button.ok,
  1516. // "action": function(){
  1517. // //if (callback) callback(_self.view.selectedItems);
  1518. // if (callback) callback(_self.view.getData());
  1519. // this.close();
  1520. // }
  1521. // },
  1522. // {
  1523. // "text": MWF.LP.process.button.cancel,
  1524. // "action": function(){this.close();}
  1525. // }
  1526. // ]
  1527. // });
  1528. // dlg.show();
  1529. // if (layout.mobile){
  1530. // var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1531. // var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1532. // if (backAction) backAction.addEvent("click", function(e){
  1533. // dlg.close();
  1534. // }.bind(this));
  1535. // if (okAction) okAction.addEvent("click", function(e){
  1536. // //if (callback) callback(this.view.selectedItems);
  1537. // if (callback) callback(this.view.getData());
  1538. // dlg.close();
  1539. // }.bind(this));
  1540. // }
  1541. //
  1542. // // MWF.xDesktop.requireApp("cms.Xform", "widget.View", function(){
  1543. // // this.view = new MWF.xApplication.cms.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  1544. // // }.bind(this));
  1545. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  1546. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  1547. // }.bind(this));
  1548. // }.bind(this));
  1549. // }
  1550. // }
  1551. //};
  1552. //include 引用脚本
  1553. //optionsOrName : {
  1554. // type : "", 默认为cms, 可以为 portal process cms
  1555. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  1556. // name : "" // 脚本名称/别名/id
  1557. //}
  1558. //或者name: "" // 脚本名称/别名/id
  1559. // if( !window.includedScripts ){
  1560. // var includedScripts = window.includedScripts = [];
  1561. // }else{
  1562. // var includedScripts = window.includedScripts;
  1563. // }
  1564. var _getScriptAction = function ( type ){
  1565. var scriptAction;
  1566. switch (type) {
  1567. case "portal" :
  1568. if (this.scriptActionPortal) {
  1569. scriptAction = this.scriptActionPortal;
  1570. } else {
  1571. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  1572. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  1573. }
  1574. break;
  1575. case "process" :
  1576. if (this.scriptActionProcess) {
  1577. scriptAction = this.scriptActionProcess;
  1578. } else {
  1579. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1580. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1581. }
  1582. break;
  1583. case "cms" :
  1584. if (this.scriptActionCMS) {
  1585. scriptAction = this.scriptActionCMS;
  1586. } else {
  1587. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1588. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1589. }
  1590. break;
  1591. case "service" :
  1592. if (this.scriptActionService) {
  1593. scriptAction = this.scriptActionService;
  1594. } else {
  1595. MWF.require("MWF.xScript.Actions.ServiceScriptActions", null, false);
  1596. scriptAction = this.scriptActionService = new MWF.xScript.Actions.ServiceScriptActions();
  1597. }
  1598. break;
  1599. }
  1600. return scriptAction;
  1601. }
  1602. //缓存名称、别名、id
  1603. var _parseScriptImportList = function (json, type){
  1604. var includedScripts = [];
  1605. var importedList = json.data.importedList || [];
  1606. importedList.each(function (flag) {
  1607. if (type === "portal") {
  1608. includedScripts.push(type + "-" + json.data.portal + "-" + flag);
  1609. if (json.data.portalName) includedScripts.push(type + "-" + json.data.portalName + "-" + flag);
  1610. if (json.data.portalAlias) includedScripts.push(type + "-" + json.data.portalAlias + "-" + flag);
  1611. } else if (type === "cms") {
  1612. includedScripts.push(type + "-" + json.data.appId + "-" + flag);
  1613. if (json.data.appName) includedScripts.push(type + "-" + json.data.appName + "-" + flag);
  1614. if (json.data.appAlias) includedScripts.push(type + "-" + json.data.appAlias + "-" + flag);
  1615. } else if (type === "process") {
  1616. includedScripts.push(type + "-" + json.data.application + "-" + flag);
  1617. if (json.data.appName) includedScripts.push(type + "-" + json.data.appName + "-" + flag);
  1618. if (json.data.appAlias) includedScripts.push(type + "-" + json.data.appAlias + "-" + flag);
  1619. }else if (type === "service") {
  1620. includedScripts.push(type + "-" + flag);
  1621. }
  1622. });
  1623. return includedScripts.concat(importedList);
  1624. }
  1625. var includedScripts = [];
  1626. var _includeSingle = function( optionsOrName , callback , async){
  1627. var options = optionsOrName;
  1628. if( typeOf( options ) === "string" ){
  1629. options = { name : options };
  1630. }
  1631. var name = options.name;
  1632. var type;
  1633. if( options.type === "service" ){
  1634. type = options.type;
  1635. }else{
  1636. type = ( options.type && options.application ) ? options.type : "cms";
  1637. }
  1638. var application = options.application || _form.json.application;
  1639. var key = type +"-" + application + "-" + name;
  1640. if( type === "service" ){
  1641. key = type + "-" + name;
  1642. }
  1643. //js 加载过就不重新加载了
  1644. if (includedScripts.indexOf( key )> -1){
  1645. if (callback) callback.apply(this);
  1646. return;
  1647. }
  1648. var successCallback = function(json){
  1649. if (json.data){
  1650. includedScripts.push( key );
  1651. includedScripts = includedScripts.concat( _parseScriptImportList(json, type) );
  1652. MWF.CMSMacro.exec(json.data.text, this);
  1653. if (callback) callback.apply(this);
  1654. }else{
  1655. if (callback) callback.apply(this);
  1656. }
  1657. }.bind(this);
  1658. if (( options.enableAnonymous || options.anonymous ) && type === "cms") {
  1659. o2.Actions.load("x_cms_assemble_control").ScriptAnonymousAction.getWithAppWithName(application, name, successCallback, null, !!async);
  1660. } else {
  1661. var scriptAction = _getScriptAction.call(this, type);
  1662. if( type === "service" ){
  1663. scriptAction.getScriptByName(name, includedScripts, successCallback, null, !!async);
  1664. }else{
  1665. scriptAction.getScriptByName(application, name, includedScripts, successCallback, null, !!async);
  1666. }
  1667. }
  1668. };
  1669. this.include = function( optionsOrName , callback, async){
  1670. if (o2.typeOf(optionsOrName)==="array"){
  1671. if (!!async){
  1672. var count = optionsOrName.length;
  1673. var loaded = 0;
  1674. optionsOrName.each(function(option){
  1675. _includeSingle.apply(this, [option, function(){
  1676. loaded++;
  1677. if (loaded>=count) if (callback) callback.apply(this);
  1678. }.bind(this), true]);
  1679. }.bind(this));
  1680. }else{
  1681. optionsOrName.each(function(option){
  1682. _includeSingle.apply(this, [option]);
  1683. }.bind(this));
  1684. if (callback) callback.apply(this);
  1685. }
  1686. }else{
  1687. _includeSingle.apply(this, [optionsOrName , callback, async])
  1688. }
  1689. };
  1690. var includedSourceMap = {};
  1691. var _includeSource = function (optionsOrName, callback, async, fileType) {
  1692. var options = typeOf(optionsOrName) === "string" ? {name: optionsOrName} : optionsOrName;
  1693. var name = options.name;
  1694. var type = options.type === "service" ? options.type : ((options.type && options.application) ? options.type : "cms");
  1695. var application = options.application || _form.json.application;
  1696. var key = type === "service" ? (type + "-" + name) : (type + "-" + application + "-" + name);
  1697. var data, result;
  1698. if( includedSourceMap[key] ){
  1699. data = includedSourceMap[key];
  1700. if(callback)callback( data.text );
  1701. return !!async ? Promise.resolve( data.text ) : data.text;
  1702. }
  1703. var successCallback = function (json) {
  1704. if (json.data) {
  1705. var includeds = [key];
  1706. includeds = includeds.concat( _parseScriptImportList(json, type) );
  1707. includeds.each(function(k){
  1708. includedSourceMap[k] = json.data;
  1709. })
  1710. result = json.data.text;
  1711. if( fileType === 'json' ){
  1712. result = JSON.parse(result);
  1713. }
  1714. if (callback) callback.call(this, result);
  1715. } else {
  1716. result = '';
  1717. if (callback) callback.call(this, '');
  1718. }
  1719. return result;
  1720. }.bind(this);
  1721. var p;
  1722. if (( options.enableAnonymous || options.anonymous ) && type === "cms") {
  1723. p = o2.Actions.load("x_cms_assemble_control").ScriptAnonymousAction.getWithAppWithName(application, name, !!async ? null : successCallback, null, !!async);
  1724. } else {
  1725. var scriptAction = _getScriptAction.call(this, type);
  1726. if( type === "service" ){
  1727. p = scriptAction.getScriptByName(name, includedScripts, successCallback, !!async ? null : successCallback, null, !!async);
  1728. }else{
  1729. p = scriptAction.getScriptByName(application, name, includedScripts, !!async ? null : successCallback, null, !!async);
  1730. }
  1731. }
  1732. return !!async ? p.then( successCallback ) : result;
  1733. };
  1734. this.includeHtml = function (optionsOrName, callback, async){
  1735. return _includeSource.apply(this, [optionsOrName, callback, async!==false, 'html'])
  1736. };
  1737. this.includeJson = function (optionsOrName, callback, async){
  1738. return _includeSource.apply(this, [optionsOrName, callback, async!==false, 'json'])
  1739. };
  1740. this.includeCss = function (optionsOrName, callback, async){
  1741. return _includeSource.apply(this, [optionsOrName, callback, async!==false, 'css']);
  1742. };
  1743. //var includedScripts = [];
  1744. //this.include = function(name, callback){
  1745. // if (includedScripts.indexOf(name)==-1){
  1746. // if (!this.scriptAction){
  1747. // MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1748. // this.scriptAction = new MWF.xScript.Actions.CMSScriptActions();
  1749. // }
  1750. // this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
  1751. // includedScripts = includedScripts.concat(json.data.importedList);
  1752. // MWF.CMSMacro.exec(json.data.text, this);
  1753. // if (callback) callback.apply(this);
  1754. // }.bind(this), null, false);
  1755. // }else{
  1756. // if (callback) callback.apply(this);
  1757. // }
  1758. //}.bind(this);
  1759. this.define = function(name, fun, overwrite){
  1760. var over = true;
  1761. if (overwrite===false) over = false;
  1762. var o = {};
  1763. o[name] = {"value": fun, "configurable": over};
  1764. MWF.defineProperties(this, o);
  1765. }.bind(this);
  1766. this.exec = function(text, bind, arg=null, throwError=true){
  1767. const b = bind || globalThis;
  1768. const p = (arg) ? Object.values(arg) : [];
  1769. const k = (arg) ? Object.keys(arg).join(',') : '';
  1770. try {
  1771. return Function('return function('+k+'){' + text + '}')().apply(b, p);
  1772. }catch(e){
  1773. if (throwError) throw e;
  1774. console.error(e);
  1775. return '';
  1776. }
  1777. }
  1778. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1779. //可在调用前执行 var resolve = this.wait();
  1780. //在异步调用结束后 执行 resolve.cb();
  1781. //目前只有表单的queryload事件支持此方法。
  1782. this.wait = function(){
  1783. resolve = {};
  1784. var setResolve = function(callback){
  1785. resolve.cb = callback;
  1786. }.bind(this);
  1787. this.target.event_resolve = setResolve;
  1788. return resolve;
  1789. };
  1790. //和this.wait配合使用,
  1791. //如果没有异步,则resolve.cb方法不存在,
  1792. //所以在回调中中使用this.goon();使表单继续加载
  1793. this.goon = function(){
  1794. this.target.event_resolve = null;
  1795. };
  1796. //仅前台对象-----------------------------------------
  1797. //form
  1798. this.form = {
  1799. "getInfor": function(){return ev.formInfor;},
  1800. "infor": ev.formInfor,
  1801. "getApp": function(){return _form.app;},
  1802. "app": _form.app,
  1803. "node": function(){return _form.node;},
  1804. // "readonly": _form.options.readonly,
  1805. "get": function(name,subformName ){
  1806. if( !_form.all )return null;
  1807. if( subformName ){
  1808. if( _form.all[subformName +"_"+ name] )return _form.all[subformName +"_"+ name];
  1809. return _form.all[name];
  1810. }else{
  1811. return _form.all[name];
  1812. }
  1813. // return (_form.all) ? _form.all[name] : null;
  1814. },
  1815. "getField": function(name){return _forms[name];},
  1816. "getAction": function(){return _form.documentAction},
  1817. "getData": function(){return new MWF.xScript.CMSJSONData(_form.getData());},
  1818. "save": function(callback){
  1819. _form.saveDocument(callback);
  1820. },
  1821. "close": function(){_form.closeDocument();},
  1822. /**
  1823. * @summary 根据表单中所有组件的校验设置和表单的“发布校验”脚本进行校验。<b>(仅内容管理表单中可用)</b>
  1824. * @method verifyPublish
  1825. * @static
  1826. * @o2syntax
  1827. * this.form.verifyPublish()
  1828. * @example
  1829. * if( !this.form.verifyPublish() ){
  1830. * return false;
  1831. * }
  1832. * @return {Boolean} 是否通过校验
  1833. */
  1834. "verifyPublish": function(isSave){
  1835. return !(!_form.formValidation("publish") || !_form[isSave ? 'formSaveValidation' : 'formPublishValidation']());
  1836. },
  1837. /**发布当前文档。<b>(仅内容管理表单中可用)</b>
  1838. * @method publish
  1839. * @memberOf module:form
  1840. * @param {Function} callback - 发布后的回调方法,如果接收的参数<b>为空</b>表示校验未通过,如果参数<b>不为空</b>为发布后的回调
  1841. * @o2syntax
  1842. * this.form.publish( callback );
  1843. * @sample
  1844. * this.form.publish( function(json){
  1845. * if( !json ){
  1846. * //校验未通过
  1847. * }else{
  1848. * //校验通过,json.data.id 为文档id
  1849. * }
  1850. * });
  1851. */
  1852. "publish": function(callback){
  1853. _form.publishDocument(callback)
  1854. },
  1855. //"archive": function(option){
  1856. // _form.archiveDocument()
  1857. //},
  1858. //"redraft": function(option){
  1859. // _form.redraftDocument()
  1860. //},
  1861. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  1862. // var p = MWF.getCenter({"x": width, "y": height});
  1863. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1864. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1865. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  1866. var p = MWF.getCenter({"x": width, "y": height});
  1867. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1868. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1869. }else{
  1870. e = (arguments.length>1) ? arguments[1] : null;
  1871. title = (arguments.length>2) ? arguments[2] : null;
  1872. text = (arguments.length>3) ? arguments[3] : null;
  1873. width = (arguments.length>4) ? arguments[4] : null;
  1874. height = (arguments.length>5) ? arguments[5] : null;
  1875. ok = (arguments.length>6) ? arguments[6] : null;
  1876. cancel = (arguments.length>7) ? arguments[7] : null;
  1877. callback = (arguments.length>8) ? arguments[8] : null;
  1878. mask = (arguments.length>9) ? arguments[9] : null;
  1879. style = (arguments.length>10) ? arguments[10] : null;
  1880. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1881. }
  1882. },
  1883. //"confirm": function(type, e, title, text, width, height, ok, cancel, callback){
  1884. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  1885. //},
  1886. "alert": function(type, title, text, width, height){
  1887. _form.alert(type, title, text, width, height);
  1888. },
  1889. "notice": function(content, type, target, where, offset, option){
  1890. _form.notice(content, type, target, where, offset, option);
  1891. },
  1892. "dialog": function ( options ) {
  1893. return _form.dialog( options );
  1894. },
  1895. "selectOrg": function ( container, options, delayLoad) {
  1896. if( !container )container = _form.app.content;
  1897. return new MWF.O2Selector(container, options, delayLoad);
  1898. },
  1899. "addEvent": function(e, f){_form.addEvent(e, f);},
  1900. "openWork": function(id, completedId, title, options){
  1901. var op = options || {};
  1902. op.workId = id;
  1903. op.workCompletedId = completedId;
  1904. op.docTitle = title;
  1905. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1906. return layout.desktop.openApplication(this.event, "process.Work", op);
  1907. },
  1908. "openJob": function(id, choice, options, callback){
  1909. var workData = null, handel;
  1910. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1911. if (json.data) workData = json.data;
  1912. }.bind(this), null, false);
  1913. if( !layout.inBrowser && o2.typeOf(callback) === "function" ){
  1914. if( !options )options = {};
  1915. var queryLoad = options.onQueryLoad;
  1916. options.onQueryLoad = function () {
  1917. if( o2.typeOf(queryLoad) === "function" )queryLoad.call(this);
  1918. callback(this);
  1919. }
  1920. }
  1921. runCallback = function ( handel ) {
  1922. if( o2.typeOf(callback) === "function" ) {
  1923. if (layout.inBrowser) {
  1924. callback(handel);
  1925. } else if (options && options.appId) {
  1926. if (layout.desktop && layout.desktop.apps && layout.desktop.apps[options.appId]) {
  1927. callback(layout.desktop.apps[options.appId], true);
  1928. }else{
  1929. callback(handel, false);
  1930. }
  1931. }else{
  1932. callback(handel, false);
  1933. }
  1934. }
  1935. };
  1936. if (workData){
  1937. var len = workData.workList.length + workData.workCompletedList.length;
  1938. if (len){
  1939. if (len>1 && choice){
  1940. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1941. workData.workList.each(function(work){
  1942. var workNode = new Element("div", {
  1943. "styles": {
  1944. "background": "#ffffff",
  1945. "border-radius": "10px",
  1946. "clear": "both",
  1947. "margin-bottom": "10px",
  1948. "height": "40px",
  1949. "padding": "10px 10px"
  1950. }
  1951. }).inject(node);
  1952. 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>" +
  1953. "<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>"+
  1954. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1955. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1956. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1957. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1958. workNode.set("html", html);
  1959. var action = workNode.getElement(".MWFAction");
  1960. action.store("work", work);
  1961. action.addEvent("click", function(e){
  1962. var work = e.target.retrieve("work");
  1963. if (work){
  1964. handel = this.openWork(work.id, null, work.title, options);
  1965. runCallback( handel );
  1966. }
  1967. dlg.close();
  1968. }.bind(this));
  1969. }.bind(this));
  1970. workData.workCompletedList.each(function(work){
  1971. var workNode = new Element("div", {
  1972. "styles": {
  1973. "background": "#ffffff",
  1974. "border-radius": "10px",
  1975. "clear": "both",
  1976. "margin-bottom": "10px",
  1977. "height": "40px",
  1978. "padding": "10px 10px"
  1979. }
  1980. }).inject(node);
  1981. 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>" +
  1982. "<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>"+
  1983. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1984. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1985. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1986. workNode.set("html", html);
  1987. var action = workNode.getElement(".MWFAction");
  1988. action.store("work", work);
  1989. action.addEvent("click", function(e){
  1990. var work = e.target.retrieve("work");
  1991. if (work){
  1992. handel = this.openWork(null, work.id, work.title, options);
  1993. runCallback( handel );
  1994. }
  1995. dlg.close();
  1996. }.bind(this));
  1997. }.bind(this));
  1998. var height = node.getSize().y+20;
  1999. if (height>600) height = 600;
  2000. var dlg = o2.DL.open({
  2001. "title": o2.LP.widget.choiceWork,
  2002. "style" : "user",
  2003. "isResize": false,
  2004. "content": node,
  2005. "buttonList": [
  2006. {
  2007. "type" : "cancel",
  2008. "text": o2.LP.widget.close,
  2009. "action": function(){dlg.close();}
  2010. }
  2011. ]
  2012. });
  2013. }else{
  2014. if (workData.workList.length){
  2015. var work = workData.workList[0];
  2016. handel = this.openWork(work.id, null, work.title, options);
  2017. runCallback( handel );
  2018. return handel;
  2019. }else{
  2020. var work = workData.workCompletedList[0];
  2021. handel = this.openWork(null, work.id, work.title, options);
  2022. runCallback( handel );
  2023. return handel;
  2024. }
  2025. }
  2026. }else{
  2027. runCallback(new Error("Can't open this Job", {
  2028. cause: workData
  2029. }));
  2030. }
  2031. }else{
  2032. runCallback(new Error("Can't open this Job", {
  2033. cause: workData
  2034. }));
  2035. }
  2036. },
  2037. "openDocument": function(id, title, options){
  2038. var op = options || {};
  2039. op.documentId = id;
  2040. op.docTitle = title || "";
  2041. op.appId = (op.appId) || ("cms.Document"+id);
  2042. if( op.onPostPublish ){
  2043. op.postPublish = op.onPostPublish;
  2044. delete op.onPostPublish;
  2045. }
  2046. if( op.onAfterPublish ){
  2047. op.afterPublish = op.onAfterPublish;
  2048. delete op.onAfterPublish;
  2049. }
  2050. if( op.onAfterSave ){
  2051. op.afterSave = op.onAfterSave;
  2052. delete op.onAfterSave;
  2053. }
  2054. if( op.onBeforeClose ){
  2055. op.beforeClose = op.onBeforeClose;
  2056. delete op.onBeforeClose;
  2057. }
  2058. if( op.onPostDelete ){
  2059. op.postDelete = op.onPostDelete;
  2060. delete op.onPostDelete;
  2061. }
  2062. return layout.desktop.openApplication(this.event, "cms.Document", op);
  2063. },
  2064. "openPortal": function (name, page, par) {
  2065. var action = MWF.Actions.get("x_portal_assemble_surface");
  2066. action.getApplication(name, function (json) {
  2067. if (json.data) {
  2068. if (page) {
  2069. action.getPageByName(page, json.data.id, function (pageJson) {
  2070. var pageId = (pageJson.data) ? pageJson.data.id : "";
  2071. layout.desktop.openApplication(null, "portal.Portal", {
  2072. "portalId": json.data.id,
  2073. "pageId": pageId,
  2074. "parameters": par,
  2075. "appId": (par && par.appId) || ("portal.Portal" + json.data.id + pageId)
  2076. })
  2077. });
  2078. } else {
  2079. layout.desktop.openApplication(null, "portal.Portal", {
  2080. "portalId": json.data.id,
  2081. "parameters": par,
  2082. "appId": (par && par.appId) || ("portal.Portal" + json.data.id)
  2083. })
  2084. }
  2085. }
  2086. });
  2087. },
  2088. "openCMS": function(name){
  2089. var action = MWF.Actions.get("x_cms_assemble_control");
  2090. action.getColumn(name, function(json){
  2091. if (json.data){
  2092. layout.desktop.openApplication(null, "cms.Module", {
  2093. "columnId": json.data.id,
  2094. "appId": "cms.Module"+json.data.id
  2095. });
  2096. }
  2097. });
  2098. },
  2099. "openProcess": function(name){
  2100. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2101. action.getApplication(name, function(json){
  2102. if (json.data){
  2103. layout.desktop.openApplication(null, "process.Application", {
  2104. "id": json.data.id,
  2105. "appId": "process.Application"+json.data.id
  2106. });
  2107. }
  2108. });
  2109. },
  2110. "openApplication":function(name, options, status){
  2111. return layout.desktop.openApplication(null, name, options, status);
  2112. },
  2113. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle, restrictToColumn) {
  2114. var column = columnOrOptions;
  2115. var onAfterPublish, onPostPublish;
  2116. if (typeOf(columnOrOptions) == "object") {
  2117. column = columnOrOptions.column;
  2118. category = columnOrOptions.category;
  2119. data = columnOrOptions.data;
  2120. identity = columnOrOptions.identity;
  2121. callback = columnOrOptions.callback;
  2122. target = columnOrOptions.target;
  2123. latest = columnOrOptions.latest;
  2124. selectColumnEnable = columnOrOptions.selectColumnEnable;
  2125. ignoreTitle = columnOrOptions.ignoreTitle;
  2126. restrictToColumn = columnOrOptions.restrictToColumn;
  2127. onAfterPublish = columnOrOptions.onAfterPublish;
  2128. onPostPublish = columnOrOptions.onPostPublish;
  2129. }
  2130. if (target) {
  2131. if (layout.app && layout.app.inBrowser) {
  2132. layout.app.content.empty();
  2133. layout.app = null;
  2134. }
  2135. }
  2136. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  2137. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  2138. "documentData": data,
  2139. "identity": identity,
  2140. "ignoreTitle": ignoreTitle === true,
  2141. "ignoreDrafted": latest === false,
  2142. "selectColumnEnable": !category || selectColumnEnable === true,
  2143. "restrictToColumn": restrictToColumn === true || (!!category && selectColumnEnable !== true),
  2144. "categoryFlag": category, //category id or name
  2145. "columnFlag": column, //column id or name,
  2146. "onStarted": function (documentId, data, windowHandle) {
  2147. if (callback) callback(documentId, data, windowHandle);
  2148. },
  2149. "onPostPublish": function () {
  2150. if(onPostPublish)onPostPublish();
  2151. },
  2152. "onAfterPublish": function () {
  2153. if(onAfterPublish)onAfterPublish();
  2154. }
  2155. });
  2156. starter.load();
  2157. })
  2158. },
  2159. "startProcess": function(app, process, data, identity, callback, target, latest, afterCreated, skipDraftCheck){
  2160. if (arguments.length>2){
  2161. for (var i=2; i<arguments.length; i++){
  2162. if (typeOf(arguments[i])=="boolean"){
  2163. target = arguments[i];
  2164. break;
  2165. }
  2166. }
  2167. }
  2168. if (target){
  2169. if (layout.app && layout.app.inBrowser){
  2170. //layout.app.content.empty();
  2171. layout.app.$openWithSelf = true;
  2172. }
  2173. }
  2174. if (!app || !process){
  2175. var cmpt = this.getApp();
  2176. o2.requireApp([["process.TaskCenter", "lp."+o2.language], ["process.TaskCenter", ""]],"", function(){
  2177. var obj = {
  2178. "lp": o2.xApplication.process.TaskCenter.LP,
  2179. "content": cmpt.content,
  2180. "addEvent": function(type, fun){
  2181. cmpt.addEvent(type, fun);
  2182. },
  2183. "getAction": function (callback) {
  2184. if (!this.action) {
  2185. this.action = o2.Actions.get("x_processplatform_assemble_surface");
  2186. if (callback) callback();
  2187. } else {
  2188. if (callback) callback();
  2189. }
  2190. },
  2191. "desktop": layout.desktop,
  2192. "refreshAll": function(){},
  2193. "notice": cmpt.notice,
  2194. }
  2195. o2.JSON.get("../x_component_process_TaskCenter/$Main/default/css.wcss", function(data){
  2196. obj.css = data;
  2197. }, false);
  2198. if (!cmpt.processStarter) cmpt.processStarter = new o2.xApplication.process.TaskCenter.Starter(obj);
  2199. cmpt.processStarter.load({
  2200. "appFlag": app
  2201. });
  2202. }, true, true);
  2203. return "";
  2204. }
  2205. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", null, false);
  2206. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  2207. if (json.data){
  2208. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  2209. "workData": data,
  2210. "identity": identity,
  2211. "latest": latest,
  2212. "skipDraftCheck": skipDraftCheck,
  2213. "onStarted": function(data, title, processName){
  2214. var application;
  2215. if (data.work){
  2216. var work = data.work;
  2217. var options = {
  2218. "draft": work,
  2219. "draftData":data.data||{},
  2220. "appId": "process.Work"+(new o2.widget.UUID).toString(),
  2221. "desktopReload": false
  2222. };
  2223. if( !layout.inBrowser && afterCreated )options.onPostLoadForm = afterCreated;
  2224. application = layout.desktop.openApplication(null, "process.Work", options);
  2225. }else{
  2226. var currentTask = [];
  2227. data.each(function(work){
  2228. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  2229. }.bind(this));
  2230. if (currentTask.length==1){
  2231. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  2232. if( !layout.inBrowser && afterCreated )options.onPostLoadForm = afterCreated;
  2233. application =layout.desktop.openApplication(null, "process.Work", options);
  2234. }else{}
  2235. }
  2236. // var currentTask = [];
  2237. // data.each(function(work){
  2238. // if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  2239. // }.bind(this));
  2240. //
  2241. // if (currentTask.length==1){
  2242. // var options = {"workId": currentTask[0], "appId": currentTask[0]};
  2243. // layout.desktop.openApplication(null, "process.Work", options);
  2244. // }else{}
  2245. if (callback) callback(data);
  2246. if(layout.inBrowser && afterCreated){
  2247. afterCreated(application)
  2248. }
  2249. }.bind(this)
  2250. });
  2251. starter.load();
  2252. }
  2253. });
  2254. }
  2255. };
  2256. Object.defineProperty(this.form, "readonly", {
  2257. get: function(){ return !!_form.options.readonly; }
  2258. });
  2259. this.target = ev.target;
  2260. this.event = ev.event;
  2261. this.status = ev.status;
  2262. this.session = layout.desktop.session;
  2263. this.Actions = o2.Actions;
  2264. this.query = function(option){
  2265. // options = {
  2266. // "name": "statementName",
  2267. // "data": "json data",
  2268. // "firstResult": 1,
  2269. // "maxResults": 100,
  2270. // "success": function(){},
  2271. // "error": function(){},
  2272. // "async": true or false, default is true
  2273. // }
  2274. if (option){
  2275. var json = (option.data) || {};
  2276. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  2277. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  2278. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  2279. }
  2280. };
  2281. this.Table = MWF.xScript.createTable();
  2282. //兼容流程拷贝过来的表单
  2283. var _fitWorkContextList = function(callback, error){
  2284. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  2285. var list = [];
  2286. if (cb) cb(list);
  2287. return [];
  2288. };
  2289. this.workContext = {
  2290. "getWork": function(){
  2291. return (ev.data || {}).$work || {} ;
  2292. },
  2293. "getActivity": function(){return {}},
  2294. "getTask": function(){return {}},
  2295. "getTaskList": function(callback, error){
  2296. return _fitWorkContextList(callback, error)
  2297. },
  2298. "getTaskListByJob": function(callback, error){
  2299. return _fitWorkContextList(callback, error)
  2300. },
  2301. "getTaskCompletedList": function(callback, error){
  2302. return _fitWorkContextList(callback, error)
  2303. },
  2304. "getTaskCompletedListByJob": function(callback, error){
  2305. return _fitWorkContextList(callback, error)
  2306. },
  2307. "getReadList": function(callback, error){
  2308. return _fitWorkContextList(callback, error)
  2309. },
  2310. "getReadListByJob": function(callback, error){
  2311. return _fitWorkContextList(callback, error)
  2312. },
  2313. "getReadCompletedList": function(callback, error){
  2314. return _fitWorkContextList(callback, error)
  2315. },
  2316. "getReadCompletedListByJob": function(callback, error){
  2317. return _fitWorkContextList(callback, error)
  2318. },
  2319. "getReviewList": function(callback, error){
  2320. return _fitWorkContextList(callback, error)
  2321. },
  2322. "getReviewListByJob": this.getReviewList,
  2323. "getJobTaskList": this.getTaskListByJob,
  2324. "getJobReadList": this.getReadListByJob,
  2325. "getJobTaskCompletedList": this.getTaskCompletedListByJob,
  2326. "getJobReadCompletedList": this.getReadCompletedListByJob,
  2327. "getJobReviewList": this.getReviewList,
  2328. "getControl": function(){return ev.control;},
  2329. "getWorkLogList": function(){return [];},
  2330. "getRecordList": function(){return [];},
  2331. "getAttachmentList": function(callback, error){
  2332. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  2333. if(cb)cb( ev.attachmentList );
  2334. return ev.attachmentList;
  2335. },
  2336. "getRouteList": function(){return [];},
  2337. "getInquiredRouteList": function(){return null;}
  2338. };
  2339. this.workContent = this.workContext;
  2340. };
  2341. if( !MWF.xScript.createTable )MWF.xScript.createTable = function(){
  2342. return function(name){
  2343. this.name = name;
  2344. this.action = o2.Actions.load("x_query_assemble_surface").TableAction;
  2345. this.listRowNext = function(id, count, success, error, async){
  2346. return this.action.listRowNext(this.name, id, count, success, error, async);
  2347. };
  2348. this.listRowPrev = function(id, count, success, error, async){
  2349. return this.action.listRowPrev(this.name, id, count, success, error, async);
  2350. };
  2351. this.listRowSelect = function(where, orderBy, size, success, error, async){
  2352. return this.action.listRowSelect(this.name, {"where": where, "orderBy": orderBy, "size": size || ""}, success, error, async);
  2353. };
  2354. this.listRowSelectWhere = function(where, success, error, async){
  2355. return this.action.listRowSelectWhere(this.name, where, success, error, async);
  2356. };
  2357. this.rowCountWhere = function(where, success, error, async){
  2358. return this.action.rowCountWhere(this.name, where, success, error, async);
  2359. };
  2360. this.deleteRow = function(id, success, error, async){
  2361. return this.action.rowDelete(this.name, id, success, error, async);
  2362. };
  2363. this.deleteAllRow = function(success, error, async){
  2364. return this.action.rowDeleteAll(this.name, success, error, async);
  2365. };
  2366. this.getRow = function(id, success, error, async){
  2367. return this.action.rowGet(this.name, id, success, error, async);
  2368. };
  2369. this.insertRow = function(data, success, error, async){
  2370. return this.action.rowInsert(this.name, data, success, error, async);
  2371. };
  2372. this.addRow = function(data, success, error, async){
  2373. return this.action.rowInsertOne(this.name, data, success, error, async);
  2374. };
  2375. this.updateRow = function(id, data, success, error, async){
  2376. return this.action.rowUpdate(this.name, id, data, success, error, async);
  2377. };
  2378. this.partUpdateRow = function(id, data, success, error, async){
  2379. return this.action.rowPartUpdate(this.name, id, data, success, error, async);
  2380. };
  2381. }
  2382. };
  2383. var getArrayJSONData = function(jData, p, _form){
  2384. return new MWF.xScript.CMSJSONData(jData, function(data, key, _self){
  2385. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  2386. while (p && !_form.forms[p.getKey()]) p = p.getParent();
  2387. //if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  2388. var k = (p) ? p.getKey() : "";
  2389. if (k) if(_form.forms[k]) if(_form.forms[k].resetData) _form.forms[k].resetData();
  2390. //if(p) if(p.getKey()) if(_forms[p.getKey()]) if(_forms[p.getKey()].render) _forms[p.getKey()].render();
  2391. }, "", p, _form);
  2392. };
  2393. MWF.xScript.CMSJSONData = function(data, callback, key, parent, _form){
  2394. var getter = function(data, callback, k, _self){
  2395. return function(){
  2396. var t = typeOf(data[k]);
  2397. if (["array","object"].indexOf(t)===-1){
  2398. return data[k]
  2399. }else{
  2400. if (t==="array"){
  2401. if (window.Proxy){
  2402. var arr = new Proxy(data[k], {
  2403. get: function(o, k){
  2404. return (o2.typeOf(o[k])==="object") ? getArrayJSONData(o[k], _self, _form) : o[k];
  2405. },
  2406. set: function(o, k, v){
  2407. o[k] = v;
  2408. if (callback) callback(o, k, _self);
  2409. return true;
  2410. }
  2411. });
  2412. return arr;
  2413. }else{
  2414. var arr =[];
  2415. data[k].forEach(function(d, i){
  2416. arr.push((o2.typeOf(d)==="object") ? getArrayJSONData(d, _self, _form) : d);
  2417. });
  2418. return arr;
  2419. }
  2420. // var arr =[];
  2421. // data[k].forEach(function(d, i){
  2422. // arr.push((o2.typeOf(d)==="object") ? getArrayJSONData(d, _self, _form) : d);
  2423. // });
  2424. // return arr;
  2425. //return data[k];
  2426. }else{
  2427. return new MWF.xScript.CMSJSONData(data[k], callback, k, _self, _form);
  2428. }
  2429. }
  2430. };
  2431. };
  2432. var setter = function(data, callback, k, _self){
  2433. return function(v){
  2434. data[k] = v;
  2435. //debugger;
  2436. //this.add(k, v, true);
  2437. if (callback) callback(data, k, _self);
  2438. }
  2439. };
  2440. var define = function(){
  2441. var o = {};
  2442. 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])};
  2443. o["length"] = {"get": function(){return Object.keys(data).length;}};
  2444. o["some"] = {"get": function(){return data.some;}};
  2445. MWF.defineProperties(this, o);
  2446. var methods = {
  2447. "getKey": {"value": function(){ return key; }},
  2448. "getParent": {"value": function(){ return parent; }},
  2449. "toString": {"value": function() { return data.toString();}},
  2450. "setSection": {"value": function(newKey, newValue){
  2451. this.add(newKey, newValue, true);
  2452. try {
  2453. var path = [this.getKey()];
  2454. p = this.getParent();
  2455. while (p && p.getKey()){
  2456. path.unshift(p.getKey());
  2457. p = p.getParent();
  2458. }
  2459. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  2460. }catch(e){
  2461. }
  2462. }},
  2463. "add": {"value": function(newKey, newValue, overwrite, noreset){
  2464. if( newKey.test(/^\d+$/) ){
  2465. throw new Error("Field name '"+newKey+"' cannot contain only numbers" );
  2466. }
  2467. if (arguments.length<2 || newKey.indexOf("..")===-1){
  2468. var flag = true;
  2469. var type = typeOf(data);
  2470. if (type==="array"){
  2471. if (arguments.length<2){
  2472. data.push(newKey);
  2473. newValue = newKey;
  2474. newKey = data.length-1;
  2475. }else{
  2476. if (!newKey && newKey!==0){
  2477. data.push(newValue);
  2478. newKey = data.length-1;
  2479. }else{
  2480. if (newKey>=data.length){
  2481. data.push(newValue);
  2482. newKey = data.length-1;
  2483. }else{
  2484. if (overwrite) data[newKey] = newValue;
  2485. newValue = data[newKey];
  2486. flag = false;
  2487. }
  2488. }
  2489. }
  2490. if (flag){
  2491. var o = {};
  2492. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2493. MWF.defineProperties(this, o);
  2494. }
  2495. if (!noreset) this[newKey] = newValue;
  2496. }else if (type==="object"){
  2497. if (!this.hasOwnProperty(newKey)){
  2498. if (!data[newKey] || overwrite){
  2499. data[newKey] = newValue;
  2500. }
  2501. newValue = data[newKey];
  2502. if (flag){
  2503. var o = {};
  2504. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2505. MWF.defineProperties(this, o);
  2506. }
  2507. if (!noreset) this[newKey] = newValue;
  2508. }else{
  2509. if (!Object.getOwnPropertyDescriptor(this, newKey).get){
  2510. var o = {};
  2511. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2512. MWF.defineProperties(this, o);
  2513. }
  2514. if (overwrite){
  2515. data[newKey] = newValue;
  2516. if (!noreset) this[newKey] = newValue;
  2517. }
  2518. }
  2519. }
  2520. return this[newKey];
  2521. }else{
  2522. var keys = newKey.split("..");
  2523. var kk = keys.shift();
  2524. var d = this.add(kk, {}, false, true);
  2525. if (keys.length) return d.add(keys.join(".."), newValue, overwrite, noreset);
  2526. return d;
  2527. }
  2528. }},
  2529. "check": {
  2530. "value": function(kk, v){
  2531. var value = typeOf( v ) === "null" ? "" : v;
  2532. this.add(kk, value, false, true);
  2533. }
  2534. },
  2535. "del": {"value": function(delKey){
  2536. if (!this.hasOwnProperty(delKey)) return null;
  2537. // delete data[delKey];
  2538. // delete this[delKey];
  2539. data[delKey] = "";
  2540. this[delKey] = "";
  2541. return this;
  2542. }}
  2543. };
  2544. MWF.defineProperties(this, methods);
  2545. };
  2546. var type = typeOf(data);
  2547. if (type==="object" || type==="array") define.apply(this);
  2548. };
  2549. // MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  2550. // var getter = function(data, callback, k, _self){
  2551. // return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  2552. // };
  2553. // var setter = function(data, callback, k, _self){
  2554. // return function(v){
  2555. // data[k] = v;
  2556. // //debugger;
  2557. // //this.add(k, v, true);
  2558. // if (callback) callback(data, k, _self);
  2559. // }
  2560. // };
  2561. // var define = function(){
  2562. // var o = {};
  2563. // 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])};
  2564. // o["length"] = {"get": function(){return Object.keys(data).length;}};
  2565. // o["some"] = {"get": function(){return data.some;}};
  2566. // MWF.defineProperties(this, o);
  2567. //
  2568. // var methods = {
  2569. // "getKey": {"value": function(){ return key; }},
  2570. // "getParent": {"value": function(){ return parent; }},
  2571. // "toString": {"value": function() { return data.toString();}},
  2572. // "add": {"value": function(newKey, newValue, overwrite){
  2573. // var flag = true;
  2574. // var type = typeOf(data);
  2575. // if (type==="array"){
  2576. // if (arguments.length<2){
  2577. // data.push(newKey);
  2578. // newValue = newKey;
  2579. // newKey = data.length-1;
  2580. // }else{
  2581. // if (!newKey && newKey!==0){
  2582. // data.push(newValue);
  2583. // newKey = data.length-1;
  2584. // }else{
  2585. // flag = false;
  2586. // }
  2587. // }
  2588. // if (flag){
  2589. // var o = {};
  2590. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2591. // MWF.defineProperties(this, o);
  2592. // }
  2593. // this[newKey] = newValue;
  2594. // }else if (type==="object"){
  2595. // if (!this.hasOwnProperty(newKey)){
  2596. // data[newKey] = newValue;
  2597. //
  2598. // if (flag){
  2599. // var o = {};
  2600. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2601. // MWF.defineProperties(this, o);
  2602. // }
  2603. // this[newKey] = newValue;
  2604. // }else{
  2605. // if (overwrite) this[newKey] = newValue;
  2606. // }
  2607. // }
  2608. //
  2609. // return this[newKey];
  2610. // }},
  2611. // "del": {"value": function(delKey){
  2612. // if (!this.hasOwnProperty(delKey)) return null;
  2613. // delete data[delKey];
  2614. // delete this[delKey];
  2615. // return this;
  2616. // }}
  2617. // };
  2618. // MWF.defineProperties(this, methods);
  2619. // };
  2620. // var type = typeOf(data);
  2621. // if (type==="object" || type==="array") define.apply(this);
  2622. // };
  2623. //MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  2624. // var getter = function(data, callback, k, _self){
  2625. // return function(){return (["array","object"].indexOf(typeOf(data[k]))==-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  2626. // }
  2627. // var setter = function(data, callback, k, _self){
  2628. // return function(v){
  2629. // data[k] = v;
  2630. // if (callback) callback(data, k, _self);
  2631. // }
  2632. // }
  2633. // var define = function(){
  2634. // var o = {};
  2635. // for (var k in data) o[k] = {
  2636. // "configurable": true,
  2637. // "get": getter.apply(this, [data, callback, k, this]),
  2638. // "set": setter.apply(this, [data, callback, k, this])
  2639. // };
  2640. // o["length"] = {"get": function(){return Object.keys(data).length;}};
  2641. // MWF.defineProperties(this, o);
  2642. // this.getKey = function(){ return key; };
  2643. // this.getParent = function(){ return parent; };
  2644. // this.toString = function() { return data.toString();};
  2645. // this.add = function(newKey, newValue){
  2646. // var type = typeOf(data);
  2647. // if (!this.hasOwnProperty(newKey)){
  2648. // if (type=="array"){
  2649. // data.push(newValue || {});
  2650. // newKey = data.length-1;
  2651. // }else{
  2652. // data[newKey] = newValue || {};
  2653. // }
  2654. // var o = {};
  2655. // o[newKey] = {"configurable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  2656. // MWF.defineProperties(this, o);
  2657. // }
  2658. // this[newKey] = newValue;
  2659. // return this;
  2660. // };
  2661. // this.del = function(delKey){
  2662. // if (!this.hasOwnProperty(delKey)) return null;
  2663. // delete data[newKey];
  2664. // delete this[newKey];
  2665. // return this;
  2666. // };
  2667. // }
  2668. // var type = typeOf(data);
  2669. // if (type=="object" || type=="array") define.apply(this);
  2670. //};
  2671. //MWF.xScript.createCMSDict = function(application){
  2672. // return function(name){
  2673. // var applicationId = application;
  2674. // this.name = name;
  2675. // MWF.require("MWF.xScript.Actions.CMSDictActions", null, false);
  2676. // var action = new MWF.xScript.Actions.CMSDictActions();
  2677. //
  2678. // this.get = function(path, success, failure){
  2679. // var value = null;
  2680. // if( path ){
  2681. // var arr = path.split(/\./g);
  2682. // var ar = arr.map(function(v){
  2683. // return encodeURIComponent(v);
  2684. // });
  2685. // //var p = path.replace(/\./g, "/");
  2686. // var p = ar.join("/");
  2687. // action.getDict(applicationId, encodeURIComponent(this.name), p, function(json){
  2688. // value = json.data;
  2689. // if (success) success(json.data);
  2690. // }, function(xhr, text, error){
  2691. // if (failure) failure(xhr, text, error);
  2692. // }, false);
  2693. // }else{
  2694. // action.getDictWhole(applicationId, encodeURIComponent(this.name), function(json){
  2695. // value = json.data;
  2696. // if (success) success(json.data);
  2697. // }, function(xhr, text, error){
  2698. // if (failure) failure(xhr, text, error);
  2699. // }, false);
  2700. // }
  2701. // return value;
  2702. // };
  2703. //
  2704. // this.set = function(path, value, success, failure){
  2705. // var p = path.replace(/\./g, "/");
  2706. // action.setDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  2707. // if (success) success(json.data);
  2708. // }, function(xhr, text, error){
  2709. // if (failure) failure(xhr, text, error);
  2710. // });
  2711. // };
  2712. // this.add = function(path, value, success, failure){
  2713. // var p = path.replace(/\./g, "/");
  2714. // action.addDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  2715. // if (success) success(json.data);
  2716. // }, function(xhr, text, error){
  2717. // if (failure) failure(xhr, text, error);
  2718. // });
  2719. // };
  2720. // this["delete"] = function(path, success, failure){
  2721. // var p = path.replace(/\./g, "/");
  2722. // action.deleteDict(applicationId, encodeURIComponent(this.name), p, function(json){
  2723. // if (success) success(json.data);
  2724. // }, function(xhr, text, error){
  2725. // if (failure) failure(xhr, text, error);
  2726. // });
  2727. // };
  2728. // this.destory = this["delete"];
  2729. // }
  2730. //};
  2731. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  2732. if( !MWF.xScript.addDictToCache )MWF.xScript.addDictToCache = function ( options, path, json ) {
  2733. if( !path )path = "root";
  2734. if( path.indexOf("root") !== 0 )path = "root." + path ;
  2735. var type = options.appType || "process";
  2736. var enableAnonymous = (options.enableAnonymous || options.anonymous) || false;
  2737. var appFlagList = [];
  2738. if( options.application )appFlagList.push( options.application );
  2739. if( options.appId )appFlagList.push( options.appId );
  2740. if( options.appName )appFlagList.push( options.appName );
  2741. if( options.appAlias )appFlagList.push( options.appAlias );
  2742. var dictFlagList = [];
  2743. if( options.id )dictFlagList.push( options.id );
  2744. if( options.name )dictFlagList.push( options.name );
  2745. if( options.alias )dictFlagList.push( options.alias );
  2746. var cache = {};
  2747. cache[path] = json;
  2748. for( var i=0; i<appFlagList.length; i++ ){
  2749. for( var j=0; j<dictFlagList.length; j++ ){
  2750. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  2751. if( !MWF.xScript.dictLoaded[k] ){
  2752. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  2753. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  2754. }else if( i===0 && j===0 ){
  2755. MWF.xScript.setDictToCache( k, path ,json );
  2756. var arr = path.split(/\./g);
  2757. var p;
  2758. var cache = MWF.xScript.dictLoaded[k];
  2759. for( var l=0 ; l<arr.length; l++ ){
  2760. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  2761. if( cache[ p ] )break;
  2762. }
  2763. if( p ){
  2764. var mathP = p+".";
  2765. Object.keys( cache ).each( function( path, idx){
  2766. if( path.indexOf( mathP ) === 0 )delete cache[path];
  2767. })
  2768. }
  2769. }
  2770. }
  2771. }
  2772. };
  2773. if( !MWF.xScript.getMatchedDict )MWF.xScript.getMatchedDict = function(key, path){
  2774. if( !path )path = "root";
  2775. if( path.indexOf("root") !== 0 )path = "root." + path ;
  2776. var arr = path.split(/\./g);
  2777. if( MWF.xScript.dictLoaded[key] ){
  2778. var dicts = MWF.xScript.dictLoaded[key];
  2779. var list = Array.clone(arr);
  2780. var p;
  2781. var dict;
  2782. for( var i=0 ; i<arr.length; i++ ){
  2783. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  2784. list.shift();
  2785. if( dicts[ p ] ){
  2786. dict = dicts[ p ];
  2787. break;
  2788. }
  2789. }
  2790. return {
  2791. dict : dict,
  2792. unmatchedPathList : list
  2793. }
  2794. }
  2795. return {
  2796. dict : null,
  2797. unmatchedPathList : list
  2798. }
  2799. };
  2800. if( !MWF.xScript.insertDictToCache )MWF.xScript.insertDictToCache = function(key, path, json){
  2801. var p = path;
  2802. if( !p )p = "root";
  2803. if( p.indexOf("root") !== 0 )p = "root." + p ;
  2804. if( MWF.xScript.dictLoaded[key] ){
  2805. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2806. var dict = matchedDict.dict;
  2807. var list = matchedDict.unmatchedPathList;
  2808. if( !dict ){
  2809. MWF.xScript.dictLoaded[key][p] = json;
  2810. }else if( !list || list.length === 0 ){
  2811. MWF.xScript.dictLoaded[key][p] = json;
  2812. }else{
  2813. for( var j=0; j<list.length-1; j++ ){
  2814. if( !dict[ list[j] ] ){
  2815. dict[ list[j] ] = {};
  2816. }
  2817. dict = dict[ list[j] ];
  2818. }
  2819. var lastPath = list[list.length-1];
  2820. if( !dict[lastPath] ){
  2821. dict[lastPath] = json;
  2822. }else if( typeOf( dict[lastPath] ) === "array" ){
  2823. dict[lastPath].push( json );
  2824. }
  2825. }
  2826. }else{
  2827. MWF.xScript.dictLoaded[key] = {};
  2828. MWF.xScript.dictLoaded[key][p] = json;
  2829. }
  2830. };
  2831. if( !MWF.xScript.setDictToCache )MWF.xScript.setDictToCache = function(key, path, json){
  2832. var p = path;
  2833. if( !p )p = "root";
  2834. if( p.indexOf("root") !== 0 )p = "root." + p ;
  2835. if( MWF.xScript.dictLoaded[key] ){
  2836. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2837. var dict = matchedDict.dict;
  2838. var list = matchedDict.unmatchedPathList;
  2839. if( !dict ){
  2840. MWF.xScript.dictLoaded[key][p] = json;
  2841. }else if( !list || list.length === 0 ){
  2842. MWF.xScript.dictLoaded[key][p] = json;
  2843. }else{
  2844. for( var j=0; j<list.length-1; j++ ){
  2845. if( !dict[ list[j] ] ){
  2846. dict[ list[j] ] = {};
  2847. }
  2848. dict = dict[ list[j] ];
  2849. }
  2850. dict[list[list.length-1]] = json;
  2851. }
  2852. }else{
  2853. MWF.xScript.dictLoaded[key] = {};
  2854. MWF.xScript.dictLoaded[key][p] = json;
  2855. }
  2856. };
  2857. if( !MWF.xScript.getDictFromCache )MWF.xScript.getDictFromCache = function( key, path ){
  2858. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2859. var dict = matchedDict.dict;
  2860. var list = matchedDict.unmatchedPathList;
  2861. if( dict ){
  2862. for( var j=0; j<list.length; j++ ){
  2863. dict = dict[ list[j] ];
  2864. if( !dict )return null;
  2865. }
  2866. return dict;
  2867. }
  2868. return null;
  2869. };
  2870. if( !MWF.xScript.deleteDictToCache )MWF.xScript.deleteDictToCache = function(key, path){
  2871. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2872. var dict = matchedDict.dict;
  2873. var list = matchedDict.unmatchedPathList;
  2874. if( dict){
  2875. for( var j=0; j<list.length-1; j++ ){
  2876. dict = dict[ list[j] ];
  2877. if( !dict )return;
  2878. }
  2879. if( list.length ){
  2880. delete dict[list[list.length-1]];
  2881. }
  2882. }
  2883. };
  2884. if( !MWF.xScript.createCMSDict )MWF.xScript.createCMSDict = function(application, appType){
  2885. //optionsOrName : {
  2886. // type : "", //默认为process, 可以为 process cms
  2887. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  2888. // name : "", // 数据字典名称/别名/id
  2889. // anonymous : false //允许在未登录的情况下读取CMS的数据字典, 该参数名也可以是 enableAnonymous
  2890. //}
  2891. //或者name: "" // 数据字典名称/别名/id
  2892. return function(optionsOrName){
  2893. var options = optionsOrName;
  2894. if( typeOf( options ) == "string" ){
  2895. options = {
  2896. name : options,
  2897. type: appType,
  2898. application: application
  2899. };
  2900. }
  2901. var name = this.name = options.name;
  2902. var type;
  2903. if( options.type === "service"){
  2904. type = options.type;
  2905. }else{
  2906. type = ( options.type && options.application ) ? options.type : "cms";
  2907. }
  2908. var applicationId = options.application || application;
  2909. var enableAnonymous = ( options.enableAnonymous || options.anonymous ) || false;
  2910. var opt = {
  2911. "appType" : type,
  2912. "name" : name,
  2913. "appId" : applicationId,
  2914. "enableAnonymous" : enableAnonymous
  2915. };
  2916. var key = name+type+applicationId+enableAnonymous;
  2917. // if (!dictLoaded[key]) dictLoaded[key] = {};
  2918. // this.dictData = dictLoaded[key];
  2919. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2920. var action;
  2921. if (type === "cms") {
  2922. action = MWF.Actions.get("x_cms_assemble_control");
  2923. } else if( type === "portal" ){
  2924. action = MWF.Actions.get("x_portal_assemble_surface");
  2925. }else if( type === "service" ){
  2926. key = name+type+enableAnonymous;
  2927. action = MWF.Actions.get("x_program_center");
  2928. } else {
  2929. action = MWF.Actions.get("x_processplatform_assemble_surface");
  2930. }
  2931. var encodePath = function( path ){
  2932. var arr = path.split(/\./g);
  2933. var ar = arr.map(function(v){
  2934. return encodeURIComponent(v);
  2935. });
  2936. return ( type === "portal" || type === "service" ) ? ar.join(".") : ar.join("/");
  2937. };
  2938. this.get = function(path, success, failure, async, refresh){
  2939. var value = null;
  2940. if (success===true) async=true;
  2941. if (failure===true) async=true;
  2942. if (!refresh ){
  2943. var data = MWF.xScript.getDictFromCache( key, path );
  2944. if( data ){
  2945. if (success && o2.typeOf(success)=="function") success( data );
  2946. if( !!async ){
  2947. return Promise.resolve( data );
  2948. }else{
  2949. return data;
  2950. }
  2951. }
  2952. }
  2953. // var cb = function(json){
  2954. // value = json.data;
  2955. // MWF.xScript.addDictToCache(opt, path, value);
  2956. // if (success && o2.typeOf(success)=="function") value = success(json.data);
  2957. // return value;
  2958. // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  2959. var cb = function(json){
  2960. value = json.data;
  2961. MWF.xScript.addDictToCache(opt, path, value);
  2962. if (success && o2.typeOf(success)=="function") value = success(json.data);
  2963. return value;
  2964. };
  2965. var promise;
  2966. if( type === "service" ){
  2967. if (path){
  2968. var p = encodePath( path );
  2969. promise = action.getDictData(encodeURIComponent(this.name), p, cb, null, !!async, false);
  2970. }else{
  2971. promise = action.getDictRoot(this.name, cb, null, !!async, false);
  2972. }
  2973. }else{
  2974. if (path){
  2975. var p = encodePath( path );
  2976. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async, false);
  2977. }else{
  2978. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async, false);
  2979. }
  2980. }
  2981. return (!!async) ? promise : value;
  2982. // if (path){
  2983. // var p = encodePath( path );
  2984. // //var p = path.replace(/\./g, "/");
  2985. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  2986. // value = json.data;
  2987. // // this.dictData[path] = value;
  2988. // MWF.xScript.addDictToCache(opt, path, value);
  2989. // if (success) success(json.data);
  2990. // }.bind(this), function(xhr, text, error){
  2991. // if (failure) failure(xhr, text, error);
  2992. // }, !!async);
  2993. // }else{
  2994. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  2995. // value = json.data;
  2996. // // this.dictData["root"] = value;
  2997. // MWF.xScript.addDictToCache(opt, path, value);
  2998. // if (success) success(json.data);
  2999. // }.bind(this), function(xhr, text, error){
  3000. // if (failure) failure(xhr, text, error);
  3001. // }, !!async);
  3002. // }
  3003. //return value;
  3004. };
  3005. this.set = function(path, value, success, failure){
  3006. var p = encodePath( path );
  3007. //var p = path.replace(/\./g, "/");
  3008. var successCallback = function(json){
  3009. MWF.xScript.setDictToCache(key, path, value);
  3010. if (success) return success(json.data);
  3011. };
  3012. var failureCallback = function(xhr, text, error){
  3013. if (failure) return failure(xhr, text, error);
  3014. };
  3015. if( type === "service" ){
  3016. return action.setDictData(encodeURIComponent(this.name), p, value, successCallback, failureCallback, false, false);
  3017. }else{
  3018. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, successCallback, failureCallback, false, false);
  3019. }
  3020. };
  3021. this.add = function(path, value, success, failure){
  3022. var p = encodePath( path );
  3023. //var p = path.replace(/\./g, "/");
  3024. var successCallback = function(json){
  3025. MWF.xScript.insertDictToCache(key, path, value);
  3026. if (success) return success(json.data);
  3027. };
  3028. var failureCallback = function(xhr, text, error){
  3029. if (failure) return failure(xhr, text, error);
  3030. };
  3031. if( type === "service" ) {
  3032. return action.addDictData(encodeURIComponent(this.name), p, value, successCallback, failureCallback, false, false);
  3033. }else{
  3034. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, successCallback, failureCallback, false, false);
  3035. }
  3036. };
  3037. this["delete"] = function(path, success, failure){
  3038. var p = encodePath( path );
  3039. //var p = path.replace(/\./g, "/");
  3040. var successCallback = function(json){
  3041. MWF.xScript.deleteDictToCache(key, path);
  3042. if (success) return success(json.data);
  3043. };
  3044. var failureCallback = function(xhr, text, error){
  3045. if (failure) return failure(xhr, text, error);
  3046. };
  3047. if( type === "service" ) {
  3048. return action.deleteDictData(encodeURIComponent(this.name), p, successCallback, failureCallback, false, false);
  3049. }else{
  3050. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, successCallback, failureCallback, false, false);
  3051. }
  3052. };
  3053. this.destory = this["delete"];
  3054. }
  3055. };