Duty.js 4.3 KB

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