$Module.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. MWF.require("MWF.widget.Common", null, false);
  2. /** @classdesc $Module 组件类,此类为所有组件的父类。
  3. * @class
  4. * @o2category FormComponents
  5. * @hideconstructor
  6. * */
  7. MWF.xApplication.process.Xform.$Module = MWF.APP$Module = new Class(
  8. /** @lends MWF.xApplication.process.Xform.$Module# */
  9. {
  10. Implements: [Events],
  11. options: {
  12. /**
  13. * 组件加载前触发。queryLoad执行的时候,当前组件没有在form里注册,通过this.form.get("fieldId")不能获取到当前组件,需要用this.target获取。
  14. * @event MWF.xApplication.process.Xform.$Module#queryLoad
  15. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  16. */
  17. /**
  18. * 组件加载后触发.
  19. * @event MWF.xApplication.process.Xform.$Module#postLoad
  20. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  21. */
  22. /**
  23. * 组件加载后触发.
  24. * @event MWF.xApplication.process.Xform.$Module#load
  25. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  26. */
  27. "moduleEvents": ["load", "queryLoad", "postLoad"]
  28. },
  29. initialize: function(node, json, form, options){
  30. /**
  31. * @summary 组件的节点,mootools封装过的Dom对象,可以直接使用原生的js和moootools方法访问和操作该对象。
  32. * @see https://mootools.net/core/docs/1.6.0/Element/Element
  33. * @member {Element}
  34. * @example
  35. * //可以在脚本中获取该组件
  36. * var field = this.form.get("fieldId"); //获取组件对象
  37. * field.node.setStyle("font-size","12px"); //给节点设置样式
  38. */
  39. this.node = $(node);
  40. this.node.store("module", this);
  41. /**
  42. * @summary 组件的配置信息,比如id,类型,是否只读等等。可以在组件的queryLoad事件里修改该配置来对组件做一些改变。
  43. * @member {JsonObject}
  44. * @example
  45. * //可以在脚本中获取该组件
  46. * var json = this.form.get("fieldId").json; //获取组件对象
  47. * var id = json.id; //获取组件的id
  48. * var type = json.type; //获取组件的类型,如Textfield 为文本输入组件,Select为下拉组件
  49. *
  50. * //在组件queryLoad事件里设置组件只读。
  51. * //当前组件的queryLoad事件运行时还没有在form里注册,通过this.form.get("fieldId")不能获取到当前组件,需要用this.target获取。
  52. * var json = this.target.json;
  53. * json.isReadonly = true; //设置组件为只读。
  54. */
  55. this.json = json;
  56. /**
  57. * @summary 组件的所在表单对象.
  58. * @member {MWF.xApplication.process.Xform.Form}
  59. * @example
  60. * var form = this.form.get("fieldId").form; //获取组件所在表单对象
  61. * var container = form.container; //获取表单容器
  62. */
  63. this.form = form;
  64. /**
  65. * 当前组件在数据表格或者数据模板中时,可以通过此属性获取所在行(条目)对象.
  66. * @member {MWF.xApplication.process.Xform.Datatemplate.Line|MWF.xApplication.process.Xform.DatatablePC.Line|MWF.xApplication.process.Xform.DatatableMobile.Line}
  67. * @example
  68. * //获取当前组件所在数据模板/数据表格的行(条目)对象
  69. * var line = this.target.parentLine;
  70. * //获取当前字段所在行下标
  71. * var index = line.getIndex();
  72. * //获取当前字段所在条目的subject字段的值
  73. * var data = line.getModule("subject").getData();
  74. * //设置当前字段所在条目的subject字段的值
  75. * line.getModule("subject").setData("test1");
  76. */
  77. this.parentLine = null;
  78. },
  79. /**
  80. * @summary 根据组件的校验设置进行校验。
  81. * @param {String} [routeName] - 可选,路由名称.
  82. * @example
  83. * if( !this.form.get('fieldId').validate() ){
  84. * return false;
  85. * }
  86. * @return {Boolean} 是否通过校验
  87. */
  88. validate: function (routeName, opinion) {
  89. if( this.validationMode )this.validationMode();
  90. if( this.validation ){
  91. return this.validation(routeName, opinion);
  92. }else{
  93. return true;
  94. }
  95. },
  96. validation: function (routeName, opinion) {
  97. if (!this.isReadonly()){
  98. if (this.getInputData){
  99. this._setBusinessData(this.getInputData("change"));
  100. }
  101. if (this.validationFormat){
  102. if (!this.validationFormat()) return false;
  103. }
  104. if (!this.validationConfig(routeName, opinion)) return false;
  105. if (!this.json.validation) return true;
  106. if (!this.json.validation.code) return true;
  107. this.currentRouteName = routeName;
  108. var flag = this.form.Macro.exec(this.json.validation.code, this);
  109. this.currentRouteName = "";
  110. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  111. if (flag.toString() !== "true") {
  112. this.notValidationMode(flag);
  113. return false;
  114. }
  115. }
  116. return true;
  117. },
  118. saveValidation: function () {
  119. return true;
  120. },
  121. /**
  122. * 当前组件在数据源组件中时,可以通过此方法获取所在的上级数据源/子数据源/子数项组件.
  123. * @param {String} [type] 需要获取的类型,"source"为表示数据源,"subSource"表示子数据源,"subSourceItem"表示子数据项组件。
  124. * 如果该参数省略,则获取离当前组件最近的上述组件。
  125. * @return {Source|SubSource|SubSourceItem}。
  126. * @example
  127. * var source = this.target.getSource(); //获取当前组件的所在子上级数据源/子数据源/子数项组件.
  128. * var data = source.data; //获取数据
  129. *
  130. * var source = this.form.get("fieldId").getSource("source"); //获取数据源组件
  131. * var data = source.data; //获取数据
  132. */
  133. getSource: function( type ){
  134. if( type ){
  135. var parent = this.node.getParent();
  136. while(parent && parent.get("MWFtype")!= type ){
  137. parent = parent.getParent();
  138. }
  139. return (parent) ? parent.retrieve("module") : null;
  140. }else{
  141. return this._getSource();
  142. }
  143. },
  144. _getSource: function(){
  145. var parent = this.node.getParent();
  146. while(parent && (
  147. parent.get("MWFtype")!="source" &&
  148. parent.get("MWFtype")!="subSource" &&
  149. parent.get("MWFtype")!="subSourceItem"
  150. )) parent = parent.getParent();
  151. return (parent) ? parent.retrieve("module") : null;
  152. },
  153. /**
  154. * 获取当前组件所在的祖先组件.
  155. * @param {String} [type] 需要获取的组件类型。
  156. * 如果该参数省略,则获取离当前组件最近的祖先组件。type有效值如下:
  157. * <div>form- 表单</div>
  158. * <div>common- 通用组件</div>
  159. * <div>datatable- 数据表格</div>
  160. * <div>datatableline- 数据表格行</div>
  161. * <div>datatemplate- 数据模板</div>
  162. * <div>datatemplateline- 数据模板行</div>
  163. * <div>div- 容器组件</div>
  164. * <div>elcommon- Element通用组件</div>
  165. * <div>elcontainer- Element容器组件</div>
  166. * <div>subform- 子表单</div>
  167. * <div>source- 数据源组件</div>
  168. * <div>subsource- 子数据源</div>
  169. * <div>subsourceitem- 子数据项组件</div>
  170. * <div>tab- 分页组件</div>
  171. * <div>tabpage- 分页组件的某个分页</div>
  172. * <div>table- 表格</div>
  173. * <div>tabletd- 单元格</div>
  174. * <div>widget- 部件</div>
  175. * @param {Function} [validateFunction] 进一步校验,参数为获取到匹配到类型的组件,返回false继续往上取对应类型的组件,返回true返回该组件。
  176. * @return {MWF.xApplication.process.Xform.$Module}。
  177. * @example
  178. * var module = this.target.getParentModule(); //获取最近的祖先。
  179. *
  180. * var datatemplateLine = this.target.getParentModule("datatemplateline"); //获取当前组件所在的数据模板行.
  181. *
  182. * var module = this.target.getParentModule(null, function(module){
  183. * return module.json.id === "div_1";
  184. * }); //获取当前组件id为div_1的父组件。
  185. */
  186. getParentModule: function( type, validateFunction ){
  187. var lcType = ( type || "" ).toLowerCase();
  188. if( lcType === "form" )return this.form;
  189. var module, vm;
  190. var parent;
  191. if( ["datatableline","datatemplateline", "tabpage", "tab", "widget", "table"].contains( lcType ) ){
  192. parent = this.node;
  193. }else{
  194. parent = this.node.getParent();
  195. }
  196. while(parent) {
  197. module = null;
  198. vm = null;
  199. var MWFtype = parent.get("MWFtype");
  200. if( MWFtype ){
  201. module = parent.retrieve("module");
  202. if( module ){
  203. switch (lcType) {
  204. case "":
  205. vm = module;
  206. break;
  207. case "table":
  208. if( module.table )vm = module.table;
  209. break;
  210. case "widget":
  211. if( module.widget )vm = module.widget;
  212. break;
  213. case "tab":
  214. if( module.tab )vm = module.tab;
  215. break;
  216. case "tabpage":
  217. if( module.page && module.tab )vm = module.page;
  218. break;
  219. case "datatableline":
  220. if( module.parentLine && module.parentDatatable )vm = module.parentLine;
  221. break;
  222. case "datatemplateline":
  223. if( module.parentLine && module.parentDatatemplate )vm = module.parentLine;
  224. break;
  225. case "subsourceitem":
  226. if( MWFtype.toLowerCase() === "subsourceitem" )vm = module;
  227. break;
  228. case "tabletd":
  229. if( module.json.type === "Table$Td" )vm = module;
  230. break;
  231. default:
  232. if( module.json.type.toLowerCase() === lcType )vm = module;
  233. break;
  234. }
  235. }
  236. if( vm ){
  237. if( !validateFunction ){
  238. return vm;
  239. }else if( validateFunction && validateFunction.call(this.form.Macro, vm) ){
  240. return vm;
  241. }
  242. }
  243. parent = parent.getParent();
  244. }else{
  245. parent = parent.getParent();
  246. }
  247. }
  248. return null;
  249. },
  250. isReadonly : function(){
  251. return !!(this.readonly || this.json.isReadonly || this.form.json.isReadonly || this.isSectionMergeRead());
  252. },
  253. isAllSectionShow: function(){
  254. return this.json.showAllSection && this.json.section === "yes" && this.isSectionData();
  255. },
  256. isSectionMergeRead: function(){
  257. return this.json.sectionMerge === "read" && this.json.section !== "yes" && this.isSectionData()
  258. },
  259. isSectionMergeEdit: function(){
  260. return this.json.sectionMerge === "edit" && this.json.section !== "yes" && this.isSectionData()
  261. },
  262. isSectionData: function(){ //数据是否经过区段处理
  263. var data = this.getBusinessDataById();
  264. return o2.typeOf( data ) === "object";
  265. },
  266. getSortedSectionData: function(){ //获取合并排序后的数据
  267. var data = this.getBusinessDataById();
  268. var array = [];
  269. for( var key in data ){
  270. array.push({
  271. sectionKey: key,
  272. key: key,
  273. data: data[key]
  274. })
  275. }
  276. if( this.json.sectionMergeSortScript && this.json.sectionMergeSortScript.code){
  277. array.sort( function(a, b){
  278. this.form.Macro.environment.event = {
  279. "a": a,
  280. "b": b
  281. };
  282. var flag = this.form.Macro.exec(this.json.sectionMergeSortScript.code, this);
  283. this.form.Macro.environment.event = null;
  284. return flag;
  285. }.bind(this))
  286. }
  287. return array;
  288. },
  289. //区段合并的区段值
  290. _getMergeSectionKey: function( data ){
  291. switch (this.json.sectionKey){
  292. case "person":
  293. return layout.desktop.session.user.id;
  294. case "unit":
  295. return (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  296. case "activity":
  297. return (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  298. case "splitValue":
  299. return (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  300. case "script":
  301. var d;
  302. if( this.json.sectionKeyScript && this.json.sectionKeyScript.code){
  303. this.form.Macro.environment.event = data;
  304. d = this.form.Macro.exec(this.json.sectionKeyScript.code, this);
  305. this.form.Macro.environment.event = null;
  306. }else{
  307. d = "";
  308. }
  309. return d;
  310. default:
  311. return "";
  312. }
  313. },
  314. getSectionKeyWithMerge: function(data, callback){
  315. switch (this.json.sectionKey) {
  316. case "person":
  317. if( !this.form.sectionKeyPersonMap )this.form.sectionKeyPersonMap = {};
  318. if( this.form.sectionKeyPersonMap[data.key] ){
  319. callback(this.form.sectionKeyPersonMap[data.key]);
  320. return;
  321. }
  322. //只获取一次。把callback存起来,等异步调用完成后一次性执行callback
  323. if( !this.form.sectionKeyCallbackMap )this.form.sectionKeyCallbackMap = {};
  324. var map = this.form.sectionKeyCallbackMap;
  325. if( !map[ data.key ] )map[ data.key ] = [];
  326. if( !map[ data.key ].length ){
  327. Promise.resolve( o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({
  328. "personList": [data.key]
  329. })).then(function(json){
  330. var key = json.data.length ? json.data[0].name : data.key;
  331. this.form.sectionKeyPersonMap[data.key] = key;
  332. while( map[ data.key ].length ){
  333. map[ data.key ].shift()( key );
  334. }
  335. }.bind(this));
  336. }
  337. map[ data.key ].push( callback );
  338. break;
  339. case "unit":
  340. callback( data.key.split("@")[0] );
  341. break;
  342. case "activity":
  343. case "splitValue":
  344. callback( data.key );
  345. break;
  346. case "script":
  347. var d;
  348. if( this.json.sectionKeyScript && this.json.sectionKeyScript.code){
  349. this.form.Macro.environment.event = data;
  350. d = this.form.Macro.exec(this.json.sectionKeyScript.code, this);
  351. this.form.Macro.environment.event = null;
  352. }else{
  353. d = "";
  354. }
  355. callback( d );
  356. break;
  357. }
  358. },
  359. _loadMergeReadNode: function(keepHtml, position) {
  360. if (!keepHtml) {
  361. this.node.empty();
  362. this.node.set({
  363. "nodeId": this.json.id,
  364. "MWFType": this.json.type
  365. });
  366. }
  367. switch (this.json.mergeTypeRead) {
  368. case "htmlScript":
  369. this._loadMergeReadNodeByHtml();
  370. break;
  371. case "dataScript":
  372. this._loadMergeReadNodeByData();
  373. break;
  374. default:
  375. this._loadMergeReadNodeByDefault(position);
  376. break;
  377. }
  378. },
  379. _loadMergeReadNodeByHtml: function(){
  380. if (this.json.sectionMergeReadHtmlScript && this.json.sectionMergeReadHtmlScript.code) {
  381. var html = this.form.Macro.exec(this.json.sectionMergeReadHtmlScript.code, this);
  382. this.node.set("html", html);
  383. }
  384. },
  385. _loadMergeReadNodeByData: function(){
  386. if (this.json.sectionMergeReadDataScript && this.json.sectionMergeReadDataScript.code) {
  387. var data = this.form.Macro.exec(this.json.sectionMergeReadDataScript.code, this);
  388. }
  389. },
  390. _loadMergeReadNodeByDefault: function( position ){
  391. var data = this.getSortedSectionData();
  392. var sectionNodeStyles = this._parseStyles(this.json.sectionNodeStyles);
  393. var sectionKeyStyles = this._parseStyles(this.json.sectionKeyStyles);
  394. var sectionContentStyles = this._parseStyles(this.json.sectionContentStyles);
  395. data.each(function(d){
  396. var node = new Element("div.mwf_sectionnode", {
  397. styles : sectionNodeStyles
  398. }).inject(this.node, position || "bottom");
  399. if( this.json.showSectionKey ){
  400. var keyNode = new Element("div.mwf_sectionkey", {
  401. styles : sectionKeyStyles
  402. }).inject(node);
  403. this.getSectionKeyWithMerge( d, function (key) {
  404. if( o2.typeOf(key) === "string" ){
  405. keyNode.set("text", key + (this.json.keyContentSeparator || ""));
  406. }else{
  407. Promise.resolve(key).then(function (k) {
  408. keyNode.set("text", k + (this.json.keyContentSeparator || ""));
  409. }.bind(this))
  410. }
  411. }.bind(this));
  412. }
  413. var contentNode = new Element("div.mwf_sectioncontent", {
  414. styles : sectionContentStyles
  415. }).inject(node);
  416. this._loadMergeReadContentNode( contentNode, d )
  417. }.bind(this))
  418. },
  419. _loadMergeReadContentNode: function( contentNode, data ){
  420. contentNode.set("text", data.data)
  421. },
  422. _loadMergeEditNode: function(){
  423. if( this.json.mergeTypeEdit === "script" ){
  424. this._loadMergeEditNodeByScript();
  425. }else{
  426. this._loadMergeEditNodeByDefault();
  427. }
  428. },
  429. _loadMergeEditNodeByScript: function(){
  430. if (this.json.sectionMergeEditScript && this.json.sectionMergeEditScript.code) {
  431. var data = this.form.Macro.exec(this.json.sectionMergeEditScript.code, this);
  432. this._setBusinessData( data );
  433. this._loadNode();
  434. }
  435. },
  436. _loadMergeEditNodeByDefault: function(){
  437. var data = this.getSortedSectionData();
  438. data = data.map(function(d){ return d.data; });
  439. this._setBusinessData( data.join("") );
  440. this._loadNode();
  441. },
  442. /**
  443. * @summary 隐藏组件.
  444. * @example
  445. * this.form.get("fieldId").hide(); //隐藏组件
  446. */
  447. hide: function(){
  448. var dsp = this.node.getStyle("display");
  449. if (dsp!=="none") this.node.store("mwf_display", dsp);
  450. this.node.setStyle("display", "none");
  451. if (this.iconNode) this.iconNode.setStyle("display", "none");
  452. },
  453. /**
  454. * @summary 显示组件.
  455. * @example
  456. * this.form.get("fieldId").show(); //显示组件
  457. */
  458. show: function(){
  459. var dsp = this.node.retrieve("mwf_display", dsp);
  460. this.node.setStyle("display", dsp);
  461. if (this.iconNode) this.iconNode.setStyle("display", "block");
  462. },
  463. load: function(){
  464. this._loadModuleEvents();
  465. if (this.fireEvent("queryLoad")){
  466. this._queryLoaded();
  467. this._loadUserInterface();
  468. this._loadStyles();
  469. this._loadDomEvents();
  470. //this._loadEvents();
  471. this._afterLoaded();
  472. this.fireEvent("postLoad");
  473. if( this.moduleSelectAG && typeOf(this.moduleSelectAG.then) === "function" ){
  474. this.moduleSelectAG.then(function () {
  475. this.fireEvent("load");
  476. this.isLoaded = true;
  477. }.bind(this))
  478. }else{
  479. this.fireEvent("load");
  480. this.isLoaded = true;
  481. }
  482. }
  483. },
  484. _loadUserInterface: function(){
  485. // this.node = this.node;
  486. },
  487. _loadStyles: function(){
  488. if (this.json.styles){
  489. this.node.setStyles( this._parseStyles(this.json.styles) );
  490. }
  491. // if (this.json.styles) Object.each(this.json.styles, function(value, key){
  492. // if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  493. // var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  494. // var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  495. // var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  496. // if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  497. // value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  498. // }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  499. // value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  500. // }
  501. // if (value.indexOf("/x_portal_assemble_surface")!==-1){
  502. // value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  503. // }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  504. // value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  505. // }
  506. // if (value.indexOf("/x_cms_assemble_control")!==-1){
  507. // value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  508. // }else if (value.indexOf("x_cms_assemble_control")!==-1){
  509. // value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  510. // }
  511. // value = o2.filterUrl(value);
  512. // }
  513. // this.node.setStyle(key, value);
  514. // }.bind(this));
  515. },
  516. _parseStyles: function( styles ){
  517. var s = {};
  518. Object.each(styles || {}, function(value, key){
  519. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  520. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  521. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  522. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  523. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  524. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  525. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  526. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  527. }
  528. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  529. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  530. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  531. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  532. }
  533. if (value.indexOf("/x_cms_assemble_control")!==-1){
  534. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  535. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  536. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  537. }
  538. value = o2.filterUrl(value);
  539. }
  540. s[key] = value;
  541. }.bind(this));
  542. return s;
  543. },
  544. _loadModuleEvents : function(){
  545. Object.each(this.json.events, function(e, key){
  546. if (e.code){
  547. if (this.options.moduleEvents.indexOf(key)!==-1){
  548. this.addEvent(key, function(event){
  549. return this.form.Macro.fire(e.code, this, event);
  550. }.bind(this));
  551. }
  552. }
  553. }.bind(this));
  554. },
  555. _loadDomEvents: function(){
  556. Object.each(this.json.events, function(e, key){
  557. if (e.code){
  558. if (this.options.moduleEvents.indexOf(key)===-1){
  559. this.node.addEvent(key, function(event){
  560. return this.form.Macro.fire(e.code, this, event);
  561. }.bind(this));
  562. }
  563. }
  564. }.bind(this));
  565. },
  566. _loadEvents: function(){
  567. Object.each(this.json.events, function(e, key){
  568. if (e.code){
  569. if (this.options.moduleEvents.indexOf(key)!==-1){
  570. this.addEvent(key, function(event){
  571. return this.form.Macro.fire(e.code, this, event);
  572. }.bind(this));
  573. }else{
  574. this.node.addEvent(key, function(event){
  575. return this.form.Macro.fire(e.code, this, event);
  576. }.bind(this));
  577. }
  578. }
  579. }.bind(this));
  580. },
  581. addModuleEvent: function(key, fun){
  582. if (this.options.moduleEvents.indexOf(key)!==-1){
  583. this.addEvent(key, function(event){
  584. return (fun) ? fun(this, event) : null;
  585. }.bind(this));
  586. }else{
  587. this.node.addEvent(key, function(event){
  588. return (fun) ? fun(this, event) : null;
  589. }.bind(this));
  590. }
  591. },
  592. _getBusinessData: function(id){
  593. var v;
  594. if (this.json.section=="yes"){
  595. v = this._getBusinessSectionData(id);
  596. }else {
  597. if (this.json.type==="Opinion"){
  598. v = this._getBusinessSectionDataByPerson(id);
  599. }else{
  600. // return this.form.businessData.data[this.json.id] || "";
  601. var value = this.getBusinessDataById(null, id);
  602. return (o2.typeOf(value)!=="null") ? value : "";
  603. //return this.getBusinessDataById() || "";
  604. }
  605. }
  606. //if (o2.typeOf(v)==="string") v = o2.dtxt(v);
  607. return v;
  608. },
  609. _getBusinessSectionData: function(id){
  610. switch (this.json.sectionBy){
  611. case "person":
  612. return this._getBusinessSectionDataByPerson(id);
  613. case "unit":
  614. return this._getBusinessSectionDataByUnit(id);
  615. case "activity":
  616. return this._getBusinessSectionDataByActivity(id);
  617. case "splitValue":
  618. return this._getBusinessSectionDataBySplitValue(id);
  619. case "script":
  620. return this._getBusinessSectionDataByScript(((this.json.sectionByScript) ? this.json.sectionByScript.code : ""), id);
  621. default:
  622. // return this.form.businessData.data[this.json.id] || "";
  623. return this.getBusinessDataById(null, id) || "";
  624. }
  625. },
  626. _getBusinessSectionDataByPerson: function(id){
  627. this.form.sectionListObj[id||this.json.id] = layout.desktop.session.user.id;
  628. // var dataObj = this.form.businessData.data[this.json.id];
  629. var dataObj = this.getBusinessDataById(null, id);
  630. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  631. },
  632. _getBusinessSectionDataByUnit: function(id){
  633. this.form.sectionListObj[id || this.json.id] = "";
  634. // var dataObj = this.form.businessData.data[this.json.id];
  635. var dataObj = this.getBusinessDataById(null, id);
  636. if (!dataObj) return "";
  637. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  638. if (key) this.form.sectionListObj[id||this.json.id] = key;
  639. return (key) ? (dataObj[key] || "") : "";
  640. },
  641. _getBusinessSectionDataByActivity: function(id){
  642. this.form.sectionListObj[id||this.json.id] = "";
  643. // var dataObj = this.form.businessData.data[this.json.id];
  644. var dataObj = this.getBusinessDataById(null, id);
  645. if (!dataObj) return "";
  646. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  647. if (key) this.form.sectionListObj[id||this.json.id] = key;
  648. return (key) ? (dataObj[key] || "") : "";
  649. },
  650. _getBusinessSectionDataBySplitValue: function(id){
  651. this.form.sectionListObj[id||this.json.id] = "";
  652. // var dataObj = this.form.businessData.data[this.json.id];
  653. var dataObj = this.getBusinessDataById(null, id);
  654. if (!dataObj) return "";
  655. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  656. if (key) this.form.sectionListObj[id||this.json.id] = key;
  657. return (key) ? (dataObj[key] || "") : "";
  658. },
  659. _getBusinessSectionDataByScript: function(code, id){
  660. this.form.sectionListObj[id||this.json.id] = "";
  661. // var dataObj = this.form.businessData.data[this.json.id];
  662. var dataObj = this.getBusinessDataById(null, id);
  663. if (!dataObj) return "";
  664. var key = this.form.Macro.exec(code, this);
  665. if (key) this.form.sectionListObj[id||this.json.id] = key;
  666. return (key) ? (dataObj[key] || "") : "";
  667. },
  668. _setEnvironmentData: function(v){
  669. if (this.json.section=="yes"){
  670. this._setEnvironmentSectionData(v);
  671. }else {
  672. if (this.json.type==="Opinion"){
  673. this._setEnvironmentSectionDataByPerson(v);
  674. }else{
  675. this.setEnvironmentDataById(v);
  676. }
  677. }
  678. },
  679. _setEnvironmentSectionData: function(v){
  680. switch (this.json.sectionBy){
  681. case "person":
  682. var key = layout.desktop.session.user.id;
  683. this._setEnvironmentSectionDataByKey(key, v);
  684. break;
  685. case "unit":
  686. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  687. this._setEnvironmentSectionDataByKey(key, v);
  688. break;
  689. case "activity":
  690. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  691. this._setEnvironmentSectionDataByKey(key, v);
  692. break;
  693. case "splitValue":
  694. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  695. this._setEnvironmentSectionDataByKey(key, v);
  696. break;
  697. case "script":
  698. var key = this.form.Macro.exec(this.json.sectionByScript.code, this);
  699. this._setEnvironmentSectionDataByKey(key, v);
  700. break;
  701. default:
  702. this.setEnvironmentDataById(v);
  703. }
  704. },
  705. _setEnvironmentSectionDataByKey: function(key, v){
  706. if (key){
  707. var evdata = this.getBusinessDataById(this.form.Macro.environment.data);
  708. var evdata;
  709. if (!evdata){
  710. evdata = this.setEnvironmentDataById({});
  711. }
  712. if (!evdata.hasOwnProperty(key)){
  713. evdata.add(key, v);
  714. }else{
  715. evdata[key] = v;
  716. }
  717. }
  718. },
  719. setEnvironmentDataById: function(v){
  720. //对id类似于 xx..0..xx 的字段进行拆分
  721. var evdata = this.form.Macro.environment.data;
  722. if(this.json.id.indexOf("..") < 1){
  723. if (!evdata.hasOwnProperty(this.json.id)){
  724. evdata.add(this.json.id, v);
  725. }else{
  726. evdata[this.json.id] = v;
  727. }
  728. }else{
  729. var idList = this.json.id.split("..");
  730. idList = idList.map( function(d){ return d.test(/^\d+$/) ? d.toInt() : d; });
  731. //var data = this.form.businessData.data;
  732. var lastIndex = idList.length - 1;
  733. for(var i=0; i<=lastIndex; i++){
  734. var id = idList[i];
  735. if( !id && id !== 0 )return;
  736. if( i === lastIndex ){
  737. if (!evdata.hasOwnProperty(id)){
  738. evdata.add(id, v);
  739. }else{
  740. evdata[id] = v;
  741. }
  742. }else{
  743. var nexId = idList[i+1];
  744. if(o2.typeOf(nexId) === "number"){ //下一个ID是数字
  745. if( !evdata[id] && o2.typeOf(evdata[id]) !== "array" ){
  746. evdata.add(id, []);
  747. }
  748. if( nexId > evdata[id].length ){ //超过了最大下标,丢弃
  749. return;
  750. }
  751. }else{ //下一个ID是字符串
  752. if( !evdata[id] || o2.typeOf(evdata[id]) !== "object"){
  753. evdata.add(id, {});
  754. }
  755. }
  756. evdata = evdata[id];
  757. }
  758. }
  759. }
  760. return evdata;
  761. },
  762. _setBusinessData: function(v, id){
  763. //if (o2.typeOf(v)==="string") v = o2.txt(v);
  764. if (this.json.section=="yes"){
  765. this._setBusinessSectionData(v, id);
  766. }else {
  767. if (this.json.type==="Opinion"){
  768. this._setBusinessSectionDataByPerson(v, id);
  769. }else{
  770. this.setBusinessDataById(v, id);
  771. if (this.json.isTitle) this.form.businessData.data.$work.title = v;
  772. }
  773. }
  774. },
  775. _setBusinessSectionData: function(v, id){
  776. switch (this.json.sectionBy){
  777. case "person":
  778. this._setBusinessSectionDataByPerson(v, id);
  779. break;
  780. case "unit":
  781. this._setBusinessSectionDataByUnit(v, id);
  782. break;
  783. case "activity":
  784. this._setBusinessSectionDataByActivity(v, id);
  785. break;
  786. case "splitValue":
  787. this._setBusinessSectionDataBySplitValue(v, id);
  788. break;
  789. case "script":
  790. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v, id);
  791. break;
  792. default:
  793. this.setBusinessDataById(v, id);
  794. }
  795. },
  796. _setBusinessSectionDataByPerson: function(v, id){
  797. var key = layout.desktop.session.user.id;
  798. this._setBusinessSectionDataByKey(key, v, id);
  799. },
  800. _setBusinessSectionDataByUnit: function(v, id){
  801. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  802. this._setBusinessSectionDataByKey(key, v, id);
  803. },
  804. _setBusinessSectionDataByActivity: function(v, id){
  805. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  806. this._setBusinessSectionDataByKey(key, v, id);
  807. },
  808. _setBusinessSectionDataBySplitValue: function(v, id){
  809. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  810. this._setBusinessSectionDataByKey(key, v, id);
  811. },
  812. _setBusinessSectionDataByScript: function(code, v, id){
  813. var key = this.form.Macro.exec(code, this);
  814. this._setBusinessSectionDataByKey(key, v, id);
  815. },
  816. _setBusinessSectionDataByKey: function(key, v, id){
  817. if (key){
  818. var dataObj = this.getBusinessDataById(null, id);
  819. var evdata;
  820. if (!dataObj){
  821. dataObj = {};
  822. evdata = this.setBusinessDataById(dataObj, id);
  823. }
  824. dataObj[key] = v;
  825. if (evdata) evdata.check(key, v);
  826. }
  827. },
  828. getBusinessDataById: function(d, id){
  829. var data = d || this.form.businessData.data;
  830. var thisId = id || this.json.id;
  831. //对id类似于 xx..0..xx 的字段进行拆分
  832. if(thisId.indexOf("..") < 1){
  833. return data[thisId];
  834. }else{
  835. var idList = thisId.split("..");
  836. idList = idList.map( function(d){ return d.test(/^\d+$/) ? d.toInt() : d; });
  837. var lastIndex = idList.length - 1;
  838. for(var i=0; i<=lastIndex; i++){
  839. var id = idList[i];
  840. if( !id && id !== 0 )return null;
  841. if( ["object","array"].contains(o2.typeOf(data)) ){
  842. if( i === lastIndex ){
  843. return data[id];
  844. }else{
  845. data = data[id];
  846. }
  847. }else{
  848. return null;
  849. }
  850. }
  851. }
  852. },
  853. _checkEvdata: function(evdata, id, v){
  854. switch (o2.typeOf(evdata)){
  855. case "array":
  856. break;
  857. default:
  858. evdata.check(id, v);
  859. }
  860. },
  861. setBusinessDataById: function(v, id){
  862. //对id类似于 xx..0..xx 的字段进行拆分
  863. var evdata = this.form.Macro.environment.data;
  864. var data = this.form.businessData.data;
  865. var thisId = id || this.json.id;
  866. if(thisId.indexOf("..") < 1){
  867. data[thisId] = v;
  868. this._checkEvdata(evdata, thisId, v);
  869. //this.form.businessData.data[this.json.id] = v;
  870. }else{
  871. var idList = thisId.split("..");
  872. idList = idList.map( function(d){ return d.test(/^\d+$/) ? d.toInt() : d; });
  873. //var data = this.form.businessData.data;
  874. var lastIndex = idList.length - 1;
  875. for(var i=0; i<=lastIndex; i++){
  876. var id = idList[i];
  877. if( !id && id !== 0 )return;
  878. if( i === lastIndex ){
  879. data[id] = v;
  880. //evdata.check(id, v);
  881. this._checkEvdata(evdata, id, v);
  882. }else{
  883. var nexId = idList[i+1];
  884. if(o2.typeOf(nexId) === "number"){ //下一个ID是数字
  885. if( !data[id] && o2.typeOf(data[id]) !== "array" ){
  886. data[id] = [];
  887. //evdata.check(id, []);
  888. this._checkEvdata(evdata, id, []);
  889. }
  890. if( nexId > data[id].length ){ //超过了最大下标,丢弃
  891. return;
  892. }
  893. }else{ //下一个ID是字符串
  894. if( !data[id] || o2.typeOf(data[id]) !== "object"){
  895. data[id] = {};
  896. //evdata.check(id, {});
  897. this._checkEvdata(evdata, id, {});
  898. }
  899. }
  900. data = data[id];
  901. evdata = evdata[id];
  902. }
  903. }
  904. }
  905. return evdata;
  906. },
  907. _queryLoaded: function(){},
  908. _afterLoaded: function(){},
  909. setValue: function(){
  910. },
  911. focus: function(){
  912. this.node.focus();
  913. },
  914. _getModuleByPath: function( path ){
  915. /*
  916. 注: 系统的数据中允许多层路径,id上通过..来区分层次:
  917. 1、单层或者是最外层,填"fieldId",表示表单上的直接组件。
  918. 2、如果有多层数据模板,"./fieldId"表示和当前组件id同层次的组件,"../fieldId"表示和上一层组件同层次的组件,以此类推。
  919. 3、如果有多层数据模板,也可通过"datatemplateId.*.datatemplateId2.*.fieldId"来表示全层次路径。datatemplateId表示第一层数据模板的id,datatemplateId2表示第二层的id。
  920. */
  921. if(!path)return;
  922. var idList = this.json.id.split("..");
  923. if( path.contains("*") ){ //允许path中包含*,替代当前path的层次
  924. var paths = path.split(".");
  925. for( var i=0; i<paths.length; i++ ){
  926. if( paths[i].contains("*") && idList[i] ){
  927. var key = paths[i].replace("*", idList[i]);
  928. key = this.form.Macro.exec("return "+key, this);
  929. paths[i] = (key||"").toString();
  930. }
  931. }
  932. path = paths.join("..");
  933. }else if( path.contains("./") ){
  934. var lastName = path.substring(path.indexOf("./")+2, path.length);
  935. var level = (path.substring(0, path.indexOf("./"))+".").split(".").length-1; // /前面有几个.
  936. var idList_copy = Array.clone(idList);
  937. if( idList_copy.length > level*2 ){
  938. for( var i=0; i<level; i++ ){
  939. idList_copy.pop();
  940. if( i > 0)idList_copy.pop();
  941. }
  942. path = idList_copy.join("..")+".."+lastName;
  943. }else{
  944. idList_copy[idList_copy.length-1] = lastName;
  945. path = idList_copy.join("..")
  946. }
  947. }
  948. return this.form.all[path];
  949. }
  950. });