PortalFile.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Process", null, false);
  3. MWF.xApplication.Selector.PortalFile = new Class({
  4. Extends: MWF.xApplication.Selector.Process,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": "",
  9. "values": [],
  10. "names": [],
  11. "isImage": false,
  12. "accept": [],
  13. "expand": false,
  14. "forceSearchInItem" : true
  15. },
  16. setInitTitle: function(){
  17. this.setOptions({"title": MWF.xApplication.Selector.LP.selectFile});
  18. },
  19. _init : function(){
  20. this.selectType = "file";
  21. this.className = "PortalFile";
  22. },
  23. loadSelectItems: function(addToNext){
  24. if (this.options.isImage) this.options.accept = ["png","jpg","bmp","gif","jpeg","jpe"];
  25. this.portalAction.listApplication(function(json){
  26. if (json.data.length){
  27. json.data.each(function(data){
  28. this.portalAction.listFile(data.id, function(fileJson){
  29. var files = fileJson.data;
  30. if (this.options.accept && this.options.accept.length){
  31. files = files.filter(function(file){
  32. var extName = file.fileName.substring(file.fileName.lastIndexOf(".")+1, file.fileName.length).toLowerCase();
  33. return (this.options.accept.indexOf(extName)!==-1)
  34. }.bind(this));
  35. }
  36. if (files.length){
  37. data.files = files;
  38. var category = this._newItemCategory(data, this, this.itemAreaNode);
  39. files.each(function(d){
  40. d.applicationName = data.name;
  41. var item = this._newItem(d, this, category.children);
  42. this.items.push(item);
  43. }.bind(this));
  44. }
  45. }.bind(this));
  46. }.bind(this));
  47. }
  48. }.bind(this));
  49. },
  50. //loadSelectNode: function(){
  51. // this.selectNode = new Element("div", {
  52. // "styles": this.css.selectNode //(this.options.count.toInt()===1) ? this.css.selectNodeSingle : this.css.selectNode
  53. // }).inject(this.contentNode);
  54. //
  55. // this.itemAreaScrollNode = new Element("div", {
  56. // "styles": this.css.itemAreaScrollNode
  57. // }).inject(this.selectNode);
  58. // this.itemAreaScrollNode.setStyle("height", "408px");
  59. //
  60. // this.itemAreaNode = new Element("div", {
  61. // "styles": this.css.itemAreaNode
  62. // }).inject(this.itemAreaScrollNode);
  63. // this.itemSearchAreaNode = new Element("div", {
  64. // "styles": this.css.itemAreaNode
  65. // }).inject(this.itemAreaScrollNode);
  66. // this.itemSearchAreaNode.setStyle("display", "none");
  67. //
  68. // this.loadSelectNodeScroll();
  69. // this.initLoadSelectItems();
  70. // this.checkLoadSelectItems();
  71. //},
  72. close: function(){
  73. this.fireEvent("close");
  74. this.node.destroy();
  75. this.container.unmask();
  76. if (this.maskInterval){
  77. window.clearInterval(this.maskInterval);
  78. this.maskInterval = null;
  79. }
  80. this.selectedItems.each(function(item){
  81. item.destroy();
  82. });
  83. this.items.each(function(item){
  84. item.destroy();
  85. });
  86. this.active = false;
  87. MWF.release(this);
  88. delete this;
  89. },
  90. _getChildrenItemIds: function(data){
  91. return data.files || [];
  92. },
  93. _newItemCategory: function(data, selector, item, level){
  94. return new MWF.xApplication.Selector.PortalFile.ItemCategory(data, selector, item, level)
  95. },
  96. _newItemSelected: function(data, selector, item){
  97. return new MWF.xApplication.Selector.PortalFile.ItemSelected(data, selector, item)
  98. },
  99. _newItem: function(data, selector, container, level){
  100. return new MWF.xApplication.Selector.PortalFile.Item(data, selector, container, level);
  101. }
  102. });
  103. MWF.xApplication.Selector.PortalFile.Item = new Class({
  104. Extends: MWF.xApplication.Selector.Process.Item,
  105. _setIcon: function(){
  106. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  107. },
  108. loadSubItem: function(){
  109. return false;
  110. },
  111. checkSelectedSingle: function(){
  112. var selectedItem = this.selector.options.values.filter(function(item, index){
  113. if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  114. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  115. return false;
  116. }.bind(this));
  117. if (selectedItem.length){
  118. this.selectedSingle();
  119. }
  120. },
  121. checkSelected: function(){
  122. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  123. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  124. }.bind(this));
  125. if (selectedItem.length){
  126. //selectedItem[0].item = this;
  127. selectedItem[0].addItem(this);
  128. this.selectedItem = selectedItem[0];
  129. this.setSelected();
  130. }
  131. },
  132. setEvent: function(){
  133. var url = MWF.xDesktop.getPortalFileUr(this.data.id, this.data.portal);
  134. this.data.url = url;
  135. this.node.addEvents({
  136. "mouseover": function(){
  137. this.overItem();
  138. if (!this.previewNode){
  139. var extName = this.data.fileName.substring(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length).toLowerCase();
  140. if (["png","jpg","bmp","gif","jpeg","jpe"].indexOf(extName)!==-1){
  141. this.previewNode = new Element("div", {"styles": this.selector.css.filePreviewNode});
  142. var img = new Element("img", {"src": url, "styles": this.selector.css.filePreviewNode}).inject(this.previewNode);
  143. this.tooltip = new mBox.Tooltip({
  144. content: this.previewNode,
  145. setStyles: {content: {padding: 15, lineHeight: 20}},
  146. attach: this.node,
  147. position: {
  148. y: ['center'],
  149. x: ['right', 'outside']
  150. },
  151. transition: 'flyin'
  152. });
  153. }
  154. }
  155. }.bind(this),
  156. "mouseout": function(){
  157. this.outItem();
  158. }.bind(this),
  159. "click": function(){
  160. this.clickItem();
  161. }.bind(this)
  162. });
  163. },
  164. destroy: function(){
  165. if (this.tooltip) this.tooltip.destroy();
  166. this.node.destroy();
  167. }
  168. });
  169. MWF.xApplication.Selector.PortalFile.ItemSelected = new Class({
  170. Extends: MWF.xApplication.Selector.Process.ItemSelected,
  171. _getShowName: function(){
  172. return this.data.name;
  173. },
  174. _setIcon: function(){
  175. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  176. },
  177. check: function(){
  178. if (this.selector.items.length){
  179. var items = this.selector.items.filter(function(item, index){
  180. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  181. }.bind(this));
  182. this.items = items;
  183. if (items.length){
  184. items.each(function(item){
  185. item.selectedItem = this;
  186. item.setSelected();
  187. }.bind(this));
  188. }
  189. }
  190. },
  191. setEvent: function(){
  192. var url = MWF.xDesktop.getPortalFileUr(this.data.id, this.data.portal);
  193. this.data.url = url;
  194. this.node.addEvents({
  195. "mouseover": function(){
  196. this.overItem();
  197. if (!this.previewNode){
  198. var extName = this.data.fileName.substring(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length).toLowerCase();
  199. if (["png","jpg","bmp","gif","jpeg","jpe"].indexOf(extName)!==-1){
  200. this.previewNode = new Element("div", {"styles": this.selector.css.filePreviewNode}).inject(this.selector.node);
  201. var img = new Element("img", {"src": url, "styles": this.selector.css.filePreviewNode}).inject(this.previewNode);
  202. this.tooltip = new mBox.Tooltip({
  203. content: this.previewNode,
  204. setStyles: {content: {padding: 15, lineHeight: 20}},
  205. attach: this.node,
  206. position: {
  207. y: ['center'],
  208. x: ['left', 'outside']
  209. },
  210. transition: 'flyin'
  211. });
  212. }
  213. }
  214. }.bind(this),
  215. "mouseout": function(){
  216. this.outItem();
  217. }.bind(this),
  218. "click": function(){
  219. this.clickItem();
  220. }.bind(this)
  221. });
  222. },
  223. destroy: function(){
  224. if (this.tooltip) this.tooltip.destroy();
  225. this.node.destroy();
  226. }
  227. });
  228. MWF.xApplication.Selector.PortalFile.ItemCategory = new Class({
  229. Extends: MWF.xApplication.Selector.Process.ItemCategory,
  230. _getShowName: function(){
  231. return this.data.name;
  232. },
  233. createNode: function(){
  234. this.node = new Element("div", {
  235. "styles": this.selector.css.selectorItemCategory_department
  236. }).inject(this.container);
  237. },
  238. _setIcon: function(){
  239. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/applicationicon.png)");
  240. },
  241. afterLoad: function(){
  242. return true;
  243. },
  244. loadSub: function(callback){
  245. if (!this.loaded){
  246. this.selector.portalAction.listFile(this.data.id, function(subJson){
  247. subJson.data.each(function(subData){
  248. subData.applicationName = this.data.name;
  249. subData.application = this.data.id;
  250. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  251. this.selector.items.push( category );
  252. }.bind(this));
  253. this.loaded = true;
  254. if (callback) callback();
  255. }.bind(this), null, this.data.id);
  256. }else{
  257. if (callback) callback();
  258. }
  259. },
  260. _hasChild: function(){
  261. return true;
  262. },
  263. check: function(){}
  264. });