Property.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. MWF.require("MWF.widget.UUID", null,false);
  2. MWF.require("MWF.widget.JsonTemplate", null, false);
  3. MWF.xApplication.process.ProcessDesigner.Property = new Class({
  4. Implements: [Options, Events],
  5. load: function(){
  6. if (!this.process.options.isView){
  7. if (this.fireEvent("queryLoad")){
  8. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  9. this.htmlString = responseText;
  10. this.fireEvent("postLoad");
  11. }.bind(this));
  12. }
  13. this.process.propertyListNode.addEvent("keydown", function(e){e.stopPropagation();});
  14. }
  15. },
  16. editProperty: function(td){
  17. },
  18. getHtmlString: function(callback){
  19. if (!this.htmlString){
  20. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  21. this.htmlString = responseText;
  22. if (callback) callback();
  23. }.bind(this));
  24. }else{
  25. if (callback) callback();
  26. }
  27. },
  28. //隐藏高级属性
  29. hideAdvanced: function(){
  30. if (this.process.panel.showAdvanced && !this.process.panel.showAdvanced.checked){
  31. var advs = this.propertyContent.querySelectorAll("*[data-o2-advanced=\"yes\"]");
  32. if (advs && advs.length){
  33. for (var i=0; i<advs.length; i++){
  34. advs[i].hide();
  35. }
  36. }
  37. }
  38. },
  39. show: function(){
  40. if (!this.process.options.isView){
  41. if (!this.propertyContent){
  42. this.getHtmlString(function(){
  43. debugger;
  44. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.process.propertyListNode);
  45. this.process.panel.propertyTabPage.showTabIm();
  46. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  47. this.propertyContent.set("html", this.JsonTemplate.load());
  48. this.process.panel.data = this.data;
  49. this.setEditNodeEvent();
  50. this.setEditNodeStyles(this.propertyContent);
  51. this.loadPropertyTab();
  52. this.loadFormFieldInput();
  53. this.loadPersonInput();
  54. this.loadCalendarInput();
  55. this.loadScriptInput();
  56. this.loadScriptText();
  57. this.loadConditionInput();
  58. this.loadFormSelect();
  59. this.loadSerial();
  60. this.loadSericalActivitySelect();
  61. this.loadApplicationSelector();
  62. this.loadProcessSelector();
  63. this.loadIconSelect();
  64. this.loadContextRoot();
  65. this.loadProjection();
  66. this.hideAdvanced();
  67. }.bind(this));
  68. //this.loadDutySelector();
  69. }else{
  70. this.process.panel.data = this.data;
  71. this.propertyContent.setStyle("display", "block");
  72. this.process.panel.propertyTabPage.showTabIm();
  73. }
  74. // this.process.isFocus = true;
  75. }
  76. },
  77. //hide: function(){
  78. // if (!this.process.options.isView) {
  79. // this.JsonTemplate = null;
  80. //
  81. // this.scriptTexts.each(function(script){
  82. // MWF.release(script);
  83. // }.bind(this));
  84. // this.scriptTexts = null;
  85. //
  86. // this.propertyContent.set("html", "");
  87. // }
  88. //},
  89. hide: function(){
  90. if (!this.process.options.isView) {
  91. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  92. }
  93. },
  94. loadPropertyTab: function(){
  95. var tabNodes = this.propertyContent.getElements(".MWFTab");
  96. if (tabNodes.length){
  97. var tmpNode = this.propertyContent.getFirst();
  98. var tabAreaNode = new Element("div", {
  99. "styles": this.process.css.propertyTabNode
  100. }).inject(tmpNode, "before");
  101. debugger;
  102. MWF.require("MWF.widget.Tab", function(){
  103. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "moduleList"});
  104. tab.load();
  105. var tabPages = [];
  106. tabNodes.each(function(node){
  107. var tabPage = tab.addTab(node, node.get("title"), false);
  108. tabPages.push(tabPage);
  109. if (node.hasAttribute("data-o2-advanced") && node.dataset["o2Advanced"]=="yes"){
  110. tabPage.tabNode.setAttribute("data-o2-advanced", "yes");
  111. tabPage.tabNode.hide();
  112. }
  113. }.bind(this));
  114. tabPages[0].showTab();
  115. }.bind(this));
  116. }
  117. },
  118. setEditNodeEvent: function(){
  119. var property = this;
  120. // var inputs = this.propertyContent.getElements(".editTableInput");
  121. var inputs = this.propertyContent.getElements("input");
  122. inputs.each(function(input){
  123. var jsondata = input.get("name");
  124. var id = this.process.process.id;
  125. if (this.activity) id = this.activity.data.id;
  126. if (this.route) id = this.route.data.id;
  127. input.set("name", id+jsondata);
  128. if (jsondata){
  129. var inputType = input.get("type").toLowerCase();
  130. switch (inputType){
  131. case "radio":
  132. input.addEvent("change", function(e){
  133. property.setRadioValue(jsondata, this);
  134. });
  135. input.addEvent("blur", function(e){
  136. property.setRadioValue(jsondata, this);
  137. });
  138. input.addEvent("keydown", function(e){
  139. e.stopPropagation();
  140. });
  141. property.setRadioValue(jsondata, input);
  142. break;
  143. case "checkbox":
  144. input.addEvent("keydown", function(e){
  145. e.stopPropagation();
  146. });
  147. break;
  148. default:
  149. input.addEvent("change", function(e){
  150. property.setValue(jsondata, this.value);
  151. });
  152. input.addEvent("blur", function(e){
  153. property.setValue(jsondata, this.value);
  154. });
  155. input.addEvent("keydown", function(e){
  156. if (e.code===13){
  157. property.setValue(jsondata, this.value);
  158. }
  159. e.stopPropagation();
  160. });
  161. property.setValue(jsondata, input.get("value"));
  162. }
  163. }
  164. }.bind(this));
  165. var selects = this.propertyContent.getElements("select");
  166. selects.each(function(select){
  167. var jsondata = select.get("name");
  168. if (jsondata){
  169. select.addEvent("change", function(e){
  170. property.setSelectValue(jsondata, this);
  171. });
  172. //property.setSelectValue(jsondata, select);
  173. }
  174. });
  175. var textareas = this.propertyContent.getElements("textarea");
  176. textareas.each(function(input){
  177. var jsondata = input.get("name");
  178. if (jsondata){
  179. input.addEvent("change", function(e){
  180. property.setValue(jsondata, this.value);
  181. });
  182. input.addEvent("blur", function(e){
  183. property.setValue(jsondata, this.value);
  184. });
  185. input.addEvent("keydown", function(e){
  186. e.stopPropagation();
  187. });
  188. }
  189. }.bind(this));
  190. },
  191. setSelectValue: function(name, select){
  192. var idx = select.selectedIndex;
  193. var options = select.getElements("option");
  194. var value = "";
  195. if (options[idx]){
  196. value = options[idx].get("value");
  197. }
  198. this.data[name] = value;
  199. },
  200. setRadioValue: function(name, input){
  201. if (input.checked){
  202. var oldValue = this.data[name];
  203. var value = input.value;
  204. if (value=="false") value = false;
  205. if (value=="true") value = true;
  206. this.data[name] = value;
  207. if (this.route) this.route._setEditProperty(name, input, oldValue);
  208. }
  209. },
  210. setValue: function(name, value){
  211. var oldValue = this.data[name];
  212. this.data[name] = value;
  213. if (name=="name"){
  214. if (!value) this.data[name] = MWF.APPPD.LP.unnamed;
  215. // this.activity.redraw();
  216. }
  217. if (this.route) this.route._setEditProperty(name, input, oldValue);
  218. },
  219. setEditNodeStyles: function(node){
  220. var nodes = node.getChildren();
  221. if (nodes.length){
  222. nodes.each(function(el){
  223. var cName = el.get("class");
  224. if (cName){
  225. if (this.process.css[cName]) el.setStyles(this.process.css[cName]);
  226. }
  227. this.setEditNodeStyles(el);
  228. }.bind(this));
  229. }
  230. },
  231. loadScriptText: function(){
  232. this.scriptTexts = [];
  233. var scriptNodes = this.propertyContent.getElements(".MWFScriptText");
  234. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptText", function(){
  235. var _self = this;
  236. scriptNodes.each(function(node){
  237. var script = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(node, this.data[node.get("name")], this.process.designer, {
  238. "maskNode": this.process.designer.content,
  239. "maxObj": this.process.designer.paperNode,
  240. "onChange": function(code){
  241. _self.data[node.get("name")] = code;
  242. }
  243. });
  244. this.scriptTexts.push(script);
  245. //this.setScriptItems(script, node);
  246. }.bind(this));
  247. }.bind(this));
  248. },
  249. loadScriptInput: function(){
  250. var scriptNodes = this.propertyContent.getElements(".MWFScript");
  251. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ScriptSelector", function(){
  252. var _self = this;
  253. scriptNodes.each(function(node){
  254. var script = new MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector(node, this.data[node.get("name")], this.process.designer, {
  255. "maskNode": this.process.designer.content,
  256. "onSelected": function(scriptData){
  257. _self.data[node.get("name")] = scriptData.name;
  258. },
  259. "onDelete": function(){
  260. _self.data[node.get("name")] = "";
  261. node.empty();
  262. }
  263. //"onPostSave": function(script){
  264. // this.saveScriptItem(node, script);
  265. //}.bind(this),
  266. //"onQueryDelete": function(script){
  267. // this.deleteScriptItem(node, script);
  268. //}.bind(this)
  269. });
  270. //this.setScriptItems(script, node);
  271. }.bind(this));
  272. }.bind(this));
  273. },
  274. loadScriptArea: function(){
  275. var scriptAreas = this.propertyContent.getElements(".MWFScriptArea");
  276. var formulaAreas = this.propertyContent.getElements(".MWFFormulaArea");
  277. this.loadScriptEditor(scriptAreas);
  278. this.loadScriptEditor(formulaAreas, "formula");
  279. },
  280. loadScriptEditor: function(scriptAreas, style){
  281. scriptAreas.each(function(node){
  282. var title = node.get("title");
  283. var name = node.get("name");
  284. if (!this.data[name]) this.data[name] = {"code": "", "html": ""};
  285. var scriptContent = this.data[name];
  286. MWF.require("MWF.widget.ScriptArea", function(){
  287. var scriptArea = new MWF.widget.ScriptArea(node, {
  288. "title": title,
  289. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  290. "maxObj": this.process.designer.content,
  291. "onChange": function(){
  292. if (!this.data[name]){
  293. this.data[name] = {"code": "", "html": ""};
  294. //if (this.module.form.scriptDesigner) this.module.form.scriptDesigner.addScriptItem(this.data[name], "code", this.data, name);
  295. }
  296. var json = scriptArea.toJson();
  297. this.data[name].code = json.code;
  298. }.bind(this),
  299. //"onSave": function(){
  300. // this.designer.saveForm();
  301. //}.bind(this),
  302. "style": style || "default"
  303. });
  304. scriptArea.load(scriptContent);
  305. }.bind(this));
  306. }.bind(this));
  307. },
  308. loadUnitTypeSelector: function(){
  309. var nodes = this.propertyContent.getElements(".MWFFormUnitTypeSelector");
  310. if (nodes.length){
  311. this.getUnitTypeList(function(){
  312. nodes.each(function(node){
  313. var select = new Element("select").inject(node);
  314. select.addEvent("change", function(e){
  315. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value);
  316. }.bind(this));
  317. this.setUnitTypeSelectOptions(node, select);
  318. this.setValue(select.getParent("div").get("name"), select.options[select.selectedIndex].value);
  319. // var refreshNode = new Element("div", {"styles": this.form.css.propertyRefreshFormNode}).inject(node);
  320. // refreshNode.addEvent("click", function(e){
  321. // this.getUnitTypeList(function(){
  322. // this.setUnitTypeSelectOptions(node, select);
  323. // }.bind(this), true);
  324. // }.bind(this));
  325. }.bind(this));
  326. }.bind(this));
  327. }
  328. },
  329. setUnitTypeSelectOptions: function(node, select){
  330. var name = node.get("name");
  331. select.empty();
  332. var option = new Element("option", {"value":"all", "text": MWF.xApplication.process.ProcessDesigner.LP.all, "selected": (!this.data[name] || this.data[name]==="all")}).inject(select);
  333. this.unitTypeList.each(function(unitType){
  334. var option = new Element("option", {
  335. "text": unitType,
  336. "value": unitType,
  337. "selected": (this.data[name]===unitType)
  338. }).inject(select);
  339. }.bind(this));
  340. },
  341. getUnitTypeList: function(callback, refresh){
  342. if (!this.unitTypeList || refresh){
  343. //MWF.xDesktop.requireApp("Org", "Actions.RestActions", function(){
  344. // var action = new MWF.xApplication.Org.Actions.RestActions();
  345. var action = MWF.Actions.get("x_organization_assemble_control");
  346. action.listUnitType(function(json){
  347. this.unitTypeList = json.data.valueList;
  348. if (callback) callback();
  349. }.bind(this));
  350. //}.bind(this));
  351. }else{
  352. if (callback) callback();
  353. }
  354. },
  355. loadFormFieldInput: function(){
  356. var fieldNodes = this.propertyContent.getElements(".MWFFormFieldPerson");
  357. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  358. fieldNodes.each(function(node){
  359. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  360. "type": "formField",
  361. "application": this.process.process.application,
  362. "fieldType": "person",
  363. "names": this.data[node.get("name")] || [],
  364. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  365. });
  366. }.bind(this));
  367. }.bind(this));
  368. },
  369. createCalendar: function(node){
  370. if (!node.retrieve("calendar")){
  371. var calendar = new MWF.widget.Calendar(node, {
  372. "isTime": true,
  373. "target": node.getParent(),
  374. "style": "xform",
  375. "onChange": function(dv, date, t){
  376. this.setValue(node.get("name"), dv)
  377. }.bind(this)
  378. });
  379. node.store("calendar", calendar);
  380. }
  381. },
  382. loadCalendarInput: function(){
  383. var nodes = this.propertyContent.getElements(".MWFDateTime");
  384. MWF.require("MWF.widget.Calendar", function(){
  385. nodes.each(function(node){
  386. var input = node.getFirst();
  387. input.addEvents({
  388. "click": function(){ this.createCalendar(input) }.bind(this),
  389. "focus": function(){ this.createCalendar(input) }.bind(this)
  390. });
  391. }.bind(this));
  392. }.bind(this));
  393. },
  394. loadPersonInput: function(){
  395. debugger;
  396. var personIdentityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  397. var personNodes = this.propertyContent.getElements(".MWFPersonPerson");
  398. var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  399. var personGroupNodes = this.propertyContent.getElements(".MWFPersonGroup");
  400. var dutyNameNodes = this.propertyContent.getElements(".MWFPersonDuty");
  401. // var personDepartmentNodes = this.propertyContent.getElements(".MWFPersonDepartment");
  402. // var personCompanyNodes = this.propertyContent.getElements(".MWFPersonCompany");
  403. var dutyNodes = this.propertyContent.getElements(".MWFDutySelector");
  404. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  405. personIdentityNodes.each(function(node){
  406. count = node.get("count") || 0;
  407. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  408. "type": "identity",
  409. "names": this.data[node.get("name")],
  410. "count": count,
  411. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  412. });
  413. }.bind(this));
  414. personNodes.each(function(node){
  415. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  416. "type": "person",
  417. "names": this.data[node.get("name")],
  418. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  419. });
  420. }.bind(this));
  421. personUnitNodes.each(function(node){
  422. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  423. "type": "unit",
  424. "names": this.data[node.get("name")],
  425. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  426. });
  427. }.bind(this));
  428. personGroupNodes.each(function(node){
  429. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  430. "type": "group",
  431. "names": this.data[node.get("name")],
  432. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  433. });
  434. }.bind(this));
  435. dutyNodes.each(function(node){
  436. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  437. "type": "duty",
  438. "names": this.data[node.get("name")],
  439. "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this),
  440. "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this)
  441. });
  442. }.bind(this));
  443. dutyNameNodes.each(function(node){
  444. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  445. "type": "dutyName",
  446. "names": this.data[node.get("name")],
  447. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  448. });
  449. }.bind(this));
  450. // personDepartmentNodes.each(function(node){
  451. // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  452. // "type": "department",
  453. // "names": this.data[node.get("name")],
  454. // "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  455. // });
  456. // }.bind(this));
  457. // personCompanyNodes.each(function(node){
  458. // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  459. // "type": "company",
  460. // "names": this.data[node.get("name")],
  461. // "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  462. // });
  463. // }.bind(this));
  464. // dutyNodes.each(function(node){
  465. // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  466. // "type": "duty",
  467. // "names": this.data[node.get("name")],
  468. // "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this),
  469. // "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this)
  470. // });
  471. // }.bind(this));
  472. }.bind(this));
  473. },
  474. removeDutyItem: function(node, item){
  475. if (item.data.id){
  476. var values = JSON.decode(this.data[node.get("name")]) || [];
  477. var value = values.filter(function(v){
  478. return v.id == item.data.id;
  479. });
  480. value.each(function(v) {
  481. values = values.erase(v);
  482. });
  483. this.data[node.get("name")] = JSON.encode(values);
  484. }
  485. item.node.destroy();
  486. MWF.release(item);
  487. delete item;
  488. },
  489. addDutyItem: function(node, ids){
  490. var value = this.data[node.get("name")] || "";
  491. if (!value) value = "[]";
  492. var values = JSON.decode(value);
  493. ids.each(function(id){
  494. if (id.data.dutyId){
  495. for (var i=0; i<values.length; i++){
  496. if (values[i].dutyId===id.data.dutyId){
  497. values[i].name = id.data.name;
  498. values[i].code = id.data.code;
  499. break;
  500. }
  501. }
  502. }else{
  503. id.data.dutyId = new MWF.widget.UUID().toString();
  504. values.push({"name": id.data.name, "id": id.data.id, "dutyId": id.data.dutyId, "code": id.data.code});
  505. }
  506. }.bind(this));
  507. this.data[node.get("name")] = JSON.encode(values);
  508. },
  509. savePersonItem: function(node, ids){
  510. count = node.get("count") || 0;
  511. var values = [];
  512. ids.each(function(id){
  513. values.push(id.data.distinguishedName || id.data.id);
  514. }.bind(this));
  515. this.data[node.get("name")] = (count && count.toInt()==1) ? values[0] : values;
  516. },
  517. savePersonObjectItem: function(node, ids){
  518. var values = [];
  519. ids.each(function(id){
  520. values.push(id.data);
  521. }.bind(this));
  522. this.data[node.get("name")] = values;
  523. },
  524. loadConditionInput: function(){
  525. var conditionNodes = this.propertyContent.getElements(".MWFCondition");
  526. conditionNodes.each(function(node){
  527. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ConditionEditor", function(){
  528. var script = new MWF.xApplication.process.ProcessDesigner.widget.ConditionEditor(node, {
  529. "onPostSave": function(script){
  530. this.saveScriptItem(node, script);
  531. }.bind(this),
  532. "onQueryDelete": function(script){
  533. this.deleteScriptItem(node, script);
  534. }.bind(this)
  535. });
  536. this.setScriptItems(script, node);
  537. }.bind(this));
  538. }.bind(this));
  539. },
  540. loadFormSelect: function(){
  541. var formNodes = this.propertyContent.getElements(".MWFFormSelect");
  542. if (formNodes.length){
  543. this.getFormList(function(){
  544. formNodes.each(function(node){
  545. var select = new Element("select").inject(node);
  546. var option = new Element("option", {"text": "none"}).inject(select);
  547. select.addEvent("change", function(e){
  548. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value);
  549. }.bind(this));
  550. this.setFormSelectOptions(node, select);
  551. var refreshNode = new Element("div", {"styles": this.process.css.propertyRefreshFormNode}).inject(node);
  552. refreshNode.addEvent("click", function(e){
  553. this.getFormList(function(){
  554. this.setFormSelectOptions(node, select);
  555. }.bind(this), true);
  556. }.bind(this));
  557. }.bind(this));
  558. }.bind(this));
  559. }
  560. },
  561. setFormSelectOptions: function(node, select){
  562. var name = node.get("name");
  563. select.empty();
  564. var option = new Element("option", {"text": "none"}).inject(select);
  565. this.forms.each(function(form){
  566. var option = new Element("option", {
  567. "text": form.name,
  568. "value": form.id,
  569. "selected": (this.data[name]==form.id)
  570. }).inject(select);
  571. }.bind(this));
  572. },
  573. getFormList: function(callback, refresh){
  574. if (!this.forms || refresh){
  575. this.process.designer.actions.listForm(this.process.designer.application.id, function(json){
  576. this.forms = json.data;
  577. if (callback) callback();
  578. }.bind(this));
  579. }else{
  580. if (callback) callback();
  581. }
  582. },
  583. loadSerial: function(){
  584. var serialNodes = this.propertyContent.getElements(".MWFSerial");
  585. if (serialNodes.length){
  586. // this.getSerialRule(function(){
  587. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.SerialEditor", function(){
  588. serialNodes.each(function(node){
  589. var serialEditor = new MWF.xApplication.process.ProcessDesigner.widget.SerialEditor(node, this.data[node.get("name")]);
  590. serialEditor.addEvent("change", function(e){
  591. this.setValue(node.get("name"), JSON.encode(serialEditor.getData()));
  592. }.bind(this));
  593. serialEditor.process = this.process;
  594. serialEditor.load();
  595. }.bind(this));
  596. }.bind(this));
  597. // }.bind(this));
  598. }
  599. },
  600. loadSericalActivitySelect: function(){
  601. var serialNodes = this.propertyContent.getElements(".MWFSericalActivitySelect");
  602. if (serialNodes.length){
  603. serialNodes.each(function(node){
  604. var select = new Element("select").inject(node);
  605. select.addEvent("change", function(e){
  606. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value);
  607. }.bind(this));
  608. this.listSericalActivityOptions(node, select);
  609. var refreshNode = new Element("div", {"styles": this.process.css.propertyRefreshFormNode}).inject(node);
  610. refreshNode.addEvent("click", function(e){
  611. this.listSericalActivityOptions(node, select);
  612. }.bind(this));
  613. }.bind(this));
  614. }
  615. },
  616. listSericalActivityOptions: function(node, select){
  617. var name = node.get("name");
  618. select.empty();
  619. var option = new Element("option", {"text": "none"}).inject(select);
  620. var option = new Element("option", {
  621. "text": this.process.process.begin.name,
  622. "value": this.process.process.begin.id,
  623. "selected": (this.data[name]===this.process.process.begin.id)
  624. }).inject(select);
  625. this.listSericalActivitys("endList", name, select);
  626. this.listSericalActivitys("cancelList", name, select);
  627. this.listSericalActivitys("manualList", name, select);
  628. this.listSericalActivitys("conditionList", name, select);
  629. this.listSericalActivitys("choiceList", name, select);
  630. this.listSericalActivitys("splitList", name, select);
  631. this.listSericalActivitys("parallelList", name, select);
  632. this.listSericalActivitys("mergeList", name, select);
  633. this.listSericalActivitys("embedList", name, select);
  634. this.listSericalActivitys("delayList", name, select);
  635. this.listSericalActivitys("invokeList", name, select);
  636. this.listSericalActivitys("serviceList", name, select);
  637. this.listSericalActivitys("agentList", name, select);
  638. this.listSericalActivitys("messageList", name, select);
  639. },
  640. listSericalActivitys: function(p, name, select){
  641. var datas = this.process.process[p];
  642. if (datas){
  643. var count = datas.length;
  644. if (count){
  645. datas.each(function(data){
  646. var option = new Element("option", {
  647. "text": data.name,
  648. "value": data.id,
  649. "selected": (this.data[name]===data.id)
  650. }).inject(select);
  651. }.bind(this));
  652. }
  653. }
  654. },
  655. loadApplicationSelector: function(){
  656. var nodes = this.propertyContent.getElements(".MWFApplicationSelect");
  657. if (nodes.length){
  658. this._getAppSelector(function(){
  659. nodes.each(function(node){
  660. var title = new Element("div", {"styles": this.process.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  661. var action = new Element("div", {"styles": this.process.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  662. var content = new Element("div", {"styles": this.process.css.applicationSelectContent}).inject(node);
  663. action.addEvent("click", function(e){
  664. this.appSelector.load(function(apps){
  665. content.empty();
  666. if (apps.length){
  667. this.data.targetApplication = apps[0].id;
  668. this.data.targetApplicationName = apps[0].name;
  669. this.data.targetApplicationAlias = apps[0].alias;
  670. new Element("div", {
  671. "styles": this.process.css.applicationSelectItem,
  672. "text": apps[0].name
  673. }).inject(content);
  674. }else{
  675. this.data.targetApplication = "";
  676. this.data.targetApplicationName = "";
  677. this.data.targetApplicationAlias = "";
  678. }
  679. var processNodes = this.propertyContent.getElements(".MWFProcessSelect");
  680. processNodes.each(function(n){
  681. this.data.targetProcess = "";
  682. this.data.targetProcessName = "";
  683. this.data.targetProcessAlias = "";
  684. var processContent = n.getLast();
  685. processContent.empty();
  686. }.bind(this));
  687. }.bind(this));
  688. }.bind(this));
  689. if (this.data.targetApplication){
  690. new Element("div", {
  691. "styles": this.process.css.applicationSelectItem,
  692. "text": this.data.targetApplicationName
  693. }).inject(content);
  694. }
  695. }.bind(this));
  696. }.bind(this));
  697. }
  698. },
  699. _getAppSelector: function(callback){
  700. if (!this.appSelector){
  701. MWF.xDesktop.requireApp("process.ProcessManager", "widget.ApplicationSelector", function(){
  702. this.appSelector = new MWF.xApplication.process.ProcessManager.widget.ApplicationSelector(this.process.designer, {"maskNode": this.process.designer.content, "multi": false});
  703. if (callback) callback();
  704. }.bind(this));
  705. }else{
  706. if (callback) callback();
  707. }
  708. },
  709. loadProcessSelector: function(){
  710. var nodes = this.propertyContent.getElements(".MWFProcessSelect");
  711. if (nodes.length){
  712. nodes.each(function(node){
  713. var title = new Element("div", {"styles": this.process.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  714. var action = new Element("div", {"styles": this.process.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  715. var content = new Element("div", {"styles": this.process.css.applicationSelectContent}).inject(node);
  716. action.addEvent("click", function(e){
  717. new o2.O2Selector(this.process.designer.content, {
  718. "count": 1,
  719. "type": "process",
  720. "onComplete": function(items){
  721. if (items.length){
  722. content.empty();
  723. this.data.targetApplication = items[0].data.application;
  724. this.data.targetApplicationName = items[0].data.applicationName;
  725. this.data.targetApplicationAlias = "";
  726. this.data.targetProcess = items[0].data.id;
  727. this.data.targetProcessName = items[0].data.name;
  728. this.data.targetProcessAlias = items[0].data.alias;
  729. new Element("div", {
  730. "styles": this.process.css.applicationSelectItem,
  731. "text": this.data.targetProcessName
  732. }).inject(content);
  733. }else{
  734. this.data.targetApplication = "";
  735. this.data.targetApplicationName = "";
  736. this.data.targetApplicationAlias = "";
  737. this.data.targetProcess = "";
  738. this.data.targetProcessName = "";
  739. this.data.targetProcessAlias = "";
  740. content.empty();
  741. }
  742. }.bind(this)
  743. });
  744. }.bind(this));
  745. if (this.data.targetProcess){
  746. new Element("div", {
  747. "styles": this.process.css.applicationSelectItem,
  748. "text": this.data.targetProcessName
  749. }).inject(content);
  750. }
  751. }.bind(this));
  752. // this._getProcessSelector(function(){
  753. // nodes.each(function(node){
  754. // var title = new Element("div", {"styles": this.process.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  755. // var action = new Element("div", {"styles": this.process.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  756. // var content = new Element("div", {"styles": this.process.css.applicationSelectContent}).inject(node);
  757. // action.addEvent("click", function(e){
  758. // var id = this.data.targetApplication;
  759. // this.processSelector.load([id], function(pros){
  760. // content.empty();
  761. // if (pros.length){
  762. // this.data.targetProcess = pros[0].id;
  763. // this.data.targetProcessName = pros[0].name;
  764. // this.data.targetProcessAlias = pros[0].alias;
  765. //
  766. // new Element("div", {
  767. // "styles": this.process.css.applicationSelectItem,
  768. // "text": pros[0].name
  769. // }).inject(content);
  770. // }else{
  771. // this.data.targetProcess = "";
  772. // this.data.targetProcessName = "";
  773. // this.data.targetProcessAlias = "";
  774. // }
  775. // }.bind(this));
  776. // }.bind(this));
  777. //
  778. // if (this.data.targetProcess){
  779. // new Element("div", {
  780. // "styles": this.process.css.applicationSelectItem,
  781. // "text": this.data.targetProcessName
  782. // }).inject(content);
  783. // }
  784. // }.bind(this));
  785. // }.bind(this));
  786. }
  787. },
  788. _getProcessSelector: function(callback){
  789. if (!this.processSelector){
  790. MWF.xDesktop.requireApp("process.ProcessManager", "widget.ProcessSelector", function(){
  791. this.processSelector = new MWF.xApplication.process.ProcessManager.widget.ProcessSelector(this.process.designer, {"maskNode": this.process.designer.content, "multi": false});
  792. if (callback) callback();
  793. }.bind(this));
  794. }else{
  795. if (callback) callback();
  796. }
  797. },
  798. loadIconSelect: function(){
  799. var nodes = this.propertyContent.getElements(".MWFIcon");
  800. if (nodes.length){
  801. nodes.each(function(node){
  802. var id = node.get("name");
  803. var icon = this.data[id];
  804. var iconNode = new Element("div", {"styles": this.process.css.processIconNode}).inject(node);
  805. if (icon) iconNode.setStyles({"background": "url("+icon+") center center no-repeat"});
  806. var selectNode = new Element("div", {"styles": this.process.css.processIconSelectNode, "text": this.process.designer.lp.selectIcon}).inject(node);
  807. selectNode.addEvent("click", function(){
  808. this.selectIcon(node);
  809. }.bind(this));
  810. }.bind(this));
  811. }
  812. },
  813. loadContextRoot: function(){
  814. var nodes = this.propertyContent.getElements(".MWFContextRoot");
  815. if (nodes){
  816. nodes.each(function(node){
  817. var name = node.get("name");
  818. var value = this.data[name];
  819. var select = new Element("select").inject(node);
  820. Object.each(layout.serviceAddressList, function(v, key){
  821. var option = new Element("option", {"value": key, "text": v.name, "selected": (value==key)}).inject(select);
  822. }.bind(this));
  823. select.addEvent("change", function(){
  824. var data = select.options[select.selectedIndex].value;
  825. // this.changeJsonDate(name, data);
  826. // this.changeData(name, node, value);
  827. this.setValue(name, data);
  828. }.bind(this));
  829. }.bind(this));
  830. }
  831. },
  832. loadProjection: function(){
  833. var nodes = this.propertyContent.getElements(".MWFProjection");
  834. if (nodes){
  835. nodes.each(function(node){
  836. var name = node.get("name");
  837. var value = this.data[name];
  838. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ProjectionEditor", function(){
  839. var projection = new MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor(node, value, {
  840. "onChange": function(){
  841. this.setValue(node.get("name"), JSON.encode(projection.getData()));
  842. }.bind(this),
  843. "process": this.process.process.id
  844. });
  845. projection.load();
  846. }.bind(this));
  847. // var select = new Element("select").inject(node);
  848. // Object.each(layout.desktop.serviceAddressList, function(v, key){
  849. // var option = new Element("option", {"value": key, "text": v.name, "selected": (value==key)}).inject(select);
  850. // }.bind(this));
  851. // select.addEvent("change", function(){
  852. // var data = select.options[select.selectedIndex].value;
  853. // // this.changeJsonDate(name, data);
  854. // // this.changeData(name, node, value);
  855. // this.setValue(name, data);
  856. // }.bind(this));
  857. }.bind(this));
  858. }
  859. },
  860. selectIcon: function(node){
  861. if (!node.iconMenu){
  862. var iconSelectMenu = new MWF.widget.Menu(node, {"event": "click", "style": "processIcon"});
  863. iconSelectMenu.load();
  864. node.iconMenu = iconSelectMenu;
  865. var _self = this;
  866. for (var i=0; i<=48; i++){
  867. var icon = "../x_component_process_ProcessManager/$Explorer/default/processIcon/process_icon_"+i+".png";
  868. var item = iconSelectMenu.addMenuItem("", "click", function(){
  869. var id = node.get("name");
  870. var src = this.item.getElement("img").get("src");
  871. _self.data[id] = src;
  872. node.getFirst("div").setStyle("background-image", "url("+src+")");
  873. }, icon);
  874. item.iconName = icon;
  875. }
  876. }
  877. },
  878. deleteScriptItem: function(node, script){
  879. var jsondata = node.get("name");
  880. this.data[jsondata].erase(script.data.id);
  881. this.process.scripts[script.data.id] = null;
  882. delete this.process.scripts[script.data.id];
  883. this.process.process.scriptList.erase(script.data);
  884. },
  885. saveScriptItem: function(node, script){
  886. var jsondata = node.get("name");
  887. var scriptList = this.data[jsondata];
  888. var data = script.data;
  889. var scriptData = this.process.scripts[script.data.id];
  890. if (!scriptData){
  891. this.process.process.scriptList.push(data);
  892. this.process.scripts[script.data.id] = data;
  893. }
  894. if (scriptList.indexOf(data.id) == -1){
  895. this.data[jsondata].push(data.id);
  896. }
  897. },
  898. setScriptItems: function(script, node){
  899. var jsondata = node.get("name");
  900. var scriptList = this.data[jsondata];
  901. if (scriptList){
  902. scriptList.each(function(id){
  903. if (id){
  904. var data = this.process.scripts[id];
  905. if (data) script.setScriptItem(data);
  906. }
  907. }.bind(this));
  908. }
  909. },
  910. showMultiActivity: function(activitys){
  911. this.hide();
  912. var multiActivityTable = new HtmlTable({
  913. "properties": this.process.css.activityListTable
  914. }).inject(this.propertyContent);
  915. activitys.each(function(activity){
  916. this.row = multiActivityTable.push([
  917. {
  918. "content": " ",
  919. "properties": {
  920. "styles": activity.style.listIcon
  921. }
  922. },
  923. {
  924. "content": activity.data.name,
  925. "properties": {
  926. "width": "80px",
  927. "styles": this.process.css.list.listText
  928. }
  929. },
  930. {
  931. "content": " "+activity.data.description,
  932. "properties": {
  933. "styles": this.process.css.list.listTextDescription
  934. }
  935. }
  936. ]);
  937. }.bind(this));
  938. },
  939. loadOrgEditor: function(){
  940. var orgNodes = this.propertyContent.getElements(".MWFOrgEditor");
  941. if(orgNodes.length){
  942. orgNodes.each(function(node){
  943. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.OrgEditor", function(){
  944. var editor = new MWF.xApplication.process.ProcessDesigner.widget.OrgEditor(node, this.route, this.data.selectConfig, {
  945. "onPostSave": function(script){
  946. //this.saveScriptItem(node, script);
  947. }.bind(this),
  948. "onQueryDelete": function(script){
  949. //this.deleteScriptItem(node, script);
  950. }.bind(this)
  951. });
  952. editor.load();
  953. //this.setScriptItems(script, node);
  954. }.bind(this));
  955. }.bind(this));
  956. }
  957. }
  958. });