IdentityWidthDutyCategoryByUnit.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "IdentityWidthDuty", null, false);
  3. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({
  4. Extends: MWF.xApplication.Selector.IdentityWidthDuty,
  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. "dutyUnitLevelBy": "duty", //组织层级是按身份所在群组还是职务,
  21. "identitySortBy" : "identityNumber", //身份排序按身份排序号,还是传入的duty
  22. "selectType": "identity"
  23. },
  24. setInitTitle: function(){
  25. this.setOptions({"title": MWF.xApplication.Selector.LP.selectIdentity});
  26. },
  27. _init: function () {
  28. this.selectType = "identity";
  29. this.className = "IdentityWidthDutyCategoryByUnit";
  30. },
  31. getUnitUniqueFormDn : function(dn){
  32. if(!dn)return "";
  33. var arr = dn.split("@");
  34. if( arr.length === 3 )return arr[1];
  35. return dn;
  36. },
  37. loadSelectItems: function (addToNext) {
  38. //根据组织分类展现职务
  39. if (this.options.resultType === "person") {
  40. if (this.titleTextNode) {
  41. this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson);
  42. } else {
  43. this.options.title = MWF.xApplication.Selector.LP.selectPerson;
  44. }
  45. }
  46. if (this.options.disabled) {
  47. this.afterLoadSelectItem();
  48. return;
  49. }
  50. if (this.options.dutys.length) {
  51. this.loadInclude(function () {
  52. this.includeLoaded = true;
  53. if (this.dutyLoaded) {
  54. this.afterLoadSelectItem();
  55. }
  56. }.bind(this));
  57. var units = [];
  58. var unitUniques = [];
  59. for (var i = 0; i < this.options.units.length; i++) {
  60. var unit = this.options.units[i];
  61. if (typeOf(unit) === "string") {
  62. units.push(unit);
  63. unitUniques.push( this.getUnitUniqueFormDn(unit) );
  64. } else {
  65. units.push(unit.distinguishedName || unit.unique || unit.levelName || unit.id );
  66. unitUniques.push( unit.distinguishedName ? this.getUnitUniqueFormDn(unit.distinguishedName) : (unit.unique || unit.levelName || unit.id) );
  67. }
  68. }
  69. this.unitStringList = units;
  70. this.unitUniqueList = unitUniques;
  71. this.loadingCountDuty = "wait";
  72. o2.Actions.load("x_organization_assemble_express").UnitDutyAction.listIdentityWithUnitWithNameObject({
  73. nameList: this.options.dutys,
  74. unitList: units,
  75. recursiveUnit : !!this.options.expandSubEnable
  76. }, function (json) {
  77. this.allIdentityData = json.data;
  78. this.setUnitLevelNameMap(); //如果需要检查状态,创建身份-所在组织层次名对应关系
  79. // this.setUnitLevelNameMapInValues(); //如果需要检查状态,创建已选值身份-所在组织层次名对应关系
  80. this._loadSelectItems(json.data)
  81. }.bind(this))
  82. }else{
  83. this.afterLoadSelectItem();
  84. }
  85. if( this.isCheckStatusOrCount() ) {
  86. this.loadingCountInclude = "wait";
  87. this.loadIncludeCount();
  88. }
  89. },
  90. _loadSelectItems: function (identityList) {
  91. //this.listAllIdentityInUnitObject( identityList );
  92. this.listNestedUnitByIdentity(identityList, function (unitTree) {
  93. this.dataTree = unitTree;
  94. this.uniqueIdentity(unitTree);
  95. this.loadingCountDuty = "ready";
  96. this.checkLoadingCount();
  97. if (this.options.dutyUnitLevelBy === "duty") {
  98. this.level1Container = [];
  99. if (this.options.units && this.options.units.length) {
  100. this.options.units.each( function (unit ,i) {
  101. var div = new Element("div").inject(this.itemAreaNode);
  102. this.level1Container.push(div);
  103. }.bind(this))
  104. }
  105. this._loadSelectItemsByDutyUnit(unitTree);
  106. } else {
  107. this._loadSelectItemsByIdentityUnit(unitTree);
  108. }
  109. this.dutyLoaded = true;
  110. if (this.includeLoaded) {
  111. this.afterLoadSelectItem();
  112. }
  113. }.bind(this));
  114. },
  115. _loadSelectItemsByIdentityUnit: function (unitTree) {
  116. if (!unitTree.unitList) return;
  117. this.sortUnit(unitTree.unitList);
  118. for (var i = 0; i < unitTree.unitList.length; i++) {
  119. var unit = unitTree.unitList[i];
  120. // if( !this.isExcluded( unit ) ) {
  121. var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  122. this.subCategorys.push(category);
  123. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  124. this.subCategoryMapWithDuty[unit.matchLevelName || unit.levelName] = category;
  125. // }
  126. }
  127. },
  128. sortUnit: function (unitList) {
  129. if (this.options.dutyUnitLevelBy === "duty") {
  130. if (this.options.units) {
  131. unitList.sort(function (a, b) {
  132. var idxA = this.getIndexFromUnitOption(a);
  133. var idxB = this.getIndexFromUnitOption(b);
  134. if( a.orderNumber === 0 )a.orderNumber = -1;
  135. if( b.orderNumber === 0 )b.orderNumber = -1;
  136. idxA = idxA === -1 ? 9999999 + (a.orderNumber || 9999999) : idxA;
  137. idxB = idxB === -1 ? 9999999 + (b.orderNumber || 9999999) : idxB;
  138. return idxA - idxB;
  139. }.bind(this))
  140. } else {
  141. unitList.sort(function (a, b) {
  142. if( a.orderNumber === 0 )a.orderNumber = -1;
  143. if( b.orderNumber === 0 )b.orderNumber = -1;
  144. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  145. }.bind(this))
  146. }
  147. } else {
  148. unitList.sort(function (a, b) {
  149. if( a.orderNumber === 0 )a.orderNumber = -1;
  150. if( b.orderNumber === 0 )b.orderNumber = -1;
  151. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  152. }.bind(this))
  153. }
  154. },
  155. _loadSelectItemsByDutyUnit: function (unitTree) {
  156. if (!unitTree.unitList) return;
  157. // this.sortUnit( unitTree.unitList );
  158. for (var i = 0; i < unitTree.unitList.length; i++) {
  159. var unit = unitTree.unitList[i];
  160. if (this.isUnitContain(unit)) {
  161. // if( !this.isExcluded( unit ) ) {
  162. var container = this.itemAreaNode;
  163. if (this.level1Container && this.level1Container.length) {
  164. var index = this.getIndexFromUnitOption(unit);
  165. if (index > -1 && (this.level1Container.length > index) && this.level1Container[index]) container = this.level1Container[index];
  166. }
  167. var category = this._newItemCategory("ItemCategory", unit, this, container);
  168. this.subCategorys.push(category);
  169. this.subCategoryMapWithDuty[unit.matchLevelName || unit.levelName] = category;
  170. // }
  171. } else {
  172. this._loadSelectItemsByDutyUnit(unit);
  173. }
  174. }
  175. },
  176. getIndexFromUnitOption: function (unit) {
  177. if (!this.unitStringList || !this.unitStringList.length) return -1;
  178. var idx = -1;
  179. if (idx == -1 && unit.distinguishedName) idx = this.unitStringList.indexOf(unit.distinguishedName);
  180. if (idx == -1 && unit.id) idx = this.unitStringList.indexOf(unit.id);
  181. if (idx == -1 && unit.unique) idx = this.unitStringList.indexOf(unit.unique);
  182. if (idx == -1 && unit.levelName) idx = this.unitStringList.indexOf(unit.levelName);
  183. if (idx == -1 && unit.unique ) idx = this.unitUniqueList.indexOf(unit.unique);
  184. if (idx == -1 && !unit.unique && unit.distinguishedName ) idx = this.unitUniqueList.indexOf(unit.distinguishedName.split("@")[1]||"");
  185. return idx
  186. },
  187. isUnitContain: function (d) {
  188. if (this.options.units.length === 0) return true;
  189. if (!this.unitFlagMap) {
  190. this.unitFlagMap = {};
  191. this.options.units.each(function (e) {
  192. if (!e) return;
  193. this.unitFlagMap[typeOf(e) === "string" ? e : (e.distinguishedName || e.unique || e.employee || e.levelName || e.id)] = true;
  194. }.bind(this));
  195. }
  196. if (!this.unitUniqueMap) {
  197. this.unitUniqueMap = {};
  198. this.unitUniqueList.each(function (e) {
  199. if (!e) return;
  200. this.unitUniqueMap[e] = true;
  201. }.bind(this));
  202. }
  203. var map = this.unitFlagMap;
  204. var uniqueMap = this.unitUniqueMap;
  205. var flag = (d.distinguishedName && map[d.distinguishedName]) ||
  206. (d.levelName && map[d.levelName]) ||
  207. (d.id && map[d.id]) ||
  208. (d.unique && map[d.unique]) ||
  209. (d.unique && uniqueMap[d.unique]);
  210. if( !flag && !d.unique && d.distinguishedName ){
  211. var arr = d.distinguishedName.split("@");
  212. if( arr.length === 3 && arr[1] && uniqueMap[arr[1]] ){
  213. flag = true;
  214. }
  215. }
  216. return flag;
  217. },
  218. listAllUnitObject: function (identityList, callback) {
  219. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  220. var unitArray = [];
  221. for (var i = 0; i < identityList.length; i++) {
  222. var levelNames = identityList[i][key];
  223. //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  224. var unitLevelNameList = levelNames.split("/");
  225. var nameList = [];
  226. for (var j = 0; j < unitLevelNameList.length; j++) {
  227. nameList.push(unitLevelNameList[j]);
  228. var name = nameList.join("/");
  229. if (!unitArray.contains(name)) {
  230. unitArray.push(name);
  231. }
  232. }
  233. }
  234. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  235. o2.Actions.load("x_organization_assemble_express").UnitAction.listWithLevelNameObject({
  236. unitList: unitArray
  237. }, function (json) {
  238. this.allUnitObjectWithDuty = {};
  239. json.data.each(function (u) {
  240. if(u && u.levelName)this.allUnitObjectWithDuty[u.levelName] = u;
  241. }.bind(this));
  242. if (callback) callback();
  243. }.bind(this))
  244. },
  245. listNestedUnitByIdentity: function (identityList, callback) {
  246. this.listAllUnitObject(identityList, function () {
  247. this._listNestedUnitByIdentity(identityList, callback);
  248. }.bind(this));
  249. },
  250. _listNestedUnitByIdentity: function (identityList, callback) {
  251. debugger;
  252. //identityList = Array.unique(identityList);
  253. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  254. //根据unitLevelName整合成组织树
  255. var unitTree = {};
  256. for (var i = 0; i < identityList.length; i++) {
  257. var flag = true;
  258. if (this.isExcluded(identityList[i])) continue;
  259. var levelNames = identityList[i][key];
  260. //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  261. var unitLevelNameList = levelNames.split("/");
  262. var nameList = [];
  263. var tree = unitTree;
  264. for (var j = 0; j < unitLevelNameList.length; j++) {
  265. nameList.push(unitLevelNameList[j]);
  266. var name = nameList.join("/");
  267. if (this.isExcluded(this.allUnitObjectWithDuty[name] || {})) {
  268. flag = false;
  269. break;
  270. }
  271. if (!tree.unitList) tree.unitList = [];
  272. var found = false;
  273. for (var k = 0; k < tree.unitList.length; k++) {
  274. if (tree.unitList[k].levelName == name) {
  275. tree = tree.unitList[k];
  276. found = true;
  277. break;
  278. }
  279. }
  280. if (!found) {
  281. // var obj = {};
  282. var obj = this.allUnitObjectWithDuty[name] || {};
  283. obj.matchLevelName = name;
  284. tree.unitList.push(obj);
  285. tree = obj;
  286. }
  287. // if( !tree.distinguishedName ){
  288. // tree = Object.merge( tree, this.allUnitObjectWithDuty[name] );
  289. // }
  290. if (!tree.identityList) tree.identityList = [];
  291. }
  292. if (flag) tree.identityList.push(identityList[i]);
  293. }
  294. if(callback)callback(unitTree);
  295. },
  296. uniqueIdentity: function (tree) {
  297. var map = {};
  298. var indexMap = {};
  299. var isExist = function (d, index) {
  300. if ((d.distinguishedName && map[d.distinguishedName]) ||
  301. (d.levelName && map[d.levelName]) ||
  302. (d.id && map[d.id]) ||
  303. (d.unique && map[d.unique])) {
  304. return true;
  305. } else {
  306. var key = typeOf(d) === "string" ? d : (d.distinguishedName || d.unique || d.employee || d.levelName || d.id);
  307. map[key] = true;
  308. indexMap[key] = index+1;
  309. return false;
  310. }
  311. };
  312. var getIndex = function (d){
  313. var index = ((d.distinguishedName && indexMap[d.distinguishedName]) ||
  314. (d.levelName && indexMap[d.levelName]) ||
  315. (d.id && indexMap[d.id]) ||
  316. (d.unique && indexMap[d.unique]));
  317. if( !index )index = 0;
  318. return index-1;
  319. };
  320. var identityList = [];
  321. if (tree.identityList) {
  322. for (var i = 0; i < tree.identityList.length; i++) {
  323. if (!isExist(tree.identityList[i], i)){
  324. identityList.push(tree.identityList[i]);
  325. }else if( this.options.identitySortBy !== "identityNumber" ){
  326. var index = getIndex(tree.identityList[i]);
  327. if( index > -1 ){
  328. var identity = tree.identityList[index];
  329. if( !identity.otherMatchUnitDutyList ){
  330. identity.otherMatchUnitDutyList = []
  331. }
  332. identity.otherMatchUnitDutyList.push({
  333. matchUnitDutyNumber : tree.identityList[i].matchUnitDutyNumber,
  334. matchUnitDutyName : tree.identityList[i].matchUnitDutyName
  335. })
  336. }
  337. }
  338. }
  339. }
  340. tree.identityList = identityList;
  341. if (this.isCheckStatusOrCount()) {
  342. var names = (tree.matchLevelName || tree.levelName || "").split("/");
  343. var nameList = [];
  344. var selectedCount = 0;
  345. tree.identityList.each(function (id) {
  346. if( this.isInValues(id) )selectedCount++;
  347. }.bind(this));
  348. for (var i = 0; i < names.length; i++) {
  349. nameList.push(names[i]);
  350. var name = nameList.join("/");
  351. var obj = this.allUnitObjectWithDuty[name];
  352. if (obj) {
  353. obj.subNestedIdentityCount = (obj.subNestedIdentityCount || 0) + identityList.length;
  354. obj.selectedNestedIdentityCount = (obj.selectedNestedIdentityCount || 0) + selectedCount;
  355. }
  356. }
  357. }
  358. if (tree.unitList) {
  359. for (var i = 0; i < tree.unitList.length; i++) {
  360. this.uniqueIdentity(tree.unitList[i]);
  361. }
  362. }
  363. },
  364. createItemsSearchData: function(callback){
  365. if (!this.itemsSearchData){
  366. this.itemsSearchData = [];
  367. MWF.require("MWF.widget.PinYin", function(){
  368. var initIds = [];
  369. var _self = this;
  370. function checkIdentity(data) {
  371. var id = data.distinguishedName || data.name || data.id || data.text;
  372. if (initIds.indexOf( id )==-1){
  373. var text = data.name || "";
  374. if( !text && data.distinguishedName ){
  375. var dn = data.distinguishedName.split("@");
  376. text = dn[0];
  377. }
  378. var pinyin = text.toPY().toLowerCase();
  379. var firstPY = text.toPYFirst().toLowerCase();
  380. _self.itemsSearchData.push({
  381. "text": text,
  382. "pinyin": pinyin,
  383. "firstPY": firstPY,
  384. "data": data
  385. });
  386. initIds.push( id );
  387. }
  388. }
  389. function checkUnit(unit) {
  390. if(unit.identityList && unit.identityList.length){
  391. unit.identityList.each( function (identity) {
  392. checkIdentity(identity);
  393. })
  394. }
  395. if(unit.unitList && unit.unitList.length){
  396. unit.unitList.each( function (unit) {
  397. checkUnit(unit);
  398. })
  399. }
  400. }
  401. this.dataTree.unitList.each(function(unit){
  402. checkUnit(unit);
  403. }.bind(this));
  404. delete initIds;
  405. if (callback) callback();
  406. }.bind(this));
  407. }else{
  408. if (callback) callback();
  409. }
  410. },
  411. //listNestedUnitByIdentity : function( identityList ){
  412. // debugger;
  413. // this.unitArray = [];
  414. // var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  415. // //根据unitLevelName整合成组织树
  416. // var unitTree = {};
  417. // for( var i=0; i<identityList.length; i++ ){
  418. // var levelNames = identityList[i][key];
  419. // //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  420. // var unitLevelNameList = levelNames.split("/");
  421. // var nameList = [];
  422. // var tree = unitTree;
  423. // for( var j=0; j<unitLevelNameList.length; j++ ){
  424. // nameList.push( unitLevelNameList[j] );
  425. // var name = nameList.join("/");
  426. // if( !tree[ name ] ){
  427. // tree[ name ] = {
  428. // name : unitLevelNameList[j],
  429. // levelName : name,
  430. // identityList : []
  431. // };
  432. // this.unitArray.push( name );
  433. // }
  434. // tree = tree[name];
  435. // }
  436. // tree.identityList.push( identityList[i] );
  437. // }
  438. // return unitTree;
  439. //},
  440. _scrollEvent: function (y) {
  441. return true;
  442. },
  443. _getChildrenItemIds: function () {
  444. return null;
  445. },
  446. _newItemCategory: function (type, data, selector, item, level, category, delay) {
  447. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit[type](data, selector, item, level, category, delay)
  448. },
  449. _listItemByKey: function (callback, failure, key) {
  450. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  451. this.orgAction.listIdentityByKey(function (json) {
  452. if (callback) callback.apply(this, [json]);
  453. }.bind(this), failure, key);
  454. },
  455. _getItem: function (callback, failure, id, async) {
  456. if (typeOf(id) === "string") {
  457. this.orgAction.getIdentity(function (json) {
  458. if (callback) callback.apply(this, [json]);
  459. }.bind(this), failure, ((typeOf(id) === "string") ? id : id.distinguishedName), async);
  460. } else {
  461. if (callback) callback.apply(this, [id]);
  462. }
  463. //this.orgAction.getIdentity(function(json){
  464. // if (callback) callback.apply(this, [json]);
  465. //}.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  466. },
  467. _newItemSelected: function (data, selector, item, selectedNode) {
  468. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemSelected(data, selector, item, selectedNode)
  469. },
  470. _listItemByPinyin: function (callback, failure, key) {
  471. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  472. this.orgAction.listIdentityByPinyin(function (json) {
  473. if (callback) callback.apply(this, [json]);
  474. }.bind(this), failure, key);
  475. },
  476. _newItem: function (data, selector, container, level, category, delay) {
  477. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Item(data, selector, container, level, category, delay);
  478. },
  479. _newItemSearch: function (data, selector, container, level) {
  480. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.SearchItem(data, selector, container, level);
  481. },
  482. setUnitLevelNameMap: function(){
  483. var map = this.unitLevelNameMap = {};
  484. if (this.isCheckStatusOrCount() && this.allIdentityData.length > 0) {
  485. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  486. this.allIdentityData.each(function(id) {
  487. if (!map[id.distinguishedName]) {
  488. map[id.distinguishedName] = [id[key]];
  489. }else if( !map[id.distinguishedName].contains(id[key]) ){
  490. map[id.distinguishedName].push(id[key]);
  491. }
  492. })
  493. }
  494. },
  495. getUnitLevelNameFormMap: function(id){
  496. return (this.unitLevelNameMap && this.unitLevelNameMap[id.distinguishedName]) || [];
  497. },
  498. addSelectedCount: function( itemOrItemSelected, count ){
  499. if( this.loadingCountInclude === "ignore" ){
  500. this._addSelectedCountWithDuty(itemOrItemSelected, count);
  501. }else{
  502. this._addSelectedCountWithDuty(itemOrItemSelected, count);
  503. this._addSelectedCount(itemOrItemSelected, count);
  504. }
  505. },
  506. _addSelectedCountWithDuty: function( itemOrItemSelected, count ){
  507. var itemData = itemOrItemSelected.data;
  508. var unitlevelNameList = this.getUnitLevelNameFormMap(itemData);
  509. unitlevelNameList.each(function (levelName) {
  510. var subCategoryMap = this.subCategoryMapWithDuty;
  511. var list = levelName.split("/");
  512. var nameList = [];
  513. for (var j = 0; j < list.length; j++) {
  514. nameList.push(list[j]);
  515. var name = nameList.join("/");
  516. if ( subCategoryMap[name] ) {
  517. var category = subCategoryMap[name];
  518. category._addSelectedCount(count);
  519. subCategoryMap = category.subCategoryMapWithDuty;
  520. }
  521. var obj = this.allUnitObjectWithDuty[name];
  522. if (obj) {
  523. obj.selectedNestedIdentityCount = obj.selectedNestedIdentityCount + count;
  524. }
  525. }
  526. }.bind(this));
  527. },
  528. // setUnitLevelNameMapInValues: function(){ //取消选择的时候用
  529. // var map = this.unitLevelNameMapInValues = {};
  530. // if (this.isCheckStatusOrCount() && this.options.values.length > 0) {
  531. // var vMap = {};
  532. // this.options.values.each( function( e ){
  533. // if( !e )return;
  534. // vMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.unique || e.levelName) ] = true;
  535. // }.bind(this));
  536. //
  537. // var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  538. // this.allIdentityData.each(function(id) {
  539. // if (vMap[id.distinguishedName]) {
  540. // if (!map[id.distinguishedName]) {
  541. // map[id.distinguishedName] = [id[key]];
  542. // }else if( !map[id.distinguishedName].contains(id[key]) ){
  543. // map[id.distinguishedName].push(id[key]);
  544. // }
  545. // }else if (vMap[id.unique]) {
  546. // if (!map[id.unique]) {
  547. // map[id.unique] = [id[key]];
  548. // }else if( !map[id.unique].contains(id[key]) ){
  549. // map[id.unique].push(id[key]);
  550. // }
  551. // }else if (vMap[id.levelName]) {
  552. // if (!map[id.levelName]) {
  553. // map[id.levelName] = [id[key]];
  554. // }else if( !map[id.levelName].contains(id[key]) ){
  555. // map[id.levelName].push(id[key]);
  556. // }
  557. // }
  558. // })
  559. // }
  560. // },
  561. // getUnitLevelNameFormValueMap: function(id){
  562. // var map = this.unitLevelNameMapInValues;
  563. // var list = [];
  564. // if( map[id.distinguishedName] )list = list.concat(map[id.distinguishedName]);
  565. // if( map[id.unique] )list = list.concat(map[id.unique]);
  566. // if( map[id.levelName] )list = list.concat(map[id.levelName]);
  567. // return list;
  568. // },
  569. // checkCountAndStatusByUnselectItem: function( itemData ){
  570. // debugger;
  571. // var unitlevelNameList = this.getUnitLevelNameFormValueMap(itemData);
  572. // unitlevelNameList.each(function (levelName) {
  573. // var subCategoryMap = this.subCategoryMap;
  574. // var list = levelName.split("/");
  575. // var nameList = [];
  576. // for (var j = 0; j < list.length; j++) {
  577. // nameList.push(list[j]);
  578. // var name = nameList.join("/");
  579. // if ( subCategoryMap[name] ) {
  580. // var category = subCategoryMap[name];
  581. // category._addSelectedCount(-1);
  582. // subCategoryMap = category.subCategoryMap;
  583. // }
  584. //
  585. // var obj = this.allUnitObjectWithDuty[name];
  586. // if (obj) {
  587. // obj.selectedNestedIdentityCount = obj.selectedNestedIdentityCount - 1;
  588. // }
  589. // }
  590. // }.bind(this));
  591. // }
  592. //_listItemNext: function(last, count, callback){
  593. // this.action.listRoleNext(last, count, function(json){
  594. // if (callback) callback.apply(this, [json]);
  595. // }.bind(this));
  596. //}
  597. });
  598. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Item = new Class({
  599. Extends: MWF.xApplication.Selector.IdentityWidthDuty.Item
  600. });
  601. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.SearchItem = new Class({
  602. Extends: MWF.xApplication.Selector.IdentityWidthDuty.SearchItem
  603. });
  604. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemSelected = new Class({
  605. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected
  606. });
  607. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Class({
  608. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory,
  609. _getShowName: function () {
  610. return this.data.name;
  611. },
  612. _addSelectAllSelectedCount: function (count, nested) {
  613. debugger;
  614. var c = (this._getSelectAllSelectedCount() || 0) + count;
  615. this.selectedCount = c;
  616. this._checkCountAndStatus(c);
  617. if (nested && this.category && this.category._addSelectAllSelectedCount) {
  618. this.category._addSelectAllSelectedCount(count, nested);
  619. }
  620. },
  621. _getSelectAllSelectedCount: function () {
  622. debugger;
  623. if (typeOf(this.selectedCount) === "number") {
  624. return this.selectedCount;
  625. } else {
  626. return 0;
  627. }
  628. },
  629. _addSelectedCount: function (count, nested) {
  630. if( this.selector.loadingCount === "done" ){
  631. var c = (this._getSelectedCount() || 0) + count;
  632. this.selectedCount = c;
  633. this._checkCountAndStatus(c);
  634. }else{
  635. this.selectedCount_wait = (this.selectedCount_wait || 0) + count;
  636. }
  637. if (nested && this.category && this.category._addSelectedCount) {
  638. this.category._addSelectedCount(count, nested);
  639. }
  640. },
  641. _getTotalCount: function () {
  642. return this.data.subNestedIdentityCount;
  643. },
  644. _getSelectedCount : function(){
  645. if( typeOf(this.selectedCount) === "number" )return this.selectedCount;
  646. if( !this.selector.allUnitObjectWithDuty )return 0;
  647. var levelName = this.data.matchLevelName || this.data.levelName;
  648. var unit = this.selector.allUnitObjectWithDuty[levelName];
  649. var count = unit ? unit.selectedNestedIdentityCount : 0;
  650. this.selectedCount = count + (this.selectedCount_wait || 0);
  651. this.selectedCount_wait = 0;
  652. return this.selectedCount;
  653. },
  654. isExisted: function (d) {
  655. if (!d) return true;
  656. if (!this.createdItemObject) this.createdItemObject = {};
  657. var map = this.createdItemObject;
  658. if ((d.distinguishedName && map[d.distinguishedName]) ||
  659. (d.levelName && map[d.levelName]) ||
  660. (d.id && map[d.id]) ||
  661. (d.unique && map[d.unique])) {
  662. return true;
  663. } else {
  664. //if( typeOf( d ) === "string" ){
  665. // this.createdItemObject[ d ] = true;
  666. //}else{
  667. // if( d.distinguishedName )this.createdItemObject[ d.distinguishedName ] = true;
  668. // if( d.id )this.createdItemObject[ d.id ] = true;
  669. // if( d.unique )this.createdItemObject[ d.unique ] = true;
  670. // if( d.employee )this.createdItemObject[ d.employee ] = true;
  671. // if( d.levelName )this.createdItemObject[ d.levelName ] = true;
  672. //}
  673. this.createdItemObject[typeOf(d) === "string" ? d : (d.distinguishedName || d.unique || d.employee || d.levelName || d.id)] = true;
  674. return false;
  675. }
  676. },
  677. sortIdentityList : function(){
  678. if( this.selector.options.identitySortBy === "identityNumber" ){
  679. this.data.identityList.sort(function (a, b) {
  680. //this.selector.getUnitOrderNumber( a.unitLevelName )
  681. if( a.orderNumber === 0 )a.orderNumber = -1;
  682. if( b.orderNumber === 0 )b.orderNumber = -1;
  683. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  684. });
  685. }else{
  686. var getOrderNumber = function (d) {
  687. var orderNumber = "999";
  688. if( d.matchUnitDutyName ){
  689. var idx = this.selector.options.dutys.indexOf( d.matchUnitDutyName );
  690. if( idx > -1 )orderNumber = idx.toString();
  691. }
  692. if( typeOf(d.matchUnitDutyNumber) === "number" ){
  693. orderNumber += d.matchUnitDutyNumber.toString();
  694. }else{
  695. orderNumber += "9999";
  696. }
  697. return orderNumber.toInt();
  698. }.bind(this);
  699. var getOrder = function (d) {
  700. if( d.otherMatchUnitDutyList && d.otherMatchUnitDutyList.length ){
  701. var array = [getOrderNumber(d)];
  702. d.otherMatchUnitDutyList.each(function (duty) {
  703. array.push( getOrderNumber(duty) );
  704. });
  705. return array.min();
  706. }else{
  707. return getOrderNumber(d);
  708. }
  709. }.bind(this);
  710. this.data.identityList.sort(function (a, b) {
  711. return getOrder(a) - getOrder(b);
  712. });
  713. }
  714. },
  715. loadSub: function (callback) {
  716. this._loadSub(function (firstLoad) {
  717. if (firstLoad && this.selector.isCheckStatusOrCount()) {
  718. if (this.selector.loadingCount === "done"){
  719. this.checkCountAndStatus();
  720. }
  721. }
  722. if (callback) callback();
  723. }.bind(this))
  724. },
  725. _loadSub: function (callback) {
  726. if (!this.loaded) {
  727. if (!this.itemLoaded) {
  728. if (this.data.identityList && this.data.identityList.length > 0) {
  729. this.sortIdentityList();
  730. this.data.identityList.each(function (identity) {
  731. // if( !this.selector.isExcluded( identity ) ) {
  732. // if( !this.isExisted( identity ) ){
  733. var item = this.selector._newItem(identity, this.selector, this.children, this.level + 1, this);
  734. this.selector.items.push(item);
  735. if (this.subItems) this.subItems.push(item);
  736. // }
  737. // }
  738. }.bind(this))
  739. }
  740. this.itemLoaded = true;
  741. }
  742. if( !this.categoryLoaded ){
  743. if (this.data.unitList && this.data.unitList.length) {
  744. this.data.unitList.sort(function (a, b) {
  745. if( a.orderNumber === 0 )a.orderNumber = -1;
  746. if( b.orderNumber === 0 )b.orderNumber = -1;
  747. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  748. });
  749. this.data.unitList.each(function (subData) {
  750. // if( !this.selector.isExcluded( subData ) ) {
  751. var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level + 1, this);
  752. this.subCategorys.push(category);
  753. this.subCategoryMapWithDuty[subData.matchLevelName || subData.levelName] = category;
  754. // category.loadSub()
  755. // }
  756. }.bind(this));
  757. }
  758. this.categoryLoaded = true;
  759. }
  760. this.loaded = true;
  761. if (callback) callback(true);
  762. } else {
  763. if (callback) callback();
  764. }
  765. },
  766. loadCategoryChildren: function (callback) {
  767. if (!this.categoryLoaded) {
  768. this.loadSub();
  769. this.categoryLoaded = true;
  770. this.itemLoaded = true;
  771. if (callback) callback();
  772. } else {
  773. if (callback) callback();
  774. }
  775. },
  776. loadItemChildren: function (callback) {
  777. if (!this.itemLoaded) {
  778. if (this.data.identityList && this.data.identityList.length > 0) {
  779. // this.data.identityList.sort(function (a, b) {
  780. // if( a.orderNumber === 0 )a.orderNumber = -1;
  781. // if( b.orderNumber === 0 )b.orderNumber = -1;
  782. // return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  783. // });
  784. this.sortIdentityList();
  785. this.data.identityList.each(function (identity) {
  786. // if( !this.selector.isExcluded( identity ) ) {
  787. // if( !this.isExisted( identity ) ){
  788. var item = this.selector._newItem(identity, this.selector, this.children, this.level + 1, this);
  789. this.selector.items.push(item);
  790. if (this.subItems) this.subItems.push(item);
  791. // }
  792. // }
  793. }.bind(this))
  794. }
  795. this.itemLoaded = true;
  796. if (callback) callback();
  797. } else {
  798. if (callback) callback();
  799. }
  800. },
  801. _hasChild: function () {
  802. return (this.data.unitList && this.data.unitList.length > 0) ||
  803. (this.data.identityList && this.data.identityList.length > 0);
  804. },
  805. _hasChildCategory: function () {
  806. return (this.data.unitList && this.data.unitList.length > 0);
  807. },
  808. _hasChildItem: function () {
  809. return this.data.identityList && this.data.identityList.length > 0;
  810. }
  811. });
  812. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemUnitCategory = new Class({
  813. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory
  814. });
  815. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemGroupCategory = new Class({
  816. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemGroupCategory
  817. });
  818. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Filter = new Class({
  819. Extends: MWF.xApplication.Selector.IdentityWidthDuty.Filter
  820. });