ProcessFile.js 4.0 KB

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