OrgEditor.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
  2. MWF.xDesktop.requireApp("process.ProcessDesigner", "Property", null, false);
  3. MWF.xApplication.process.ProcessDesigner.widget.OrgEditor = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function(node, route, data, options){
  10. this.setOptions(options);
  11. this.node = $(node);
  12. if( !data ){
  13. this.data = [];
  14. }else{
  15. this.data = typeOf( data ) === "string" ? JSON.parse(data) : data;
  16. }
  17. this.route = route;
  18. this.process = route.process;
  19. this.path = "../x_component_process_ProcessDesigner/widget/$OrgEditor/";
  20. this.cssPath = "../x_component_process_ProcessDesigner/widget/$OrgEditor/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.selectedItems = [];
  23. this.lp = MWF.xApplication.process.ProcessDesigner.LP;
  24. },
  25. load: function(){
  26. this.scrollNode = this.process.panel.propertyTabPage.contentNodeArea;
  27. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode}).inject(this.node);
  28. //this.previewNode = new Element("div", {
  29. // "styles": this.css.previewNode,
  30. // "title" : this.lp.preview
  31. //}).inject(this.toolbarNode);
  32. this.copyNode = new Element("div", {
  33. "styles": this.css.copyNode,
  34. "title" : this.lp.copy,
  35. "events" : {
  36. "click" : function( ev ){
  37. this.selectOtherConfig( ev )
  38. }.bind(this)
  39. }
  40. }).inject(this.toolbarNode);
  41. this.selectedNode = new Element("div", {"styles": this.css.selectedNode}).inject(this.node);
  42. this.upNode = new Element("div", { "styles": this.css.upNode, "text" : this.lp.orgEditor.addOption }).inject(this.node);
  43. this.upNode.addEvent("click", function( ev ){
  44. debugger;
  45. if( this.currentItem ){
  46. var d = this.currentItem.getData();
  47. if( !d.title || !d.name || d.name === "未命名" ){
  48. MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgNoName, ev.target);
  49. return;
  50. }
  51. if( d.name.test(/^\d+$/) ){
  52. MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgNumberId, ev.target);
  53. return;
  54. }
  55. if( d.name.indexOf("..") > -1 ){
  56. MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgDoubleDotId, ev.target);
  57. return;
  58. }
  59. if( this.checkName(d.name, d.id ) ){
  60. this.currentItem.save();
  61. this.currentItem.unSelectItem();
  62. if( this.defaultProperty ){
  63. this.defaultProperty.show();
  64. }else{
  65. this.loadDefaultProperty();
  66. }
  67. this.scrollNode.scrollTo(0,0);
  68. this.upNode.set("text","添加选择项");
  69. }else{
  70. MWF.xDesktop.notice("error", {"y":"top", "x": "right"}, this.lp.orgEditor.conflictNotice+":"+ d.name, ev.target);
  71. }
  72. }else if( this.defaultProperty ){
  73. var d = this.defaultData;
  74. if( !d.title || !d.name || d.name === "未命名"){
  75. MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgNoName, ev.target);
  76. return;
  77. }
  78. if( d.name.test(/^\d+$/) ){
  79. MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgNumberId, ev.target);
  80. return;
  81. }
  82. if( d.name.indexOf("..") > -1 ){
  83. MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, this.lp.notice.saveRouteOrgDoubleDotId, ev.target);
  84. return;
  85. }
  86. if( this.checkName(d.name, d.id ) ) {
  87. this.data.push(this.defaultData);
  88. this.createSelectedItem(this.defaultData);
  89. this.save();
  90. this.defaultProperty.propertyContent.destroy();
  91. this.loadDefaultProperty();
  92. this.upNode.set("text", this.lp.orgEditor.addOption);
  93. }else{
  94. MWF.xDesktop.notice("error", {"y":"top", "x": "right"}, this.lp.orgEditor.conflictNotice+":"+ d.name, ev.target);
  95. }
  96. }
  97. }.bind(this));
  98. this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.node);
  99. this.getTemplate( function(){
  100. this.loadSelectedItems();
  101. this.loadDefaultProperty();
  102. }.bind(this));
  103. this.setUpNodeFixed();
  104. },
  105. setUpNodeFixed : function(){
  106. var scrollNode = this.scrollNode;
  107. scrollNode.getParent().setStyle("position","relative");
  108. scrollNode.addEvent("scroll",function(ev){
  109. if( this.node.offsetParent === null )return;
  110. var position = this.propertyNode.getPosition( scrollNode );
  111. if( position.y < 30 ){
  112. this.upNode.setStyles({
  113. "position" : "absolute",
  114. "top" : 1,
  115. "left" : 0,
  116. "border" : "1px solid #ffa200",
  117. "background-color" : "#fff",
  118. "width" : "99%"
  119. })
  120. }else{
  121. this.upNode.setStyles({
  122. "position" : "static",
  123. "border" : "0px"
  124. })
  125. }
  126. }.bind(this))
  127. },
  128. loadSelectedItems: function(){
  129. this.data.each(function(itemData){
  130. this.selectedItems.push(new MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.SelectedItem(this, itemData));
  131. }.bind(this));
  132. this.fireEvent("change");
  133. },
  134. createSelectedItem : function( itemData ){
  135. this.selectedItems.push(new MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.SelectedItem(this, itemData));
  136. this.fireEvent("change");
  137. },
  138. getTemplate: function(callback){
  139. if (!this.templateJson){
  140. MWF.getJSON("../x_component_process_ProcessDesigner/widget/$OrgEditor/org.json", function(json){
  141. this.templateJson = json;
  142. if (callback) callback();
  143. }.bind(this));
  144. }else{
  145. if (callback) callback();
  146. }
  147. },
  148. save : function(){
  149. this.route.data.selectConfig = JSON.stringify(this.getData());
  150. },
  151. getData: function(){
  152. var data = [];
  153. this.selectedItems.each(function(item){
  154. data.push(item.getData());
  155. });
  156. this.data = data;
  157. return data;
  158. },
  159. checkName : function( name, id ){
  160. var flag = true;
  161. debugger;
  162. this.selectedItems.each(function(item){
  163. var d = item.getData();
  164. if( d.name === name && d.id !== id ){
  165. flag = false;
  166. }
  167. });
  168. return flag;
  169. },
  170. loadDefaultProperty: function(){
  171. this.defaultData = Object.clone(this.templateJson);
  172. this.defaultProperty = new MWF.APPPD.widget.OrgEditor.Property(this, this.defaultData, {
  173. "onPostLoad": function () {
  174. this.defaultProperty.show();
  175. }.bind(this)
  176. });
  177. this.defaultProperty.load();
  178. },
  179. selectOtherConfig : function( ev ){
  180. var selectableItems = [];
  181. if( this.process && this.process.routes ){
  182. Object.each( this.process.routes, function(route){
  183. if(route.data.selectConfig){
  184. var array = JSON.parse( route.data.selectConfig );
  185. if( array && array.length ){
  186. var json = {
  187. "name": route.data.name,
  188. "id": route.data.id,
  189. "subItemList" : []
  190. }
  191. array.each( function( d ){
  192. json.subItemList.push( { name : d.name + " - "+d.title, id : d.id , data : JSON.stringify(d) } );
  193. });
  194. selectableItems.push( json );
  195. }
  196. }
  197. });
  198. }
  199. o2.xDesktop.requireApp("Template", "Selector.Custom", function () {
  200. var options = {
  201. "count": 0,
  202. "title": this.lp.orgEditor.copyConfig,
  203. "selectableItems": selectableItems,
  204. "expand": true,
  205. "category": true,
  206. "onComplete": function (items) {
  207. if( items.length > 0 ){
  208. var idList = [];
  209. var nameConflictList = [];
  210. this.process.designer.actions.getId( items.length, function(ids){
  211. idList = ids.data;
  212. }.bind(this),null,false);
  213. items.each( function(item, i){
  214. var data = JSON.parse(item.data.data);
  215. data.id = idList[i].id;
  216. if( this.checkName( data.name, data.id ) ){
  217. this.selectedItems.push(new MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.SelectedItem(this, data));
  218. }else{
  219. nameConflictList.push( data.name );
  220. }
  221. if( nameConflictList.length > 0 ){
  222. MWF.xDesktop.notice("error", {"y":"top", "x": "right"}, this.lp.orgEditor.conflictNotice+":"+ nameConflictList.join(","), ev.target);
  223. }
  224. }.bind(this));
  225. this.save();
  226. this.fireEvent("change");
  227. }
  228. }.bind(this)
  229. };
  230. var selector = new o2.xApplication.Template.Selector.Custom(this.process.designer.node, options);
  231. selector.load();
  232. }.bind(this))
  233. }
  234. });
  235. MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.SelectedItem = new Class({
  236. initialize: function(editor, itemData){
  237. this.editor = editor;
  238. this.css = this.editor.css;
  239. this.data = itemData;
  240. if( !this.data.events || Object.keys(this.data.events).length === 0 ){
  241. this.data.events = Object.clone( this.editor.templateJson.events )
  242. }
  243. this.tmpData = Object.clone(itemData);
  244. this.node = new Element("div", {"styles": this.css.selectedItemNode}).inject(this.editor.selectedNode);
  245. this.load();
  246. },
  247. load: function(){
  248. this.textNode = new Element("div", {"styles": this.css.selectedItemTextNode}).inject(this.node);
  249. this.textNode.set({
  250. "text": this.data.name,
  251. "title": this.data.description
  252. });
  253. new Element("span", {
  254. "styles": this.css.selectedItemTextNode,
  255. "html" : ( this.data.title ? ("(&nbsp;"+this.data.title+"&nbsp;)") : "" )
  256. }).inject(this.textNode);
  257. this.selectTypeNode = new Element("div", {
  258. "styles": this.css.selectedItemLabelNode,
  259. "text" : this.editor.lp.selectType + ":"
  260. }).inject(this.node);
  261. new Element("span", {
  262. "styles": this.css.selectedItemTextNode,
  263. "text" : this.data.selectType === "identity" ? this.editor.lp.identity : this.editor.lp.unit
  264. }).inject(this.selectTypeNode);
  265. this.selectCountNode = new Element("div", {
  266. "styles": this.css.selectedItemLabelNode,
  267. "text" : this.editor.lp.selectCount + ":"
  268. }).inject(this.node);
  269. new Element("span", {
  270. "styles": this.css.selectedItemTextNode,
  271. "text" : this.data.selectType === "identity" ? this.data.identityCount : this.data.unitCount
  272. }).inject(this.selectCountNode);
  273. this.node.addEvents({
  274. "mouseover": function(){
  275. if (this.editor.currentItem!=this) this.node.setStyles(this.css.selectedItemNode_over);
  276. }.bind(this),
  277. "mouseout": function(){
  278. if (this.editor.currentItem!=this) this.node.setStyles(this.css.selectedItemNode);
  279. }.bind(this),
  280. "click": function(){this.selectItem();}.bind(this)
  281. });
  282. this.closeNode = new Element("div", {
  283. "styles": this.css.selectedItemCloseNode,
  284. "title" : this.editor.lp.delete
  285. }).inject(this.node);
  286. this.closeNode.addEvent("click", function(ev){
  287. this.deleteItem(ev);
  288. ev.stopPropagation();
  289. }.bind(this));
  290. //this.loadProperty();
  291. //this.selectItem();
  292. },
  293. reload : function(){
  294. this.node.empty();
  295. this.load();
  296. },
  297. save : function(){
  298. this.data = Object.clone( this.tmpData );
  299. this.editor.save();
  300. this.reload();
  301. },
  302. getData : function( isClone ){
  303. var d = this.tmpData || this.data;
  304. return isClone ? Object.clone(d) : d;
  305. },
  306. loadProperty: function(){
  307. this.property = new MWF.APPPD.widget.OrgEditor.Property(this.editor, this.tmpData, {
  308. "onPostLoad": function () {
  309. this.property.show();
  310. }.bind(this)
  311. });
  312. this.property.load();
  313. },
  314. deleteItem: function(e){
  315. var _self = this;
  316. MWF.xDesktop.confirm("warn", e, this.editor.lp.deleteOrgConfirmTitle, this.editor.lp.deleteOrgConfirmContent, "300", "100", function(){
  317. _self._deleteItem();
  318. this.close();
  319. }, function(){
  320. this.close();
  321. })
  322. },
  323. _deleteItem: function(){
  324. this.node.destroy();
  325. if (this.property) this.property.propertyContent.destroy();
  326. this.editor.selectedItems.erase(this);
  327. //this.editor.data.erase(this.data);
  328. this.editor.save();
  329. if (this.editor.currentItem === this) this.editor.currentItem = null;
  330. this.editor.fireEvent("change");
  331. if( !this.editor.currentItem ){
  332. if(this.editor.defaultProperty){
  333. this.editor.defaultProperty.show();
  334. this.editor.upNode.set("text",this.editor.lp.orgEditor.addOption);
  335. }
  336. }
  337. MWF.release(this);
  338. },
  339. selectItem: function(){
  340. this.editor.upNode.set("text", this.editor.lp.orgEditor.modifyOption);
  341. if(this.editor.currentItem) this.editor.currentItem.unSelectItem();
  342. if(this.editor.defaultProperty)this.editor.defaultProperty.hide();
  343. if (this.property){
  344. this.property.show();
  345. }else{
  346. this.loadProperty();
  347. }
  348. this.node.setStyles(this.css.selectedItemNode_check);
  349. this.editor.currentItem = this;
  350. },
  351. unSelectItem: function(){
  352. this.node.setStyles(this.css.selectedItemNode);
  353. if (this.property) this.property.hide();
  354. this.editor.currentItem = null;
  355. }
  356. });
  357. MWF.xApplication.process.ProcessDesigner.widget.OrgEditor.Property = new Class({
  358. Implements: [Options, Events],
  359. Extends: MWF.APPPD.Property,
  360. initialize: function(org, data, options){
  361. this.setOptions(options);
  362. this.org = org;
  363. this.process = org.route.process;
  364. this.paper = this.process.paper;
  365. this.node = org.propertyNode;
  366. this.data = data;
  367. if( !this.data.id ){
  368. this.process.designer.actions.getId(1, function(ids){
  369. this.data.id = ids.data[0].id;
  370. }.bind(this),null,false);
  371. }
  372. this.data.pid = this.data.id; //this.process.process.id+this.org.route.data.id+this.data.id;
  373. this.htmlPath = "../x_component_process_ProcessDesigner/widget/$OrgEditor/org.html";
  374. },
  375. show: function(){
  376. if (!this.process.options.isView){
  377. if (!this.propertyContent){
  378. this.getHtmlString(function(){
  379. this.htmlString = o2.bindJson(this.htmlString, {"lp": o2.APPPD.LP.propertyTemplate});
  380. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.node);
  381. //this.process.panel.propertyTabPage.showTabIm();
  382. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  383. this.propertyContent.set("html", this.JsonTemplate.load());
  384. //this.process.panel.data = this.data;
  385. this.setEditNodeEvent();
  386. this.setEditNodeStyles(this.propertyContent);
  387. this.loadPropertyTab();
  388. this.loadFormFieldInput();
  389. this.loadPersonInput();
  390. this.loadScriptInput();
  391. this.loadScriptText();
  392. this.loadScriptArea();
  393. this.loadUnitTypeSelector();
  394. this.loadEventsEditor();
  395. }.bind(this));
  396. //this.loadDutySelector();
  397. }else{
  398. //this.process.panel.data = this.data;
  399. this.propertyContent.setStyle("display", "block");
  400. //this.process.panel.propertyTabPage.showTabIm();
  401. }
  402. // this.process.isFocus = true;
  403. }
  404. },
  405. setEditNodeEvent: function(){
  406. var property = this;
  407. // var inputs = this.propertyContent.getElements(".editTableInput");
  408. var inputs = this.propertyContent.getElements("input");
  409. inputs.each(function(input){
  410. var jsondata = input.get("name");
  411. var id = this.data.id;
  412. input.set("name", id+jsondata);
  413. if (jsondata){
  414. var inputType = input.get("type").toLowerCase();
  415. switch (inputType){
  416. case "radio":
  417. input.addEvent("change", function(e){
  418. property.setRadioValue(jsondata, this);
  419. });
  420. input.addEvent("blur", function(e){
  421. property.setRadioValue(jsondata, this);
  422. });
  423. input.addEvent("keydown", function(e){
  424. e.stopPropagation();
  425. });
  426. property.setRadioValue(jsondata, input);
  427. break;
  428. case "checkbox":
  429. input.addEvent("keydown", function(e){
  430. e.stopPropagation();
  431. });
  432. break;
  433. default:
  434. input.addEvent("change", function(e){
  435. property.setValue(jsondata, this.value);
  436. });
  437. input.addEvent("blur", function(e){
  438. property.setValue(jsondata, this.value);
  439. });
  440. input.addEvent("keydown", function(e){
  441. if (e.code===13){
  442. property.setValue(jsondata, this.value);
  443. }
  444. e.stopPropagation();
  445. });
  446. property.setValue(jsondata, input.get("value"));
  447. }
  448. }
  449. }.bind(this));
  450. var selects = this.propertyContent.getElements("select");
  451. selects.each(function(select){
  452. var jsondata = select.get("name");
  453. if (jsondata){
  454. select.addEvent("change", function(e){
  455. property.setSelectValue(jsondata, this);
  456. });
  457. //property.setSelectValue(jsondata, select);
  458. }
  459. });
  460. var textareas = this.propertyContent.getElements("textarea");
  461. textareas.each(function(input){
  462. var jsondata = input.get("name");
  463. if (jsondata){
  464. input.addEvent("change", function(e){
  465. property.setValue(jsondata, this.value);
  466. });
  467. input.addEvent("blur", function(e){
  468. property.setValue(jsondata, this.value);
  469. });
  470. input.addEvent("keydown", function(e){
  471. e.stopPropagation();
  472. });
  473. }
  474. }.bind(this));
  475. },
  476. loadEventsEditor: function(){
  477. var events = this.propertyContent.getElement(".MWFEventsArea");
  478. if (events){
  479. var name = events.get("name");
  480. var eventsObj = this.data[name];
  481. if( !MWF.xApplication.process.FormDesigner )MWF.xApplication.process.FormDesigner = {};
  482. if( !MWF.xApplication.process.FormDesigner.widget )MWF.xApplication.process.FormDesigner.widget = {};
  483. MWF.xDesktop.requireApp("process.FormDesigner", "widget.EventsEditor", function(){
  484. var eventsEditor = new MWF.xApplication.process.FormDesigner.widget.EventsEditor(events, this.process.designer, {
  485. //"maxObj": this.propertyNode.parentElement.parentElement.parentElement,
  486. "maxObj": this.process.designer.content
  487. });
  488. eventsEditor.load(eventsObj, this.data, name);
  489. }.bind(this));
  490. }
  491. }
  492. });