Label.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. if (this.json.prefixIcon || this.json.suffixIcon){
  119. if (!this.textNode){
  120. var text = this.node.get("text");
  121. this.node.empty();
  122. this.textNode = new Element("div", {"styles": {
  123. "margin-left": (this.json.prefixIcon) ? "20px" : "0px",
  124. "margin-right": (this.json.suffixIcon) ? "20px" : "0px",
  125. "overflow": "hidden"
  126. }, "text": text}).inject(this.node);
  127. if (this.json.prefixIcon){
  128. this.prefixNode = new Element("div", {"styles": {
  129. "float": "left",
  130. "width": "20px",
  131. "height": ""+this.node.getSize().y+"px",
  132. "background": "url("+this.json.prefixIcon+") center center no-repeat"
  133. }}).inject(this.textNode, "before");
  134. }
  135. if (this.json.suffixIcon){
  136. this.suffixNode = new Element("div", {"styles": {
  137. "float": "right",
  138. "width": "20px",
  139. "height": ""+this.node.getSize().y+"px",
  140. "background": "url("+this.json.suffixIcon+") center center no-repeat"
  141. }}).inject(this.textNode, "before");
  142. }
  143. }else{
  144. if (this.json.prefixIcon){
  145. if (!this.prefixNode){
  146. this.prefixNode = new Element("div", {"styles": {
  147. "float": "left",
  148. "width": "20px",
  149. "height": ""+this.node.getSize().y+"px",
  150. "background": "url("+this.json.prefixIcon+") center center no-repeat"
  151. }}).inject(this.textNode, "before");
  152. }else{
  153. this.prefixNode.setStyle("background", "url("+this.json.prefixIcon+") center center no-repeat");
  154. }
  155. }else{
  156. if (this.prefixNode){
  157. this.prefixNode.destroy();
  158. this.prefixNode = null;
  159. }
  160. }
  161. if (this.json.suffixIcon){
  162. if (!this.suffixNode){
  163. this.suffixNode = new Element("div", {"styles": {
  164. "float": "right",
  165. "width": "20px",
  166. "height": ""+this.node.getSize().y+"px",
  167. "background": "url("+this.json.suffixIcon+") center center no-repeat"
  168. }}).inject(this.textNode, "before");
  169. }else{
  170. this.suffixNode.setStyle("background", "url("+this.json.suffixIcon+") center center no-repeat");
  171. }
  172. }else{
  173. if (this.suffixNode){
  174. this.suffixNode.destroy();
  175. this.suffixNode = null;
  176. }
  177. }
  178. }
  179. }else{
  180. //var text = this.textNode.get("text");
  181. this.node.empty();
  182. if (this.json.valueType=="text"){
  183. this.node.set("text", this.json.text || "(T)Text");
  184. }else{
  185. this.node.set("text", this.json.text || "(C)Text");
  186. }
  187. this.prefixNode = null;
  188. this.suffixNode = null;
  189. }
  190. },
  191. _preprocessingModuleData: function(){
  192. this.node.clearStyles();
  193. this.json.recoveryStyles = Object.clone(this.json.styles);
  194. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  195. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  196. //需要运行时处理
  197. }else{
  198. this.node.setStyle(key, value);
  199. delete this.json.styles[key];
  200. }
  201. }.bind(this));
  202. if (this.json.valueType==="text"){
  203. if (!this.json.text){
  204. if (this.textNode){
  205. this.textNode.set("text", "");
  206. }else{
  207. this.node.set("text", "");
  208. }
  209. }
  210. }else{
  211. this.node.set("text", "");
  212. }
  213. this.json.preprocessing = "y";
  214. },
  215. _recoveryModuleData: function(){
  216. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  217. this.json.recoveryStyles = null;
  218. this._setEditStyle_custom("text");
  219. }
  220. });