CMSView.js 5.7 KB

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