package.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "lp."+MWF.language, null, false);
  3. //MWF.xDesktop.requireApp("Selector", "Actions.RestActions", null, false);
  4. MWF.O2Selector = new Class({
  5. Implements: [Options],
  6. options: {
  7. "count": 0,
  8. "type": "person",
  9. "title": "Select Person",
  10. "groups": [],
  11. "roles": [],
  12. "units": [],
  13. "unitType": "",
  14. "values": [],
  15. "exclude" : [],
  16. "categoryType": "unit"
  17. },
  18. initialize: function(container, options){
  19. //MWF.xDesktop.requireApp("Selector", "Actions.RestActions", null, false);
  20. this.setOptions(options);
  21. this.container = container;
  22. if( this.options.types && typeOf(this.options.types) === "array" && this.options.types.length > 0 ){
  23. MWF.xDesktop.requireApp("Selector", "MultipleSelector", function() {
  24. this.selector = new MWF.xApplication.Selector.MultipleSelector(this.container, this.options );
  25. this.selector.load();
  26. }.bind(this));
  27. }else{
  28. var type = typeOf(this.options.type) === "string" ? this.options.type.capitalize() : this.options.type;
  29. if (type){
  30. if ((type.toLowerCase()==="unit") && (this.options.unitType)){
  31. MWF.xDesktop.requireApp("Selector", "UnitWithType", function(){
  32. this.selector = new MWF.xApplication.Selector.UnitWithType(this.container, options);
  33. this.selector.load();
  34. }.bind(this));
  35. }else if ((type.toLowerCase()==="identity") && ((this.options.dutys) && this.options.dutys.length) && this.options.categoryType.toLowerCase()==="duty"){
  36. MWF.xDesktop.requireApp("Selector", "IdentityWidthDuty", function(){
  37. this.selector = new MWF.xApplication.Selector.IdentityWidthDuty(this.container, options);
  38. this.selector.load();
  39. }.bind(this));
  40. }else{
  41. MWF.xDesktop.requireApp("Selector", type, function(){
  42. this.selector = new MWF.xApplication.Selector[type](this.container, options);
  43. this.selector.load();
  44. }.bind(this));
  45. }
  46. }
  47. }
  48. }
  49. });
  50. MWF.O2SelectorFilter = new Class({
  51. Implements: [Options],
  52. options: {
  53. "count": 0,
  54. "type": "person",
  55. "title": "Select Person",
  56. "groups": [],
  57. "roles": [],
  58. "units": [],
  59. "unitType": "",
  60. "values": []
  61. },
  62. initialize: function(value, options){
  63. //MWF.xDesktop.requireApp("Selector", "Actions.RestActions", null, false);
  64. this.setOptions(options);
  65. this.value = value;
  66. //var type = this.options.type.capitalize();
  67. if( this.options.types && typeOf(this.options.types) === "array" && this.options.types.length > 0 ){
  68. MWF.xDesktop.requireApp("Selector", "MultipleSelector", function() {
  69. this.selectFilter = new MWF.xApplication.Selector.MultipleSelector.Filter(this.container, this.options );
  70. }.bind(this), false);
  71. }else{
  72. var type = typeOf(this.options.type) === "string" ? this.options.type.capitalize() : this.options.type;
  73. if (type){
  74. if ((type.toLowerCase()==="unit") && (this.options.unitType)){
  75. MWF.xDesktop.requireApp("Selector", "UnitWithType", function(){
  76. this.selector = new MWF.xApplication.Selector.UnitWithType.Filter(this.container, options);
  77. this.selector.load();
  78. }.bind(this));
  79. }else if ((type.toLowerCase()==="identity") && ((this.options.dutys) && this.options.dutys.length)){
  80. MWF.xDesktop.requireApp("Selector", "IdentityWidthDuty", function(){
  81. this.selectFilter = new MWF.xApplication.Selector.IdentityWidthDuty.Filter(this.value, options);
  82. }.bind(this), false);
  83. }else{
  84. MWF.xDesktop.requireApp("Selector", type, function(){
  85. this.selectFilter = new MWF.xApplication.Selector[type].Filter(this.value, options);
  86. }.bind(this), false);
  87. }
  88. }
  89. }
  90. //if (type){
  91. // if ((type.toLowerCase()==="unit") && (this.options.unitType)){
  92. // MWF.xDesktop.requireApp("Selector", "UnitWithType", function(){
  93. // this.selector = new MWF.xApplication.Selector.UnitWithType.Filter(this.container, options);
  94. // this.selector.load();
  95. // }.bind(this));
  96. // }else if ((type.toLowerCase()==="identity") && ((this.options.dutys) && this.options.dutys.length)){
  97. // MWF.xDesktop.requireApp("Selector", "IdentityWidthDuty", function(){
  98. // this.selectFilter = new MWF.xApplication.Selector.IdentityWidthDuty.Filter(this.value, options);
  99. // }.bind(this), false);
  100. // }else{
  101. // MWF.xDesktop.requireApp("Selector", type, function(){
  102. // this.selectFilter = new MWF.xApplication.Selector[type].Filter(this.value, options);
  103. // }.bind(this), false);
  104. // }
  105. //}else{
  106. // MWF.xDesktop.requireApp("Selector", "MultipleSelector", function() {
  107. // this.selectFilter = new MWF.xApplication.Selector.MultipleSelector.Filter(this.container, this.options );
  108. // }.bind(this), false);
  109. //}
  110. },
  111. filter: function(value, callback){
  112. return this.selectFilter.filter(value, callback);
  113. }
  114. });
  115. (function(){
  116. var _createEl = function(data, node){
  117. var dname = data.distinguishedName;
  118. if (typeOf(data)==="string"){
  119. data = {"id": data};
  120. dname = data.id;
  121. }
  122. var len = dname.length;
  123. var flag = dname.substring(len-1,len);
  124. switch (flag){
  125. case "U":
  126. new o2.widget.O2Unit(data, node, {"style": "xform"});
  127. break;
  128. case "I":
  129. new o2.widget.O2Identity(data, node, {"style": "xform"});
  130. break;
  131. case "G":
  132. new o2.widget.O2Group(data, node, {"style": "xform"});
  133. break;
  134. case "P":
  135. new o2.widget.O2Person(data, node, {"style": "xform"});
  136. break;
  137. case "R":
  138. new o2.widget.O2Role(data, node, {"style": "xform"});
  139. break;
  140. }
  141. };
  142. Element.prototype.setSelectPerson = function(container, options){
  143. if (options.types) options.type = "";
  144. options.onComplete = function(items){
  145. o2.require("o2.widget.O2Identity", function(){
  146. options.values = [];
  147. this.empty();
  148. items.each(function(item){
  149. options.values.push(item.data);
  150. _createEl(item.data, this);
  151. if (options.selectItem) options.selectItem(item);
  152. }.bind(this));
  153. this.store("data-value", options.values);
  154. }.bind(this));
  155. }.bind(this);
  156. if (options.values){
  157. options.values.each(function(v){
  158. this.store("data-value", options.values);
  159. _createEl(v, this);
  160. }.bind(this));
  161. }
  162. this.addEvent("click", function(){
  163. var i = this.getZIndex();
  164. options.zIndex = i+1;
  165. new MWF.O2Selector(container, options);
  166. }.bind(this));
  167. };
  168. })();