IdentityWidthDuty.js 23 KB

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