CMSFile.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "PortalFile", null, false);
  3. MWF.xApplication.Selector.CMSFile = new Class({
  4. Extends: MWF.xApplication.Selector.PortalFile,
  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. this.setOptions({"title": MWF.xApplication.Selector.LP.selectFile});
  16. },
  17. _init : function(){
  18. this.selectType = "file";
  19. this.className = "CMSFile";
  20. },
  21. loadSelectItems: function(addToNext){
  22. if (this.options.isImage) this.options.accept = ["png","jpg","bmp","gif","jpeg","jpe"];
  23. this.cmsAction.listApplication(function(json){
  24. if (json.data.length){
  25. json.data.each(function(data){
  26. this.cmsAction.listFile(data.id, function(fileJson){
  27. var files = fileJson.data;
  28. if (this.options.accept && this.options.accept.length){
  29. files = files.filter(function(file){
  30. var extName = file.fileName.substring(file.fileName.lastIndexOf(".")+1, file.fileName.length).toLowerCase();
  31. return (this.options.accept.indexOf(extName)!==-1)
  32. }.bind(this));
  33. }
  34. if (files.length){
  35. data.files = files;
  36. var category = this._newItemCategory(data, this, this.itemAreaNode);
  37. files.each(function(d){
  38. d.applicationName = data.appName;
  39. var item = this._newItem(d, this, category.children);
  40. this.items.push(item);
  41. }.bind(this));
  42. }
  43. }.bind(this));
  44. }.bind(this));
  45. }
  46. }.bind(this));
  47. },
  48. _newItemCategory: function(data, selector, item, level){
  49. return new MWF.xApplication.Selector.CMSFile.ItemCategory(data, selector, item, level)
  50. },
  51. _newItemSelected: function(data, selector, item){
  52. return new MWF.xApplication.Selector.CMSFile.ItemSelected(data, selector, item)
  53. },
  54. _newItem: function(data, selector, container, level){
  55. return new MWF.xApplication.Selector.CMSFile.Item(data, selector, container, level);
  56. }
  57. });
  58. MWF.xApplication.Selector.CMSFile.Item = new Class({
  59. Extends: MWF.xApplication.Selector.PortalFile.Item,
  60. setEvent: function(){
  61. this.node.addEvents({
  62. "mouseover": function(){
  63. this.overItem();
  64. }.bind(this),
  65. "mouseout": function(){
  66. this.outItem();
  67. }.bind(this),
  68. "click": function(){
  69. this.clickItem();
  70. }.bind(this)
  71. });
  72. var url = MWF.xDesktop.getCMSFileUr(this.data.id, this.data.appId);
  73. this.data.url = url;
  74. var extName = this.data.fileName.substring(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length).toLowerCase();
  75. if (["png","jpg","bmp","gif","jpeg","jpe"].indexOf(extName)!==-1){
  76. this.previewNode = new Element("div", {"styles": this.selector.css.filePreviewNode});
  77. var img = new Element("img", {"src": url, "styles": this.selector.css.filePreviewNode}).inject(this.previewNode);
  78. this.tooltip = new mBox.Tooltip({
  79. content: this.previewNode,
  80. setStyles: {content: {padding: 15, lineHeight: 20}},
  81. attach: this.node,
  82. position: {
  83. y: ['center'],
  84. x: ['right', 'outside']
  85. },
  86. transition: 'flyin'
  87. });
  88. }
  89. }
  90. });
  91. MWF.xApplication.Selector.CMSFile.ItemSelected = new Class({
  92. Extends: MWF.xApplication.Selector.PortalFile.ItemSelected
  93. });
  94. MWF.xApplication.Selector.CMSFile.ItemCategory = new Class({
  95. Extends: MWF.xApplication.Selector.PortalFile.ItemCategory,
  96. _getShowName: function(){
  97. return this.data.name || this.data.appName;
  98. }
  99. });