PortalFile.js 11 KB

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