IdentityWidthDutyCategoryByUnit.js 31 KB

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