ProcessFile.js 4.0 KB

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