DictItemSelector.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. MWF.xApplication.process.FormDesigner.widget = MWF.xApplication.process.FormDesigner.widget || {};
  2. MWF.require("MWF.widget.O2Identity", null, false);
  3. MWF.xApplication.process.FormDesigner.widget.DictItemSelector = new Class({
  4. Implements: [Options, Events],
  5. Extends: MWF.widget.Common,
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function(node, property, options){
  10. this.setOptions(options);
  11. this.node = $(node);
  12. this.app = property.designer;
  13. this.data = property.data;
  14. this.path = "../x_component_process_ProcessDesigner/widget/$PersonSelector/";
  15. this.cssPath = "../x_component_process_ProcessDesigner/widget/$PersonSelector/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.widgetList = [];
  18. this.title = this.node.get("title");
  19. this.name = this.node.get("name");
  20. this.load();
  21. },
  22. load: function(){
  23. this.node.setStyles(this.css.node);
  24. this.createAddNode();
  25. var path = this.data[this.name];
  26. this.loadOrgWidget(path);
  27. },
  28. reload: function(){
  29. this.destroyWidget();
  30. this.node.empty();
  31. var path = this.data[this.name];
  32. this.loadOrgWidget(path);
  33. },
  34. getDict: function(){
  35. var dictField = this.node.dataset["dict"];
  36. if( !this.data[dictField] || !this.data[dictField].length )return null;
  37. return this.data[dictField][0];
  38. },
  39. destroyWidget: function(){
  40. this.widgetList.each(function (widget) {
  41. widget.destroy();
  42. });
  43. this.widgetList = [];
  44. },
  45. loadOrgWidget: function( path ){
  46. var widget = new MWF.widget.O2DictItem( this.getDict(), path, this.node, {
  47. "style": "xform","lazy":true,"disableInfor" : false
  48. });
  49. this.widgetList.push(widget);
  50. },
  51. createAddNode: function(){
  52. this.addNode = new Element("div", {"styles": this.css.addPersonNode}).inject(this.node, "before");
  53. this.addNode.addEvent("click", function(e){
  54. var dict = this.getDict();
  55. var action = this.getAction( dict );
  56. var p = dict.appType === "service" ? action.getData(dict.id) : action.getData(dict.id, dict.appId);
  57. p.then(function (json) {
  58. this.loadJsonSelector(json.data, this.title, function ( path ) {
  59. this.destroyWidget();
  60. this.loadOrgWidget(path);
  61. this.fireEvent("change", [path]);
  62. }.bind(this));
  63. }.bind(this));
  64. }.bind(this));
  65. },
  66. getAction: function(dict){
  67. switch (dict.appType) {
  68. case "process":
  69. return o2.Actions.load("x_processplatform_assemble_surface").ApplicationDictAction;
  70. case "cms":
  71. return o2.Actions.load("x_cms_assemble_control").AppDictAction;
  72. case "portal":
  73. return o2.Actions.load("x_portal_assemble_surface").DictAction;
  74. case "service":
  75. return o2.Actions.load("x_program_center").DictAction;
  76. }
  77. },
  78. loadJsonSelector: function(data, title, callback){
  79. var width = "770";
  80. var height = "580";
  81. width = width.toInt();
  82. height = height.toInt();
  83. var size = this.app.content.getSize();
  84. var x = (size.x-width)/2;
  85. var y = (size.y-height)/2;
  86. if (x<0) x = 0;
  87. if (y<0) y = 0;
  88. var _self = this;
  89. var jsonParse;
  90. MWF.require("MWF.xDesktop.Dialog", function() {
  91. var dlg = new MWF.xDesktop.Dialog({
  92. "title": title,
  93. "style": "user",
  94. "top": y,
  95. "left": x - 20,
  96. "fromTop": y,
  97. "fromLeft": x - 20,
  98. "width": width,
  99. "height": height,
  100. "html": "<div></div>",
  101. "maskNode": this.app.content,
  102. "container": this.app.content,
  103. "buttonList": [
  104. {
  105. "text": MWF.LP.process.button.ok,
  106. "action": function () {
  107. if( !jsonParse.objectTree.currentNode ){
  108. _self.app.notice(MWF.APPFD.LP.mustSelect, "error");
  109. return;
  110. }else{
  111. var path = jsonParse.objectTree.currentNode.getPath();
  112. if( path.contains(":") )path = path.split(":")[0];
  113. if(callback)callback(path);
  114. }
  115. this.close();
  116. }
  117. },
  118. {
  119. "text": MWF.LP.process.button.cancel,
  120. "action": function () {
  121. this.close();
  122. }
  123. }
  124. ]
  125. });
  126. dlg.show();
  127. MWF.require("MWF.widget.JsonParse", function(){
  128. jsonParse = new MWF.widget.JsonParse(data, dlg.content.getFirst(), null, {
  129. topkey: "root"
  130. });
  131. jsonParse.load();
  132. }.bind(this));
  133. }.bind(this))
  134. }
  135. });
  136. MWF.widget.O2DictItem = new Class({
  137. Extends: MWF.widget.O2Group,
  138. options: {
  139. "style": "default",
  140. "canRemove": false,
  141. "lazy": false,
  142. "disableInfor" : false,
  143. "styles": ""
  144. },
  145. initialize: function(dict, path, container, options){
  146. this.setOptions(options);
  147. this.loadedInfor = false;
  148. this.path = o2.session.path+"/widget/$O2Identity/";
  149. this.cssPath = o2.session.path+"/widget/$O2Identity/"+this.options.style+"/css.wcss";
  150. this._loadCss();
  151. this.container = $(container);
  152. this.dict = dict;
  153. this.path = path;
  154. this.style = this.css;
  155. this.load();
  156. //o2.widget.O2Identity.iditems.push(this);
  157. },
  158. getPersonData: function(){},
  159. setText: function(){
  160. this.node.set("text", this.path);
  161. },
  162. createInforNode: function(callback){
  163. this.loadedInfor = true;
  164. var path = this.path;
  165. var dict = this.dict;
  166. var action;
  167. if( dict.appType === "cms" ) {
  168. action = MWF.Actions.get("x_cms_assemble_control");
  169. }else if( dict.appType === "portal" ){
  170. action = MWF.Actions.get("x_portal_assemble_surface");
  171. }else if( dict.appType === "service" ){
  172. action = MWF.Actions.get("x_program_center");
  173. }else{
  174. action = MWF.Actions.get("x_processplatform_assemble_surface");
  175. }
  176. var encodePath = function( path ){
  177. var arr = path.split(/\//g);
  178. if( arr[0] === "root" )arr.splice(0, 1);
  179. // var ar = arr.map(function(v){ return encodeURIComponent(v); });
  180. return ( dict.appType === "portal" || dict.appType === "service" ) ? arr.join(".") : arr.join("/");
  181. };
  182. var p;
  183. debugger;
  184. if( dict.appType === "service" ){
  185. p = path === "root" ? action.getDictRoot(dict.id) : action.getDictData(dict.id, encodePath( path ));
  186. }else{
  187. p = path === "root" ? action.getDictRoot(dict.id, dict.appId) : action.getDictData(dict.id, dict.appId, encodePath( path ));
  188. }
  189. p.then(function (json) {
  190. this.inforNode = new Element("div", {
  191. style: "max-width:300px;white-space:pre-wrap; overflow-wrap:break-word; word-break:break-all;",
  192. text: JSON.stringify(json.data || "", null, 4)
  193. });
  194. this.tooltip = new mBox.Tooltip({
  195. content: this.inforNode,
  196. setStyles: {content: {padding: 15, lineHeight: 20}},
  197. attach: this.node,
  198. transition: 'flyin'
  199. });
  200. if( this.options.lazy ){
  201. this.tooltip.open();
  202. }
  203. }.bind(this))
  204. if (callback) callback();
  205. }
  206. });