Property_bak.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. MWF.xApplication.process.ProcessDesigner.Property = new Class({
  2. Implements: [Options, Events],
  3. load: function(){
  4. if (!this.process.options.isView){
  5. if (this.fireEvent("queryLoad")){
  6. MWF.getRequestText(this.htmlPath, function(responseText, responseXML){
  7. this.htmlString = responseText;
  8. MWF.require("MWF.widget.JsonTemplate", function(){
  9. this.fireEvent("postLoad");
  10. }.bind(this));
  11. }.bind(this));
  12. }
  13. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.process.propertyListNode);
  14. this.process.propertyListNode.addEvent("keydown", function(e){e.stopPropagation();});
  15. }
  16. },
  17. editProperty: function(td){
  18. },
  19. show: function(){
  20. if (!this.process.options.isView){
  21. this.process.panel.propertyTabPage.showTabIm();
  22. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  23. this.process.propertyContent.set("html", this.JsonTemplate.load());
  24. this.process.panel.data = this.data;
  25. this.setEditNodeEvent();
  26. this.setEditNodeStyles(this.process.propertyListNode);
  27. this.loadPropertyTab();
  28. this.loadPersonInput();
  29. this.loadScriptInput();
  30. this.loadScriptText();
  31. //this.loadConditionInput();
  32. this.loadFormSelect();
  33. // this.process.isFocus = true;
  34. }
  35. },
  36. //hide: function(){
  37. // if (!this.process.options.isView) {
  38. // this.JsonTemplate = null;
  39. //
  40. // this.scriptTexts.each(function(script){
  41. // MWF.release(script);
  42. // }.bind(this));
  43. // this.scriptTexts = null;
  44. //
  45. // this.process.propertyListNode.set("html", "");
  46. // }
  47. //},
  48. hide: function(){
  49. if (!this.process.options.isView) {
  50. this.JsonTemplate = null;
  51. }
  52. },
  53. loadPropertyTab: function(){
  54. var tabNodes = this.process.propertyListNode.getElements(".MWFTab");
  55. if (tabNodes.length){
  56. var tmpNode = this.process.propertyListNode.getFirst();
  57. var tabAreaNode = new Element("div", {
  58. "styles": this.process.css.propertyTabNode
  59. }).inject(tmpNode, "before");
  60. MWF.require("MWF.widget.Tab", function(){
  61. var tab = new MWF.widget.Tab(tabAreaNode, {"style": "moduleList"});
  62. tab.load();
  63. var tabPages = [];
  64. tabNodes.each(function(node){
  65. var tabPage = tab.addTab(node, node.get("title"), false);
  66. tabPages.push(tabPage);
  67. }.bind(this));
  68. tabPages[0].showTab();
  69. }.bind(this));
  70. }
  71. },
  72. setEditNodeEvent: function(){
  73. var property = this;
  74. // var inputs = this.process.propertyListNode.getElements(".editTableInput");
  75. var inputs = this.process.propertyListNode.getElements("input");
  76. inputs.each(function(input){
  77. var jsondata = input.get("name");
  78. if (jsondata){
  79. var inputType = input.get("type").toLowerCase();
  80. switch (inputType){
  81. case "radio":
  82. input.addEvent("change", function(e){
  83. property.setRadioValue(jsondata, this);
  84. });
  85. input.addEvent("blur", function(e){
  86. property.setRadioValue(jsondata, this);
  87. });
  88. input.addEvent("keydown", function(e){
  89. e.stopPropagation();
  90. });
  91. break;
  92. case "checkbox":
  93. input.addEvent("keydown", function(e){
  94. e.stopPropagation();
  95. });
  96. break;
  97. default:
  98. input.addEvent("change", function(e){
  99. property.setValue(jsondata, this.value);
  100. });
  101. input.addEvent("blur", function(e){
  102. property.setValue(jsondata, this.value);
  103. });
  104. input.addEvent("keydown", function(e){
  105. if (e.code==13){
  106. property.setValue(jsondata, this.value);
  107. }
  108. e.stopPropagation();
  109. });
  110. }
  111. }
  112. }.bind(this));
  113. var selects = this.process.propertyListNode.getElements("select");
  114. selects.each(function(select){
  115. var jsondata = select.get("name");
  116. if (jsondata){
  117. select.addEvent("change", function(e){
  118. property.setSelectValue(jsondata, this);
  119. });
  120. }
  121. });
  122. var textareas = this.process.propertyListNode.getElements("textarea");
  123. textareas.each(function(input){
  124. var jsondata = input.get("name");
  125. if (jsondata){
  126. input.addEvent("change", function(e){
  127. property.setValue(jsondata, this.value);
  128. });
  129. input.addEvent("blur", function(e){
  130. property.setValue(jsondata, this.value);
  131. });
  132. input.addEvent("keydown", function(e){
  133. e.stopPropagation();
  134. });
  135. }
  136. }.bind(this));
  137. },
  138. setSelectValue: function(name, select){
  139. var idx = select.selectedIndex;
  140. var options = select.getElements("option");
  141. var value = "";
  142. if (options[idx]){
  143. value = options[idx].get("value");
  144. }
  145. this.data[name] = value;
  146. },
  147. setRadioValue: function(name, input){
  148. if (input.checked){
  149. var value = input.value;
  150. if (value=="false") c = false;
  151. if (value=="true") c = true;
  152. this.data[name] = value;
  153. }
  154. },
  155. setValue: function(name, value){
  156. this.data[name] = value;
  157. if (name=="name"){
  158. if (!value) this.data[name] = MWF.APPPD.LP.unnamed;
  159. // this.activity.redraw();
  160. }
  161. },
  162. setEditNodeStyles: function(node){
  163. var nodes = node.getChildren();
  164. if (nodes.length){
  165. nodes.each(function(el){
  166. var cName = el.get("class");
  167. if (cName){
  168. if (this.process.css[cName]) el.setStyles(this.process.css[cName]);
  169. }
  170. this.setEditNodeStyles(el);
  171. }.bind(this));
  172. }
  173. },
  174. loadScriptText: function(){
  175. this.scriptTexts = [];
  176. var scriptNodes = this.process.propertyListNode.getElements(".MWFScriptText");
  177. MWF.require("MWF.xApplication.process.ProcessDesigner.widget.ScriptText", function(){
  178. var _self = this;
  179. scriptNodes.each(function(node){
  180. var script = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(node, this.data[node.get("name")], this.process.designer, {
  181. "maskNode": this.process.designer.content,
  182. "maxObj": this.process.designer.paperNode,
  183. "onChange": function(code){
  184. _self.data[node.get("name")] = code;
  185. }
  186. });
  187. this.scriptTexts.push(script);
  188. //this.setScriptItems(script, node);
  189. }.bind(this));
  190. }.bind(this));
  191. },
  192. loadScriptInput: function(){
  193. var scriptNodes = this.process.propertyListNode.getElements(".MWFScript");
  194. MWF.require("MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector", function(){
  195. var _self = this;
  196. scriptNodes.each(function(node){
  197. var script = new MWF.xApplication.process.ProcessDesigner.widget.ScriptSelector(node, this.data[node.get("name")], this.process.designer, {
  198. "maskNode": this.process.designer.content,
  199. "onSelected": function(scriptData){
  200. _self.data[node.get("name")] = scriptData.name;
  201. },
  202. "onDelete": function(){
  203. _self.data[node.get("name")] = "";
  204. node.empty();
  205. }
  206. //"onPostSave": function(script){
  207. // this.saveScriptItem(node, script);
  208. //}.bind(this),
  209. //"onQueryDelete": function(script){
  210. // this.deleteScriptItem(node, script);
  211. //}.bind(this)
  212. });
  213. //this.setScriptItems(script, node);
  214. }.bind(this));
  215. }.bind(this));
  216. },
  217. loadPersonInput: function(){
  218. var personIdentityNodes = this.process.propertyListNode.getElements(".MWFPersonIdentity");
  219. var personDepartmentNodes = this.process.propertyListNode.getElements(".MWFPersonDepartment");
  220. var personCompanyNodes = this.process.propertyListNode.getElements(".MWFPersonCompany");
  221. MWF.require("MWF.xApplication.process.ProcessDesigner.widget.PersonSelector", function(){
  222. personIdentityNodes.each(function(node){
  223. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  224. "type": "identity",
  225. "names": this.data[node.get("name")],
  226. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  227. });
  228. }.bind(this));
  229. personDepartmentNodes.each(function(node){
  230. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  231. "type": "department",
  232. "names": this.data[node.get("name")],
  233. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  234. });
  235. }.bind(this));
  236. personCompanyNodes.each(function(node){
  237. new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(node, this.process.designer, {
  238. "type": "company",
  239. "names": this.data[node.get("name")],
  240. "onChange": function(ids){this.savePersonItem(node, ids);}.bind(this)
  241. });
  242. }.bind(this));
  243. }.bind(this));
  244. //personNodes.each(function(node){
  245. // MWF.require("MWF.xApplication.process.ProcessDesigner.widget.ScriptEditor", function(){
  246. // var script = new MWF.xApplication.process.ProcessDesigner.widget.ScriptEditor(node, {
  247. // "onPostSave": function(script){
  248. // this.saveScriptItem(node, script);
  249. // }.bind(this),
  250. // "onQueryDelete": function(script){
  251. // this.deleteScriptItem(node, script);
  252. // }.bind(this)
  253. // });
  254. // this.setScriptItems(script, node);
  255. // }.bind(this));
  256. //}.bind(this));
  257. },
  258. savePersonItem: function(node, ids){
  259. var values = [];
  260. ids.each(function(id){
  261. values.push(id.data.name);
  262. }.bind(this));
  263. this.data[node.get("name")] = values;
  264. },
  265. loadConditionInput: function(){
  266. var conditionNodes = this.process.propertyListNode.getElements(".MWFCondition");
  267. conditionNodes.each(function(node){
  268. MWF.require("MWF.xApplication.process.ProcessDesigner.widget.ConditionEditor", function(){
  269. var script = new MWF.xApplication.process.ProcessDesigner.widget.ConditionEditor(node, {
  270. "onPostSave": function(script){
  271. this.saveScriptItem(node, script);
  272. }.bind(this),
  273. "onQueryDelete": function(script){
  274. this.deleteScriptItem(node, script);
  275. }.bind(this)
  276. });
  277. this.setScriptItems(script, node);
  278. }.bind(this));
  279. }.bind(this));
  280. },
  281. loadFormSelect: function(){
  282. var formNodes = this.process.propertyListNode.getElements(".MWFFormSelect");
  283. if (formNodes.length){
  284. this.getFormList(function(){
  285. formNodes.each(function(node){
  286. var select = new Element("select").inject(node);
  287. var option = new Element("option", {"text": "none"}).inject(select);
  288. select.addEvent("change", function(e){
  289. this.setValue(e.target.getParent("div").get("name"), e.target.options[e.target.selectedIndex].value);
  290. }.bind(this));
  291. var name = node.get("name");
  292. this.forms.each(function(form){
  293. var option = new Element("option", {
  294. "text": form.name,
  295. "value": form.id,
  296. "selected": (this.data[name]==form.id)
  297. }).inject(select);
  298. }.bind(this));
  299. }.bind(this));
  300. }.bind(this));
  301. }
  302. },
  303. getFormList: function(callback){
  304. if (!this.forms){
  305. this.process.designer.actions.listForm(this.process.designer.application.id, function(json){
  306. this.forms = json.data;
  307. if (callback) callback();
  308. }.bind(this));
  309. }else{
  310. if (callback) callback();
  311. }
  312. },
  313. deleteScriptItem: function(node, script){
  314. var jsondata = node.get("name");
  315. this.data[jsondata].erase(script.data.id);
  316. this.process.scripts[script.data.id] = null;
  317. delete this.process.scripts[script.data.id];
  318. this.process.process.scriptList.erase(script.data);
  319. },
  320. saveScriptItem: function(node, script){
  321. var jsondata = node.get("name");
  322. var scriptList = this.data[jsondata];
  323. var data = script.data;
  324. var scriptData = this.process.scripts[script.data.id];
  325. if (!scriptData){
  326. this.process.process.scriptList.push(data);
  327. this.process.scripts[script.data.id] = data;
  328. }
  329. if (scriptList.indexOf(data.id) == -1){
  330. this.data[jsondata].push(data.id);
  331. }
  332. },
  333. setScriptItems: function(script, node){
  334. var jsondata = node.get("name");
  335. var scriptList = this.data[jsondata];
  336. if (scriptList){
  337. scriptList.each(function(id){
  338. if (id){
  339. var data = this.process.scripts[id];
  340. if (data) script.setScriptItem(data);
  341. }
  342. }.bind(this));
  343. }
  344. },
  345. showMultiActivity: function(activitys){
  346. this.hide();
  347. var multiActivityTable = new HtmlTable({
  348. "properties": this.process.css.activityListTable
  349. }).inject(this.process.propertyListNode);
  350. activitys.each(function(activity){
  351. this.row = multiActivityTable.push([
  352. {
  353. "content": " ",
  354. "properties": {
  355. "styles": activity.style.listIcon
  356. }
  357. },
  358. {
  359. "content": activity.data.name,
  360. "properties": {
  361. "width": "80px",
  362. "styles": this.process.css.list.listText
  363. }
  364. },
  365. {
  366. "content": " "+activity.data.description,
  367. "properties": {
  368. "styles": this.process.css.list.listTextDescription
  369. }
  370. }
  371. ]);
  372. }.bind(this));
  373. }
  374. });