Main.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. MWF.xApplication.SelecterTest.options.multitask = true;
  2. MWF.xDesktop.requireApp("Selector", "package", null, false);
  3. MWF.xApplication.SelecterTest.Main = new Class({
  4. Extends: MWF.xApplication.Common.Main,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "name": "SelecterTest",
  9. "icon": "icon.png",
  10. "width": "1200",
  11. "height": "600",
  12. "isResize": true,
  13. "isMax": true,
  14. "title": MWF.xApplication.SelecterTest.LP.title
  15. },
  16. onQueryLoad: function(){
  17. this.lp = MWF.xApplication.SelecterTest.LP;
  18. },
  19. loadApplication: function(callback){
  20. this.createNode();
  21. this.sel1Content = new Element("div", {"styles":{"padding": "10px"}}).inject(this.node);
  22. this.sel2Content = new Element("div", {"styles":{"padding": "10px"}}).inject(this.node);
  23. MWF.require("MWF.widget.Tab", function(){
  24. this.tab = new MWF.widget.Tab(this.node, {"style": "processlayout"});
  25. this.tab.load();
  26. this.page1 = this.tab.addTab(this.sel1Content, "组织选人", false);
  27. this.page2 = this.tab.addTab(this.sel2Content, "缓存选人", false);
  28. this.page1.showIm();
  29. this.setContentHeight();
  30. this.addEvent("resize", function(){this.setContentHeight();}.bind(this));
  31. }.bind(this));
  32. this.loadApplicationContent();
  33. },
  34. createNode: function(){
  35. this.content.setStyle("overflow", "hidden");
  36. this.node = new Element("div", {
  37. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  38. }).inject(this.content);
  39. },
  40. loadApplicationContent: function(){
  41. //MWF.xDesktop.requireApp("Organization", "Selector.package", null, false);
  42. var textareaStyle = {
  43. "height": "120px",
  44. "width": "360px"
  45. };
  46. this.textarea1 = new Element("textarea", {
  47. "value": "{\n\t\"title\": \"Select Identity\", \n\t\"count\": 0, \n\t\"groups\": [], \n\t\"roles\": [], \n\t\"companys\": [], \n\t\"departments\": []\n}",
  48. "styles": textareaStyle
  49. }).inject(this.sel1Content);
  50. this.selecteds = [];
  51. this.textareaResault1 = new Element("textarea", {
  52. "value": "",
  53. "styles": textareaStyle
  54. }).inject(this.sel1Content);
  55. this.textareaResault2 = new Element("textarea", {
  56. "value": "",
  57. "styles": textareaStyle
  58. }).inject(this.sel1Content);
  59. this.selecteds = [];
  60. new Element("p").inject(this.sel1Content);
  61. //new Element("br").inject(this.sel1Content);
  62. this.createButton1("选择人员", "Person");
  63. this.createButton1("选择群组", "Group");
  64. this.createButton1("选择角色", "Role");
  65. this.createButton1("选择身份", "Identity");
  66. this.createButton1("选择部门", "Department");
  67. this.createButton1("选择公司", "Company");
  68. this.createButton3("复合选择")
  69. new Element("p").inject(this.sel1Content);
  70. //this.createButton2("选择人员", "Person");
  71. //this.createButton2("选择群组", "Group");
  72. //this.createButton2("选择角色", "Role");
  73. //this.createButton2("选择身份", "Identity");
  74. //this.createButton2("选择部门", "Department");
  75. //this.createButton2("选择公司", "Company");
  76. this.currentButton = null;
  77. },
  78. createButton3: function(text){
  79. var button = new Element("input", {
  80. "type": "button",
  81. "value": text,
  82. "events": {
  83. "click": function(e) {
  84. var options = {
  85. "types": ["company","group","department", "identity","person"],
  86. "names": [],
  87. "count": 0,
  88. "departments": ["公司领导","工程部"],
  89. "groups" : ["工作组"],
  90. "companys": ["兰德纵横"],
  91. "personNames" : ["王艳琴"],
  92. "identityNames": ["李杰(人力资源部)","林玲(人力资源部)"],
  93. "departmentNames": ["公司领导","工程部"],
  94. "groupNames" : ["工作组"],
  95. "companyValues": ["2cd4ef06-6105-4c85-b0d9-9e9aa806558d"],
  96. "onComplete": function (items, itemsObject) {
  97. var values = {};
  98. for( var key in itemsObject ){
  99. var item = itemsObject[key];
  100. var value = [];
  101. item.each( function(it){
  102. value.push({
  103. id : it.id,
  104. name: it.name
  105. })
  106. })
  107. values[ key + "Value" ] = value;
  108. }
  109. }.bind(this),
  110. "onCancel": function () {
  111. }.bind(this),
  112. "onLoad": function () {
  113. // if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  114. }.bind(this),
  115. "onClose": function () {
  116. // var v = this.node.getFirst().get("value");
  117. // if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  118. }.bind(this)
  119. };
  120. //if (layout.mobile) options.style = "mobile";
  121. //var selector = new MWF.OrgSelector(this.form.node.getParent(), options);
  122. var selector = new MWF.O2Selector(this.content, options);
  123. }.bind(this)}}).inject(this.sel1Content);
  124. },
  125. createButton1: function(text, type){
  126. var button = new Element("input", {
  127. "type": "button",
  128. "value": text,
  129. "events": {
  130. "click": function(e){
  131. if (this.currentButton!= e.target){
  132. this.textareaResault1.set("value", "");
  133. this.textareaResault2.set("value", "");
  134. this.selecteds = [];
  135. this.currentButton = e.target;
  136. }else{
  137. var v = this.textareaResault1.get("value");
  138. if (v){this.selecteds = v.split("\n");}else{this.selecteds = [];}
  139. }
  140. var options = {
  141. "type": type,
  142. "values": this.selecteds,
  143. "onComplete": function(items){
  144. var ids = [];
  145. var names = [];
  146. items.each(function(item){
  147. ids.push(item.data.id);
  148. names.push(item.data.name);
  149. });
  150. this.selecteds = ids;
  151. this.textareaResault1.set("value", this.selecteds.join("\n"));
  152. this.textareaResault2.set("value", names.join("\n"));
  153. }.bind(this)
  154. };
  155. //try {
  156. var jsonStr = this.textarea1.get("value");
  157. var json = JSON.decode(jsonStr);
  158. Object.each(json, function(v, k){
  159. options[k] = v;
  160. });
  161. var selector = new MWF.O2Selector(this.content, options);
  162. // selector.load();
  163. // }catch(e){
  164. // this.notice("json参数有错误:"+ e.message, "error");
  165. //}
  166. }.bind(this)
  167. }
  168. }).inject(this.sel1Content);
  169. },
  170. createButton2: function(text, type){
  171. var button = new Element("input", {
  172. "type": "button",
  173. "value": text,
  174. "events": {
  175. "click": function(e){
  176. if (this.currentButton!= e.target){
  177. this.textareaResault1.set("value", "");
  178. this.textareaResault2.set("value", "");
  179. this.selecteds = [];
  180. this.currentButton = e.target;
  181. }else{
  182. var v = this.textareaResault1.get("value");
  183. if (v){this.selecteds = v.split("\n");}else{this.selecteds = [];}
  184. }
  185. var options = {
  186. "type": type,
  187. "values": this.selecteds,
  188. "onComplete": function(items){
  189. var ids = [];
  190. var names = [];
  191. items.each(function(item){
  192. ids.push(item.data.id);
  193. names.push(item.data.name);
  194. });
  195. this.selecteds = ids;
  196. this.textareaResault1.set("value", this.selecteds.join("\n"));
  197. this.textareaResault2.set("value", names.join("\n"));
  198. }.bind(this)
  199. };
  200. try {
  201. var jsonStr = this.textarea1.get("value");
  202. var json = JSON.decode(jsonStr);
  203. Object.each(json, function(v, k){
  204. options[k] = v;
  205. });
  206. var selector = new MWF.O2Selector(this.content, options);
  207. // selector.load();
  208. }catch(e){
  209. this.notice("json参数有错误:"+ e.message, "error");
  210. }
  211. }.bind(this)
  212. }
  213. }).inject(this.sel1Content);
  214. },
  215. setContentHeight: function(node){
  216. var size = this.node.getSize();
  217. var tabSize = this.tab.tabNodeContainer.getSize();
  218. var height = size.y-tabSize.y-20;
  219. this.sel1Content.setStyle("height", height);
  220. this.sel2Content.setStyle("height", height);
  221. }
  222. });