Custom.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xApplication.Template = MWF.xApplication.Template || {};
  3. MWF.xApplication.Template.Selector = MWF.xApplication.Template.Selector || {};
  4. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  5. MWF.xApplication.Template.Selector.Custom = new Class({
  6. Extends: MWF.xApplication.Selector.Person,
  7. options: {
  8. "style": "default",
  9. "count": 0,
  10. "title": "选择列表",
  11. "selectableItems" : [],
  12. "values": [],
  13. "expand": false
  14. },
  15. initialize: function(container, options){
  16. this.setOptions(options);
  17. this.path = "/x_component_Selector/$Selector/";
  18. this.cssPath = "/x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
  19. this._loadCss(true);
  20. this.container = $(container);
  21. this.selectedItems = [];
  22. this.items = [];
  23. },
  24. loadSelectItems: function(addToNext){
  25. this.options.selectableItems.each( function( it ){
  26. var name = typeOf( it ) == "string" ? it : it.name;
  27. var id = typeOf( it ) == "string" ? it : it.id;
  28. var item = this._newItem({ name : name, id : id }, this, this.itemAreaNode );
  29. this.items.push(item);
  30. }.bind(this))
  31. },
  32. _scrollEvent: function(y){
  33. return true;
  34. },
  35. _getChildrenItemIds: function(data){
  36. return data.viewList || [];
  37. },
  38. _listItemByKey: function(callback, failure, key){
  39. return false;
  40. },
  41. _getItem: function(callback, failure, id, async){
  42. this.action.getProcess(function(json){
  43. if (callback) callback.apply(this, [json]);
  44. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  45. },
  46. _newItemSelected: function(data, selector, item){
  47. return new MWF.xApplication.Template.Selector.Custom.ItemSelected(data, selector, item)
  48. },
  49. _listItemByPinyin: function(callback, failure, key){
  50. return false;
  51. },
  52. _newItem: function(data, selector, container, level){
  53. return new MWF.xApplication.Template.Selector.Custom.Item(data, selector, container, level);
  54. }
  55. });
  56. MWF.xApplication.Template.Selector.Custom.Item = new Class({
  57. Extends: MWF.xApplication.Selector.Person.Item,
  58. _getShowName: function(){
  59. return this.data.name;
  60. },
  61. _setIcon: function(){
  62. this.iconNode.setStyle("background-image", "url("+"/x_component_Organization/Selector/$Selector/default/icon/processicon.png)");
  63. },
  64. loadSubItem: function(){
  65. return false;
  66. },
  67. checkSelectedSingle: function(){
  68. var selectedItem = this.selector.options.values.filter(function(item, index){
  69. if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  70. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  71. return false;
  72. }.bind(this));
  73. if (selectedItem.length){
  74. this.selectedSingle();
  75. }
  76. },
  77. checkSelected: function(){
  78. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  79. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  80. }.bind(this));
  81. if (selectedItem.length){
  82. //selectedItem[0].item = this;
  83. selectedItem[0].addItem(this);
  84. this.selectedItem = selectedItem[0];
  85. this.setSelected();
  86. }
  87. }
  88. });
  89. MWF.xApplication.Template.Selector.Custom.ItemSelected = new Class({
  90. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  91. _getShowName: function(){
  92. return this.data.name;
  93. },
  94. _setIcon: function(){
  95. this.iconNode.setStyle("background-image", "url("+"/x_component_Organization/Selector/$Selector/default/icon/processicon.png)");
  96. },
  97. check: function(){
  98. if (this.selector.items.length){
  99. var items = this.selector.items.filter(function(item, index){
  100. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  101. }.bind(this));
  102. this.items = items;
  103. if (items.length){
  104. items.each(function(item){
  105. item.selectedItem = this;
  106. item.setSelected();
  107. }.bind(this));
  108. }
  109. }
  110. }
  111. });