Duty.js 4.2 KB

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