View.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. if( this.actionbarNode ){
  90. this.actionbarNode.destroy();
  91. this.actionbarNode = null;
  92. }
  93. this.viewTable = this.viewNode.getElement("table").setStyles(this.css.viewTitleTableNode);
  94. this.viewLine = this.viewTable.getElement("tr").setStyles(this.css.viewTitleLineNode);
  95. this.viewSelectCell = this.viewLine.getElement("td");
  96. if (this.viewSelectCell) this.viewSelectCell.setStyles(this.css.viewTitleCellNode);
  97. this._setViewNodeTitle();
  98. }
  99. },
  100. _createViewNode: function(callback){
  101. if (!this.viewNode) this.viewNode = new Element("div", {"styles": this.css.viewNode}).inject(this.node);
  102. if( !this.actionbarNode)this.actionbarNode = new Element("div.actionbarNode",{}).inject( this.viewNode, "top" );
  103. this.node.setStyle("background", "transparent");
  104. this.viewTable = new Element("table", {
  105. "styles": this.css.viewTitleTableNode,
  106. "border": "0px",
  107. "cellPadding": "0",
  108. "cellSpacing": "0"
  109. }).inject(this.viewNode);
  110. this.viewLine = new Element("tr", {"styles": this.css.viewTitleLineNode}).inject(this.viewTable);
  111. if (this.json.select!="no"){
  112. this.viewSelectCell = new Element("td", {
  113. "styles": this.css.viewTitleCellNode
  114. }).inject(this.viewLine);
  115. this.viewSelectCell.setStyle("width", "10px");
  116. }
  117. MWF.Actions.get("x_query_assemble_designer").getView(this.json["queryView"].id, function(json){
  118. var viewData = JSON.decode(json.data.data);
  119. this.viewData = viewData;
  120. if( this.json.actionbar === "show" ){
  121. this.actionbarList = [];
  122. this._showActionbar();
  123. }
  124. var columnList = viewData.selectEntryList || viewData.selectList;
  125. columnList.each(function(column){
  126. if (!column.hideColumn){
  127. var viewCell = new Element("td", {
  128. "styles": this.css.viewTitleCellNode,
  129. "text": column.displayName
  130. }).inject(this.viewLine);
  131. }
  132. }.bind(this));
  133. if (callback) callback();
  134. }.bind(this));
  135. this._setViewNodeTitle();
  136. },
  137. _setViewNodeTitle: function(){
  138. if (this.viewTable){
  139. if (this.json["isTitle"] == "no"){
  140. this.viewTable.setStyle("opacity", 0.5);
  141. }else{
  142. this.viewTable.setStyle("opacity", 1);
  143. }
  144. }
  145. },
  146. _setEditStyle: function(name, input, oldValue){
  147. if (name=="view" || name=="processView" || name=="CMSView" || name=="queryView"){
  148. if (this.json[name]!=oldValue) this._checkView();
  149. }
  150. if (name=="select") this._checkSelect();
  151. if (name=="isTitle") this._checkTitle();
  152. if (name=="titleStyles") this._setTitleStyles();
  153. if (name=="name"){
  154. var title = this.json.name || this.json.id;
  155. var text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  156. this.treeNode.setText("<"+text+"> "+title);
  157. }
  158. if (name=="id"){
  159. if (!this.json.name){
  160. var text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  161. this.treeNode.setText("<"+text+"> "+this.json.id);
  162. }
  163. this.treeNode.setTitle(this.json.id);
  164. this.node.set("id", this.json.id);
  165. }
  166. if(name=="actionbar"){
  167. this.json.actionbar === "show" ? this._showActionbar() : this._hideActionbar();
  168. }
  169. this._setEditStyle_custom(name, input, oldValue);
  170. },
  171. _setTitleStyles: function(){
  172. if (this.viewLine){
  173. this.viewLine.getElements("td").each(function(td){
  174. td.clearStyles();
  175. td.setStyles(this.css.viewTitleCellNode);
  176. if (this.json.titleStyles) td.setStyles(this.json.titleStyles);
  177. }.bind(this));
  178. if (this.viewSelectCell) this.viewSelectCell.setStyle("width", "10px");
  179. this._checkSelect();
  180. this._checkTitle();
  181. }
  182. },
  183. _checkView: function(callback){
  184. if (this.json["queryView"] && this.json["queryView"]!="none"){
  185. this.iconNode.setStyle("display", "none");
  186. if (this.viewNode) this.viewNode.destroy();
  187. this.viewNode = null;
  188. this._createViewNode(function(){
  189. if (callback) callback();
  190. }.bind(this));
  191. }else{
  192. this.iconNode.setStyle("display", "block");
  193. if (this.viewNode) this.viewNode.destroy();
  194. this.node.setStyles(this.css.moduleNode);
  195. if (callback) callback();
  196. }
  197. },
  198. _checkSelect: function(){
  199. if (this.json["select"]!="no"){
  200. if (!this.viewSelectCell){
  201. this.viewSelectCell = new Element("td", {
  202. "styles": this.css.viewTitleCellNode
  203. }).inject(this.viewLine, "top");
  204. this.viewSelectCell.setStyle("width", "10px");
  205. }
  206. if (this.json["select"]=="single"){
  207. this.viewSelectCell.setStyle("background", "url(../x_component_process_FormDesigner/Module/View/default/icon/single.png) center center no-repeat");
  208. }else{
  209. this.viewSelectCell.setStyle("background", "url(../x_component_process_FormDesigner/Module/View/default/icon/multi.png) center center no-repeat");
  210. }
  211. }else{
  212. if (this.viewSelectCell){
  213. this.viewSelectCell.destroy();
  214. this.viewSelectCell = null;
  215. }
  216. }
  217. },
  218. _checkTitle: function(){
  219. if (!this.json["isTitle"]) this.json["isTitle"] = "yes";
  220. if (this.viewNode) this._setViewNodeTitle();
  221. },
  222. _hideActionbar : function(){
  223. if(this.actionbarNode)this.actionbarNode.hide();
  224. },
  225. _showActionbar : function(){
  226. if( this.actionbarLoading )return;
  227. if( !this.actionbarNode )return;
  228. this.actionbarLoading = true;
  229. MWF.require("MWF.widget.Toolbar", null, false);
  230. this.actionbarNode.show();
  231. if( !this.viewData.actionbarList )this.viewData.actionbarList = [];
  232. if( !this.actionbarList || this.actionbarList.length == 0 ){
  233. this.actionbarNode.empty();
  234. if( this.viewData.actionbarList.length ){
  235. if( !this.actionbarList )this.actionbarList = [];
  236. this.viewData.actionbarList.each( function(json){
  237. var toolbarWidget = new MWF.widget.Toolbar(this.actionbarNode, {"style": json.style}, this);
  238. if (json.actionStyles)toolbarWidget.css = json.actionStyles;
  239. if( !json.hideSystemTools )this.setToolbars( json.defaultTools, this.actionbarNode, json );
  240. this.setCustomToolbars( json.tools, this.actionbarNode, json );
  241. toolbarWidget.load();
  242. this.actionbarList.push( toolbarWidget );
  243. this.actionbarLoading = false;
  244. }.bind(this));
  245. }else{
  246. this.actionbarLoading = false;
  247. }
  248. }else{
  249. this.actionbarLoading = false;
  250. }
  251. },
  252. setToolbars: function(tools, node, json){
  253. var style = "default";
  254. tools.each(function(tool){
  255. var actionNode = new Element("div", {
  256. "MWFnodetype": tool.type,
  257. "MWFButtonImage": this.imagePath_default+""+style+"/actionbar/"+tool.img,
  258. "title": tool.title,
  259. "MWFButtonAction": tool.action,
  260. "MWFButtonText": tool.text
  261. }).inject(node);
  262. if( this.json.iconOverStyle ){
  263. actionNode.set("MWFButtonImageOver" , this.imagePath_default+""+ style+"/actionbar/"+json.iconOverStyle+"/"+tool.img );
  264. }
  265. // this.systemTools.push(actionNode);
  266. // if (tool.sub){
  267. // var subNode = node.getLast();
  268. // this.setToolbars(tool.sub, subNode);
  269. // }
  270. }.bind(this));
  271. },
  272. setCustomToolbars: function(tools, node, json){
  273. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  274. var path = "";
  275. if( json.customIconStyle ){
  276. path = json.customIconStyle+ "/";
  277. }
  278. var customImageStyle = "default";
  279. tools.each(function(tool){
  280. var actionNode = new Element("div", {
  281. "MWFnodetype": tool.type,
  282. "MWFButtonImage": this.imagePath_custom+""+customImageStyle +"/custom/"+path+tool.img,
  283. "title": tool.title,
  284. "MWFButtonAction": tool.action,
  285. "MWFButtonText": tool.text
  286. }).inject(node);
  287. if( this.json.customIconOverStyle ){
  288. actionNode.set("MWFButtonImageOver" , this.imagePath_custom+""+customImageStyle +"/custom/"+json.customIconOverStyle+ "/" +tool.img );
  289. }
  290. // this.customTools.push(actionNode);
  291. // if (tool.sub){
  292. // var subNode = node.getLast();
  293. // this.setCustomToolbars(tool.sub, subNode);
  294. // }
  295. }.bind(this));
  296. }
  297. });