Dictionary.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.service = MWF.xApplication.service || {};
  3. MWF.xApplication.service.DictionaryDesigner = MWF.xApplication.service.DictionaryDesigner || {};
  4. MWF.xDesktop.requireApp("process.DictionaryDesigner", "Dictionary", null, false);
  5. MWF.xApplication.service.DictionaryDesigner.Dictionary = new Class({
  6. Extends: MWF.xApplication.process.DictionaryDesigner.Dictionary,
  7. createRootItem: function() {
  8. this.items.push(new MWF.xApplication.service.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true));
  9. },
  10. saveSilence: function(callback){
  11. if (!this.isSave){
  12. if( this.scriptPage.isShow ){
  13. if( this.scriptEditor ){
  14. var data = this.getEditorValidData( true );
  15. if( data !== false ){
  16. this.data.data = data;
  17. }else{
  18. return false;
  19. }
  20. }
  21. }
  22. var name = this.designer.propertyNameNode.get("value");
  23. var alias = this.designer.propertyAliasNode.get("value");
  24. var description = this.designer.propertyDescriptionNode.get("value");
  25. if (!name){
  26. this.designer.notice(this.designer.lp.notice.inputName, "error");
  27. return false;
  28. }
  29. this.data.name = name;
  30. this.data.alias = alias;
  31. this.data.description = description;
  32. this.isSave = true;
  33. this.saveDictionary(function(json){
  34. this.isSave = false;
  35. this.data.id = json.data.id;
  36. this.designer.propertyIdNode.set("text", json.data.id);
  37. if (callback) callback();
  38. }.bind(this), function(xhr, text, error){
  39. this.isSave = false;
  40. //
  41. //var errorText = error+":"+text;
  42. //if (xhr) errorText = xhr.responseText;
  43. //MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  44. }.bind(this));
  45. }
  46. },
  47. save: function(callback){
  48. if (!this.isSave){
  49. if (this.designer.tab.showPage==this.page){
  50. if( this.scriptPage.isShow ){
  51. if( this.scriptEditor ){
  52. var data = this.getEditorValidData();
  53. if( data !== false ){
  54. this.data.data = data;
  55. }else{
  56. return false;
  57. }
  58. }
  59. }
  60. var name = this.designer.propertyNameNode.get("value");
  61. var alias = this.designer.propertyAliasNode.get("value");
  62. var description = this.designer.propertyDescriptionNode.get("value");
  63. if (!name || !alias){
  64. this.designer.notice(this.designer.lp.notice.inputName, "error");
  65. return false;
  66. }
  67. this.data.name = name;
  68. this.data.alias = alias;
  69. this.data.description = description;
  70. }
  71. this.isSave = true;
  72. this.saveDictionary(function(json){
  73. this.isSave = false;
  74. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  75. this.data.isNewDictionary = false;
  76. this.isNewDictionary = false;
  77. this.designer.propertyIdNode.set("text", json.data.id);
  78. this.data.id = json.data.id;
  79. this.page.textNode.set("text", this.data.name);
  80. if (this.lisNode) {
  81. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  82. }
  83. if (callback) callback();
  84. }.bind(this), function(xhr, text, error){
  85. this.isSave = false;
  86. var errorText = error+":"+text;
  87. if (xhr) errorText = xhr.responseText;
  88. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  89. }.bind(this));
  90. }else{
  91. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  92. }
  93. },
  94. saveDictionary: function (callback) {
  95. if (this.data.id){
  96. this.designer.actions.updateDictionary(this.data.id, this.data, callback);
  97. }else{
  98. delete this.data.id;
  99. this.designer.actions.addDictionary(this.data, callback);
  100. }
  101. }
  102. });
  103. MWF.xApplication.service.DictionaryDesigner.Dictionary.item = new Class({
  104. Extends: MWF.xApplication.process.DictionaryDesigner.Dictionary.item,
  105. createNewItem: function(key, value, parent, level, dictionary, exp, nextSibling){
  106. return new MWF.xApplication.service.DictionaryDesigner.Dictionary.item(key, value, parent, level, dictionary, exp, nextSibling);
  107. }
  108. });
  109. MWF.xApplication.service.DictionaryDesigner.DictionaryReader = new Class({
  110. Extends: MWF.xApplication.process.DictionaryDesigner.DictionaryReader,
  111. autoSave: function(){},
  112. createRootItem: function() {
  113. this.items.push(new MWF.xApplication.service.DictionaryDesigner.Dictionary.ItemReader("ROOT", this.data.data, null, 0, this, true));
  114. },
  115. });
  116. MWF.xApplication.service.DictionaryDesigner.Dictionary.ItemReader= new Class({
  117. Extends: MWF.xApplication.process.DictionaryDesigner.Dictionary.ItemReader,
  118. createNewItem: function(key, value, parent, level, dictionary, exp, nextSibling){
  119. return new MWF.xApplication.service.DictionaryDesigner.Dictionary.ItemReader(key, value, parent, level, dictionary, exp, nextSibling);
  120. }
  121. });