DictionaryIncluder.js 11 KB

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