IdentityWidthDutyCategoryByUnit.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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": 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. "dutyUnitLevelBy": "duty", //组织层级是按身份所在群组还是职务,
  21. "selectType": "identity"
  22. },
  23. _init: function () {
  24. this.selectType = "identity";
  25. this.className = "IdentityWidthDutyCategoryByUnit";
  26. },
  27. // loadSelectItems: function (addToNext) {
  28. // //根据组织分类展现职务
  29. // if (this.options.resultType === "person") {
  30. // if (this.titleTextNode) {
  31. // this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson);
  32. // } else {
  33. // this.options.title = MWF.xApplication.Selector.LP.selectPerson;
  34. // }
  35. // }
  36. // if (this.options.disabled) {
  37. // this.afterLoadSelectItem();
  38. // return;
  39. // }
  40. //
  41. // if (this.options.dutys.length) {
  42. // this.loadInclude(function () {
  43. // this.includeLoaded = true;
  44. // if (this.dutyLoaded) {
  45. // this.afterLoadSelectItem();
  46. // }
  47. // }.bind(this));
  48. // if (this.options.units.length) {
  49. //
  50. // var units = [];
  51. // for (var i = 0; i < this.options.units.length; i++) {
  52. // var unit = this.options.units[i];
  53. // if (typeOf(unit) === "string") {
  54. // units.push(unit)
  55. // } else {
  56. // units.push(unit.distinguishedName || unit.unique || unit.id || unit.levelName)
  57. // }
  58. // }
  59. // this.unitStringList = units;
  60. //
  61. // var getAllIdentity = function (unitList) {
  62. // o2.Actions.load("x_organization_assemble_express").UnitDutyAction.listIdentityWithUnitWithNameObject({
  63. // nameList: this.options.dutys,
  64. // unitList: unitList
  65. // }, function (json) {
  66. // this._loadSelectItems(json.data)
  67. // }.bind(this))
  68. // }.bind(this);
  69. //
  70. // if (this.options.expandSubEnable) {
  71. // o2.Actions.load("x_organization_assemble_express").UnitAction.listWithUnitSubNested({
  72. // unitList: units
  73. // }, function (json) {
  74. // getAllIdentity(units.combine(json.data ? json.data.unitList : []));
  75. // }.bind(this))
  76. // } else {
  77. // getAllIdentity(units);
  78. // }
  79. // } else {
  80. // var identityList = [];
  81. // var count = 0;
  82. // this.options.dutys.each(function (d) {
  83. // this.orgAction.listIdentityWithDuty(function (json) {
  84. // count++;
  85. // identityList = identityList.combine(json.data);
  86. // if (this.options.dutys.length === count) this._loadSelectItems(identityList);
  87. // }.bind(this), function () {
  88. // count++;
  89. // if (this.options.dutys.length === count) this._loadSelectItems(identityList);
  90. // }.bind(this), d);
  91. // }.bind(this));
  92. // }
  93. // }
  94. // },
  95. getUnitUniqueFormDn : function(dn){
  96. if(!dn)return "";
  97. var arr = dn.split("@");
  98. if( arr.length === 3 )return arr[1];
  99. return dn;
  100. },
  101. loadSelectItems: function (addToNext) {
  102. //根据组织分类展现职务
  103. if (this.options.resultType === "person") {
  104. if (this.titleTextNode) {
  105. this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson);
  106. } else {
  107. this.options.title = MWF.xApplication.Selector.LP.selectPerson;
  108. }
  109. }
  110. if (this.options.disabled) {
  111. this.afterLoadSelectItem();
  112. return;
  113. }
  114. if (this.options.dutys.length) {
  115. this.loadInclude(function () {
  116. this.includeLoaded = true;
  117. if (this.dutyLoaded) {
  118. this.afterLoadSelectItem();
  119. }
  120. }.bind(this));
  121. var units = [];
  122. var unitUniques = [];
  123. for (var i = 0; i < this.options.units.length; i++) {
  124. var unit = this.options.units[i];
  125. if (typeOf(unit) === "string") {
  126. units.push(unit);
  127. unitUniques.push( this.getUnitUniqueFormDn(unit) );
  128. } else {
  129. units.push(unit.distinguishedName || unit.unique || unit.id || unit.levelName);
  130. unitUniques.push( unit.distinguishedName ? this.getUnitUniqueFormDn(unit.distinguishedName) : (unit.unique || unit.id || unit.levelName) );
  131. }
  132. }
  133. this.unitStringList = units;
  134. this.unitUniqueList = unitUniques;
  135. o2.Actions.load("x_organization_assemble_express").UnitDutyAction.listIdentityWithUnitWithNameObject({
  136. nameList: this.options.dutys,
  137. unitList: units,
  138. recursiveUnit : !!this.options.expandSubEnable
  139. }, function (json) {
  140. this.allIdentityData = json.data;
  141. this._loadSelectItems(json.data)
  142. }.bind(this))
  143. }else{
  144. this.afterLoadSelectItem();
  145. }
  146. },
  147. _loadSelectItems: function (identityList) {
  148. //this.listAllIdentityInUnitObject( identityList );
  149. var unitTree = this.listNestedUnitByIdentity(identityList);
  150. this.uniqueIdentity(unitTree);
  151. if (this.options.dutyUnitLevelBy === "duty") {
  152. this.level1Container = [];
  153. if (this.options.units && this.options.units.length) {
  154. this.options.units.each( function (unit ,i) {
  155. var div = new Element("div").inject(this.itemAreaNode);
  156. this.level1Container.push(div);
  157. }.bind(this))
  158. }
  159. this._loadSelectItemsByDutyUnit(unitTree);
  160. } else {
  161. this._loadSelectItemsByIdentityUnit(unitTree);
  162. }
  163. this.dutyLoaded = true;
  164. if (this.includeLoaded) {
  165. this.afterLoadSelectItem();
  166. }
  167. },
  168. _loadSelectItemsByIdentityUnit: function (unitTree) {
  169. if (!unitTree.unitList) return;
  170. this.sortUnit(unitTree.unitList);
  171. for (var i = 0; i < unitTree.unitList.length; i++) {
  172. var unit = unitTree.unitList[i];
  173. // if( !this.isExcluded( unit ) ) {
  174. var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode);
  175. this.subCategorys.push(category);
  176. // }
  177. }
  178. },
  179. sortUnit: function (unitList) {
  180. if (this.options.dutyUnitLevelBy === "duty") {
  181. if (this.options.units) {
  182. unitList.sort(function (a, b) {
  183. var idxA = this.getIndexFromUnitOption(a);
  184. var idxB = this.getIndexFromUnitOption(b);
  185. if( a.orderNumber === 0 )a.orderNumber = -1;
  186. if( b.orderNumber === 0 )b.orderNumber = -1;
  187. idxA = idxA === -1 ? 9999999 + (a.orderNumber || 9999999) : idxA;
  188. idxB = idxB === -1 ? 9999999 + (b.orderNumber || 9999999) : idxB;
  189. return idxA - idxB;
  190. }.bind(this))
  191. } else {
  192. unitList.sort(function (a, b) {
  193. if( a.orderNumber === 0 )a.orderNumber = -1;
  194. if( b.orderNumber === 0 )b.orderNumber = -1;
  195. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  196. }.bind(this))
  197. }
  198. } else {
  199. unitList.sort(function (a, b) {
  200. if( a.orderNumber === 0 )a.orderNumber = -1;
  201. if( b.orderNumber === 0 )b.orderNumber = -1;
  202. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  203. }.bind(this))
  204. }
  205. },
  206. _loadSelectItemsByDutyUnit: function (unitTree) {
  207. if (!unitTree.unitList) return;
  208. // this.sortUnit( unitTree.unitList );
  209. for (var i = 0; i < unitTree.unitList.length; i++) {
  210. var unit = unitTree.unitList[i];
  211. if (this.isUnitContain(unit)) {
  212. // if( !this.isExcluded( unit ) ) {
  213. var container = this.itemAreaNode;
  214. if (this.level1Container && this.level1Container.length) {
  215. var index = this.getIndexFromUnitOption(unit);
  216. if (index > -1 && (this.level1Container.length > index) && this.level1Container[index]) container = this.level1Container[index];
  217. }
  218. var category = this._newItemCategory("ItemCategory", unit, this, container);
  219. this.subCategorys.push(category);
  220. // }
  221. } else {
  222. this._loadSelectItemsByDutyUnit(unit);
  223. }
  224. }
  225. },
  226. getIndexFromUnitOption: function (unit) {
  227. if (!this.unitStringList || !this.unitStringList.length) return -1;
  228. var idx = -1;
  229. if (idx == -1 && unit.distinguishedName) idx = this.unitStringList.indexOf(unit.distinguishedName);
  230. if (idx == -1 && unit.id) idx = this.unitStringList.indexOf(unit.id);
  231. if (idx == -1 && unit.unique) idx = this.unitStringList.indexOf(unit.unique);
  232. if (idx == -1 && unit.levelName) idx = this.unitStringList.indexOf(unit.levelName);
  233. if (idx == -1 && unit.unique ) idx = this.unitUniqueList.indexOf(unit.unique);
  234. if (idx == -1 && !unit.unique && unit.distinguishedName ) idx = this.unitUniqueList.indexOf(unit.distinguishedName.split("@")[1]||"");
  235. return idx
  236. },
  237. isUnitContain: function (d) {
  238. if (this.options.units.length === 0) return true;
  239. if (!this.unitFlagMap) {
  240. this.unitFlagMap = {};
  241. this.options.units.each(function (e) {
  242. if (!e) return;
  243. this.unitFlagMap[typeOf(e) === "string" ? e : (e.distinguishedName || e.id || e.unique || e.employee || e.levelName)] = true;
  244. }.bind(this));
  245. }
  246. if (!this.unitUniqueMap) {
  247. this.unitUniqueMap = {};
  248. this.unitUniqueList.each(function (e) {
  249. if (!e) return;
  250. this.unitUniqueMap[e] = true;
  251. }.bind(this));
  252. }
  253. var map = this.unitFlagMap;
  254. var uniqueMap = this.unitUniqueMap;
  255. var flag = (d.distinguishedName && map[d.distinguishedName]) ||
  256. (d.levelName && map[d.levelName]) ||
  257. (d.id && map[d.id]) ||
  258. (d.unique && map[d.unique]) ||
  259. (d.unique && uniqueMap[d.unique]);
  260. if( !flag && !d.unique && d.distinguishedName ){
  261. var arr = d.distinguishedName.split("@");
  262. if( arr.length === 3 && arr[1] && uniqueMap[arr[1]] ){
  263. flag = true;
  264. }
  265. }
  266. return flag;
  267. },
  268. // listAllIdentityInUnitObject: function () {
  269. // var unitArray = [];
  270. // for (var i = 0; i < identityList.length; i++) {
  271. // unitArray.push(identityList[i].unit || identityList[i].unitLevelName);
  272. // }
  273. // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  274. // unitList: unitArray
  275. // }, function (json) {
  276. // this.allIdentityInUnitObject = {};
  277. // json.data.each(function (u) {
  278. // this.allIdentityInUnitObject[u.levelName] = u;
  279. // }.bind(this));
  280. // if (callback) callback();
  281. // }.bind(this), null, false)
  282. // },
  283. getUnitOrderNumber: function (unit) {
  284. return this.allIdentityInUnitObject[unit.levelName].orderNumber;
  285. },
  286. listAllUnitObject: function (identityList, callback) {
  287. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  288. var unitArray = [];
  289. for (var i = 0; i < identityList.length; i++) {
  290. var levelNames = identityList[i][key];
  291. //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  292. var unitLevelNameList = levelNames.split("/");
  293. var nameList = [];
  294. for (var j = 0; j < unitLevelNameList.length; j++) {
  295. nameList.push(unitLevelNameList[j]);
  296. var name = nameList.join("/");
  297. if (!unitArray.contains(name)) {
  298. unitArray.push(name);
  299. }
  300. }
  301. }
  302. o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({
  303. unitList: unitArray
  304. }, function (json) {
  305. this.allUnitObject = {};
  306. json.data.each(function (u) {
  307. this.allUnitObject[u.levelName] = u;
  308. }.bind(this));
  309. if (callback) callback();
  310. }.bind(this), null, false)
  311. },
  312. listNestedUnitByIdentity: function (identityList) {
  313. this.listAllUnitObject(identityList);
  314. return this._listNestedUnitByIdentity(identityList);
  315. },
  316. _listNestedUnitByIdentity: function (identityList) {
  317. debugger;
  318. //identityList = Array.unique(identityList);
  319. var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  320. //根据unitLevelName整合成组织树
  321. var unitTree = {};
  322. for (var i = 0; i < identityList.length; i++) {
  323. var flag = true;
  324. if (this.isExcluded(identityList[i])) continue;
  325. var levelNames = identityList[i][key];
  326. //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  327. var unitLevelNameList = levelNames.split("/");
  328. var nameList = [];
  329. var tree = unitTree;
  330. for (var j = 0; j < unitLevelNameList.length; j++) {
  331. nameList.push(unitLevelNameList[j]);
  332. var name = nameList.join("/");
  333. if (this.isExcluded(this.allUnitObject[name] || {})) {
  334. flag = false;
  335. break;
  336. }
  337. if (!tree.unitList) tree.unitList = [];
  338. var found = false;
  339. for (var k = 0; k < tree.unitList.length; k++) {
  340. if (tree.unitList[k].levelName == name) {
  341. tree = tree.unitList[k];
  342. found = true;
  343. break;
  344. }
  345. }
  346. if (!found) {
  347. // var obj = {};
  348. var obj = this.allUnitObject[name] || {};
  349. obj.matchLevelName = name;
  350. tree.unitList.push(obj);
  351. tree = obj;
  352. }
  353. // if( !tree.distinguishedName ){
  354. // tree = Object.merge( tree, this.allUnitObject[name] );
  355. // }
  356. if (!tree.identityList) tree.identityList = [];
  357. }
  358. if (flag) tree.identityList.push(identityList[i]);
  359. }
  360. return unitTree;
  361. },
  362. uniqueIdentity: function (tree) {
  363. var map = {};
  364. var isExist = function (d) {
  365. if ((d.distinguishedName && map[d.distinguishedName]) ||
  366. (d.levelName && map[d.levelName]) ||
  367. (d.id && map[d.id]) ||
  368. (d.unique && map[d.unique])) {
  369. return true;
  370. } else {
  371. map[typeOf(d) === "string" ? d : (d.distinguishedName || d.id || d.unique || d.employee || d.levelName)] = true;
  372. return false;
  373. }
  374. };
  375. var identityList = [];
  376. if (tree.identityList) {
  377. for (var i = 0; i < tree.identityList.length; i++) {
  378. if (!isExist(tree.identityList[i])) identityList.push(tree.identityList[i]);
  379. }
  380. }
  381. tree.identityList = identityList;
  382. if (this.options.isCheckStatus) {
  383. var names = (tree.matchLevelName || tree.levelName || "").split("/");
  384. var nameList = [];
  385. for (var i = 0; i < names.length; i++) {
  386. nameList.push(names[i]);
  387. var name = nameList.join("/");
  388. var obj = this.allUnitObject[name];
  389. if (obj) {
  390. obj.subNestedIdentityCount = (obj.subNestedIdentityCount || 0) + identityList.length;
  391. }
  392. }
  393. }
  394. if (tree.unitList) {
  395. for (var i = 0; i < tree.unitList.length; i++) {
  396. this.uniqueIdentity(tree.unitList[i]);
  397. }
  398. }
  399. },
  400. //listNestedUnitByIdentity : function( identityList ){
  401. // debugger;
  402. // this.unitArray = [];
  403. // var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName";
  404. // //根据unitLevelName整合成组织树
  405. // var unitTree = {};
  406. // for( var i=0; i<identityList.length; i++ ){
  407. // var levelNames = identityList[i][key];
  408. // //if( !levelNames && key === "matchUnitLevelName" )levelNames = identityList[i].unitLevelName;
  409. // var unitLevelNameList = levelNames.split("/");
  410. // var nameList = [];
  411. // var tree = unitTree;
  412. // for( var j=0; j<unitLevelNameList.length; j++ ){
  413. // nameList.push( unitLevelNameList[j] );
  414. // var name = nameList.join("/");
  415. // if( !tree[ name ] ){
  416. // tree[ name ] = {
  417. // name : unitLevelNameList[j],
  418. // levelName : name,
  419. // identityList : []
  420. // };
  421. // this.unitArray.push( name );
  422. // }
  423. // tree = tree[name];
  424. // }
  425. // tree.identityList.push( identityList[i] );
  426. // }
  427. // return unitTree;
  428. //},
  429. _scrollEvent: function (y) {
  430. return true;
  431. },
  432. _getChildrenItemIds: function () {
  433. return null;
  434. },
  435. _newItemCategory: function (type, data, selector, item, level, category, delay) {
  436. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit[type](data, selector, item, level, category, delay)
  437. },
  438. _listItemByKey: function (callback, failure, key) {
  439. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  440. this.orgAction.listIdentityByKey(function (json) {
  441. if (callback) callback.apply(this, [json]);
  442. }.bind(this), failure, key);
  443. },
  444. _getItem: function (callback, failure, id, async) {
  445. if (typeOf(id) === "string") {
  446. this.orgAction.getIdentity(function (json) {
  447. if (callback) callback.apply(this, [json]);
  448. }.bind(this), failure, ((typeOf(id) === "string") ? id : id.distinguishedName), async);
  449. } else {
  450. if (callback) callback.apply(this, [id]);
  451. }
  452. //this.orgAction.getIdentity(function(json){
  453. // if (callback) callback.apply(this, [json]);
  454. //}.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  455. },
  456. _newItemSelected: function (data, selector, item, selectedNode) {
  457. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemSelected(data, selector, item, selectedNode)
  458. },
  459. _listItemByPinyin: function (callback, failure, key) {
  460. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  461. this.orgAction.listIdentityByPinyin(function (json) {
  462. if (callback) callback.apply(this, [json]);
  463. }.bind(this), failure, key);
  464. },
  465. _newItem: function (data, selector, container, level, category, delay) {
  466. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Item(data, selector, container, level, category, delay);
  467. },
  468. _newItemSearch: function (data, selector, container, level) {
  469. return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.SearchItem(data, selector, container, level);
  470. }
  471. //_listItemNext: function(last, count, callback){
  472. // this.action.listRoleNext(last, count, function(json){
  473. // if (callback) callback.apply(this, [json]);
  474. // }.bind(this));
  475. //}
  476. });
  477. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Item = new Class({
  478. Extends: MWF.xApplication.Selector.IdentityWidthDuty.Item
  479. });
  480. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.SearchItem = new Class({
  481. Extends: MWF.xApplication.Selector.IdentityWidthDuty.SearchItem
  482. });
  483. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemSelected = new Class({
  484. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected
  485. });
  486. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Class({
  487. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory,
  488. _getShowName: function () {
  489. return this.data.name;
  490. },
  491. _addSelectedCount: function (count, nested) {
  492. debugger;
  493. var c = (this._getSelectedCount() || 0) + count;
  494. this.selectedCount = c;
  495. this.checkCountAndStatus(c);
  496. if (nested && this.category && this.category._addSelectedCount) {
  497. this.category._addSelectedCount(count, nested);
  498. }
  499. },
  500. // _getSelectedCount : function(){
  501. // var list = this.subItems.filter( function (item) { return item.isSelected; });
  502. // return list.length;
  503. // },
  504. _getTotalCount: function () {
  505. return this.data.subNestedIdentityCount;
  506. },
  507. _getSelectedCount: function () {
  508. debugger;
  509. if (typeOf(this.selectedCount) === "number") {
  510. return this.selectedCount;
  511. } else {
  512. return 0;
  513. }
  514. },
  515. _checkStatus: function () {
  516. },
  517. isExisted: function (d) {
  518. if (!d) return true;
  519. if (!this.createdItemObject) this.createdItemObject = {};
  520. var map = this.createdItemObject;
  521. if ((d.distinguishedName && map[d.distinguishedName]) ||
  522. (d.levelName && map[d.levelName]) ||
  523. (d.id && map[d.id]) ||
  524. (d.unique && map[d.unique])) {
  525. return true;
  526. } else {
  527. //if( typeOf( d ) === "string" ){
  528. // this.createdItemObject[ d ] = true;
  529. //}else{
  530. // if( d.distinguishedName )this.createdItemObject[ d.distinguishedName ] = true;
  531. // if( d.id )this.createdItemObject[ d.id ] = true;
  532. // if( d.unique )this.createdItemObject[ d.unique ] = true;
  533. // if( d.employee )this.createdItemObject[ d.employee ] = true;
  534. // if( d.levelName )this.createdItemObject[ d.levelName ] = true;
  535. //}
  536. this.createdItemObject[typeOf(d) === "string" ? d : (d.distinguishedName || d.id || d.unique || d.employee || d.levelName)] = true;
  537. return false;
  538. }
  539. },
  540. loadSub: function (callback) {
  541. this._loadSub(function (firstLoad) {
  542. if (firstLoad && (this.selector.options.showSelectedCount || this.selector.options.isCheckStatus)) {
  543. var count = 0;
  544. this.subCategorys.each(function (category) {
  545. var l = category.subItems.filter(function (item) {
  546. return item.isSelected;
  547. });
  548. count = count + l.length;
  549. });
  550. var list = this.subItems.filter(function (item) {
  551. return item.isSelected;
  552. });
  553. this.selectedCount = count + list.length;
  554. this.checkCountAndStatus(this.selectedCount);
  555. }
  556. if (callback) callback();
  557. }.bind(this))
  558. },
  559. _loadSub: function (callback) {
  560. if (!this.loaded) {
  561. if (!this.itemLoaded) {
  562. if (this.data.identityList && this.data.identityList.length > 0) {
  563. this.data.identityList.sort(function (a, b) {
  564. //this.selector.getUnitOrderNumber( a.unitLevelName )
  565. if( a.orderNumber === 0 )a.orderNumber = -1;
  566. if( b.orderNumber === 0 )b.orderNumber = -1;
  567. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  568. });
  569. this.data.identityList.each(function (identity) {
  570. // if( !this.selector.isExcluded( identity ) ) {
  571. // if( !this.isExisted( identity ) ){
  572. var item = this.selector._newItem(identity, this.selector, this.children, this.level + 1, this);
  573. this.selector.items.push(item);
  574. if (this.subItems) this.subItems.push(item);
  575. // }
  576. // }
  577. }.bind(this))
  578. }
  579. this.itemLoaded = true;
  580. }
  581. if( !this.categoryLoaded ){
  582. if (this.data.unitList && this.data.unitList.length) {
  583. this.data.unitList.sort(function (a, b) {
  584. if( a.orderNumber === 0 )a.orderNumber = -1;
  585. if( b.orderNumber === 0 )b.orderNumber = -1;
  586. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  587. });
  588. this.data.unitList.each(function (subData) {
  589. // if( !this.selector.isExcluded( subData ) ) {
  590. var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level + 1, this);
  591. this.subCategorys.push(category);
  592. // category.loadSub()
  593. // }
  594. }.bind(this));
  595. }
  596. this.categoryLoaded = true;
  597. }
  598. this.loaded = true;
  599. if (callback) callback(true);
  600. } else {
  601. if (callback) callback();
  602. }
  603. },
  604. loadCategoryChildren: function (callback) {
  605. if (!this.categoryLoaded) {
  606. this.loadSub();
  607. this.categoryLoaded = true;
  608. this.itemLoaded = true;
  609. if (callback) callback();
  610. } else {
  611. if (callback) callback();
  612. }
  613. },
  614. loadItemChildren: function (callback) {
  615. if (!this.itemLoaded) {
  616. if (this.data.identityList && this.data.identityList.length > 0) {
  617. this.data.identityList.sort(function (a, b) {
  618. //this.selector.getUnitOrderNumber( a.unitLevelName )
  619. if( a.orderNumber === 0 )a.orderNumber = -1;
  620. if( b.orderNumber === 0 )b.orderNumber = -1;
  621. return (a.orderNumber || 9999999) - (b.orderNumber || 9999999);
  622. });
  623. this.data.identityList.each(function (identity) {
  624. // if( !this.selector.isExcluded( identity ) ) {
  625. // if( !this.isExisted( identity ) ){
  626. var item = this.selector._newItem(identity, this.selector, this.children, this.level + 1, this);
  627. this.selector.items.push(item);
  628. if (this.subItems) this.subItems.push(item);
  629. // }
  630. // }
  631. }.bind(this))
  632. }
  633. this.itemLoaded = true;
  634. if (callback) callback();
  635. } else {
  636. if (callback) callback();
  637. }
  638. },
  639. _hasChild: function () {
  640. return (this.data.unitList && this.data.unitList.length > 0) ||
  641. (this.data.identityList && this.data.identityList.length > 0);
  642. },
  643. _hasChildCategory: function () {
  644. return (this.data.unitList && this.data.unitList.length > 0);
  645. },
  646. _hasChildItem: function () {
  647. return this.data.identityList && this.data.identityList.length > 0;
  648. }
  649. });
  650. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemUnitCategory = new Class({
  651. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory
  652. });
  653. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemGroupCategory = new Class({
  654. Extends: MWF.xApplication.Selector.IdentityWidthDuty.ItemGroupCategory
  655. });
  656. MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.Filter = new Class({
  657. Extends: MWF.xApplication.Selector.IdentityWidthDuty.Filter
  658. });