Label.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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.Label = MWF.FCLabel = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_process_FormDesigner/Module/Label/label.html"
  9. },
  10. initialize: function(form, options){
  11. this.setOptions(options);
  12. this.path = "/x_component_process_FormDesigner/Module/Label/";
  13. this.cssPath = "/x_component_process_FormDesigner/Module/Label/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.moduleType = "element";
  16. this.moduleName = "label";
  17. this.form = form;
  18. this.container = null;
  19. this.containerNode = null;
  20. },
  21. clearTemplateStyles: function(styles){
  22. if (this.json.templateType){
  23. if (styles){
  24. if (styles[this.json.templateType]){
  25. if (styles[this.json.templateType].styles) this.removeStyles(styles[this.json.templateType].styles, "styles");
  26. if (styles[this.json.templateType].inputStyles) this.removeStyles(styles[this.json.templateType].inputStyles, "inputStyles");
  27. if (styles[this.json.templateType].properties) this.removeStyles(styles[this.json.templateType].properties, "properties");
  28. }
  29. }
  30. }
  31. },
  32. setTemplateStyles: function(styles){
  33. if (this.json.templateType){
  34. if (styles[this.json.templateType]){
  35. if (styles[this.json.templateType].styles) this.copyStyles(styles[this.json.templateType].styles, "styles");
  36. if (styles[this.json.templateType].properties) this.copyStyles(styles[this.json.templateType].properties, "properties");
  37. }
  38. }
  39. },
  40. _createMoveNode: function(){
  41. this.moveNode = new Element("div", {
  42. "MWFType": "label",
  43. "id": this.json.id,
  44. "styles": this.css.moduleNodeMove,
  45. "text": "(T)Text",
  46. "events": {
  47. "selectstart": function(){
  48. return false;
  49. }
  50. }
  51. }).inject(this.form.container);
  52. },
  53. _setNodeProperty: function(){
  54. if (this.form.moduleList.indexOf(this)==-1) this.form.moduleList.push(this);
  55. if (this.form.moduleNodeList.indexOf(this.node)==-1) this.form.moduleNodeList.push(this.node);
  56. if (this.form.moduleElementNodeList.indexOf(this.node)==-1) this.form.moduleElementNodeList.push(this.node);
  57. this.node.store("module", this);
  58. this.setPrefixOrSuffix();
  59. },
  60. _setEditStyle_custom: function(name, obj, oldValue){
  61. if (name=="valueType" || name=="text"){
  62. if (this.json.valueType=="text"){
  63. if (this.json.text){
  64. if (this.textNode){
  65. this.textNode.set("text", this.json.text);
  66. }else{
  67. this.node.set("text", this.json.text);
  68. }
  69. }else{
  70. if (this.textNode){
  71. this.textNode.set("text", "(T)Text");
  72. }else{
  73. this.node.set("text", "(T)Text");
  74. }
  75. }
  76. }else{
  77. this.node.set("text", "(C)Text");
  78. }
  79. }
  80. if (name=="templateType"){
  81. if (this.form.templateStyles){
  82. var moduleStyles = this.form.templateStyles[this.moduleName];
  83. if (moduleStyles) {
  84. if (oldValue){
  85. if (moduleStyles[oldValue]){
  86. this.removeStyles(moduleStyles[oldValue].styles, "styles");
  87. this.removeStyles(moduleStyles[oldValue].styles, "properties");
  88. }
  89. }
  90. if (moduleStyles[this.json.templateType]){
  91. if (moduleStyles[this.json.templateType].styles) this.copyStyles(moduleStyles[this.json.templateType].styles, "styles");
  92. if (moduleStyles[this.json.templateType].styles) this.copyStyles(moduleStyles[this.json.templateType].properties, "properties");
  93. }
  94. this.setPropertiesOrStyles("styles");
  95. this.setPropertiesOrStyles("properties");
  96. this.reloadMaplist();
  97. }
  98. }
  99. }
  100. if (name=="prefixIcon" || name=="suffixIcon"){
  101. this.setPrefixOrSuffix();
  102. }
  103. if (name=="styles"){
  104. this.resetPrefixOrSuffix();
  105. }
  106. },
  107. resetPrefixOrSuffix: function(){
  108. if (this.prefixNode){
  109. var y = this.textNode.getSize().y;
  110. this.prefixNode.setStyle("height", ""+y+"px");
  111. }
  112. if (this.suffixNode){
  113. var y = this.textNode.getSize().y;
  114. this.suffixNode.setStyle("height", ""+y+"px");
  115. }
  116. },
  117. setPrefixOrSuffix: function(){
  118. debugger;
  119. if (this.json.prefixIcon || this.json.suffixIcon){
  120. if (!this.textNode){
  121. var text = this.node.get("text");
  122. this.node.empty();
  123. this.textNode = new Element("div", {"styles": {
  124. "margin-left": (this.json.prefixIcon) ? "20px" : "0px",
  125. "margin-right": (this.json.suffixIcon) ? "20px" : "0px",
  126. "overflow": "hidden"
  127. }, "text": text}).inject(this.node);
  128. if (this.json.prefixIcon){
  129. this.prefixNode = new Element("div", {"styles": {
  130. "float": "left",
  131. "width": "20px",
  132. "height": ""+this.node.getSize().y+"px",
  133. "background": "url("+this.json.prefixIcon+") center center no-repeat"
  134. }}).inject(this.textNode, "before");
  135. }
  136. if (this.json.suffixIcon){
  137. this.suffixNode = new Element("div", {"styles": {
  138. "float": "right",
  139. "width": "20px",
  140. "height": ""+this.node.getSize().y+"px",
  141. "background": "url("+this.json.suffixIcon+") center center no-repeat"
  142. }}).inject(this.textNode, "before");
  143. }
  144. }else{
  145. if (this.json.prefixIcon){
  146. if (!this.prefixNode){
  147. this.prefixNode = new Element("div", {"styles": {
  148. "float": "left",
  149. "width": "20px",
  150. "height": ""+this.node.getSize().y+"px",
  151. "background": "url("+this.json.prefixIcon+") center center no-repeat"
  152. }}).inject(this.textNode, "before");
  153. }else{
  154. this.prefixNode.setStyle("background", "url("+this.json.prefixIcon+") center center no-repeat");
  155. }
  156. }else{
  157. if (this.prefixNode){
  158. this.prefixNode.destroy();
  159. this.prefixNode = null;
  160. }
  161. }
  162. if (this.json.suffixIcon){
  163. if (!this.suffixNode){
  164. this.suffixNode = new Element("div", {"styles": {
  165. "float": "right",
  166. "width": "20px",
  167. "height": ""+this.node.getSize().y+"px",
  168. "background": "url("+this.json.suffixIcon+") center center no-repeat"
  169. }}).inject(this.textNode, "before");
  170. }else{
  171. this.suffixNode.setStyle("background", "url("+this.json.suffixIcon+") center center no-repeat");
  172. }
  173. }else{
  174. if (this.suffixNode){
  175. this.suffixNode.destroy();
  176. this.suffixNode = null;
  177. }
  178. }
  179. }
  180. }else{
  181. debugger;
  182. //var text = this.textNode.get("text");
  183. this.node.empty();
  184. if (this.json.valueType=="text"){
  185. this.node.set("text", this.json.text || "(T)Text");
  186. }else{
  187. this.node.set("text", this.json.text || "(C)Text");
  188. }
  189. this.prefixNode = null;
  190. this.suffixNode = null;
  191. }
  192. }
  193. });