UserData.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. MWF.xDesktop = MWF.xDesktop || {};
  2. MWF.xApplication = MWF.xApplication || {};
  3. MWF.require("MWF.xDesktop.Actions.RestActions", null, false);
  4. MWF.xDesktop.UserData = MWF.UD = {
  5. getAction: function(){
  6. //this.action = new MWF.xDesktop.Actions.RestActions("/xDesktop/Actions/action.json", "x_organization_assemble_personal");
  7. this.action = o2.Actions.get("x_organization_assemble_personal");
  8. },
  9. getData: function(name, callback, async){
  10. if (!this.action) this.getAction();
  11. this.action.getUserData(name, function(json){
  12. if (callback) callback(json);
  13. }, null, async);
  14. },
  15. getDataJson: function(name, callback, async){
  16. if (!this.action) this.getAction();
  17. this.action.getUserData(name, function(json){
  18. var returnJson = null;
  19. if (json.data){
  20. try{
  21. returnJson = JSON.decode(json.data);
  22. }catch(e){}
  23. }
  24. if (callback) callback(returnJson);
  25. }, null, async);
  26. },
  27. putData: function(name, data, callback, async){
  28. if (!this.action) this.getAction();
  29. this.action.putUserData(name, data, function(json){
  30. if (callback) callback(json);
  31. }, null, async)
  32. // this.action.invoke({"name": "putUserData", "async": async, "data": data, "parameter": {"name": name}, "success": function(json){
  33. // if (callback) callback(json);
  34. // }.bind(this)});
  35. },
  36. deleteData: function(name, callback, async){
  37. if (!this.action) this.getAction();
  38. this.action.deleteUserData(name, function(json){
  39. if (callback) callback(json);
  40. }, null, async)
  41. // this.action.invoke({"name": "deleteUserData", "async": async, "parameter": {"name": name}, "success": function(json){
  42. // if (callback) callback(json);
  43. // }.bind(this)});
  44. },
  45. getPublicData: function(name, callback, async){
  46. if (!this.action) this.getAction();
  47. this.action.getPublicUserData(name, function(json){
  48. var returnJson = null;
  49. if (json.data){
  50. try{
  51. returnJson = JSON.decode(json.data);
  52. }catch(e){}
  53. }
  54. if (callback) callback(returnJson);
  55. }, null, async)
  56. // this.action.invoke({"name": "getPublicUserData", "async": async, "parameter": {"name": name}, "success": function(json){
  57. // var returnJson = null;
  58. // if (json.data) returnJson = JSON.decode(json.data);
  59. // if (callback) callback(returnJson);
  60. // }.bind(this)});
  61. },
  62. putPublicData: function(name, data, callback, async){
  63. if (!this.action) this.getAction();
  64. this.action.putPublicUserData(name, data, function(json){
  65. if (callback){
  66. if (callback.success){
  67. callback.success(json);
  68. }else{
  69. callback(json);
  70. }
  71. }
  72. }, function(xhr, text, error){
  73. if (xhr.status!=0){
  74. var errorText = error;
  75. if (xhr){
  76. var json = JSON.decode(xhr.responseText);
  77. if (json){
  78. errorText = json.message.trim() || "request json error";
  79. }else{
  80. errorText = "request json error: "+xhr.responseText;
  81. }
  82. }
  83. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  84. }
  85. if (callback) if (callback.failure) callback.failure(xhr, text, error);
  86. }, async);
  87. // this.action.invoke({"name": "putPublicUserData", "async": async, "data": data, "parameter": {"name": name}, "success": function(json){
  88. // if (callback){
  89. // if (callback.success){
  90. // callback.success(json);
  91. // }else{
  92. // callback(json);
  93. // }
  94. // }
  95. // }.bind(this), "failure": function(xhr, text, error){
  96. // if (xhr.status!=0){
  97. // var errorText = error;
  98. // if (xhr){
  99. // var json = JSON.decode(xhr.responseText);
  100. // if (json){
  101. // errorText = json.message.trim() || "request json error";
  102. // }else{
  103. // errorText = "request json error: "+xhr.responseText;
  104. // }
  105. // }
  106. // MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  107. // }
  108. // if (callback) if (callback.failure) callback.failure(xhr, text, error);
  109. // }});
  110. },
  111. deletePublicData: function(name, callback, async){
  112. if (!this.action) this.getAction();
  113. this.action.deletePublicUserData(name, function(json){
  114. if (callback) callback(json);
  115. }, null, async);
  116. // this.action.invoke({"name": "deletePublicUserData", "async": async, "parameter": {"name": name}, "success": function(json){
  117. // if (callback) callback(json);
  118. // }.bind(this)});
  119. }
  120. };