DictionaryIncluder.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. MWF.xApplication.process.FormDesigner.widget = MWF.xApplication.process.FormDesigner.widget || {};
  2. MWF.require("MWF.widget.UUID", null, false);
  3. MWF.require("MWF.widget.O2Identity", null, false);
  4. MWF.xApplication.process.FormDesigner.widget.DictionaryIncluder = new Class({
  5. Implements: [Options, Events],
  6. Extends: MWF.widget.Common,
  7. options: {
  8. "style": "default",
  9. "maxObj": document.body
  10. },
  11. initialize: function(node, designer, options){
  12. this.setOptions(options);
  13. this.node = $(node);
  14. this.designer = designer;
  15. this.path = "../x_component_process_FormDesigner/widget/$DictionaryIncluder/";
  16. this.cssPath = "../x_component_process_FormDesigner/widget/$DictionaryIncluder/"+this.options.style+"/css.wcss";
  17. this._loadCss();
  18. this.lp = this.designer.lp.dictionaryIncluder;
  19. this.items = [];
  20. },
  21. load: function(data){
  22. this.editorNode = new Element("div", {"styles": this.css.editorNode}).inject(this.node);
  23. this.actionNode = new Element("div", {"styles": this.css.actionNode}).inject(this.node);
  24. this.listNode = new Element("div", {"styles": this.css.listNode}).inject(this.node);
  25. this.loadEditorNode();
  26. this.loadActionNode();
  27. this.loadListNode(data);
  28. },
  29. loadEditorNode: function(){
  30. debugger;
  31. var html = "<table width='100%' border='0' cellpadding='5' cellspacing='0' class='editTable'>" +
  32. "<tr><td>"+this.lp.selectDictionary+"</td><td><div class='dictionarySelectorArea'></div></td></tr>" +
  33. "<tr><td>"+this.lp.path+"</td><td><input type='text' style='width:90%'/></td></tr>"+
  34. "</table>";
  35. this.editorNode.set("html", html);
  36. var tds = this.editorNode.getElements("td").setStyles(this.css.editTableTdValue);
  37. this.dictionarySelectorArea = this.editorNode.getElement(".dictionarySelectorArea");
  38. this.pathField = this.editorNode.getElement("input[type='text']");
  39. this.loadDictionarySelector();
  40. },
  41. loadDictionarySelector: function( data ){
  42. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.PersonSelector", function(){
  43. var _self = this;
  44. if( !data )data = [];
  45. this.dictionarySelector = new MWF.xApplication.process.ProcessDesigner.widget.PersonSelector(this.dictionarySelectorArea, this.designer, {
  46. "type": "Dictionary",
  47. "count": 1,
  48. "names": data,
  49. "onChange": function(ids){
  50. var json;
  51. if( ids.length ){
  52. var d = ids[0].data;
  53. json = {
  54. "type" : "dictionary",
  55. "name": d.name,
  56. "alias": d.alias,
  57. "id": d.id,
  58. "appName" : d.appName || d.applicationName,
  59. "appId": d.appId || d.application,
  60. "appAilas": d.appAilas || d.applicationAilas,
  61. "appType" : d.appType
  62. };
  63. }
  64. this.currentSelectDictionary = json;
  65. }.bind(this)
  66. });
  67. }.bind(this));
  68. },
  69. loadActionNode: function(){
  70. this.actionAreaNode = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.actionNode);
  71. this.addAction = new Element("div", {"styles": this.css.addAction, "text": this.designer.lp.validation.add}).inject(this.actionAreaNode);
  72. this.modifyAction = new Element("div", {"styles": this.css.modifyAction_disabled, "text": this.designer.lp.validation.modify}).inject(this.actionAreaNode);
  73. this.addAction.addEvent("click", function(){
  74. this.add();
  75. }.bind(this));
  76. this.modifyAction.addEvent("click", function(){
  77. this.modify();
  78. }.bind(this));
  79. },
  80. getCurrentData: function(){
  81. return {
  82. "path": this.pathField.get("value"),
  83. "dictionary": this.currentSelectDictionary || null
  84. };
  85. },
  86. add: function(){
  87. debugger;
  88. this.hideErrorNode();
  89. var data = this.getCurrentData();
  90. if ( !data.dictionary ){
  91. this.showErrorNode(this.lp.selectDictionaryNotice);
  92. return false;
  93. }
  94. for( var i=0; i<this.items.length; i++ ){
  95. var d = this.items[i].data;
  96. if( d.dictionary.id === data.dictionary.id ){
  97. if( d.path === data.path ){
  98. this.showErrorNode(this.lp.repeatAddDictionaryNotice);
  99. return false;
  100. }else if( !d.path || d.path === "root" ){
  101. this.showErrorNode(this.lp.rootDictionaryExistNotice);
  102. return false;
  103. }else if( !data.path || data.path === "root" ){
  104. this.showErrorNode(this.lp.subDictionaryExistNotice);
  105. return false;
  106. }else if( d.path.indexOf( data.path + "." ) === 0 ){
  107. this.showErrorNode(this.lp.subDictionaryExistNotice);
  108. return false;
  109. }else if( data.path.indexOf( d.path + "." ) === 0 ){
  110. this.showErrorNode(this.lp.parentDictionaryExistNotice);
  111. return false;
  112. }
  113. }
  114. }
  115. var item = new MWF.xApplication.process.FormDesigner.widget.DictionaryIncluder.Item(data, this);
  116. this.items.push(item);
  117. item.selected();
  118. this.empty();
  119. this.fireEvent("change");
  120. },
  121. empty: function(){
  122. this.pathField.set("value","");
  123. if(this.dictionarySelector)this.dictionarySelector.setData( [] );
  124. this.currentSelectDictionary = null;
  125. },
  126. showErrorNode: function(text){
  127. this.errorNode = new Element("div", {"styles": this.css.errorNode}).inject(this.actionNode, "before");
  128. this.errorTextNode = new Element("div", {"styles": this.css.errorTextNode}).inject(this.errorNode);
  129. this.errorTextNode.set("text", text);
  130. this.errorNode.addEvent("click", function(){this.hideErrorNode();}.bind(this));
  131. },
  132. hideErrorNode: function(){
  133. if (this.errorNode) this.errorNode.destroy();
  134. },
  135. modify: function(){
  136. debugger;
  137. if (this.currentItem){
  138. this.hideErrorNode();
  139. var data = this.getCurrentData();
  140. if ( !data.dictionary ){
  141. this.showErrorNode(this.lp.selectDictionaryNotice);
  142. return false;
  143. }
  144. for( var i=0; i<this.items.length; i++ ){
  145. if( this.items[i] === this.currentItem )continue;
  146. var d = this.items[i].data;
  147. if( d.dictionary.id === data.dictionary.id ){
  148. if( d.path === data.path ){
  149. this.showErrorNode(this.lp.repeatAddDictionaryNotice);
  150. return false;
  151. }else if( !d.path || d.path === "root" ){
  152. this.showErrorNode(this.lp.rootDictionaryExistNotice);
  153. return false;
  154. }else if( !data.path || data.path === "root" ){
  155. this.showErrorNode(this.lp.subDictionaryExistNotice);
  156. return false;
  157. }else if( d.path.indexOf( data.path + "." ) === 0 ){
  158. this.showErrorNode(this.lp.subDictionaryExistNotice);
  159. return false;
  160. }else if( data.path.indexOf( d.path + "." ) === 0 ){
  161. this.showErrorNode(this.lp.parentDictionaryExistNotice);
  162. return false;
  163. }
  164. }
  165. }
  166. this.currentItem.reload(data);
  167. this.currentItem.unSelected();
  168. this.disabledModify();
  169. this.empty();
  170. this.fireEvent("change");
  171. }
  172. },
  173. loadListNode: function(data){
  174. if (data){
  175. if (data.length){
  176. data.each(function(itemData){
  177. var item = new MWF.xApplication.process.FormDesigner.widget.DictionaryIncluder.Item(itemData, this);
  178. this.items.push(item);
  179. }.bind(this));
  180. }
  181. }
  182. },
  183. enabledModify: function(){
  184. this.modifyAction.setStyles(this.css.modifyAction);
  185. },
  186. disabledModify: function(){
  187. this.modifyAction.setStyles(this.css.modifyAction_disabled);
  188. },
  189. setData: function(data){
  190. this.pathField.set( "value", data.path || "");
  191. if( !this.dictionarySelector ){
  192. this.loadDictionarySelector( data.dictionary ? [data.dictionary] : [] );
  193. }else{
  194. this.dictionarySelector.setData( data.dictionary ? [data.dictionary] : [] );
  195. }
  196. this.currentSelectDictionary = data.dictionary;
  197. },
  198. deleteItem: function(item){
  199. if (this.currentItem == item) item.unSelected();
  200. this.items.erase(item);
  201. item.node.destroy();
  202. MWF.release(item);
  203. this.fireEvent("change");
  204. },
  205. getData: function(){
  206. var data = [];
  207. this.items.each(function(item){
  208. data.push(item.data);
  209. });
  210. return data;
  211. }
  212. });
  213. MWF.xApplication.process.FormDesigner.widget.DictionaryIncluder.Item = new Class({
  214. initialize: function(data, editor){
  215. this.data = data;
  216. this.editor = editor;
  217. this.container = this.editor.listNode;
  218. this.css = this.editor.css;
  219. this.lp = this.editor.designer.lp;
  220. this.load();
  221. },
  222. load: function(){
  223. debugger;
  224. this.node = new Element("div", {"styles": this.css.itemNode}).inject(this.container);
  225. this.deleteNode = new Element("div", {"styles": this.css.itemDeleteNode}).inject(this.node);
  226. this.contentNode = new Element("div", {"styles": this.css.itemContentNode}).inject(this.node);
  227. this.dictionaryNode = new Element("div", {
  228. styles : this.css.dictionaryNode
  229. }).inject(this.contentNode);
  230. new MWF.widget.O2Dictionary(this.data.dictionary, this.dictionaryNode);
  231. this.pathNode = new Element("div", {"styles": {"padding-left": "5px","padding-top": "5px"}}).inject(this.contentNode);
  232. this.pathNode.set({
  233. "text": this.lp.dictionaryIncluder.path + (this.data.path || "root")
  234. });
  235. this.contentNode.addEvent("click", function(){
  236. this.selected();
  237. }.bind(this));
  238. this.deleteNode.addEvent("click", function(e){
  239. this.deleteItem(e);
  240. }.bind(this));
  241. },
  242. reload: function(data){
  243. this.data = data;
  244. this.pathNode.set({
  245. "text": this.lp.dictionaryIncluder.path + (this.data.path || "root")
  246. });
  247. this.dictionaryNode.empty();
  248. new MWF.widget.O2Dictionary(data.dictionary, this.dictionaryNode)
  249. },
  250. selected: function(){
  251. if (this.editor.currentItem) this.editor.currentItem.unSelected();
  252. this.node.setStyles(this.css.itemNode_current);
  253. this.editor.currentItem = this;
  254. this.editor.setData(this.data);
  255. this.editor.enabledModify();
  256. },
  257. unSelected: function(){
  258. this.node.setStyles(this.css.itemNode);
  259. this.editor.currentItem = null;
  260. //this.editor.modifyValidation();
  261. this.editor.disabledModify();
  262. },
  263. deleteItem: function(e){
  264. var _self = this;
  265. this.editor.designer.confirm("warn", e, this.lp.dictionaryIncluder.delete_title, this.lp.dictionaryIncluder.delete_text, 300, 120, function(){
  266. _self.destroy();
  267. this.close();
  268. }, function(){
  269. this.close();
  270. });
  271. },
  272. destroy: function(){
  273. this.editor.deleteItem(this);
  274. }
  275. });