Property.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  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. debugger;
  378. var personIdentityNodes = this.propertyContent.getElements(".MWFPersonIdentity");
  379. var personNodes = this.propertyContent.getElements(".MWFPersonPerson");
  380. var personUnitNodes = this.propertyContent.getElements(".MWFPersonUnit");
  381. var personGroupNodes = this.propertyContent.getElements(".MWFPersonGroup");
  382. var dutyNameNodes = this.propertyContent.getElements(".MWFPersonDuty");
  383. // var personDepartmentNodes = this.propertyContent.getElements(".MWFPersonDepartment");
  384. // var personCompanyNodes = this.propertyContent.getElements(".MWFPersonCompany");
  385. var dutyNodes = this.propertyContent.getElements(".MWFDutySelector");
  386. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  387. personIdentityNodes.each(function(node){
  388. count = node.get("count") || 0;
  389. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  390. "type": "identity",
  391. "names": this.data[node.get("name")],
  392. "count": count,
  393. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  394. });
  395. }.bind(this));
  396. personNodes.each(function(node){
  397. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  398. "type": "person",
  399. "names": this.data[node.get("name")],
  400. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  401. });
  402. }.bind(this));
  403. personUnitNodes.each(function(node){
  404. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  405. "type": "unit",
  406. "names": this.data[node.get("name")],
  407. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  408. });
  409. }.bind(this));
  410. personGroupNodes.each(function(node){
  411. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  412. "type": "group",
  413. "names": this.data[node.get("name")],
  414. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  415. });
  416. }.bind(this));
  417. dutyNodes.each(function(node){
  418. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  419. "type": "duty",
  420. "names": this.data[node.get("name")],
  421. "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this),
  422. "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this)
  423. });
  424. }.bind(this));
  425. dutyNameNodes.each(function(node){
  426. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  427. "type": "dutyName",
  428. "names": this.data[node.get("name")],
  429. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  430. });
  431. }.bind(this));
  432. // personDepartmentNodes.each(function(node){
  433. // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  434. // "type": "department",
  435. // "names": this.data[node.get("name")],
  436. // "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  437. // });
  438. // }.bind(this));
  439. // personCompanyNodes.each(function(node){
  440. // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  441. // "type": "company",
  442. // "names": this.data[node.get("name")],
  443. // "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  444. // });
  445. // }.bind(this));
  446. // dutyNodes.each(function(node){
  447. // new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  448. // "type": "duty",
  449. // "names": this.data[node.get("name")],
  450. // "onChange": function(ids){this.addDutyItem(node, ids);}.bind(this),
  451. // "onRemoveDuty": function(item){this.removeDutyItem(node, item);}.bind(this)
  452. // });
  453. // }.bind(this));
  454. }.bind(this));
  455. },
  456. removeDutyItem: function(node, item){
  457. if (item.data.id){
  458. var values = JSON.decode(this.data[node.get("name")]) || [];
  459. var value = values.filter(function(v){
  460. return v.id == item.data.id;
  461. });
  462. value.each(function(v) {
  463. values = values.erase(v);
  464. });
  465. this.data[node.get("name")] = JSON.encode(values);
  466. }
  467. item.node.destroy();
  468. MWF.release(item);
  469. delete item;
  470. },
  471. addDutyItem: function(node, ids){
  472. var value = this.data[node.get("name")] || "";
  473. if (!value) value = "[]";
  474. var values = JSON.decode(value);
  475. ids.each(function(id){
  476. if (id.data.dutyId){
  477. for (var i=0; i<values.length; i++){
  478. if (values[i].dutyId===id.data.dutyId){
  479. values[i].name = id.data.name;
  480. values[i].code = id.data.code;
  481. break;
  482. }
  483. }
  484. }else{
  485. id.data.dutyId = new MWF.widget.UUID().toString();
  486. values.push({"name": id.data.name, "id": id.data.id, "dutyId": id.data.dutyId, "code": id.data.code});
  487. }
  488. }.bind(this));
  489. this.data[node.get("name")] = JSON.encode(values);
  490. },
  491. savePersonItem: function(node, ids){
  492. count = node.get("count") || 0;
  493. var values = [];
  494. ids.each(function(id){
  495. values.push(id.data.distinguishedName || id.data.id);
  496. }.bind(this));
  497. this.data[node.get("name")] = (count && count.toInt()==1) ? values[0] : values;
  498. },
  499. savePersonObjectItem: function(node, ids){
  500. var values = [];
  501. ids.each(function(id){
  502. values.push(id.data);
  503. }.bind(this));
  504. this.data[node.get("name")] = values;
  505. },
  506. loadConditionInput: function(){
  507. var conditionNodes = this.propertyContent.getElements(".MWFCondition");
  508. conditionNodes.each(function(node){
  509. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ConditionEditor", function(){
  510. var script = new MWF.xApplication.process.ProcessDesigner.widget.ConditionEditor(node, {
  511. "onPostSave": function(script){
  512. this.saveScriptItem(node, script);
  513. }.bind(this),
  514. "onQueryDelete": function(script){
  515. this.deleteScriptItem(node, script);
  516. }.bind(this)
  517. });
  518. this.setScriptItems(script, node);
  519. }.bind(this));
  520. }.bind(this));
  521. },
  522. loadFormSelect: function(){
  523. var formNodes = this.propertyContent.getElements(".MWFFormSelect");
  524. if (formNodes.length){
  525. this.getFormList(function(){
  526. formNodes.each(function(node){
  527. var select = new Element("select").inject(node);
  528. var option = new Element("option", {"text": "none"}).inject(select);
  529. select.addEvent("change", function(e){
  530. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value);
  531. }.bind(this));
  532. this.setFormSelectOptions(node, select);
  533. var refreshNode = new Element("div", {"styles": this.process.css.propertyRefreshFormNode}).inject(node);
  534. refreshNode.addEvent("click", function(e){
  535. this.getFormList(function(){
  536. this.setFormSelectOptions(node, select);
  537. }.bind(this), true);
  538. }.bind(this));
  539. }.bind(this));
  540. }.bind(this));
  541. }
  542. },
  543. setFormSelectOptions: function(node, select){
  544. var name = node.get("name");
  545. select.empty();
  546. var option = new Element("option", {"text": "none"}).inject(select);
  547. this.forms.each(function(form){
  548. var option = new Element("option", {
  549. "text": form.name,
  550. "value": form.id,
  551. "selected": (this.data[name]==form.id)
  552. }).inject(select);
  553. }.bind(this));
  554. },
  555. getFormList: function(callback, refresh){
  556. if (!this.forms || refresh){
  557. this.process.designer.actions.listForm(this.process.designer.application.id, function(json){
  558. this.forms = json.data;
  559. if (callback) callback();
  560. }.bind(this));
  561. }else{
  562. if (callback) callback();
  563. }
  564. },
  565. loadSerial: function(){
  566. var serialNodes = this.propertyContent.getElements(".MWFSerial");
  567. if (serialNodes.length){
  568. // this.getSerialRule(function(){
  569. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.SerialEditor", function(){
  570. serialNodes.each(function(node){
  571. var serialEditor = new MWF.xApplication.process.ProcessDesigner.widget.SerialEditor(node, this.data[node.get("name")]);
  572. serialEditor.addEvent("change", function(e){
  573. this.setValue(node.get("name"), JSON.encode(serialEditor.getData()));
  574. }.bind(this));
  575. serialEditor.process = this.process;
  576. serialEditor.load();
  577. }.bind(this));
  578. }.bind(this));
  579. // }.bind(this));
  580. }
  581. },
  582. loadSericalActivitySelect: function(){
  583. var serialNodes = this.propertyContent.getElements(".MWFSericalActivitySelect");
  584. if (serialNodes.length){
  585. serialNodes.each(function(node){
  586. var select = new Element("select").inject(node);
  587. select.addEvent("change", function(e){
  588. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value);
  589. }.bind(this));
  590. this.listSericalActivityOptions(node, select);
  591. var refreshNode = new Element("div", {"styles": this.process.css.propertyRefreshFormNode}).inject(node);
  592. refreshNode.addEvent("click", function(e){
  593. this.listSericalActivityOptions(node, select);
  594. }.bind(this));
  595. }.bind(this));
  596. }
  597. },
  598. listSericalActivityOptions: function(node, select){
  599. var name = node.get("name");
  600. select.empty();
  601. var option = new Element("option", {"text": "none"}).inject(select);
  602. var option = new Element("option", {
  603. "text": this.process.process.begin.name,
  604. "value": this.process.process.begin.id,
  605. "selected": (this.data[name]===this.process.process.begin.id)
  606. }).inject(select);
  607. this.listSericalActivitys("endList", name, select);
  608. this.listSericalActivitys("cancelList", name, select);
  609. this.listSericalActivitys("manualList", name, select);
  610. this.listSericalActivitys("conditionList", name, select);
  611. this.listSericalActivitys("choiceList", name, select);
  612. this.listSericalActivitys("splitList", name, select);
  613. this.listSericalActivitys("parallelList", name, select);
  614. this.listSericalActivitys("mergeList", name, select);
  615. this.listSericalActivitys("embedList", name, select);
  616. this.listSericalActivitys("delayList", name, select);
  617. this.listSericalActivitys("invokeList", name, select);
  618. this.listSericalActivitys("serviceList", name, select);
  619. this.listSericalActivitys("agentList", name, select);
  620. this.listSericalActivitys("messageList", name, select);
  621. },
  622. listSericalActivitys: function(p, name, select){
  623. var datas = this.process.process[p];
  624. if (datas){
  625. var count = datas.length;
  626. if (count){
  627. datas.each(function(data){
  628. var option = new Element("option", {
  629. "text": data.name,
  630. "value": data.id,
  631. "selected": (this.data[name]===data.id)
  632. }).inject(select);
  633. }.bind(this));
  634. }
  635. }
  636. },
  637. loadApplicationSelector: function(){
  638. var nodes = this.propertyContent.getElements(".MWFApplicationSelect");
  639. if (nodes.length){
  640. this._getAppSelector(function(){
  641. nodes.each(function(node){
  642. var title = new Element("div", {"styles": this.process.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  643. var action = new Element("div", {"styles": this.process.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  644. var content = new Element("div", {"styles": this.process.css.applicationSelectContent}).inject(node);
  645. action.addEvent("click", function(e){
  646. this.appSelector.load(function(apps){
  647. content.empty();
  648. if (apps.length){
  649. this.data.targetApplication = apps[0].id;
  650. this.data.targetApplicationName = apps[0].name;
  651. this.data.targetApplicationAlias = apps[0].alias;
  652. new Element("div", {
  653. "styles": this.process.css.applicationSelectItem,
  654. "text": apps[0].name
  655. }).inject(content);
  656. }else{
  657. this.data.targetApplication = "";
  658. this.data.targetApplicationName = "";
  659. this.data.targetApplicationAlias = "";
  660. }
  661. var processNodes = this.propertyContent.getElements(".MWFProcessSelect");
  662. processNodes.each(function(n){
  663. this.data.targetProcess = "";
  664. this.data.targetProcessName = "";
  665. this.data.targetProcessAlias = "";
  666. var processContent = n.getLast();
  667. processContent.empty();
  668. }.bind(this));
  669. }.bind(this));
  670. }.bind(this));
  671. if (this.data.targetApplication){
  672. new Element("div", {
  673. "styles": this.process.css.applicationSelectItem,
  674. "text": this.data.targetApplicationName
  675. }).inject(content);
  676. }
  677. }.bind(this));
  678. }.bind(this));
  679. }
  680. },
  681. _getAppSelector: function(callback){
  682. if (!this.appSelector){
  683. MWF.xDesktop.requireApp("process.ProcessManager", "widget.ApplicationSelector", function(){
  684. this.appSelector = new MWF.xApplication.process.ProcessManager.widget.ApplicationSelector(this.process.designer, {"maskNode": this.process.designer.content, "multi": false});
  685. if (callback) callback();
  686. }.bind(this));
  687. }else{
  688. if (callback) callback();
  689. }
  690. },
  691. loadProcessSelector: function(){
  692. var nodes = this.propertyContent.getElements(".MWFProcessSelect");
  693. if (nodes.length){
  694. nodes.each(function(node){
  695. var title = new Element("div", {"styles": this.process.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  696. var action = new Element("div", {"styles": this.process.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  697. var content = new Element("div", {"styles": this.process.css.applicationSelectContent}).inject(node);
  698. action.addEvent("click", function(e){
  699. new o2.O2Selector(this.process.designer.content, {
  700. "count": 1,
  701. "type": "process",
  702. "onComplete": function(items){
  703. if (items.length){
  704. content.empty();
  705. this.data.targetApplication = items[0].data.application;
  706. this.data.targetApplicationName = items[0].data.applicationName;
  707. this.data.targetApplicationAlias = "";
  708. this.data.targetProcess = items[0].data.id;
  709. this.data.targetProcessName = items[0].data.name;
  710. this.data.targetProcessAlias = items[0].data.alias;
  711. new Element("div", {
  712. "styles": this.process.css.applicationSelectItem,
  713. "text": this.data.targetProcessName
  714. }).inject(content);
  715. }else{
  716. this.data.targetApplication = "";
  717. this.data.targetApplicationName = "";
  718. this.data.targetApplicationAlias = "";
  719. this.data.targetProcess = "";
  720. this.data.targetProcessName = "";
  721. this.data.targetProcessAlias = "";
  722. content.empty();
  723. }
  724. }.bind(this)
  725. });
  726. }.bind(this));
  727. if (this.data.targetProcess){
  728. new Element("div", {
  729. "styles": this.process.css.applicationSelectItem,
  730. "text": this.data.targetProcessName
  731. }).inject(content);
  732. }
  733. }.bind(this));
  734. // this._getProcessSelector(function(){
  735. // nodes.each(function(node){
  736. // var title = new Element("div", {"styles": this.process.css.applicationSelectTitle, "text": node.get("title")}).inject(node);
  737. // var action = new Element("div", {"styles": this.process.css.applicationSelectAction, "text": node.get("title")}).inject(node);
  738. // var content = new Element("div", {"styles": this.process.css.applicationSelectContent}).inject(node);
  739. // action.addEvent("click", function(e){
  740. // var id = this.data.targetApplication;
  741. // this.processSelector.load([id], function(pros){
  742. // content.empty();
  743. // if (pros.length){
  744. // this.data.targetProcess = pros[0].id;
  745. // this.data.targetProcessName = pros[0].name;
  746. // this.data.targetProcessAlias = pros[0].alias;
  747. //
  748. // new Element("div", {
  749. // "styles": this.process.css.applicationSelectItem,
  750. // "text": pros[0].name
  751. // }).inject(content);
  752. // }else{
  753. // this.data.targetProcess = "";
  754. // this.data.targetProcessName = "";
  755. // this.data.targetProcessAlias = "";
  756. // }
  757. // }.bind(this));
  758. // }.bind(this));
  759. //
  760. // if (this.data.targetProcess){
  761. // new Element("div", {
  762. // "styles": this.process.css.applicationSelectItem,
  763. // "text": this.data.targetProcessName
  764. // }).inject(content);
  765. // }
  766. // }.bind(this));
  767. // }.bind(this));
  768. }
  769. },
  770. _getProcessSelector: function(callback){
  771. if (!this.processSelector){
  772. MWF.xDesktop.requireApp("process.ProcessManager", "widget.ProcessSelector", function(){
  773. this.processSelector = new MWF.xApplication.process.ProcessManager.widget.ProcessSelector(this.process.designer, {"maskNode": this.process.designer.content, "multi": false});
  774. if (callback) callback();
  775. }.bind(this));
  776. }else{
  777. if (callback) callback();
  778. }
  779. },
  780. loadIconSelect: function(){
  781. var nodes = this.propertyContent.getElements(".MWFIcon");
  782. if (nodes.length){
  783. nodes.each(function(node){
  784. var id = node.get("name");
  785. var icon = this.data[id];
  786. var iconNode = new Element("div", {"styles": this.process.css.processIconNode}).inject(node);
  787. if (icon) iconNode.setStyles({"background": "url("+icon+") center center no-repeat"});
  788. var selectNode = new Element("div", {"styles": this.process.css.processIconSelectNode, "text": this.process.designer.lp.selectIcon}).inject(node);
  789. selectNode.addEvent("click", function(){
  790. this.selectIcon(node);
  791. }.bind(this));
  792. }.bind(this));
  793. }
  794. },
  795. loadContextRoot: function(){
  796. var nodes = this.propertyContent.getElements(".MWFContextRoot");
  797. if (nodes){
  798. nodes.each(function(node){
  799. var name = node.get("name");
  800. var value = this.data[name];
  801. var select = new Element("select").inject(node);
  802. Object.each(layout.desktop.serviceAddressList, function(v, key){
  803. var option = new Element("option", {"value": key, "text": v.name, "selected": (value==key)}).inject(select);
  804. }.bind(this));
  805. select.addEvent("change", function(){
  806. var data = select.options[select.selectedIndex].value;
  807. // this.changeJsonDate(name, data);
  808. // this.changeData(name, node, value);
  809. this.setValue(name, data);
  810. }.bind(this));
  811. }.bind(this));
  812. }
  813. },
  814. loadProjection: function(){
  815. var nodes = this.propertyContent.getElements(".MWFProjection");
  816. if (nodes){
  817. nodes.each(function(node){
  818. var name = node.get("name");
  819. var value = this.data[name];
  820. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.ProjectionEditor", function(){
  821. var projection = new MWF.xApplication.process.ProcessDesigner.widget.ProjectionEditor(node, value, {
  822. "onChange": function(){
  823. this.setValue(node.get("name"), JSON.encode(projection.getData()));
  824. }.bind(this),
  825. "process": this.process.process.id
  826. });
  827. projection.load();
  828. }.bind(this));
  829. // var select = new Element("select").inject(node);
  830. // Object.each(layout.desktop.serviceAddressList, function(v, key){
  831. // var option = new Element("option", {"value": key, "text": v.name, "selected": (value==key)}).inject(select);
  832. // }.bind(this));
  833. // select.addEvent("change", function(){
  834. // var data = select.options[select.selectedIndex].value;
  835. // // this.changeJsonDate(name, data);
  836. // // this.changeData(name, node, value);
  837. // this.setValue(name, data);
  838. // }.bind(this));
  839. }.bind(this));
  840. }
  841. },
  842. selectIcon: function(node){
  843. if (!node.iconMenu){
  844. var iconSelectMenu = new MWF.widget.Menu(node, {"event": "click", "style": "processIcon"});
  845. iconSelectMenu.load();
  846. node.iconMenu = iconSelectMenu;
  847. var _self = this;
  848. for (var i=0; i<=48; i++){
  849. var icon = "/x_component_process_ProcessManager/$Explorer/default/processIcon/process_icon_"+i+".png";
  850. var item = iconSelectMenu.addMenuItem("", "click", function(){
  851. var id = node.get("name");
  852. var src = this.item.getElement("img").get("src");
  853. _self.data[id] = src;
  854. node.getFirst("div").setStyle("background-image", "url("+src+")");
  855. }, icon);
  856. item.iconName = icon;
  857. }
  858. }
  859. },
  860. deleteScriptItem: function(node, script){
  861. var jsondata = node.get("name");
  862. this.data[jsondata].erase(script.data.id);
  863. this.process.scripts[script.data.id] = null;
  864. delete this.process.scripts[script.data.id];
  865. this.process.process.scriptList.erase(script.data);
  866. },
  867. saveScriptItem: function(node, script){
  868. var jsondata = node.get("name");
  869. var scriptList = this.data[jsondata];
  870. var data = script.data;
  871. var scriptData = this.process.scripts[script.data.id];
  872. if (!scriptData){
  873. this.process.process.scriptList.push(data);
  874. this.process.scripts[script.data.id] = data;
  875. }
  876. if (scriptList.indexOf(data.id) == -1){
  877. this.data[jsondata].push(data.id);
  878. }
  879. },
  880. setScriptItems: function(script, node){
  881. var jsondata = node.get("name");
  882. var scriptList = this.data[jsondata];
  883. if (scriptList){
  884. scriptList.each(function(id){
  885. if (id){
  886. var data = this.process.scripts[id];
  887. if (data) script.setScriptItem(data);
  888. }
  889. }.bind(this));
  890. }
  891. },
  892. showMultiActivity: function(activitys){
  893. this.hide();
  894. var multiActivityTable = new HtmlTable({
  895. "properties": this.process.css.activityListTable
  896. }).inject(this.propertyContent);
  897. activitys.each(function(activity){
  898. this.row = multiActivityTable.push([
  899. {
  900. "content": " ",
  901. "properties": {
  902. "styles": activity.style.listIcon
  903. }
  904. },
  905. {
  906. "content": activity.data.name,
  907. "properties": {
  908. "width": "80px",
  909. "styles": this.process.css.list.listText
  910. }
  911. },
  912. {
  913. "content": " "+activity.data.description,
  914. "properties": {
  915. "styles": this.process.css.list.listTextDescription
  916. }
  917. }
  918. ]);
  919. }.bind(this));
  920. },
  921. loadOrgEditor: function(){
  922. var orgNodes = this.propertyContent.getElements(".MWFOrgEditor");
  923. if(orgNodes.length){
  924. orgNodes.each(function(node){
  925. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.OrgEditor", function(){
  926. var editor = new MWF.xApplication.process.ProcessDesigner.widget.OrgEditor(node, this.route, this.data.selectConfig, {
  927. "onPostSave": function(script){
  928. //this.saveScriptItem(node, script);
  929. }.bind(this),
  930. "onQueryDelete": function(script){
  931. //this.deleteScriptItem(node, script);
  932. }.bind(this)
  933. });
  934. editor.load();
  935. //this.setScriptItems(script, node);
  936. }.bind(this));
  937. }.bind(this));
  938. }
  939. }
  940. });