IdentityWidthDuty.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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": "",
  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. "selectType" : "identity"
  21. },
  22. setInitTitle: function(){
  23. this.setOptions({"title": MWF.xApplication.Selector.LP.selectIdentity});
  24. },
  25. _init : function(){
  26. this.selectType = "identity";
  27. this.className = "IdentityWidthDuty"
  28. },
  29. loadSelectItems: function(addToNext){
  30. this.loadingCountDuty = "wait";
  31. this.allUnitObjectWithDuty = {};
  32. var afterLoadSelectItemFun = this.afterLoadSelectItem.bind(this);
  33. if( this.options.disabled ){
  34. this.afterLoadSelectItem();
  35. return;
  36. }
  37. if( this.options.resultType === "person" ){
  38. if( this.titleTextNode ){
  39. this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson );
  40. }else{
  41. this.options.title = MWF.xApplication.Selector.LP.selectPerson;
  42. }
  43. }
  44. if (this.options.dutys.length){
  45. var dutyLoaded = 0;
  46. var loadDutySuccess = function () {
  47. dutyLoaded++;
  48. if( dutyLoaded === this.options.dutys.length ){
  49. this.dutyLoaded = true;
  50. if( this.includeLoaded ){
  51. afterLoadSelectItemFun();
  52. }
  53. }
  54. }.bind(this);
  55. this.loadInclude( function () {
  56. this.includeLoaded = true;
  57. if( this.dutyLoaded ){
  58. afterLoadSelectItemFun();
  59. }
  60. }.bind(this));
  61. var loadDuty = function () {
  62. if( this.isCheckStatusOrCount() ){
  63. this.loadingCountDuty = "ready";
  64. this.checkLoadingCount();
  65. }
  66. this.options.dutys.each(function(duty){
  67. var data = {"name": duty, "id":duty};
  68. var category = this._newItemCategory("ItemCategory",data, this, this.itemAreaNode);
  69. this.subCategorys.push(category);
  70. this.allUnitObjectWithDuty[data.name] = category;
  71. loadDutySuccess();
  72. }.bind(this));
  73. }.bind(this);
  74. if( this.options.units.length === 0 ){
  75. loadDuty();
  76. }else{
  77. var unitList = [];
  78. this.options.units.each(function(u) {
  79. var unitName = typeOf(u) === "string" ? u : (u.distinguishedName || u.unique || u.levelName || u.id);
  80. if (unitName)unitList.push( unitName )
  81. });
  82. debugger;
  83. if( !this.options.expandSubEnable ){
  84. this.allUnitNames = unitList;
  85. loadDuty();
  86. }else{
  87. var unitObjectList = [];
  88. var loadNestedUnit = function(){
  89. MWF.Actions.get("x_organization_assemble_express").listUnitSubNested({"unitList": unitList }, function(json1){
  90. var unitNames = [];
  91. //排序
  92. if( this.options.units.length === 1 ){
  93. // unitNames = unitList.concat( json1.data );
  94. unitNames = Array.clone(unitList);
  95. for( var i=0; i<json1.data.length; i++ ){
  96. if( !unitNames.contains(json1.data[i].distinguishedName) ){
  97. unitNames.push( json1.data[i].distinguishedName );
  98. }
  99. }
  100. }else{
  101. unitObjectList.each( function ( u ) {
  102. unitNames.push( u.distinguishedName || u.unique || u.levelName || u.id );
  103. for( var i=0; i<json1.data.length; i++ ){
  104. if( json1.data[i].levelName.indexOf(u.levelName) > -1 ){
  105. unitNames.push( json1.data[i].distinguishedName );
  106. }
  107. }
  108. })
  109. }
  110. this.allUnitNames = unitNames;
  111. loadDuty();
  112. }.bind(this), null);
  113. }.bind(this);
  114. var flag = false; //需要获取层次名用于排序
  115. if( this.options.units.length === 1 ){
  116. loadNestedUnit();
  117. }else{
  118. this.options.units.each(function(u) {
  119. if (typeOf(u) === "string" ) {
  120. u.indexOf("/") === -1 ? (flag = true) : unitObjectList.push( { levelName : u } );
  121. } else {
  122. u.levelName ? unitObjectList.push( u ) : (flag = true);
  123. }
  124. });
  125. if( flag ){ //需要获取层次名来排序
  126. o2.Actions.load("x_organization_assemble_express").UnitAction.listObject( {
  127. unitList: unitList
  128. }, function (json) {
  129. unitObjectList = json.data || [];
  130. loadNestedUnit();
  131. }.bind(this) )
  132. }else{
  133. loadNestedUnit();
  134. }
  135. }
  136. }
  137. }
  138. }
  139. if( this.isCheckStatusOrCount() ) {
  140. this.loadingCountInclude = "wait";
  141. this.loadIncludeCount();
  142. }
  143. },
  144. search: function(){
  145. var key = this.searchInput.get("value");
  146. if (key){
  147. this.initSearchArea(true);
  148. var createdId = this.searchInItems(key) || [];
  149. if( this.options.include && this.options.include.length ){
  150. this.includeObject.listByFilter( "key", key, function( array ){
  151. array.each( function(d){
  152. if( !createdId.contains( d.distinguishedName ) ){
  153. if( !this.isExcluded( d ) ) {
  154. this._newItem( d, this, this.itemSearchAreaNode);
  155. }
  156. }
  157. }.bind(this))
  158. }.bind(this))
  159. }
  160. }else{
  161. this.initSearchArea(false);
  162. }
  163. },
  164. listPersonByPinyin: function(node){
  165. this.searchInput.focus();
  166. var pinyin = this.searchInput.get("value");
  167. pinyin = pinyin+node.get("text");
  168. this.searchInput.set("value", pinyin);
  169. this.search();
  170. },
  171. checkLoadSelectItems: function(){
  172. if (!this.options.units.length){
  173. this.loadSelectItems();
  174. }else{
  175. this.loadSelectItems();
  176. }
  177. },
  178. _scrollEvent: function(y){
  179. return true;
  180. },
  181. _getChildrenItemIds: function(){
  182. return null;
  183. },
  184. _newItemCategory: function(type, data, selector, item, level, category, delay){
  185. return new MWF.xApplication.Selector.IdentityWidthDuty[type](data, selector, item, level, category, delay)
  186. },
  187. _listItemByKey: function(callback, failure, key){
  188. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  189. this.orgAction.listIdentityByKey(function(json){
  190. if (callback) callback.apply(this, [json]);
  191. }.bind(this), failure, key);
  192. },
  193. _getItem: function(callback, failure, id, async){
  194. this.orgAction.getIdentity(function(json){
  195. if (callback) callback.apply(this, [json]);
  196. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  197. },
  198. _newItemSelected: function(data, selector, item, selectedNode){
  199. return new MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected(data, selector, item, selectedNode)
  200. },
  201. _listItemByPinyin: function(callback, failure, key){
  202. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  203. this.orgAction.listIdentityByPinyin(function(json){
  204. if (callback) callback.apply(this, [json]);
  205. }.bind(this), failure, key);
  206. },
  207. _newItem: function(data, selector, container, level, category, delay){
  208. return new MWF.xApplication.Selector.IdentityWidthDuty.Item(data, selector, container, level, category, delay);
  209. },
  210. _newItemSearch: function(data, selector, container, level){
  211. return new MWF.xApplication.Selector.IdentityWidthDuty.SearchItem(data, selector, container, level);
  212. },
  213. uniqueIdentityList: function(list){
  214. var items = [], map = {};
  215. (list||[]).each(function(d) {
  216. if (d.distinguishedName || d.unique) {
  217. if ((!d.distinguishedName || !map[d.distinguishedName]) && (!d.unique || !map[d.unique])) {
  218. items.push(d);
  219. map[d.distinguishedName] = true;
  220. map[d.unique] = true;
  221. }
  222. } else {
  223. items.push(d);
  224. }
  225. })
  226. return items;
  227. },
  228. loadIncludeCount: function(){
  229. var unitList = [];
  230. var groupList = [];
  231. if (this.options.include.length > 0) {
  232. this.options.include.each(function (d) {
  233. var dn = typeOf(d) === "string" ? d : d.distinguishedName;
  234. var flag = dn.split("@").getLast().toLowerCase();
  235. if (flag === "u") {
  236. unitList.push(dn);
  237. } else if (flag === "g") {
  238. groupList.push(dn)
  239. }
  240. })
  241. }
  242. if(unitList.length || groupList.length){
  243. this._loadUnitAndGroupCount(unitList, groupList, function () {
  244. this.loadingCountInclude = "ready";
  245. this.checkLoadingCount();
  246. }.bind(this));
  247. }else{
  248. this.loadingCountInclude = "ignore";
  249. this.checkLoadingCount();
  250. }
  251. },
  252. checkLoadingCount: function(){
  253. if(this.loadingCountDuty === "ready" && this.loadingCountInclude === "ready"){
  254. this.checkCountAndStatus();
  255. this.loadingCount = "done";
  256. }else if(this.loadingCountDuty === "ready" && this.loadingCountInclude === "ignore"){
  257. this.loadingCount = "done";
  258. }
  259. },
  260. addSelectedCount: function( itemOrItemSelected, count, items ){
  261. if( this.loadingCountInclude === "ignore" ){
  262. this._addSelectedCountWithDuty(itemOrItemSelected, count, items);
  263. }else{
  264. this._addSelectedCountWithDuty(itemOrItemSelected, count, items);
  265. this._addSelectedCount(itemOrItemSelected, count);
  266. }
  267. },
  268. _addSelectedCountWithDuty: function( itemOrItemSelected, count, items ){
  269. var itemData = itemOrItemSelected.data;
  270. debugger;
  271. items.each(function(item){
  272. if(item.category && item.category._addSelectedCount && item.category.className === "ItemCategory"){
  273. item.category._addSelectedCount( count );
  274. }
  275. }.bind(this));
  276. },
  277. //_listItemNext: function(last, count, callback){
  278. // this.action.listRoleNext(last, count, function(json){
  279. // if (callback) callback.apply(this, [json]);
  280. // }.bind(this));
  281. //}
  282. });
  283. MWF.xApplication.Selector.IdentityWidthDuty.Item = new Class({
  284. Extends: MWF.xApplication.Selector.Identity.Item,
  285. _getShowName: function(){
  286. return this.data.name;
  287. },
  288. _getTtiteText: function(){
  289. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  290. },
  291. _setIcon: function(){
  292. var style = this.selector.options.style;
  293. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  294. }
  295. });
  296. MWF.xApplication.Selector.IdentityWidthDuty.SearchItem = new Class({
  297. Extends: MWF.xApplication.Selector.Identity.Item,
  298. _getShowName: function(){
  299. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  300. }
  301. });
  302. MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected = new Class({
  303. Extends: MWF.xApplication.Selector.Identity.ItemSelected,
  304. _getShowName: function(){
  305. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  306. },
  307. _getTtiteText: function(){
  308. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  309. },
  310. _setIcon: function(){
  311. var style = this.selector.options.style;
  312. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  313. }
  314. });
  315. MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory = new Class({
  316. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  317. createNode: function(){
  318. this.className = "ItemCategory";
  319. this.node = new Element("div", {
  320. "styles": this.selector.css.selectorItemCategory_department,
  321. "title" : this._getTtiteText()
  322. }).inject(this.container);
  323. },
  324. _getShowName: function(){
  325. return this.data.name;
  326. },
  327. _setIcon: function(){
  328. var style = this.selector.options.style;
  329. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/companyicon.png)");
  330. },
  331. _addSelectAllSelectedCount: function(){
  332. var count = this._getSelectedCount();
  333. this._checkCountAndStatus(count);
  334. },
  335. _addSelectedCount : function(){
  336. if( this.selector.loadingCount === "done" ){
  337. var count = this._getSelectedCount();
  338. this._checkCountAndStatus(count);
  339. }
  340. },
  341. _getTotalCount : function(){
  342. return this.subItems.length;
  343. },
  344. _getSelectedCount : function(){
  345. var list = this.subItems.filter( function (item) { return item.isSelected; });
  346. return list.length;
  347. },
  348. loadSub : function(callback){
  349. this._loadSub( function( firstLoad ) {
  350. if(firstLoad){
  351. if( this.selector.isCheckStatusOrCount() ){
  352. // var count = this._getSelectedCount();
  353. // this.checkCountAndStatus(count);
  354. if( this.selector.loadingCount === "done" ){
  355. this.checkCountAndStatus();
  356. }
  357. }
  358. }
  359. if(callback)callback();
  360. }.bind(this))
  361. },
  362. _loadSub: function(callback){
  363. if (!this.loaded && !this.loadingsub){
  364. this.loadingsub = true;
  365. if (this.selector.options.units.length){
  366. var data = {
  367. "name":this.data.name,
  368. "unit":"",
  369. "unitList" : this.selector.allUnitNames
  370. };
  371. MWF.Actions.get("x_organization_assemble_express").getDuty(data, function(json){
  372. var list = this.selector.uniqueIdentityList(json.data);
  373. list.each(function(idSubData){
  374. if( !this.selector.isExcluded( idSubData ) ) {
  375. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  376. this.selector.items.push(item);
  377. if(this.subItems)this.subItems.push( item );
  378. }
  379. }.bind(this));
  380. if (!this.loaded) {
  381. this.loaded = true;
  382. this.loadingsub = false;
  383. this.itemLoaded = true;
  384. if (callback) callback( true );
  385. }
  386. }.bind(this), null, false);
  387. // if (this.selector.options.units.length){
  388. // var action = MWF.Actions.get("x_organization_assemble_express");
  389. // var data = {"name":this.data.name, "unit":""};
  390. // var count = this.selector.options.units.length;
  391. // var i = 0;
  392. //
  393. // if (this.selector.options.expandSubEnable) {
  394. // this.selector.options.units.each(function(u){
  395. // var unitName = "";
  396. // if (typeOf(u)==="string"){
  397. // unitName = u;
  398. // }else{
  399. // unitName = u.distinguishedName || u.unique || u.id || u.levelName
  400. // }
  401. // if (unitName){
  402. // var unitNames;
  403. // action.listUnitNameSubNested({"unitList": [unitName]}, function(json){
  404. // unitNames = json.data.unitList;
  405. // }.bind(this), null, false);
  406. //
  407. // unitNames.push(unitName);
  408. // if (unitNames && unitNames.length){
  409. // data.unitList = unitNames;
  410. // action.getDuty(data, function(json){
  411. // json.data.each(function(idSubData){
  412. // if( !this.selector.isExcluded( idSubData ) ) {
  413. // var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  414. // this.selector.items.push(item);
  415. // if(this.subItems)this.subItems.push( item );
  416. // }
  417. // }.bind(this));
  418. // }.bind(this), null, false);
  419. // }
  420. // }
  421. //
  422. // i++;
  423. // if (i>=count){
  424. // if (!this.loaded) {
  425. // this.loaded = true;
  426. // this.loadingsub = false;
  427. // this.itemLoaded = true;
  428. // if (callback) callback();
  429. // }
  430. // }
  431. // }.bind(this));
  432. // }else{
  433. // this.selector.options.units.each(function(u){
  434. // if (typeOf(u)==="string"){
  435. // data.unit = u;
  436. // }else{
  437. // data.unit = u.distinguishedName || u.unique || u.id || u.levelName
  438. // }
  439. // action.getDuty(data, function(json){
  440. // json.data.each(function(idSubData){
  441. // if( !this.selector.isExcluded( idSubData ) ) {
  442. // var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  443. // this.selector.items.push(item);
  444. // if(this.subItems)this.subItems.push( item );
  445. // }
  446. // }.bind(this));
  447. // i++;
  448. // if (i>=count){
  449. // if (!this.loaded) {
  450. // this.loaded = true;
  451. // this.loadingsub = false;
  452. // this.itemLoaded = true;
  453. // if (callback) callback();
  454. // }
  455. // }
  456. // }.bind(this));
  457. // }.bind(this));
  458. // }
  459. }else{
  460. this.selector.orgAction.listIdentityWithDuty(function(json){
  461. var list = this.selector.uniqueIdentityList(json.data);
  462. list.each(function(idSubData){
  463. if( !this.selector.isExcluded( idSubData ) ) {
  464. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  465. this.selector.items.push(item);
  466. if(this.subItems)this.subItems.push( item );
  467. }
  468. }.bind(this));
  469. this.loaded = true;
  470. this.loadingsub = false;
  471. if (callback) callback( true );
  472. }.bind(this), null, this.data.name);
  473. }
  474. }else{
  475. if (callback) callback( );
  476. }
  477. },
  478. loadCategoryChildren: function(callback){
  479. this.loadSub(callback);
  480. this.categoryLoaded = true;
  481. //if (callback) callback();
  482. },
  483. loadItemChildren: function(callback){
  484. this.loadSub(callback);
  485. },
  486. _hasChild: function(){
  487. return true;
  488. },
  489. _hasChildCategory: function(){
  490. return true;
  491. },
  492. _hasChildItem: function(){
  493. return true;
  494. }
  495. });
  496. MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory = new Class({
  497. Extends: MWF.xApplication.Selector.Identity.ItemUnitCategory,
  498. loadSub: function(callback){
  499. if (!this.loaded){
  500. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  501. if( !this.itemLoaded ){
  502. var list = this.selector.uniqueIdentityList(idJson.data);
  503. list.each(function(idSubData){
  504. if( !this.selector.isExcluded( idSubData ) ) {
  505. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  506. this.selector.items.push(item);
  507. if(this.subItems)this.subItems.push( item );
  508. }
  509. }.bind(this));
  510. this.itemLoaded = true;
  511. }
  512. if( !this.selector.options.expandSubEnable ){
  513. this.loaded = true;
  514. if (callback) callback();
  515. }
  516. if( this.selector.options.expandSubEnable ){
  517. this.selector.orgAction.listSubUnitDirect(function(json){
  518. json.data.each(function(subData){
  519. if( !this.selector.isExcluded( subData ) ) {
  520. if( subData && this.data.parentLevelName)subData.parentLevelName = this.data.parentLevelName +"/" + subData.name;
  521. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  522. this.subCategorys.push( category );
  523. this.subCategoryMap[subData.parentLevelName || subData.levelName] = category;
  524. }
  525. }.bind(this));
  526. this.loaded = true;
  527. if (callback) callback();
  528. }.bind(this), null, this.data.distinguishedName);
  529. }
  530. }.bind(this), null, this.data.distinguishedName);
  531. }else{
  532. if (callback) callback( );
  533. }
  534. },
  535. loadCategoryChildren: function(callback){
  536. if (!this.categoryLoaded){
  537. this.loadSub(callback);
  538. this.categoryLoaded = true;
  539. this.itemLoaded = true;
  540. //if( this.selector.options.expandSubEnable ){
  541. // this.selector.orgAction.listSubUnitDirect(function(json){
  542. // json.data.each(function(subData){
  543. // if( !this.selector.isExcluded( subData ) ) {
  544. // var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  545. // this.subCategorys.push( category );
  546. // }
  547. // }.bind(this));
  548. // this.categoryLoaded = true;
  549. // if (callback) callback();
  550. // }.bind(this), null, this.data.distinguishedName);
  551. //}else{
  552. // if (callback) callback();
  553. //}
  554. }else{
  555. if (callback) callback( );
  556. }
  557. },
  558. loadItemChildren: function(callback){
  559. if (!this.itemLoaded){
  560. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  561. var list = this.selector.uniqueIdentityList(idJson.data);
  562. list.each(function(idSubData){
  563. if( !this.selector.isExcluded( idSubData ) ) {
  564. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  565. this.selector.items.push(item);
  566. if(this.subItems)this.subItems.push( item );
  567. }
  568. }.bind(this));
  569. if (callback) callback();
  570. }.bind(this), null, this.data.distinguishedName);
  571. this.itemLoaded = true;
  572. }else{
  573. if (callback) callback( );
  574. }
  575. }
  576. });
  577. MWF.xApplication.Selector.IdentityWidthDuty.ItemGroupCategory = new Class({
  578. Extends: MWF.xApplication.Selector.Identity.ItemGroupCategory
  579. });
  580. MWF.xApplication.Selector.IdentityWidthDuty.Filter = new Class({
  581. Implements: [Options, Events],
  582. options: {
  583. "style": "default",
  584. "units": [],
  585. "dutys": []
  586. },
  587. initialize: function(value, options){
  588. this.setOptions(options);
  589. this.value = value;
  590. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  591. },
  592. getList: function(callback){
  593. if (false && this.list){
  594. if (callback) callback();
  595. }else{
  596. this.list = [];
  597. MWF.require("MWF.widget.PinYin", function(){
  598. this.options.dutys.each(function(duty){
  599. if (this.options.units.length){
  600. var action = MWF.Actions.get("x_organization_assemble_express");
  601. var data = {"name":duty, "unit":""};
  602. this.options.units.each(function(u){
  603. if (typeOf(u)==="string"){
  604. data.unit = u;
  605. }else{
  606. data.unit = u.distinguishedName || u.unique || u.levelName || u.id
  607. }
  608. action.getDuty(data, function(json){
  609. json.data.each(function(d){
  610. d.pinyin = d.name.toPY().toLowerCase();
  611. d.firstPY = d.name.toPYFirst().toLowerCase();
  612. this.list.push(d);
  613. }.bind(this));
  614. }.bind(this), null, false);
  615. }.bind(this));
  616. }else{
  617. this.orgAction.listIdentityWithDuty(function(json){
  618. json.data.each(function(d){
  619. d.pinyin = d.name.toPY().toLowerCase();
  620. d.firstPY = d.name.toPYFirst().toLowerCase();
  621. this.list.push(d);
  622. }.bind(this));
  623. }.bind(this), null, duty, false);
  624. }
  625. }.bind(this));
  626. if (callback) callback();
  627. }.bind(this));
  628. }
  629. },
  630. filter: function(value, callback){
  631. this.value = value;
  632. this.getList(function(){
  633. var data = this.list.filter(function(d){
  634. var text = d.name+"#"+d.pinyin+"#"+d.firstPY;
  635. return (text.indexOf(this.value)!=-1);
  636. }.bind(this));
  637. if (callback) callback(data);
  638. }.bind(this));
  639. }
  640. });