IdentityWidthDuty.js 24 KB

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