IdentityWidthDutyCategoryByUnit.js 27 KB

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