Application.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.Application = new Class({
  4. Extends: MWF.xApplication.Selector.Person,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectAppliction,
  9. "values": [],
  10. "expand": false,
  11. "forceSearchInItem" : true
  12. },
  13. _init : function(){
  14. this.selectType = "application";
  15. this.className = "Application"
  16. },
  17. loadSelectItems: function(addToNext){
  18. this.processAction.listApplications(function(json){
  19. json.data.each(function(data){
  20. var category = this._newItem(data, this, this.itemAreaNode);
  21. this.items.push( category );
  22. }.bind(this));
  23. }.bind(this));
  24. },
  25. _scrollEvent: function(y){
  26. return true;
  27. },
  28. _getChildrenItemIds: function(){
  29. return null;
  30. },
  31. _listItemByKey: function(callback, failure, key){
  32. return false;
  33. },
  34. _getItem: function(callback, failure, id, async){
  35. this.processAction.getApplications(function(json){
  36. if (callback) callback.apply(this, [json]);
  37. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  38. },
  39. _newItemSelected: function(data, selector, item){
  40. return new MWF.xApplication.Selector.Application.ItemSelected(data, selector, item)
  41. },
  42. _listItemByPinyin: function(callback, failure, key){
  43. return false;
  44. },
  45. _newItem: function(data, selector, container, level){
  46. return new MWF.xApplication.Selector.Application.Item(data, selector, container, level);
  47. }
  48. });
  49. MWF.xApplication.Selector.Application.Item = new Class({
  50. Extends: MWF.xApplication.Selector.Person.Item,
  51. _getShowName: function(){
  52. return this.data.name;
  53. },
  54. _setIcon: function(){
  55. var style = "default";
  56. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/applicationicon.png)");
  57. },
  58. loadSubItem: function(){
  59. return false;
  60. },
  61. checkSelectedSingle: function(){
  62. var selectedItem = this.selector.options.values.filter(function(item, index){
  63. if (typeOf(item)==="object"){
  64. if( this.data.id && item.id ){
  65. return this.data.id === item.id;
  66. }else{
  67. return this.data.name === item.name;
  68. }
  69. // return (this.data.id === item.id) || (this.data.name === item.name) ;
  70. }
  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. if( item.data.id && this.data.id){
  82. return item.data.id === this.data.id;
  83. }else{
  84. return item.data.name === this.data.name;
  85. }
  86. }.bind(this));
  87. if (selectedItem.length){
  88. //selectedItem[0].item = this;
  89. selectedItem[0].addItem(this);
  90. this.selectedItem = selectedItem[0];
  91. this.setSelected();
  92. }
  93. }
  94. });
  95. MWF.xApplication.Selector.Application.ItemSelected = new Class({
  96. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  97. _getShowName: function(){
  98. return this.data.name;
  99. },
  100. _setIcon: function(){
  101. var style = "default";
  102. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/applicationicon.png)");
  103. },
  104. check: function(){
  105. if (this.selector.items.length){
  106. var items = this.selector.items.filter(function(item, index){
  107. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  108. }.bind(this));
  109. this.items = items;
  110. if (items.length){
  111. items.each(function(item){
  112. item.selectedItem = this;
  113. item.setSelected();
  114. }.bind(this));
  115. }
  116. }
  117. }
  118. });