package.js 8.1 KB

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