Duty.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.Duty = new Class({
  4. Extends: MWF.xApplication.Selector.Person,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectDuty,
  9. "values": [],
  10. "expand": false
  11. },
  12. loadSelectItems: function(addToNext){
  13. this.orgAction.listUnitdutyName(function(json){
  14. json.data.nameList.each(function(data){
  15. var category = this._newItem(data, this, this.itemAreaNode);
  16. this.items.push( category );
  17. }.bind(this));
  18. }.bind(this));
  19. },
  20. _scrollEvent: function(y){
  21. return true;
  22. },
  23. _getChildrenItemIds: function(){
  24. return null;
  25. },
  26. _newItemCategory: function(type, data, selector, item, level){
  27. return new MWF.xApplication.Selector.Duty[type](data, selector, item, level)
  28. },
  29. _listItemByKey: function(callback, failure, key){
  30. this.orgAction.listUnitdutyNameByKey(function(json){
  31. if (callback) callback.apply(this, [{"data": json.data.nameList}]);
  32. }.bind(this), failure, key);
  33. },
  34. _getItem: function(callback, failure, id, async){
  35. if (callback) callback.apply(this, [{"data": {"name": id, "id":id}}]);
  36. },
  37. _newItemSelected: function(data, selector, item){
  38. return new MWF.xApplication.Selector.Duty.ItemSelected(data, selector, item)
  39. },
  40. _listItemByPinyin: function(callback, failure, key){
  41. this.orgAction.listUnitdutyNameByKey(function(json){
  42. if (callback) callback.apply(this, [{"data": json.data.nameList}]);
  43. }.bind(this), failure, key);
  44. },
  45. _newItem: function(data, selector, container, level){
  46. return new MWF.xApplication.Selector.Duty.Item({"name":data, "id":data}, selector, container, level);
  47. }
  48. });
  49. MWF.xApplication.Selector.Duty.Item = new Class({
  50. Extends: MWF.xApplication.Selector.Person.Item,
  51. _getShowName: function(){
  52. return this.data.name;
  53. },
  54. _getTtiteText: function(){
  55. return this.data.name;
  56. },
  57. _setIcon: function() {
  58. var style = this.selector.options.style;
  59. this.iconNode.setStyle("background-image", "url(" + "../x_component_Selector/$Selector/"+style+"/icon/duty.png)");
  60. },
  61. checkSelectedSingle: function(){
  62. var selectedItem = this.selector.options.values.filter(function(item, index){
  63. if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  64. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  65. return false;
  66. }.bind(this));
  67. if (selectedItem.length){
  68. this.selectedSingle();
  69. }
  70. },
  71. checkSelected: function(){
  72. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  73. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  74. }.bind(this));
  75. if (selectedItem.length){
  76. //selectedItem[0].item = this;
  77. selectedItem[0].addItem(this);
  78. this.selectedItem = selectedItem[0];
  79. this.setSelected();
  80. }
  81. }
  82. });
  83. MWF.xApplication.Selector.Duty.ItemSelected = new Class({
  84. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  85. _getShowName: function(){
  86. return this.data.name;
  87. },
  88. _setIcon: function(){
  89. var style = this.selector.options.style;
  90. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/duty.png)");
  91. },
  92. check: function(){
  93. if (this.selector.items.length){
  94. var items = this.selector.items.filter(function(item, index){
  95. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  96. }.bind(this));
  97. this.items = items;
  98. if (items.length){
  99. items.each(function(item){
  100. item.selectedItem = this;
  101. item.setSelected();
  102. }.bind(this));
  103. }
  104. }
  105. }
  106. });