Property.js 43 KB

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