Application.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.selectApplication,
  9. "values": [],
  10. "expand": false
  11. },
  12. loadSelectItems: function(addToNext){
  13. this.processAction.listApplications(function(json){
  14. json.data.each(function(data){
  15. var category = this._newItem(data, this, this.itemAreaNode);
  16. }.bind(this));
  17. }.bind(this));
  18. },
  19. _scrollEvent: function(y){
  20. return true;
  21. },
  22. _getChildrenItemIds: function(){
  23. return null;
  24. },
  25. _listItemByKey: function(callback, failure, key){
  26. return false;
  27. },
  28. _getItem: function(callback, failure, id, async){
  29. this.processAction.getApplications(function(json){
  30. if (callback) callback.apply(this, [json]);
  31. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  32. },
  33. _newItemSelected: function(data, selector, item){
  34. return new MWF.xApplication.Selector.Application.ItemSelected(data, selector, item)
  35. },
  36. _listItemByPinyin: function(callback, failure, key){
  37. return false;
  38. },
  39. _newItem: function(data, selector, container, level){
  40. return new MWF.xApplication.Selector.Application.Item(data, selector, container, level);
  41. }
  42. });
  43. MWF.xApplication.Selector.Application.Item = new Class({
  44. Extends: MWF.xApplication.Selector.Person.Item,
  45. _getShowName: function(){
  46. return this.data.name;
  47. },
  48. _setIcon: function(){
  49. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/applicationicon.png)");
  50. },
  51. loadSubItem: function(){
  52. return false;
  53. },
  54. checkSelectedSingle: function(){
  55. var selectedItem = this.selector.options.values.filter(function(item, index){
  56. if (typeOf(item)==="object"){
  57. if( this.data.id && item.id ){
  58. return this.data.id === item.id;
  59. }else{
  60. return this.data.name === item.name;
  61. }
  62. // return (this.data.id === item.id) || (this.data.name === item.name) ;
  63. }
  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. if( item.data.id && this.data.id){
  75. return item.data.id === this.data.id;
  76. }else{
  77. return item.data.name === this.data.name;
  78. }
  79. }.bind(this));
  80. if (selectedItem.length){
  81. //selectedItem[0].item = this;
  82. selectedItem[0].addItem(this);
  83. this.selectedItem = selectedItem[0];
  84. this.setSelected();
  85. }
  86. }
  87. });
  88. MWF.xApplication.Selector.Application.ItemSelected = new Class({
  89. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  90. _getShowName: function(){
  91. return this.data.name;
  92. },
  93. _setIcon: function(){
  94. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/applicationicon.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. });