Main.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. MWF.xApplication.SelecterTest.options.multitask = true;
  2. MWF.xApplication.SelecterTest.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "SelecterTest",
  8. "icon": "icon.png",
  9. "width": "1200",
  10. "height": "600",
  11. "isResize": true,
  12. "isMax": true,
  13. "title": MWF.xApplication.SelecterTest.LP.title
  14. },
  15. onQueryLoad: function(){
  16. this.lp = MWF.xApplication.SelecterTest.LP;
  17. },
  18. loadApplication: function(callback){
  19. this.createNode();
  20. this.sel1Content = new Element("div", {"styles":{"padding": "10px"}}).inject(this.node);
  21. this.sel2Content = new Element("div", {"styles":{"padding": "10px"}}).inject(this.node);
  22. MWF.require("MWF.widget.Tab", function(){
  23. this.tab = new MWF.widget.Tab(this.node, {"style": "processlayout"});
  24. this.tab.load();
  25. this.page1 = this.tab.addTab(this.sel1Content, "组织选人", false);
  26. this.page2 = this.tab.addTab(this.sel2Content, "缓存选人", false);
  27. this.page1.showIm();
  28. this.setContentHeight();
  29. this.addEvent("resize", function(){this.setContentHeight();}.bind(this));
  30. }.bind(this));
  31. this.loadApplicationContent();
  32. },
  33. createNode: function(){
  34. this.content.setStyle("overflow", "hidden");
  35. this.node = new Element("div", {
  36. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  37. }).inject(this.content);
  38. },
  39. loadApplicationContent: function(){
  40. MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  41. var textareaStyle = {
  42. "height": "120px",
  43. "width": "360px"
  44. };
  45. this.textarea1 = new Element("textarea", {
  46. "value": "{\n\t\"title\": \"Select Identity\", \n\t\"count\": 0, \n\t\"groups\": [], \n\t\"roles\": [], \n\t\"companys\": [], \n\t\"departments\": []\n}",
  47. "styles": textareaStyle
  48. }).inject(this.sel1Content);
  49. this.selecteds = [];
  50. this.textareaResault1 = new Element("textarea", {
  51. "value": "",
  52. "styles": textareaStyle
  53. }).inject(this.sel1Content);
  54. this.textareaResault2 = new Element("textarea", {
  55. "value": "",
  56. "styles": textareaStyle
  57. }).inject(this.sel1Content);
  58. this.selecteds = [];
  59. new Element("p").inject(this.sel1Content);
  60. //new Element("br").inject(this.sel1Content);
  61. this.createButton1("选择人员", "Person");
  62. this.createButton1("选择群组", "Group");
  63. this.createButton1("选择角色", "Role");
  64. this.createButton1("选择身份", "Identity");
  65. this.createButton1("选择部门", "Department");
  66. this.createButton1("选择公司", "Company");
  67. new Element("p").inject(this.sel1Content);
  68. //this.createButton2("选择人员", "Person");
  69. //this.createButton2("选择群组", "Group");
  70. //this.createButton2("选择角色", "Role");
  71. //this.createButton2("选择身份", "Identity");
  72. //this.createButton2("选择部门", "Department");
  73. //this.createButton2("选择公司", "Company");
  74. this.currentButton = null;
  75. },
  76. createButton1: function(text, type){
  77. var button = new Element("input", {
  78. "type": "button",
  79. "value": text,
  80. "events": {
  81. "click": function(e){
  82. if (this.currentButton!= e.target){
  83. this.textareaResault1.set("value", "");
  84. this.textareaResault2.set("value", "");
  85. this.selecteds = [];
  86. this.currentButton = e.target;
  87. }else{
  88. var v = this.textareaResault1.get("value");
  89. if (v){this.selecteds = v.split("\n");}else{this.selecteds = [];}
  90. }
  91. var options = {
  92. "type": type,
  93. "values": this.selecteds,
  94. "onComplete": function(items){
  95. var ids = [];
  96. var names = [];
  97. items.each(function(item){
  98. ids.push(item.data.id);
  99. names.push(item.data.name);
  100. });
  101. this.selecteds = ids;
  102. this.textareaResault1.set("value", this.selecteds.join("\n"));
  103. this.textareaResault2.set("value", names.join("\n"));
  104. }.bind(this)
  105. };
  106. try {
  107. var jsonStr = this.textarea1.get("value");
  108. var json = JSON.decode(jsonStr);
  109. Object.each(json, function(v, k){
  110. options[k] = v;
  111. });
  112. var selector = new MWF.Selector(this.content, options);
  113. // selector.load();
  114. }catch(e){
  115. this.notice("json参数有错误:"+ e.message, "error");
  116. }
  117. }.bind(this)
  118. }
  119. }).inject(this.sel1Content);
  120. },
  121. createButton2: function(text, type){
  122. var button = new Element("input", {
  123. "type": "button",
  124. "value": text,
  125. "events": {
  126. "click": function(e){
  127. if (this.currentButton!= e.target){
  128. this.textareaResault1.set("value", "");
  129. this.textareaResault2.set("value", "");
  130. this.selecteds = [];
  131. this.currentButton = e.target;
  132. }else{
  133. var v = this.textareaResault1.get("value");
  134. if (v){this.selecteds = v.split("\n");}else{this.selecteds = [];}
  135. }
  136. var options = {
  137. "type": type,
  138. "values": this.selecteds,
  139. "onComplete": function(items){
  140. var ids = [];
  141. var names = [];
  142. items.each(function(item){
  143. ids.push(item.data.id);
  144. names.push(item.data.name);
  145. });
  146. this.selecteds = ids;
  147. this.textareaResault1.set("value", this.selecteds.join("\n"));
  148. this.textareaResault2.set("value", names.join("\n"));
  149. }.bind(this)
  150. };
  151. try {
  152. var jsonStr = this.textarea1.get("value");
  153. var json = JSON.decode(jsonStr);
  154. Object.each(json, function(v, k){
  155. options[k] = v;
  156. });
  157. var selector = new MWF.Selector(this.content, options);
  158. // selector.load();
  159. }catch(e){
  160. this.notice("json参数有错误:"+ e.message, "error");
  161. }
  162. }.bind(this)
  163. }
  164. }).inject(this.sel1Content);
  165. },
  166. setContentHeight: function(node){
  167. var size = this.node.getSize();
  168. var tabSize = this.tab.tabNodeContainer.getSize();
  169. var height = size.y-tabSize.y-20;
  170. this.sel1Content.setStyle("height", height);
  171. this.sel2Content.setStyle("height", height);
  172. }
  173. });