Sidebar.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.require("MWF.widget.Tree", null, false);
  3. MWF.xApplication.process.Xform.Sidebar = MWF.APPSidebar = new Class({
  4. Extends: MWF.APP$Module,
  5. _loadUserInterface: function(){
  6. this.node.setStyles(this.form.css.sidebar);
  7. this.toolbarNode = this.node.getFirst("div");
  8. this.toolbarNode.empty();
  9. if (this.form.businessData.task){
  10. MWF.require("MWF.widget.Toolbar", function(){
  11. var toolbars = [];
  12. this.form.businessData.task.routeNameList.each(function(route, i){
  13. if (!this.json.defaultTools) this.json.defaultTools = [];
  14. var o= {
  15. "type": "MWFToolBarButton",
  16. "img": "submit.png",
  17. "title": route,
  18. "action": "processWork:"+route,
  19. "text": route,
  20. "id": "action_processWork",
  21. "control": "allowProcessing",
  22. "condition": "",
  23. "read": false
  24. };
  25. toolbars.push(o);
  26. }.bind(this));
  27. this.json.defaultTools = toolbars.concat(this.json.defaultTools);
  28. //this.json.defaultTools.unshift(o);
  29. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  30. //alert(this.readonly)
  31. if (this.json.hideSystemTools){
  32. if (this.json.tools.length){
  33. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  34. this.toolbarWidget.load();
  35. }else{
  36. this.toolbarNode.setStyle("display", "none");
  37. }
  38. }else{
  39. if (this.json.defaultTools.length || this.json.tools.length){
  40. if (this.json.defaultTools){
  41. this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
  42. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  43. this.toolbarWidget.load();
  44. }else{
  45. MWF.getJSON(this.form.path+"toolbars.json", function(json){
  46. this.setToolbars(json, this.toolbarNode, this.readonly, true);
  47. this.setCustomToolbars(this.json.tools, this.toolbarNode);
  48. this.toolbarWidget.load();
  49. }.bind(this), false);
  50. }
  51. }else{
  52. this.toolbarNode.setStyle("display", "none");
  53. }
  54. }
  55. if (this.toolbarWidget.children.length){
  56. //this.form.app.addEvent("resize", this.loadPosition.bind(this));
  57. this.node.setStyle("display", "none");
  58. window.setTimeout(this.loadPosition.bind(this), 500);
  59. var _self = this;
  60. this.form.app.content.getFirst().addEvent("scroll", function(e){
  61. _self.loadPosition(this);
  62. });
  63. this.form.app.addEvent("resize", function(e){
  64. _self.loadPosition(this);
  65. });
  66. }else{
  67. this.toolbarNode.setStyle("display", "none");
  68. }
  69. }.bind(this));
  70. }
  71. },
  72. loadPosition: function(){
  73. // this.node.setStyle("display", "block");
  74. // var parent = this.node.getParent();
  75. // while(parent && (!parent.get("MWFtype"))) parent = parent.getParent();
  76. //
  77. // var top = this.json.styles.top;
  78. // this.sideNode = parent || this.form.node;
  79. //
  80. // var size = this.form.app.content.getSize();
  81. // var scroll = this.form.app.content.getScroll();
  82. // var sideSize = this.sideNode.getSize();
  83. //
  84. // var y = (scroll.y+size.y/2)-sideSize.y/2;
  85. // var x = 5;
  86. //
  87. // var position = "centerRight";
  88. // var edge = "centerLeft";
  89. // if (!parent){
  90. // edge = "centerRight";
  91. // x = 5;
  92. // }
  93. //
  94. // if (this.json.barPosition=="left"){
  95. // position = "centerLeft";
  96. // edge = "centerRight";
  97. // x = -5;
  98. // if (!parent){
  99. // edge = "centerLeft";
  100. // x = 5;
  101. // }
  102. // }
  103. //
  104. // this.node.position({
  105. // "relativeTo": this.sideNode,
  106. // "position": position,
  107. // "edge": edge,
  108. // "offset" : {"y": y, "x": x}
  109. // });
  110. // this.json.styles.top = top;
  111. // if (top) this.node.setStyle("top", top);
  112. this.node.setStyle("display", "block");
  113. var parent = this.node.getParent();
  114. while(parent && (!parent.get("MWFtype"))) parent = parent.getParent();
  115. this.sideNode = parent || this.form.node;
  116. var size = this.form.app.content.getSize();
  117. //var scroll = this.form.designer.designNode.getScroll();
  118. var sideSize = this.sideNode.getSize();
  119. var sidePosition = this.sideNode.getPosition(this.sideNode.getOffsetParent());
  120. var nodeSize = this.node.getSize();
  121. if (sideSize.y>size.y){
  122. var center = (size.y/2-nodeSize.y/2);
  123. if (center<sidePosition.y){
  124. this.node.setStyle("top", ""+sidePosition.y+"px");
  125. }else if (center>(sidePosition.y+sideSize.y)){
  126. var tmp = (sidePosition.y+sideSize.y)-nodeSize.y;
  127. this.node.setStyle("top", ""+tmp+"px");
  128. }else{
  129. this.node.setStyle("top", ""+center+"px");
  130. }
  131. }else{
  132. var top = sidePosition.y+sideSize.y/2-nodeSize.y/2;
  133. if (top>size.y){
  134. if (sidePosition.y+nodeSize.y>size.y){
  135. this.node.setStyle("top", ""+sidePosition.y+"px");
  136. }else{
  137. var tmp = size.y-nodeSize.y;
  138. this.node.setStyle("top", ""+tmp+"px");
  139. }
  140. }else if(top<=0){
  141. if(sidePosition.y+sideSize.y<nodeSize.y){
  142. var tmp = sidePosition.y+sideSize.y-nodeSize.y;
  143. this.node.setStyle("top", ""+tmp+"px");
  144. }else{
  145. this.node.setStyle("top", "45px");
  146. }
  147. }else{
  148. this.node.setStyle("top", ""+top+"px");
  149. }
  150. }
  151. var left = sideSize.x+sidePosition.x+5;
  152. this.node.setStyle("left", ""+left+"px");
  153. this.node.setStyle("position", "absolute");
  154. this.node.setStyles({"right": "auto", "bottom": "auto"});
  155. // this.json.styles = this.node.getStyles(["top", "left", "bottom", "right", "position"]);
  156. //
  157. // var p = this.sideNode.getPosition();
  158. // var s = this.sideNode.getSize();
  159. // this.sidePosition = {"p": p, "s": s};
  160. },
  161. setCustomToolbars: function(tools, node){
  162. var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  163. tools.each(function(tool){
  164. var flag = true;
  165. if (this.readonly){
  166. flag = tool.readShow;
  167. }else{
  168. flag = tool.editShow;
  169. }
  170. if (flag){
  171. flag = true;
  172. if (tool.control){
  173. flag = this.form.businessData.control[tool.control]
  174. }
  175. if (tool.condition){
  176. var hideFlag = this.form.Macro.exec(tool.condition, this);
  177. flag = !hideFlag;
  178. }
  179. if (flag){
  180. var actionNode = new Element("div", {
  181. "id": tool.id,
  182. "MWFnodetype": tool.type,
  183. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  184. "MWFButtonImage": path+(this.form.options.style||"default") +"/custom/"+tool.img,
  185. "title": tool.title,
  186. "MWFButtonAction": "runCustomAction",
  187. "MWFButtonText": tool.text
  188. }).inject(node);
  189. if (tool.actionScript){
  190. actionNode.store("script", tool.actionScript);
  191. }
  192. if (tool.sub){
  193. var subNode = node.getLast();
  194. this.setCustomToolbars(tool.sub, subNode);
  195. }
  196. }
  197. }
  198. }.bind(this));
  199. },
  200. setToolbars: function(tools, node, readonly, noCondition){
  201. var path = "/x_component_process_FormDesigner/Module/Actionbar/";
  202. tools.each(function(tool){
  203. var flag = true;
  204. if (tool.control){
  205. flag = this.form.businessData.control[tool.control]
  206. }
  207. if (!noCondition) if (tool.condition){
  208. var hideFlag = this.form.Macro.exec(tool.condition, this);
  209. flag = !hideFlag;
  210. }
  211. if (tool.id == "action_processWork"){
  212. if (!this.form.businessData.task){
  213. flag = false;
  214. }
  215. }
  216. if (readonly) if (!tool.read) flag = false;
  217. if (flag){
  218. var actionNode = new Element("div", {
  219. "id": tool.id,
  220. "MWFnodetype": tool.type,
  221. //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
  222. "MWFButtonImage": path+(this.form.options.style||"default") +"/tools/default/"+tool.img,
  223. "title": tool.title,
  224. "MWFButtonAction": tool.action,
  225. "MWFButtonText": tool.text
  226. }).inject(node);
  227. if (tool.sub){
  228. var subNode = node.getLast();
  229. this.setToolbars(tool.sub, subNode, readonly, noCondition);
  230. }
  231. }
  232. }.bind(this));
  233. },
  234. runCustomAction: function(bt){
  235. var script = bt.node.retrieve("script");
  236. this.form.Macro.exec(script, this);
  237. },
  238. saveWork: function(){
  239. this.form.saveWork();
  240. },
  241. closeWork: function(){
  242. this.form.closeWork();
  243. },
  244. processWork: function(route){
  245. opinion = this.form.getOpinion();
  246. if (!this.form.formCustomValidation()){
  247. this.form.app.content.unmask();
  248. // if (callback) callback();
  249. return false;
  250. }
  251. this.form.submitWork(route, opinion.opinion, opinion.medias)
  252. // var opinionField = this.json.opinion || "opinion";
  253. // var data = this.form.getData();
  254. // var opinion = data[opinionField];
  255. // data[opinionField] = "";
  256. // this.form.submitWork(route, opinion, null, null, data);
  257. },
  258. resetWork: function(){
  259. this.form.resetWork();
  260. },
  261. retractWork: function(e, ev){
  262. this.form.retractWork(e, ev);
  263. },
  264. rerouteWork: function(e, ev){
  265. this.form.rerouteWork(e, ev);
  266. },
  267. deleteWork: function(){
  268. this.form.deleteWork();
  269. },
  270. printWork: function(){
  271. this.form.printWork();
  272. }
  273. });