Main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. debugger;
  98. var values = {};
  99. for( var key in itemsObject ){
  100. var item = itemsObject[key];
  101. var value = [];
  102. item.each( function(it){
  103. value.push({
  104. id : it.id,
  105. name: it.name
  106. })
  107. })
  108. values[ key + "Value" ] = value;
  109. }
  110. }.bind(this),
  111. "onCancel": function () {
  112. }.bind(this),
  113. "onLoad": function () {
  114. // if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
  115. }.bind(this),
  116. "onClose": function () {
  117. // var v = this.node.getFirst().get("value");
  118. // if (!v || !v.length) if (this.descriptionNode) this.descriptionNode.setStyle("display", "block");
  119. }.bind(this)
  120. };
  121. //if (layout.mobile) options.style = "mobile";
  122. //var selector = new MWF.OrgSelector(this.form.node.getParent(), options);
  123. var selector = new MWF.O2Selector(this.content, options);
  124. }.bind(this)}}).inject(this.sel1Content);
  125. },
  126. createButton1: function(text, type){
  127. var button = new Element("input", {
  128. "type": "button",
  129. "value": text,
  130. "events": {
  131. "click": function(e){
  132. if (this.currentButton!= e.target){
  133. this.textareaResault1.set("value", "");
  134. this.textareaResault2.set("value", "");
  135. this.selecteds = [];
  136. this.currentButton = e.target;
  137. }else{
  138. var v = this.textareaResault1.get("value");
  139. if (v){this.selecteds = v.split("\n");}else{this.selecteds = [];}
  140. }
  141. var options = {
  142. "type": type,
  143. "values": this.selecteds,
  144. "onComplete": function(items){
  145. var ids = [];
  146. var names = [];
  147. items.each(function(item){
  148. ids.push(item.data.id);
  149. names.push(item.data.name);
  150. });
  151. this.selecteds = ids;
  152. this.textareaResault1.set("value", this.selecteds.join("\n"));
  153. this.textareaResault2.set("value", names.join("\n"));
  154. }.bind(this)
  155. };
  156. //try {
  157. var jsonStr = this.textarea1.get("value");
  158. var json = JSON.decode(jsonStr);
  159. Object.each(json, function(v, k){
  160. options[k] = v;
  161. });
  162. var selector = new MWF.O2Selector(this.content, options);
  163. // selector.load();
  164. // }catch(e){
  165. // this.notice("json参数有错误:"+ e.message, "error");
  166. //}
  167. }.bind(this)
  168. }
  169. }).inject(this.sel1Content);
  170. },
  171. createButton2: function(text, type){
  172. var button = new Element("input", {
  173. "type": "button",
  174. "value": text,
  175. "events": {
  176. "click": function(e){
  177. if (this.currentButton!= e.target){
  178. this.textareaResault1.set("value", "");
  179. this.textareaResault2.set("value", "");
  180. this.selecteds = [];
  181. this.currentButton = e.target;
  182. }else{
  183. var v = this.textareaResault1.get("value");
  184. if (v){this.selecteds = v.split("\n");}else{this.selecteds = [];}
  185. }
  186. var options = {
  187. "type": type,
  188. "values": this.selecteds,
  189. "onComplete": function(items){
  190. var ids = [];
  191. var names = [];
  192. items.each(function(item){
  193. ids.push(item.data.id);
  194. names.push(item.data.name);
  195. });
  196. this.selecteds = ids;
  197. this.textareaResault1.set("value", this.selecteds.join("\n"));
  198. this.textareaResault2.set("value", names.join("\n"));
  199. }.bind(this)
  200. };
  201. try {
  202. var jsonStr = this.textarea1.get("value");
  203. var json = JSON.decode(jsonStr);
  204. Object.each(json, function(v, k){
  205. options[k] = v;
  206. });
  207. var selector = new MWF.O2Selector(this.content, options);
  208. // selector.load();
  209. }catch(e){
  210. this.notice("json参数有错误:"+ e.message, "error");
  211. }
  212. }.bind(this)
  213. }
  214. }).inject(this.sel1Content);
  215. },
  216. setContentHeight: function(node){
  217. var size = this.node.getSize();
  218. var tabSize = this.tab.tabNodeContainer.getSize();
  219. var height = size.y-tabSize.y-20;
  220. this.sel1Content.setStyle("height", height);
  221. this.sel2Content.setStyle("height", height);
  222. }
  223. });