IdentityWidthDutyCategoryByUnit.js 27 KB

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