IdentityWidthDutyCategoryByUnit.js 26 KB

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