PortalFile.js 10 KB

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