OrgEditor.js 20 KB

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