package.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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) && this.options.categoryType.toLowerCase()==="duty"){
  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 if ((type.toLowerCase()==="identity") && ((this.options.dutys) && this.options.dutys.length) && this.options.categoryType.toLowerCase()==="unit"){
  90. MWF.xDesktop.requireApp("Selector", "IdentityWidthDutyCategoryByUnit", function(){
  91. this.selectFilter = new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Filter(this.value, options);
  92. }.bind(this));
  93. }else{
  94. MWF.xDesktop.requireApp("Selector", type, function(){
  95. this.selectFilter = new MWF.xApplication.Selector[type].Filter(this.value, options);
  96. }.bind(this), false);
  97. }
  98. }
  99. }
  100. //if (type){
  101. // if ((type.toLowerCase()==="unit") && (this.options.unitType)){
  102. // MWF.xDesktop.requireApp("Selector", "UnitWithType", function(){
  103. // this.selector = new MWF.xApplication.Selector.UnitWithType.Filter(this.container, options);
  104. // this.selector.load();
  105. // }.bind(this));
  106. // }else if ((type.toLowerCase()==="identity") && ((this.options.dutys) && this.options.dutys.length)){
  107. // MWF.xDesktop.requireApp("Selector", "IdentityWidthDuty", function(){
  108. // this.selectFilter = new MWF.xApplication.Selector.IdentityWidthDuty.Filter(this.value, options);
  109. // }.bind(this), false);
  110. // }else{
  111. // MWF.xDesktop.requireApp("Selector", type, function(){
  112. // this.selectFilter = new MWF.xApplication.Selector[type].Filter(this.value, options);
  113. // }.bind(this), false);
  114. // }
  115. //}else{
  116. // MWF.xDesktop.requireApp("Selector", "MultipleSelector", function() {
  117. // this.selectFilter = new MWF.xApplication.Selector.MultipleSelector.Filter(this.container, this.options );
  118. // }.bind(this), false);
  119. //}
  120. },
  121. filter: function(value, callback){
  122. return this.selectFilter.filter(value, callback);
  123. }
  124. });
  125. (function(){
  126. var _createEl = function(data, node){
  127. var dname;
  128. if (typeOf(data)==="string"){
  129. data = {"id": data};
  130. dname = data.id;
  131. }else{
  132. dname = data.distinguishedName || data.name || data.id
  133. }
  134. var len = dname.length;
  135. var flag = dname.substring(len-1,len);
  136. switch (flag){
  137. case "U":
  138. new o2.widget.O2Unit(data, node, {"style": "xform"});
  139. break;
  140. case "I":
  141. new o2.widget.O2Identity(data, node, {"style": "xform"});
  142. break;
  143. case "G":
  144. new o2.widget.O2Group(data, node, {"style": "xform"});
  145. break;
  146. case "P":
  147. new o2.widget.O2Person(data, node, {"style": "xform"});
  148. break;
  149. case "R":
  150. new o2.widget.O2Role(data, node, {"style": "xform"});
  151. break;
  152. }
  153. };
  154. //Element.implement({
  155. // setSelectPerson : function(container, options){
  156. // if (options.types) options.type = "";
  157. // options.onComplete = function(items){
  158. //
  159. // debugger;
  160. //
  161. // o2.require("o2.widget.O2Identity", function(){
  162. // options.values = [];
  163. // this.empty();
  164. // items.each(function(item){
  165. // options.values.push(item.data);
  166. // _createEl(item.data, this);
  167. // if (options.selectItem) options.selectItem(item);
  168. // }.bind(this));
  169. // this.store("data-value", options.values);
  170. // }.bind(this));
  171. // }.bind(this);
  172. //
  173. // if (options.values){
  174. // options.values.each(function(v){
  175. // this.store("data-value", options.values);
  176. // _createEl(v, this);
  177. // }.bind(this));
  178. // }
  179. // this.addEvent("click", function(){
  180. // var i = this.getZIndex();
  181. // options.zIndex = i+1;
  182. // new MWF.O2Selector(container, options);
  183. // }.bind(this));
  184. // }
  185. //});
  186. Element.prototype.setSelectPerson = function(container, options){
  187. if (options.types) options.type = "";
  188. options.onComplete = function(items){
  189. o2.require("o2.widget.O2Identity", function(){
  190. options.values = [];
  191. this.empty();
  192. items.each(function(item){
  193. options.values.push(item.data);
  194. _createEl(item.data, this);
  195. if (options.selectItem) options.selectItem(item);
  196. }.bind(this));
  197. this.store("data-value", options.values);
  198. }.bind(this));
  199. }.bind(this);
  200. if (options.values){
  201. options.values.each(function(v){
  202. this.store("data-value", options.values);
  203. _createEl(v, this);
  204. }.bind(this));
  205. }
  206. this.addEvent("click", function(){
  207. var i = this.getZIndex();
  208. options.zIndex = i+1;
  209. new MWF.O2Selector(container, options);
  210. //var selector = new MWF.O2Selector(container, options);
  211. //this.store("data-selector", selector)
  212. }.bind(this));
  213. };
  214. })();