IdentityWidthDuty.js 24 KB

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