CMSView.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.CMSView = new Class({
  4. Extends: MWF.xApplication.Selector.Person,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectView,
  9. "values": [],
  10. "names": [],
  11. "expand": false,
  12. "forceSearchInItem" : true
  13. },
  14. _init : function(){
  15. this.selectType = "cmsview";
  16. this.className = "CMSView";
  17. },
  18. loadSelectItems: function(addToNext){
  19. this.cmsAction.listCMSApplicationView(function(json){
  20. if (json.data.length){
  21. json.data.each(function(data){
  22. if (data.queryViews && data.queryViews.length){
  23. var category = this._newItemCategory(data, this, this.itemAreaNode);
  24. data.queryViews.each(function(d){
  25. d.applicationName = data.appName;
  26. var item = this._newItem(d, this, category.children);
  27. this.items.push(item);
  28. }.bind(this));
  29. }
  30. }.bind(this));
  31. }
  32. }.bind(this));
  33. },
  34. _scrollEvent: function(y){
  35. return true;
  36. },
  37. _getChildrenItemIds: function(data){
  38. return data.queryViews || [];
  39. },
  40. _newItemCategory: function(data, selector, item, level){
  41. return new MWF.xApplication.Selector.CMSView.ItemCategory(data, selector, item, level)
  42. },
  43. _listItemByKey: function(callback, failure, key){
  44. return false;
  45. },
  46. _getItem: function(callback, failure, id, async){
  47. this.cmsAction.getQueryView(function(json){
  48. if (callback) callback.apply(this, [json]);
  49. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  50. },
  51. _newItemSelected: function(data, selector, item){
  52. return new MWF.xApplication.Selector.CMSView.ItemSelected(data, selector, item)
  53. },
  54. _listItemByPinyin: function(callback, failure, key){
  55. return false;
  56. },
  57. _newItem: function(data, selector, container, level){
  58. return new MWF.xApplication.Selector.CMSView.Item(data, selector, container, level);
  59. }
  60. });
  61. MWF.xApplication.Selector.CMSView.Item = new Class({
  62. Extends: MWF.xApplication.Selector.Person.Item,
  63. _getShowName: function(){
  64. return this.data.name;
  65. },
  66. _setIcon: function(){
  67. var style = "default";
  68. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/processicon.png)");
  69. },
  70. loadSubItem: function(){
  71. return false;
  72. },
  73. checkSelectedSingle: function(){
  74. var selectedItem = this.selector.options.values.filter(function(item, index){
  75. if (typeOf(item)==="object") {
  76. //return (this.data.id === item.id) || (this.data.name === item.name) ;
  77. if (this.data.id && item.id) {
  78. return this.data.id === item.id;
  79. } else {
  80. return this.data.name === item.name;
  81. }
  82. }
  83. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  84. return false;
  85. }.bind(this));
  86. if (selectedItem.length){
  87. this.selectedSingle();
  88. }
  89. },
  90. checkSelected: function(){
  91. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  92. if( item.data.id && this.data.id){
  93. return item.data.id === this.data.id;
  94. }else{
  95. return item.data.name === this.data.name;
  96. }
  97. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  98. }.bind(this));
  99. if (selectedItem.length){
  100. //selectedItem[0].item = this;
  101. selectedItem[0].addItem(this);
  102. this.selectedItem = selectedItem[0];
  103. this.setSelected();
  104. }
  105. }
  106. });
  107. MWF.xApplication.Selector.CMSView.ItemSelected = new Class({
  108. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  109. _getShowName: function(){
  110. return this.data.name;
  111. },
  112. _setIcon: function(){
  113. var style = "default";
  114. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/processicon.png)");
  115. },
  116. check: function(){
  117. if (this.selector.items.length){
  118. var items = this.selector.items.filter(function(item, index){
  119. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  120. }.bind(this));
  121. this.items = items;
  122. if (items.length){
  123. items.each(function(item){
  124. item.selectedItem = this;
  125. item.setSelected();
  126. }.bind(this));
  127. }
  128. }
  129. }
  130. });
  131. MWF.xApplication.Selector.CMSView.ItemCategory = new Class({
  132. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  133. _getShowName: function(){
  134. return this.data.appName;
  135. },
  136. createNode: function(){
  137. this.node = new Element("div", {
  138. "styles": this.selector.css.selectorItemCategory_department
  139. }).inject(this.container);
  140. },
  141. _setIcon: function(){
  142. var style = "default";
  143. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/applicationicon.png)");
  144. },
  145. _hasChild: function(){
  146. return (this.data.queryViews && this.data.queryViews.length);
  147. },
  148. check: function(){}
  149. });