IdentityWidthDuty.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Identity", null, false);
  3. MWF.xApplication.Selector.IdentityWidthDuty = new Class({
  4. Extends: MWF.xApplication.Selector.Identity,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectIdentity,
  9. "dutys": [],
  10. "units": [],
  11. "values": [],
  12. "zIndex": 1000,
  13. "expand": false,
  14. "noUnit" : false,
  15. "include" : [], //增加的可选项
  16. "resultType" : "", //可以设置成个人,那么结果返回个人
  17. "expandSubEnable": true,
  18. "selectAllEnable" : true, //分类是否允许全选下一层
  19. "exclude" : []
  20. },
  21. loadSelectItems: function(addToNext){
  22. if( this.options.resultType === "person" ){
  23. if( this.titleTextNode ){
  24. this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson );
  25. }else{
  26. this.options.title = MWF.xApplication.Selector.LP.selectPerson;
  27. }
  28. }
  29. if (this.options.dutys.length){
  30. this.loadInclude();
  31. this.options.dutys.each(function(duty){
  32. var data = {"name": duty, "id":duty};
  33. var category = this._newItemCategory("ItemCategory",data, this, this.itemAreaNode);
  34. this.subCategorys.push(category);
  35. //category.loadSub();
  36. //category.clickItem();
  37. // this.action.getUnitduty(function(dutyData){
  38. // var category = this._newItemCategory("ItemCategory", dutyData.data, this, this.itemAreaNode);
  39. // }.bind(this), null, duty);
  40. }.bind(this));
  41. }
  42. },
  43. search: function(){
  44. var key = this.searchInput.get("value");
  45. if (key){
  46. this.initSearchArea(true);
  47. var createdId = this.searchInItems(key) || [];
  48. if( this.options.include && this.options.include.length ){
  49. this.includeObject.listByFilter( "key", key, function( array ){
  50. array.each( function(d){
  51. if( !createdId.contains( d.distinguishedName ) ){
  52. if( !this.isExcluded( d ) ) {
  53. this._newItem( d, this, this.itemSearchAreaNode);
  54. }
  55. }
  56. }.bind(this))
  57. }.bind(this))
  58. }
  59. }else{
  60. this.initSearchArea(false);
  61. }
  62. },
  63. listPersonByPinyin: function(node){
  64. this.searchInput.focus();
  65. var pinyin = this.searchInput.get("value");
  66. pinyin = pinyin+node.get("text");
  67. this.searchInput.set("value", pinyin);
  68. this.search();
  69. },
  70. checkLoadSelectItems: function(){
  71. if (!this.options.units.length){
  72. this.loadSelectItems();
  73. }else{
  74. this.loadSelectItems();
  75. }
  76. },
  77. _scrollEvent: function(y){
  78. return true;
  79. },
  80. _getChildrenItemIds: function(){
  81. return null;
  82. },
  83. _newItemCategory: function(type, data, selector, item, level, category){
  84. return new MWF.xApplication.Selector.IdentityWidthDuty[type](data, selector, item, level, category)
  85. },
  86. _listItemByKey: function(callback, failure, key){
  87. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  88. this.orgAction.listIdentityByKey(function(json){
  89. if (callback) callback.apply(this, [json]);
  90. }.bind(this), failure, key);
  91. },
  92. _getItem: function(callback, failure, id, async){
  93. this.orgAction.getIdentity(function(json){
  94. if (callback) callback.apply(this, [json]);
  95. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  96. },
  97. _newItemSelected: function(data, selector, item){
  98. return new MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected(data, selector, item)
  99. },
  100. _listItemByPinyin: function(callback, failure, key){
  101. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  102. this.orgAction.listIdentityByPinyin(function(json){
  103. if (callback) callback.apply(this, [json]);
  104. }.bind(this), failure, key);
  105. },
  106. _newItem: function(data, selector, container, level, category){
  107. return new MWF.xApplication.Selector.IdentityWidthDuty.Item(data, selector, container, level, category);
  108. },
  109. _newItemSearch: function(data, selector, container, level){
  110. return new MWF.xApplication.Selector.IdentityWidthDuty.SearchItem(data, selector, container, level);
  111. }
  112. //_listItemNext: function(last, count, callback){
  113. // this.action.listRoleNext(last, count, function(json){
  114. // if (callback) callback.apply(this, [json]);
  115. // }.bind(this));
  116. //}
  117. });
  118. MWF.xApplication.Selector.IdentityWidthDuty.Item = new Class({
  119. Extends: MWF.xApplication.Selector.Identity.Item,
  120. _getShowName: function(){
  121. return this.data.name;
  122. },
  123. _getTtiteText: function(){
  124. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  125. },
  126. _setIcon: function(){
  127. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  128. }
  129. });
  130. MWF.xApplication.Selector.IdentityWidthDuty.SearchItem = new Class({
  131. Extends: MWF.xApplication.Selector.Identity.Item,
  132. _getShowName: function(){
  133. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  134. }
  135. });
  136. MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected = new Class({
  137. Extends: MWF.xApplication.Selector.Identity.ItemSelected,
  138. _getShowName: function(){
  139. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  140. },
  141. _getTtiteText: function(){
  142. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  143. },
  144. _setIcon: function(){
  145. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  146. }
  147. });
  148. MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory = new Class({
  149. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  150. createNode: function(){
  151. this.node = new Element("div", {
  152. "styles": this.selector.css.selectorItemCategory_department,
  153. "title" : this._getTtiteText()
  154. }).inject(this.container);
  155. },
  156. _getShowName: function(){
  157. return this.data.name;
  158. },
  159. _setIcon: function(){
  160. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/companyicon.png)");
  161. },
  162. clickItem: function( callback ){
  163. if (this._hasChild()){
  164. var firstLoaded = !this.loaded;
  165. this.loadSub(function(){
  166. if( firstLoaded ){
  167. this.children.setStyles({"display": "block", "height": "auto"});
  168. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  169. this.isExpand = true;
  170. }else{
  171. var display = this.children.getStyle("display");
  172. if (display === "none"){
  173. this.children.setStyles({"display": "block", "height": "auto"});
  174. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  175. this.isExpand = true;
  176. }else{
  177. this.children.setStyles({"display": "none", "height": "0px"});
  178. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  179. this.isExpand = false;
  180. }
  181. }
  182. if(callback)callback();
  183. }.bind(this));
  184. }
  185. },
  186. loadSub: function(callback){
  187. if (!this.loaded){
  188. if (this.selector.options.units.length){
  189. var action = MWF.Actions.get("x_organization_assemble_express");
  190. var data = {"name":this.data.name, "unit":""};
  191. var count = this.selector.options.units.length;
  192. var i = 0;
  193. if (this.selector.options.expandSubEnable) {
  194. this.selector.options.units.each(function(u){
  195. var unitName = "";
  196. if (typeOf(u)==="string"){
  197. unitName = u;
  198. }else{
  199. unitName = u.distinguishedName || u.unique || u.id || u.levelName
  200. }
  201. if (unitName){
  202. var unitNames;
  203. action.listUnitNameSubNested({"unitList": [unitName]}, function(json){
  204. unitNames = json.data.unitList;
  205. }.bind(this), null, false);
  206. unitNames.push(unitName);
  207. if (unitNames && unitNames.length){
  208. data.unitList = unitNames;
  209. action.getDuty(data, function(json){
  210. json.data.each(function(idSubData){
  211. if( !this.selector.isExcluded( idSubData ) ) {
  212. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  213. this.selector.items.push(item);
  214. if(this.subItems)this.subItems.push( item );
  215. }
  216. }.bind(this));
  217. }.bind(this), null, false);
  218. }
  219. }
  220. i++;
  221. if (i>=count){
  222. if (!this.loaded) {
  223. this.loaded = true;
  224. if (callback) callback();
  225. }
  226. }
  227. }.bind(this));
  228. }else{
  229. this.selector.options.units.each(function(u){
  230. if (typeOf(u)==="string"){
  231. data.unit = u;
  232. }else{
  233. data.unit = u.distinguishedName || u.unique || u.id || u.levelName
  234. }
  235. action.getDuty(data, function(json){
  236. json.data.each(function(idSubData){
  237. if( !this.selector.isExcluded( idSubData ) ) {
  238. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  239. this.selector.items.push(item);
  240. if(this.subItems)this.subItems.push( item );
  241. }
  242. }.bind(this));
  243. i++;
  244. if (i>=count){
  245. if (!this.loaded) {
  246. this.loaded = true;
  247. if (callback) callback();
  248. }
  249. }
  250. }.bind(this));
  251. }.bind(this));
  252. }
  253. //if (callback) callback();
  254. }else{
  255. this.selector.orgAction.listIdentityWithDuty(function(json){
  256. json.data.each(function(idSubData){
  257. if( !this.selector.isExcluded( idSubData ) ) {
  258. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  259. this.selector.items.push(item);
  260. if(this.subItems)this.subItems.push( item );
  261. }
  262. }.bind(this));
  263. this.loaded = true;
  264. if (callback) callback();
  265. }.bind(this), null, this.data.name);
  266. }
  267. }else{
  268. if (callback) callback( );
  269. }
  270. },
  271. _hasChild: function(){
  272. return true;
  273. },
  274. _hasChildItem: function(){
  275. return true;
  276. }
  277. });
  278. MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory = new Class({
  279. Extends: MWF.xApplication.Selector.Identity.ItemUnitCategory,
  280. loadSub: function(callback){
  281. if (!this.loaded){
  282. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  283. idJson.data.each(function(idSubData){
  284. if( !this.selector.isExcluded( idSubData ) ) {
  285. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  286. this.selector.items.push(item);
  287. if(this.subItems)this.subItems.push( item );
  288. }
  289. if( !this.selector.options.expandSubEnable ){
  290. this.loaded = true;
  291. if (callback) callback();
  292. }
  293. }.bind(this));
  294. if( this.selector.options.expandSubEnable ){
  295. this.selector.orgAction.listSubUnitDirect(function(json){
  296. json.data.each(function(subData){
  297. if( !this.selector.isExcluded( subData ) ) {
  298. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  299. this.subCategorys.push( category );
  300. }
  301. }.bind(this));
  302. this.loaded = true;
  303. if (callback) callback();
  304. }.bind(this), null, this.data.distinguishedName);
  305. }
  306. }.bind(this), null, this.data.distinguishedName);
  307. }else{
  308. if (callback) callback( );
  309. }
  310. }
  311. });
  312. MWF.xApplication.Selector.IdentityWidthDuty.ItemGroupCategory = new Class({
  313. Extends: MWF.xApplication.Selector.Identity.ItemGroupCategory
  314. });
  315. MWF.xApplication.Selector.IdentityWidthDuty.Filter = new Class({
  316. Implements: [Options, Events],
  317. options: {
  318. "style": "default",
  319. "units": [],
  320. "dutys": []
  321. },
  322. initialize: function(value, options){
  323. this.setOptions(options);
  324. this.value = value;
  325. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  326. },
  327. getList: function(callback){
  328. if (false && this.list){
  329. if (callback) callback();
  330. }else{
  331. this.list = [];
  332. MWF.require("MWF.widget.PinYin", function(){
  333. this.options.dutys.each(function(duty){
  334. if (this.options.units.length){
  335. var action = MWF.Actions.get("x_organization_assemble_express");
  336. var data = {"name":duty, "unit":""};
  337. this.options.units.each(function(u){
  338. if (typeOf(u)==="string"){
  339. data.unit = u;
  340. }else{
  341. data.unit = u.distinguishedName || u.unique || u.id || u.levelName
  342. }
  343. action.getDuty(data, function(json){
  344. json.data.each(function(d){
  345. d.pinyin = d.name.toPY().toLowerCase();
  346. d.firstPY = d.name.toPYFirst().toLowerCase();
  347. this.list.push(d);
  348. }.bind(this));
  349. }.bind(this), null, false);
  350. }.bind(this));
  351. }else{
  352. this.orgAction.listIdentityWithDuty(function(json){
  353. json.data.each(function(d){
  354. d.pinyin = d.name.toPY().toLowerCase();
  355. d.firstPY = d.name.toPYFirst().toLowerCase();
  356. this.list.push(d);
  357. }.bind(this));
  358. }.bind(this), null, duty, false);
  359. }
  360. }.bind(this));
  361. if (callback) callback();
  362. }.bind(this));
  363. }
  364. },
  365. filter: function(value, callback){
  366. this.value = value;
  367. this.getList(function(){
  368. var data = this.list.filter(function(d){
  369. var text = d.name+"#"+d.pinyin+"#"+d.firstPY;
  370. return (text.indexOf(this.value)!=-1);
  371. }.bind(this));
  372. if (callback) callback(data);
  373. }.bind(this));
  374. }
  375. });