PropertyConfig.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Created by Jacky.gao on 2016/9/20.
  3. */
  4. export default class PropertyConfig{
  5. constructor(container){
  6. this.container=container;
  7. this.properties=[];
  8. this.init();
  9. }
  10. init(){
  11. var self=this;
  12. this.namePropertyContainer=$("<span>名称:</span>");
  13. this.namePropertyContainer.css({
  14. "padding":"10px"
  15. });
  16. this.container.append(this.namePropertyContainer);
  17. this.nameEditor=$("<input type='text' class='form-control' style='display: inline-block;width:160px;height:28px'>");
  18. this.namePropertyContainer.append(this.nameEditor);
  19. this.nameEditor.change(function () {
  20. self.name=$(this).val();
  21. window._setDirty();
  22. });
  23. this.propertyContainer=$("<span>");
  24. this.propertyContainer.css({
  25. "padding":"10px"
  26. });
  27. var addProp=$("<button type='button' class='rule-add-property btn btn-link'>添加属性</button>");
  28. this.container.append(addProp);
  29. this.container.append(this.propertyContainer);
  30. var onClick=function(menuItem){
  31. var prop=new urule.RuleProperty(self,menuItem.name,menuItem.defaultValue,menuItem.editorType);
  32. self.addProperty(prop);
  33. };
  34. self.menu=new URule.menu.Menu({
  35. menuItems:[{
  36. label:"优先级",
  37. name:"salience",
  38. defaultValue:"10",
  39. editorType:1,
  40. onClick:onClick
  41. },{
  42. label:"生效日期",
  43. name:"effective-date",
  44. defaultValue:"",
  45. editorType:2,
  46. onClick:onClick
  47. },{
  48. label:"失效日期",
  49. name:"expires-date",
  50. defaultValue:"",
  51. editorType:2,
  52. onClick:onClick
  53. },{
  54. label:"是否启用",
  55. name:"enabled",
  56. defaultValue:true,
  57. editorType:3,
  58. onClick:onClick
  59. },{
  60. label:"允许调试信息输出",
  61. name:"debug",
  62. defaultValue:true,
  63. editorType:3,
  64. onClick:onClick
  65. }]
  66. });
  67. addProp.click(function(e){
  68. self.menu.show(e);
  69. });
  70. }
  71. initData(data){
  72. this.name=data.name;
  73. this.nameEditor.val(data.name);
  74. var salience=data["salience"];
  75. if(salience){
  76. this.addProperty(new urule.RuleProperty(this,"salience",salience,1));
  77. }
  78. var loop=data["loop"];
  79. if(loop!=null){
  80. this.addProperty(new urule.RuleProperty(this,"loop",loop,3));
  81. }
  82. var debug=data["debug"];
  83. if(debug!=null){
  84. this.addProperty(new urule.RuleProperty(this,"debug",debug,3));
  85. }
  86. var effectiveDate=data["effectiveDate"];
  87. if(effectiveDate){
  88. this.addProperty(new urule.RuleProperty(this,"effective-date",effectiveDate,2));
  89. }
  90. var expiresDate=data["expiresDate"];
  91. if(expiresDate){
  92. this.addProperty(new urule.RuleProperty(this,"expires-date",expiresDate,2));
  93. }
  94. var enabled=data["enabled"];
  95. if(enabled!=null){
  96. this.addProperty(new urule.RuleProperty(this,"enabled",enabled,3));
  97. }
  98. }
  99. addProperty(property){
  100. this.propertyContainer.append(property.getContainer());
  101. this.properties.push(property);
  102. window._setDirty();
  103. }
  104. toXml(){
  105. if(!this.name || this.name.length<1){
  106. throw "评分卡名称不能为空";
  107. }
  108. let xml=" name=\""+this.name+"\"";
  109. for(var i=0;i<this.properties.length;i++){
  110. var prop=this.properties[i];
  111. xml+=" "+prop.toXml();
  112. }
  113. return xml;
  114. }
  115. }