CMSApplication.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Identity", null, false);
  3. MWF.xApplication.Selector.CMSApplication = new Class({
  4. Extends: MWF.xApplication.Selector.Identity,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectCMSApplication,
  9. "values": [],
  10. "names": [],
  11. "expand": false,
  12. "forceSearchInItem" : true
  13. },
  14. _init : function(){
  15. this.selectType = "application";
  16. this.className = "CMSApplication"
  17. },
  18. loadSelectItems: function(addToNext){
  19. this.cmsAction.listCMSApplication(function(json){
  20. json.data.each(function(data){
  21. data.name = data.appName;
  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. _listItemByKey: function(callback, failure, key){
  34. return false;
  35. },
  36. _getItem: function(callback, failure, id, async){
  37. this.cmsAction.getCMSApplication(function(json){
  38. if(json.data)json.data.name = json.data.appName;
  39. if (callback) callback.apply(this, [json]);
  40. }.bind(this), failure, id, async);
  41. },
  42. _newItemSelected: function(data, selector, item){
  43. return new MWF.xApplication.Selector.CMSApplication.ItemSelected(data, selector, item)
  44. },
  45. _listItemByPinyin: function(callback, failure, key){
  46. return false;
  47. },
  48. _newItem: function(data, selector, container, level){
  49. return new MWF.xApplication.Selector.CMSApplication.Item(data, selector, container, level);
  50. }
  51. });
  52. MWF.xApplication.Selector.CMSApplication.Item = new Class({
  53. Extends: MWF.xApplication.Selector.Identity.Item,
  54. _getShowName: function(){
  55. return this.data.appName;
  56. },
  57. _setIcon: function(){
  58. var style = "default";
  59. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/applicationicon.png)");
  60. },
  61. loadSubItem: function(){
  62. return false;
  63. },
  64. getData: function(callback){
  65. if (callback) callback();
  66. },
  67. checkSelectedSingle: function(){
  68. var selectedItem = this.selector.options.values.filter(function(item, index){
  69. if (typeOf(item)==="object"){
  70. // return (this.data.id === item.id) || (this.data.name === item.name) ;
  71. if( this.data.id && item.id ){
  72. return this.data.id === item.id;
  73. }else{
  74. return this.data.name === item.name;
  75. }
  76. }
  77. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  78. return false;
  79. }.bind(this));
  80. if (selectedItem.length){
  81. this.selectedSingle();
  82. }
  83. },
  84. checkSelected: function(){
  85. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  86. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  87. if( item.data.id && this.data.id){
  88. return item.data.id === this.data.id;
  89. }else{
  90. return item.data.name === this.data.name;
  91. }
  92. }.bind(this));
  93. if (selectedItem.length){
  94. //selectedItem[0].item = this;
  95. selectedItem[0].addItem(this);
  96. this.selectedItem = selectedItem[0];
  97. this.setSelected();
  98. }
  99. }
  100. });
  101. MWF.xApplication.Selector.CMSApplication.ItemSelected = new Class({
  102. Extends: MWF.xApplication.Selector.Identity.ItemSelected,
  103. getData: function(callback){
  104. if (callback) callback();
  105. },
  106. _getShowName: function(){
  107. return this.data.name;
  108. },
  109. _setIcon: function(){
  110. var style = "default";
  111. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/applicationicon.png)");
  112. },
  113. check: function(){
  114. if (this.selector.items.length){
  115. var items = this.selector.items.filter(function(item, index){
  116. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  117. }.bind(this));
  118. this.items = items;
  119. if (items.length){
  120. items.each(function(item){
  121. item.selectedItem = this;
  122. item.setSelected();
  123. }.bind(this));
  124. }
  125. }
  126. }
  127. });