FileSelector.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. MWF.xApplication.File = MWF.xApplication.File || {};
  2. MWF.xDesktop.requireApp("File", "lp.zh-cn", null, false);
  3. // MWF.xDesktop.requireApp("File", "Actions.RestActions", null, false);
  4. MWF.xDesktop.requireApp("File", "AttachmentSelector", null, false);
  5. MWF.xDesktop.requireApp("File", "Main", null, false);
  6. MWF.require("MWF.widget.Tree", null, false);
  7. MWF.xApplication.File.FileSelector = new Class({
  8. Extends: MWF.xApplication.File.Main,
  9. Implements: [Options, Events],
  10. options: {
  11. "title" : "",
  12. "style": "default",
  13. "listStyle" : "icon",
  14. "selectType" : "all",
  15. "copyToPublic" : true,
  16. "scale" : 800,
  17. "reference" : "",
  18. "referenceType" : "",
  19. //"toBase64" : false,
  20. //"base64Width" : 800,
  21. //"base64Height" : 0,
  22. "images": ["bmp", "gif", "png", "jpeg", "jpg", "jpe", "ico"],
  23. "audios": ["mp3", "wav", "wma", "wmv"],
  24. "videos": ["avi", "mkv", "mov", "ogg", "mp4", "mpa", "mpe", "mpeg", "mpg", "rmvb"]
  25. },
  26. initialize: function(container, options){
  27. this.setOptions(options);
  28. this.container = $(container);
  29. this.path = "../x_component_File/$FileSelector/";
  30. this.cssPath =this.path+this.options.style+"/css.wcss";
  31. this._loadCss();
  32. this.lp = MWF.xApplication.File.LP;
  33. },
  34. onQueryLoad: function(){
  35. this.lp = MWF.xApplication.File.LP;
  36. },
  37. load : function(){
  38. this.loadApplication();
  39. },
  40. loadApplication: function(callback){
  41. this.history = [];
  42. this.currentHistory = 1;
  43. this.currentFolder = null;
  44. //this.restActions = new MWF.xApplication.File.Actions.RestActions();
  45. this.restActions = MWF.Actions.get("x_file_assemble_control");
  46. MWF.getJSON("../x_component_File/$Main/icon.json", function(json){
  47. this.icons = json;
  48. }.bind(this), false, false);
  49. this.createNode();
  50. if (callback) callback();
  51. },
  52. createNode: function(){
  53. this.markNode = new Element("div", {
  54. "styles": this.css.markNode,
  55. "events": {
  56. "mouseover": function(e){e.stopPropagation();},
  57. "mouseout": function(e){e.stopPropagation();}
  58. }
  59. }).inject(this.container);
  60. this.content = new Element("div", {
  61. "styles": this.css.container
  62. });
  63. this.node = new Element("div",{
  64. "styles": this.css.node
  65. }).inject(this.content);
  66. this.createTopNode();
  67. this.loadApplicationContent();
  68. this.createBottomToolbarNode();
  69. this.content.inject(this.markNode, "after");
  70. this.content.fade("in");
  71. this.setNodeSize();
  72. var size = this.container.getSize();
  73. var nodeSize = this.content.getSize();
  74. this.content.makeDraggable({
  75. "handle": this.titleNode,
  76. "limit": {
  77. "x": [0, size.x-nodeSize.x],
  78. "y": [0, size.y-nodeSize.y]
  79. }
  80. });
  81. },
  82. close : function(){
  83. this.content.destroy();
  84. this.markNode.destroy();
  85. delete this;
  86. },
  87. createTopNode: function(){
  88. if (this.options.title){
  89. if (!this.titleNode){
  90. this.titleNode = new Element("div.titleNode", {"styles": this.css.titleNode, "text": this.options.title}).inject(this.node);
  91. this.titleActionNode = new Element("div", {"styles": this.css.titleActionNode}).inject(this.titleNode);
  92. this.titleActionNode.addEvent("click",function(){this.close() }.bind(this))
  93. }
  94. }
  95. },
  96. loadFileContentAreaNode: function(){
  97. this.controller = new MWF.xApplication.File.AttachmentSelector(this.attachmentContentNode, this, {
  98. "resize": false,
  99. "isSizeChange": false,
  100. "style": this.options.style,
  101. "listStyle": this.options.listStyle
  102. })
  103. this.controller.load();
  104. },
  105. createBottomToolbarNode : function( ){
  106. this.bottomToolbarNode = new Element("div.bottomToolbarNode",{ styles : this.css.bottomToolbarNode }).inject(this.node);
  107. this.cancelButton = new Element("div",{
  108. styles : this.css.cancelButton,
  109. text : MWF.LP.widget.cancel
  110. }).inject(this.bottomToolbarNode);
  111. this.cancelButton.addEvent("click",function(){
  112. this.close();
  113. }.bind(this));
  114. this.okButton = new Element("div",{
  115. styles : this.css.okButton,
  116. text : MWF.LP.widget.ok
  117. }).inject(this.bottomToolbarNode);
  118. this.okButton.addEvent("click",function(){
  119. if( this.controller.selectedAttachments.length ){
  120. this.openAttachment(null, null, this.controller.selectedAttachments );
  121. }
  122. this.close();
  123. }.bind(this));
  124. },
  125. fiterByExtension : function( attachments ){
  126. var availableExtensions = this.options[ this.options.selectType ];
  127. if( availableExtensions ){
  128. var atts = [];
  129. while (attachments.length){
  130. var att = attachments.shift();
  131. if( availableExtensions.contains(att.extension) ){
  132. atts.push(att);
  133. }
  134. }
  135. attachments = atts;
  136. }
  137. return attachments;
  138. },
  139. loadShareFile: function(treeNode){
  140. var person = treeNode.data.name;
  141. this.restActions.listShareAttachment(function(json){
  142. //this.fileContentAreaNode.empty();
  143. this.controller.clear();
  144. this.fiterByExtension( json.data ).each(function(file){
  145. this.controller.addAttachment(file);
  146. //new MWF.xApplication.File.ShareAttachment(file, this);
  147. }.bind(this));
  148. }.bind(this), null, person);
  149. },
  150. loadEditorFile: function(treeNode){
  151. var person = treeNode.data.name;
  152. this.restActions.listEditorAttachment(function(json){
  153. //this.fileContentAreaNode.empty();
  154. this.controller.clear();
  155. this.fiterByExtension( json.data ).each(function(file){
  156. this.controller.addAttachment(file);
  157. //new MWF.xApplication.File.ShareAttachment(file, this);
  158. }.bind(this));
  159. }.bind(this), null, person);
  160. },
  161. loadSub: function(treeNode){
  162. this.setPathNode(treeNode);
  163. //this.fileContentAreaNode.empty();
  164. this.controller.clear();
  165. treeNode.children.each(function(node){
  166. var folder = this.controller.addAttachmentFolder(node.data);
  167. folder.treeNode = node;
  168. //var folder = new MWF.xApplication.File.Folder(node.data, this);
  169. //folder.treeNode = node;
  170. }.bind(this));
  171. this.currentFolder = treeNode;
  172. if (treeNode.data){
  173. this.restActions.listAttachment(function(json){
  174. this.fiterByExtension( json.data ).each(function(file){
  175. this.controller.addAttachment(file);
  176. //new MWF.xApplication.File.Attachment(file, this);
  177. }.bind(this));
  178. }.bind(this), null, treeNode.data.id);
  179. }else{
  180. this.restActions.listAttachmentTop(function(json){
  181. this.fiterByExtension( json.data ).each(function(file){
  182. this.controller.addAttachment(file);
  183. //new MWF.xApplication.File.Attachment(file, this);
  184. }.bind(this));
  185. }.bind(this));
  186. }
  187. },
  188. openAttachment: function(e, node, attachment){
  189. var id = attachment[0].data.id;
  190. this.restActions.getFileUrl( id, function(url){
  191. //if( this.options.toBase64 ){
  192. // this.restActions.getBase64Code(function(json){
  193. // var data = json.data ? "data:image/png;base64,"+json.data.value : null;
  194. // this.fireEvent("postSelectAttachment",[url, data ]);
  195. // }.bind(this), null, id, this.options.base64Width, this.options.base64Height )
  196. //}else{
  197. if( this.options.copyToPublic && this.options.reference && this.options.referenceType ) {
  198. MWF.xDesktop.copyImage( this.options.reference, this.options.referenceType, id, this.options.scale, function( json ){
  199. var url = MWF.xDesktop.getImageSrc( json.data.id );
  200. this.fireEvent("postSelectAttachment",[url, json.data.id, attachment[0].data ]);
  201. }.bind(this))
  202. }else{
  203. this.fireEvent("postSelectAttachment",[url, "", attachment[0].data ]);
  204. }
  205. this.close();
  206. }.bind(this));
  207. },
  208. setContentHeight : function(node){
  209. },
  210. setNodeSize: function(node,width, height){
  211. width = width || "50%";
  212. height = height || "50%";
  213. "string" == typeof width && (1 < width.length && "%" == width.substr(width.length - 1, 1)) && (width = parseInt(window.screen.width * parseInt(width, 10) / 100, 10));
  214. "string" == typeof height && (1 < height.length && "%" == height.substr(height.length - 1, 1)) && (height = parseInt(window.screen.height * parseInt(height, 10) / 100, 10));
  215. 700 > width && (width = 700);
  216. 420 > height && (height = 420);
  217. var top = parseInt((window.screen.height - height) / 2, 10);
  218. var left = parseInt((window.screen.width - width) / 2, 10);
  219. //c = window.open("", null, d, !0);
  220. this.content.setStyles({
  221. "width": "" + width + "px",
  222. "height": "" + height + "px",
  223. "top": "" + top + "px",
  224. "left": "" + left + "px"
  225. });
  226. this.node.setStyles({
  227. "width": "" + width + "px",
  228. "height": "" + height + "px"
  229. });
  230. var titleNodeHeight = this.titleNode ? this.titleNode.getSize().y : 0;
  231. var topNodeHeight = this.topNode ? this.topNode.getSize().y : 0;
  232. var bottomToolbarNodeHeight = this.bottomToolbarNode ? this.bottomToolbarNode.getSize().y : 0;
  233. var mtt = this.topNode.getStyle("margin-top").toFloat();
  234. var mbt = this.topNode.getStyle("margin-bottom").toFloat();
  235. var mtc = this.fileContentNode.getStyle("margin-top").toFloat();
  236. var mbc = this.fileContentNode.getStyle("margin-bottom").toFloat();
  237. var h = height - titleNodeHeight - topNodeHeight - bottomToolbarNodeHeight-mtt-mbt-mtc-mbc;
  238. this.fileContentNode.setStyle("height", h);
  239. this.attachmentContentNode.setStyle("height", h);
  240. var attTopSzie = this.controller.topNode.getSize();
  241. var y = h-attTopSzie.y;
  242. this.controller.contentScrollNode.setStyle("height", ""+y+"px");
  243. var tabSize = this.treeTab.tabNodeContainer.getSize();
  244. var h = h-tabSize.y;
  245. this.folderTreeAreaScrollNode.setStyle("height", h);
  246. this.shareTreeAreaScrollNode.setStyle("height", h);
  247. this.editorTreeAreaScrollNode.setStyle("height", h);
  248. }
  249. });