View.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.View = MWF.FCView = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_process_FormDesigner/Module/View/view.html"
  9. },
  10. initialize: function(form, options){
  11. this.setOptions(options);
  12. this.path = "/x_component_process_FormDesigner/Module/View/";
  13. this.cssPath = "/x_component_process_FormDesigner/Module/View/"+this.options.style+"/css.wcss";
  14. this.imagePath_default = "/x_component_query_ViewDesigner/$View/";
  15. this.imagePath_custom = "/x_component_process_FormDesigner/Module/Actionbar/";
  16. this._loadCss();
  17. this.moduleType = "element";
  18. this.moduleName = "view";
  19. this.form = form;
  20. this.container = null;
  21. this.containerNode = null;
  22. },
  23. load : function(json, node, parent){
  24. this.json = json;
  25. this.node= node;
  26. this.node.store("module", this);
  27. //this.node.empty();
  28. this.node.setStyles(this.css.moduleNode);
  29. this._loadNodeStyles();
  30. this._initModule();
  31. this._loadTreeNode(parent);
  32. //this.setCustomStyles();
  33. this.parentContainer = this.treeNode.parentNode.module;
  34. this._setEditStyle_custom("id");
  35. this.json.moduleName = this.moduleName;
  36. // this.parseModules();
  37. },
  38. _createMoveNode: function(){
  39. this.moveNode = new Element("div", {
  40. "MWFType": "view",
  41. "id": this.json.id,
  42. "styles": this.css.moduleNodeMove,
  43. "events": {
  44. "selectstart": function(){
  45. return false;
  46. }
  47. }
  48. }).inject(this.form.container);
  49. },
  50. _initModule: function(){
  51. this.setPropertiesOrStyles("styles");
  52. this.setPropertiesOrStyles("properties");
  53. this._checkView(function(){
  54. this._setTitleStyles();
  55. }.bind(this));
  56. this._setNodeProperty();
  57. if (!this.form.isSubform) this._createIconAction();
  58. this._setNodeEvent();
  59. },
  60. _createNode: function(){
  61. this.node = this.moveNode.clone(true, true);
  62. this.node.setStyles(this.css.moduleNode);
  63. this.node.set("id", this.json.id);
  64. this.node.addEvent("selectstart", function(){
  65. return false;
  66. });
  67. this.iconNode = new Element("div", {
  68. "styles": this.css.iconNode
  69. }).inject(this.node);
  70. new Element("div", {
  71. "styles": this.css.iconNodeIcon
  72. }).inject(this.iconNode);
  73. new Element("div", {
  74. "styles": this.css.iconNodeText,
  75. "text": "VIEW"
  76. }).inject(this.iconNode);
  77. this.iconNode.addEvent("click", function(){
  78. this._checkView();
  79. }.bind(this));
  80. },
  81. _loadNodeStyles: function(){
  82. this.iconNode = this.node.getElement("div").setStyles(this.css.iconNode);
  83. this.iconNode.getFirst("div").setStyles(this.css.iconNodeIcon);
  84. this.iconNode.getLast("div").setStyles(this.css.iconNodeText);
  85. this.viewNode = this.node.getChildren("div")[1];
  86. if (this.viewNode){
  87. this.node.setStyle("background", "transparent");
  88. this.actionbarNode = this.viewNode.getChildren("div")[0];
  89. this.viewTable = this.viewNode.getElement("table").setStyles(this.css.viewTitleTableNode);
  90. this.viewLine = this.viewTable.getElement("tr").setStyles(this.css.viewTitleLineNode);
  91. this.viewSelectCell = this.viewLine.getElement("td");
  92. if (this.viewSelectCell) this.viewSelectCell.setStyles(this.css.viewTitleCellNode);
  93. this._setViewNodeTitle();
  94. }
  95. },
  96. _createViewNode: function(callback){
  97. if (!this.viewNode) this.viewNode = new Element("div", {"styles": this.css.viewNode}).inject(this.node);
  98. if( !this.actionbarNode)this.actionbarNode = new Element("div.actionbarNode",{}).inject( this.viewNode, "top" );
  99. this.node.setStyle("background", "transparent");
  100. this.viewTable = new Element("table", {
  101. "styles": this.css.viewTitleTableNode,
  102. "border": "0px",
  103. "cellPadding": "0",
  104. "cellSpacing": "0"
  105. }).inject(this.viewNode);
  106. this.viewLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  107. if (this.json.select!="no"){
  108. this.viewSelectCell = new Element("td", {
  109. "styles": this.css.viewTitleCellNode
  110. }).inject(this.viewLine);
  111. this.viewSelectCell.setStyle("width", "10px");
  112. }
  113. MWF.Actions.get("x_query_assemble_designer").getView(this.json["queryView"].id, function(json){
  114. var viewData = JSON.decode(json.data.data);
  115. this.viewData = viewData;
  116. if( this.json.actionbar === "show" ){
  117. this.actionbarList = [];
  118. this._showActionbar();
  119. }
  120. var columnList = viewData.selectEntryList || viewData.selectList;
  121. columnList.each(function(column){
  122. if (!column.hideColumn){
  123. var viewCell = new Element("td", {
  124. "styles": this.css.viewTitleCellNode,
  125. "text": column.displayName
  126. }).inject(this.viewLine);
  127. }
  128. }.bind(this));
  129. if (callback) callback();
  130. }.bind(this));
  131. this._setViewNodeTitle();
  132. },
  133. _setViewNodeTitle: function(){
  134. if (this.viewTable){
  135. if (this.json["isTitle"] == "no"){
  136. this.viewTable.setStyle("opacity", 0.5);
  137. }else{
  138. this.viewTable.setStyle("opacity", 1);
  139. }
  140. }
  141. },
  142. _setEditStyle: function(name, input, oldValue){
  143. if (name=="view" || name=="processView" || name=="CMSView" || name=="queryView"){
  144. if (this.json[name]!=oldValue) this._checkView();
  145. }
  146. if (name=="select") this._checkSelect();
  147. if (name=="isTitle") this._checkTitle();
  148. if (name=="titleStyles") this._setTitleStyles();
  149. if (name=="name"){
  150. var title = this.json.name || this.json.id;
  151. var text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  152. this.treeNode.setText("<"+text+"> "+title);
  153. }
  154. if (name=="id"){
  155. if (!this.json.name){
  156. var text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  157. this.treeNode.setText("<"+text+"> "+this.json.id);
  158. }
  159. this.treeNode.setTitle(this.json.id);
  160. this.node.set("id", this.json.id);
  161. }
  162. if(name=="actionbar"){
  163. input.get("value") === "show" ? this._showActionbar() : this._hideActionbar();
  164. }
  165. this._setEditStyle_custom(name, input, oldValue);
  166. },
  167. _setTitleStyles: function(){
  168. if (this.viewLine){
  169. this.viewLine.getElements("td").each(function(td){
  170. td.clearStyles();
  171. td.setStyles(this.css.viewTitleCellNode);
  172. if (this.json.titleStyles) td.setStyles(this.json.titleStyles);
  173. }.bind(this));
  174. if (this.viewSelectCell) this.viewSelectCell.setStyle("width", "10px");
  175. this._checkSelect();
  176. this._checkTitle();
  177. }
  178. },
  179. _checkView: function(callback){
  180. if (this.json["queryView"] && this.json["queryView"]!="none"){
  181. this.iconNode.setStyle("display", "none");
  182. if (this.viewNode) this.viewNode.destroy();
  183. this.viewNode = null;
  184. this._createViewNode(function(){
  185. if (callback) callback();
  186. }.bind(this));
  187. }else{
  188. this.iconNode.setStyle("display", "block");
  189. if (this.viewNode) this.viewNode.destroy();
  190. this.node.setStyles(this.css.moduleNode);
  191. if (callback) callback();
  192. }
  193. },
  194. _checkSelect: function(){
  195. if (this.json["select"]!="no"){
  196. if (!this.viewSelectCell){
  197. this.viewSelectCell = new Element("td", {
  198. "styles": this.css.viewTitleCellNode
  199. }).inject(this.viewLine, "top");
  200. this.viewSelectCell.setStyle("width", "10px");
  201. }
  202. if (this.json["select"]=="single"){
  203. this.viewSelectCell.setStyle("background", "url(/x_component_process_FormDesigner/Module/View/default/icon/single.png) center center no-repeat");
  204. }else{
  205. this.viewSelectCell.setStyle("background", "url(/x_component_process_FormDesigner/Module/View/default/icon/multi.png) center center no-repeat");
  206. }
  207. }else{
  208. if (this.viewSelectCell){
  209. this.viewSelectCell.destroy();
  210. this.viewSelectCell = null;
  211. }
  212. }
  213. },
  214. _checkTitle: function(){
  215. if (!this.json["isTitle"]) this.json["isTitle"] = "yes";
  216. if (this.viewNode) this._setViewNodeTitle();
  217. },
  218. _hideActionbar : function(){
  219. if(this.actionbarNode)this.actionbarNode.hide();
  220. },
  221. _showActionbar : function(){
  222. if( !this.actionbarNode )return;
  223. MWF.require("MWF.widget.Toolbar", null, false);
  224. this.actionbarNode.show();
  225. if( !this.viewData.actionbarList )this.viewData.actionbarList = [];
  226. if( !this.actionbarList || this.actionbarList.length == 0 ){
  227. this.actionbarNode.empty();
  228. if( this.viewData.actionbarList.length ){
  229. if( !this.actionbarList )this.actionbarList = [];
  230. this.viewData.actionbarList.each( function(json){
  231. var toolbarWidget = new MWF.widget.Toolbar(this.actionbarNode, {"style": json.style}, this);
  232. if (json.actionStyles)toolbarWidget.css = json.actionStyles;
  233. if( !json.hideSystemTools )this.setToolbars( json.defaultTools, this.actionbarNode, json );
  234. this.setCustomToolbars( json.tools, this.actionbarNode, json );
  235. toolbarWidget.load();
  236. this.actionbarList.push( toolbarWidget );
  237. }.bind(this));
  238. }else{
  239. }
  240. }
  241. },
  242. setToolbars: function(tools, node, json){
  243. var style = "default";
  244. tools.each(function(tool){
  245. var actionNode = new Element("div", {
  246. "MWFnodetype": tool.type,
  247. "MWFButtonImage": this.imagePath_default+""+style+"/actionbar/"+tool.img,
  248. "title": tool.title,
  249. "MWFButtonAction": tool.action,
  250. "MWFButtonText": tool.text
  251. }).inject(node);
  252. if( this.json.iconOverStyle ){
  253. actionNode.set("MWFButtonImageOver" , this.imagePath_default+""+ style+"/actionbar/"+json.iconOverStyle+"/"+tool.img );
  254. }
  255. // this.systemTools.push(actionNode);
  256. // if (tool.sub){
  257. // var subNode = node.getLast();
  258. // this.setToolbars(tool.sub, subNode);
  259. // }
  260. }.bind(this));
  261. },
  262. setCustomToolbars: function(tools, node, json){
  263. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  264. var path = "";
  265. if( json.customIconStyle ){
  266. path = json.customIconStyle+ "/";
  267. }
  268. var customImageStyle = "default";
  269. tools.each(function(tool){
  270. var actionNode = new Element("div", {
  271. "MWFnodetype": tool.type,
  272. "MWFButtonImage": this.imagePath_custom+""+customImageStyle +"/custom/"+path+tool.img,
  273. "title": tool.title,
  274. "MWFButtonAction": tool.action,
  275. "MWFButtonText": tool.text
  276. }).inject(node);
  277. if( this.json.customIconOverStyle ){
  278. actionNode.set("MWFButtonImageOver" , this.imagePath_custom+""+customImageStyle +"/custom/"+json.customIconOverStyle+ "/" +tool.img );
  279. }
  280. // this.customTools.push(actionNode);
  281. // if (tool.sub){
  282. // var subNode = node.getLast();
  283. // this.setCustomToolbars(tool.sub, subNode);
  284. // }
  285. }.bind(this));
  286. }
  287. });