Main.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. MWF.require("MWF.widget.JsonTemplate", null, false);
  2. MWF.xApplication.Selector.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "Selector",
  8. "icon": "icon.png",
  9. "width": "800",
  10. "height": "700",
  11. "isResize": false,
  12. "isMax": false,
  13. "title": ""
  14. },
  15. onQueryLoad: function(){
  16. this.setOptions({"title": MWF.xApplication.Selector.LP.title});
  17. this.lp = MWF.xApplication.Selector.LP;
  18. },
  19. loadApplication: function(callback){
  20. //this.content
  21. this.node = new Element("div", {"styles": {
  22. "padding": "20px",
  23. "text-align": "center"
  24. }}).inject(this.content);
  25. this.optionsNode = new Element("textarea", {"styles": {
  26. "width": "90%",
  27. "display": "block",
  28. "height": "160px"
  29. }}).inject(this.node);
  30. var buttonArea = new Element("div", {"styles": {
  31. "height": "30px",
  32. "margin-top": "10px",
  33. "text-align": "left"
  34. }}).inject(this.node);
  35. this.buttonNode = new Element("button", {"text": "select", "styles": {
  36. "width": "150px",
  37. "height": "30px"
  38. }}).inject(buttonArea);
  39. this.buttonMobileNode = new Element("button", {"text": "selectMobile", "styles": {
  40. "width": "150px",
  41. "height": "30px"
  42. }}).inject(buttonArea);
  43. this.resaultNode = new Element("div", {"styles": {
  44. "height": "410px",
  45. "overflow": "auto",
  46. "margin-top": "10px",
  47. "background-color": "#ffffff",
  48. "border": "1px solid #666666",
  49. "display": "block"
  50. }}).inject(this.node);
  51. var str = "{\n\t\"count\": 0, \n\t\"type\": \"identity\", \n\t\"title\": \"Select Person\",\n\t\"groups\": [], \n\t\"roles\": [],\n\t\"dutys\" : [], \n\t\"units\": [],\n\t\"unitType\": \"\",\n\t\"values\": []\n}"
  52. this.optionsNode.set("value", str);
  53. this.buttonNode.addEvent("click", function(){
  54. this.select();
  55. }.bind(this));
  56. this.buttonMobileNode.addEvent("click", function(){
  57. this.selectMobile();
  58. }.bind(this));
  59. },
  60. select: function(callback){
  61. var str = this.optionsNode.get("value");
  62. var options = JSON.decode(str);
  63. if (!options.values.length) options.values = this.values || [];
  64. options.onComplete = function(items){
  65. var json = [];
  66. this.values = [];
  67. items.each(function(item){
  68. this.values.push(item.data.distinguishedName || item.data.name);
  69. json.push(item.data);
  70. }.bind(this));
  71. this.resaultNode.empty();
  72. MWF.require("MWF.widget.JsonParse", function(){
  73. var jsonNode = new MWF.widget.JsonParse(json, this.resaultNode, null);
  74. jsonNode.load();
  75. }.bind(this));
  76. if (callback) callback();
  77. }.bind(this);
  78. options.onCancel = function(){
  79. if (callback) callback();
  80. };
  81. MWF.xDesktop.requireApp("Selector", "package", function(){
  82. new MWF.O2Selector(this.content, options)
  83. }.bind(this));
  84. },
  85. selectMobile: function(){
  86. if (!layout.mobile) layout.mobile = true;
  87. this.select(function(){layout.mobile = false;}.bind(this));
  88. }
  89. });