IdentityWidthDutyCategoryByUnit.js 27 KB

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