IdentityWidthDuty.js 24 KB

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