Property.js 43 KB

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