IdentityWidthDuty.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Identity", null, false);
  3. MWF.xApplication.Selector.IdentityWidthDuty = new Class({
  4. Extends: MWF.xApplication.Selector.Identity,
  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. },
  21. loadSelectItems: function(addToNext){
  22. if( this.options.resultType === "person" ){
  23. if( this.titleTextNode ){
  24. this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson );
  25. }else{
  26. this.options.title = MWF.xApplication.Selector.LP.selectPerson;
  27. }
  28. }
  29. if (this.options.dutys.length){
  30. this.loadInclude();
  31. this.options.dutys.each(function(duty){
  32. var data = {"name": duty, "id":duty};
  33. var category = this._newItemCategory("ItemCategory",data, this, this.itemAreaNode);
  34. this.subCategorys.push(category);
  35. //category.loadSub();
  36. //category.clickItem();
  37. // this.action.getUnitduty(function(dutyData){
  38. // var category = this._newItemCategory("ItemCategory", dutyData.data, this, this.itemAreaNode);
  39. // }.bind(this), null, duty);
  40. }.bind(this));
  41. }
  42. },
  43. search: function(){
  44. var key = this.searchInput.get("value");
  45. if (key){
  46. this.initSearchArea(true);
  47. var createdId = this.searchInItems(key) || [];
  48. if( this.options.include && this.options.include.length ){
  49. this.includeObject.listByFilter( "key", key, function( array ){
  50. array.each( function(d){
  51. if( !createdId.contains( d.distinguishedName ) ){
  52. this._newItem( d, this, this.itemSearchAreaNode);
  53. }
  54. }.bind(this))
  55. }.bind(this))
  56. }
  57. }else{
  58. this.initSearchArea(false);
  59. }
  60. },
  61. listPersonByPinyin: function(node){
  62. this.searchInput.focus();
  63. var pinyin = this.searchInput.get("value");
  64. pinyin = pinyin+node.get("text");
  65. this.searchInput.set("value", pinyin);
  66. this.search();
  67. },
  68. checkLoadSelectItems: function(){
  69. if (!this.options.units.length){
  70. this.loadSelectItems();
  71. }else{
  72. this.loadSelectItems();
  73. }
  74. },
  75. _scrollEvent: function(y){
  76. return true;
  77. },
  78. _getChildrenItemIds: function(){
  79. return null;
  80. },
  81. _newItemCategory: function(type, data, selector, item, level, category){
  82. return new MWF.xApplication.Selector.IdentityWidthDuty[type](data, selector, item, level, category)
  83. },
  84. _listItemByKey: function(callback, failure, key){
  85. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  86. this.orgAction.listIdentityByKey(function(json){
  87. if (callback) callback.apply(this, [json]);
  88. }.bind(this), failure, key);
  89. },
  90. _getItem: function(callback, failure, id, async){
  91. this.orgAction.getIdentity(function(json){
  92. if (callback) callback.apply(this, [json]);
  93. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  94. },
  95. _newItemSelected: function(data, selector, item){
  96. return new MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected(data, selector, item)
  97. },
  98. _listItemByPinyin: function(callback, failure, key){
  99. if (this.options.units.length) key = {"key": key, "unitList": this.options.units};
  100. this.orgAction.listIdentityByPinyin(function(json){
  101. if (callback) callback.apply(this, [json]);
  102. }.bind(this), failure, key);
  103. },
  104. _newItem: function(data, selector, container, level, category){
  105. return new MWF.xApplication.Selector.IdentityWidthDuty.Item(data, selector, container, level, category);
  106. },
  107. _newItemSearch: function(data, selector, container, level){
  108. return new MWF.xApplication.Selector.IdentityWidthDuty.SearchItem(data, selector, container, level);
  109. }
  110. //_listItemNext: function(last, count, callback){
  111. // this.action.listRoleNext(last, count, function(json){
  112. // if (callback) callback.apply(this, [json]);
  113. // }.bind(this));
  114. //}
  115. });
  116. MWF.xApplication.Selector.IdentityWidthDuty.Item = new Class({
  117. Extends: MWF.xApplication.Selector.Identity.Item,
  118. _getShowName: function(){
  119. return this.data.name;
  120. },
  121. _getTtiteText: function(){
  122. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  123. },
  124. _setIcon: function(){
  125. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  126. }
  127. });
  128. MWF.xApplication.Selector.IdentityWidthDuty.SearchItem = new Class({
  129. Extends: MWF.xApplication.Selector.Identity.Item,
  130. _getShowName: function(){
  131. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  132. }
  133. });
  134. MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected = new Class({
  135. Extends: MWF.xApplication.Selector.Identity.ItemSelected,
  136. _getShowName: function(){
  137. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  138. },
  139. _getTtiteText: function(){
  140. return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : "");
  141. },
  142. _setIcon: function(){
  143. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  144. }
  145. });
  146. MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory = new Class({
  147. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  148. createNode: function(){
  149. this.node = new Element("div", {
  150. "styles": this.selector.css.selectorItemCategory_department
  151. }).inject(this.container);
  152. },
  153. _getShowName: function(){
  154. return this.data.name;
  155. },
  156. _setIcon: function(){
  157. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/companyicon.png)");
  158. },
  159. clickItem: function( callback ){
  160. if (this._hasChild()){
  161. var firstLoaded = !this.loaded;
  162. this.loadSub(function(){
  163. if( firstLoaded ){
  164. this.children.setStyles({"display": "block", "height": "auto"});
  165. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  166. }else{
  167. var display = this.children.getStyle("display");
  168. if (display === "none"){
  169. this.children.setStyles({"display": "block", "height": "auto"});
  170. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  171. }else{
  172. this.children.setStyles({"display": "none", "height": "0px"});
  173. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  174. }
  175. }
  176. if(callback)callback();
  177. }.bind(this));
  178. }
  179. },
  180. loadSub: function(callback){
  181. if (!this.loaded){
  182. if (this.selector.options.units.length){
  183. var action = MWF.Actions.get("x_organization_assemble_express");
  184. var data = {"name":this.data.name, "unit":""};
  185. var count = this.selector.options.units.length;
  186. var i = 0;
  187. if (this.selector.options.expandSubEnable) {
  188. this.selector.options.units.each(function(u){
  189. var unitName = ""
  190. if (typeOf(u)==="string"){
  191. unitName = u;
  192. }else{
  193. unitName = u.distinguishedName || u.unique || u.id || u.levelName
  194. }
  195. if (unitName){
  196. var unitNames;
  197. action.listUnitNameSubNested({"unitList": [unitName]}, function(json){
  198. unitNames = json.data.unitList;
  199. }.bind(this), null, false);
  200. unitNames.push(unitName);
  201. if (unitNames && unitNames.length){
  202. data.unitList = unitNames;
  203. action.getDuty(data, function(json){
  204. json.data.each(function(idSubData){
  205. if( !this.selector.isExcluded( idSubData ) ) {
  206. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  207. this.selector.items.push(item);
  208. if(this.subItems)this.subItems.push( item );
  209. }
  210. }.bind(this));
  211. }.bind(this), null, false);
  212. }
  213. }
  214. i++;
  215. if (i>=count){
  216. if (!this.loaded) {
  217. this.loaded = true;
  218. if (callback) callback();
  219. }
  220. }
  221. }.bind(this));
  222. }else{
  223. this.selector.options.units.each(function(u){
  224. if (typeOf(u)==="string"){
  225. data.unit = u;
  226. }else{
  227. data.unit = u.distinguishedName || u.unique || u.id || u.levelName
  228. }
  229. action.getDuty(data, function(json){
  230. json.data.each(function(idSubData){
  231. if( !this.selector.isExcluded( idSubData ) ) {
  232. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  233. this.selector.items.push(item);
  234. if(this.subItems)this.subItems.push( item );
  235. }
  236. }.bind(this));
  237. i++;
  238. if (i>=count){
  239. if (!this.loaded) {
  240. this.loaded = true;
  241. if (callback) callback();
  242. }
  243. }
  244. }.bind(this));
  245. }.bind(this));
  246. }
  247. //if (callback) callback();
  248. }else{
  249. this.selector.orgAction.listIdentityWithDuty(function(json){
  250. json.data.each(function(idSubData){
  251. if( !this.selector.isExcluded( idSubData ) ) {
  252. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  253. this.selector.items.push(item);
  254. if(this.subItems)this.subItems.push( item );
  255. }
  256. }.bind(this));
  257. this.loaded = true;
  258. if (callback) callback();
  259. }.bind(this), null, this.data.name);
  260. }
  261. }else{
  262. if (callback) callback( );
  263. }
  264. },
  265. _hasChild: function(){
  266. return true;
  267. },
  268. _hasChildItem: function(){
  269. return true;
  270. }
  271. });
  272. MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory = new Class({
  273. Extends: MWF.xApplication.Selector.Identity.ItemUnitCategory,
  274. loadSub: function(callback){
  275. if (!this.loaded){
  276. this.selector.orgAction.listIdentityWithUnit(function(idJson){
  277. idJson.data.each(function(idSubData){
  278. if( !this.selector.isExcluded( idSubData ) ) {
  279. var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this);
  280. this.selector.items.push(item);
  281. if(this.subItems)this.subItems.push( item );
  282. }
  283. if( !this.selector.options.expandSubEnable ){
  284. this.loaded = true;
  285. if (callback) callback();
  286. }
  287. }.bind(this));
  288. if( this.selector.options.expandSubEnable ){
  289. this.selector.orgAction.listSubUnitDirect(function(json){
  290. json.data.each(function(subData){
  291. if( !this.selector.isExcluded( subData ) ) {
  292. var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this);
  293. this.subCategorys.push( category );
  294. }
  295. }.bind(this));
  296. this.loaded = true;
  297. if (callback) callback();
  298. }.bind(this), null, this.data.distinguishedName);
  299. }
  300. }.bind(this), null, this.data.distinguishedName);
  301. }else{
  302. if (callback) callback( );
  303. }
  304. }
  305. });
  306. MWF.xApplication.Selector.IdentityWidthDuty.ItemGroupCategory = new Class({
  307. Extends: MWF.xApplication.Selector.Identity.ItemGroupCategory
  308. });
  309. MWF.xApplication.Selector.IdentityWidthDuty.Filter = new Class({
  310. Implements: [Options, Events],
  311. options: {
  312. "style": "default",
  313. "units": [],
  314. "dutys": []
  315. },
  316. initialize: function(value, options){
  317. this.setOptions(options);
  318. this.value = value;
  319. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  320. },
  321. getList: function(callback){
  322. if (false && this.list){
  323. if (callback) callback();
  324. }else{
  325. this.list = [];
  326. MWF.require("MWF.widget.PinYin", function(){
  327. this.options.dutys.each(function(duty){
  328. if (this.options.units.length){
  329. var action = MWF.Actions.get("x_organization_assemble_express");
  330. var data = {"name":duty, "unit":""};
  331. this.options.units.each(function(u){
  332. if (typeOf(u)==="string"){
  333. data.unit = u;
  334. }else{
  335. data.unit = u.distinguishedName || u.unique || u.id || u.levelName
  336. }
  337. action.getDuty(data, function(json){
  338. json.data.each(function(d){
  339. d.pinyin = d.name.toPY().toLowerCase();
  340. d.firstPY = d.name.toPYFirst().toLowerCase();
  341. this.list.push(d);
  342. }.bind(this));
  343. }.bind(this), null, false);
  344. }.bind(this));
  345. }else{
  346. this.orgAction.listIdentityWithDuty(function(json){
  347. json.data.each(function(d){
  348. d.pinyin = d.name.toPY().toLowerCase();
  349. d.firstPY = d.name.toPYFirst().toLowerCase();
  350. this.list.push(d);
  351. }.bind(this));
  352. }.bind(this), null, duty, false);
  353. }
  354. }.bind(this));
  355. if (callback) callback();
  356. }.bind(this));
  357. }
  358. },
  359. filter: function(value, callback){
  360. this.value = value;
  361. this.getList(function(){
  362. var data = this.list.filter(function(d){
  363. var text = d.name+"#"+d.pinyin+"#"+d.firstPY;
  364. return (text.indexOf(this.value)!=-1);
  365. }.bind(this));
  366. if (callback) callback(data);
  367. }.bind(this));
  368. }
  369. });