PortalFile.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. this.active = false;
  80. MWF.release(this);
  81. delete this;
  82. },
  83. _getChildrenItemIds: function(data){
  84. return data.files || [];
  85. },
  86. _newItemCategory: function(data, selector, item, level){
  87. return new MWF.xApplication.Selector.PortalFile.ItemCategory(data, selector, item, level)
  88. },
  89. _newItemSelected: function(data, selector, item){
  90. return new MWF.xApplication.Selector.PortalFile.ItemSelected(data, selector, item)
  91. },
  92. _newItem: function(data, selector, container, level){
  93. return new MWF.xApplication.Selector.PortalFile.Item(data, selector, container, level);
  94. }
  95. });
  96. MWF.xApplication.Selector.PortalFile.Item = new Class({
  97. Extends: MWF.xApplication.Selector.Process.Item,
  98. _setIcon: function(){
  99. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/attr.png)");
  100. },
  101. loadSubItem: function(){
  102. return false;
  103. },
  104. checkSelectedSingle: function(){
  105. var selectedItem = this.selector.options.values.filter(function(item, index){
  106. if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  107. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  108. return false;
  109. }.bind(this));
  110. if (selectedItem.length){
  111. this.selectedSingle();
  112. }
  113. },
  114. checkSelected: function(){
  115. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  116. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  117. }.bind(this));
  118. if (selectedItem.length){
  119. //selectedItem[0].item = this;
  120. selectedItem[0].addItem(this);
  121. this.selectedItem = selectedItem[0];
  122. this.setSelected();
  123. }
  124. },
  125. setEvent: function(){
  126. var url = MWF.xDesktop.getPortalFileUr(this.data.id, this.data.portal);
  127. this.data.url = url;
  128. this.node.addEvents({
  129. "mouseover": function(){
  130. this.overItem();
  131. if (!this.previewNode){
  132. var extName = this.data.fileName.substring(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length).toLowerCase();
  133. if (["png","jpg","bmp","gif","jpeg","jpe"].indexOf(extName)!==-1){
  134. this.previewNode = new Element("div", {"styles": this.selector.css.filePreviewNode});
  135. var img = new Element("img", {"src": url, "styles": this.selector.css.filePreviewNode}).inject(this.previewNode);
  136. this.tooltip = new mBox.Tooltip({
  137. content: this.previewNode,
  138. setStyles: {content: {padding: 15, lineHeight: 20}},
  139. attach: this.node,
  140. position: {
  141. y: ['center'],
  142. x: ['right', 'outside']
  143. },
  144. transition: 'flyin'
  145. });
  146. }
  147. }
  148. }.bind(this),
  149. "mouseout": function(){
  150. this.outItem();
  151. }.bind(this),
  152. "click": function(){
  153. this.clickItem();
  154. }.bind(this)
  155. });
  156. },
  157. destroy: function(){
  158. if (this.tooltip) this.tooltip.destroy();
  159. this.node.destroy();
  160. }
  161. });
  162. MWF.xApplication.Selector.PortalFile.ItemSelected = new Class({
  163. Extends: MWF.xApplication.Selector.Process.ItemSelected,
  164. _getShowName: function(){
  165. return this.data.name;
  166. },
  167. _setIcon: function(){
  168. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/attr.png)");
  169. },
  170. check: function(){
  171. if (this.selector.items.length){
  172. var items = this.selector.items.filter(function(item, index){
  173. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  174. }.bind(this));
  175. this.items = items;
  176. if (items.length){
  177. items.each(function(item){
  178. item.selectedItem = this;
  179. item.setSelected();
  180. }.bind(this));
  181. }
  182. }
  183. },
  184. setEvent: function(){
  185. var url = MWF.xDesktop.getPortalFileUr(this.data.id, this.data.portal);
  186. this.data.url = url;
  187. this.node.addEvents({
  188. "mouseover": function(){
  189. this.overItem();
  190. if (!this.previewNode){
  191. var extName = this.data.fileName.substring(this.data.fileName.lastIndexOf(".")+1, this.data.fileName.length).toLowerCase();
  192. if (["png","jpg","bmp","gif","jpeg","jpe"].indexOf(extName)!==-1){
  193. this.previewNode = new Element("div", {"styles": this.selector.css.filePreviewNode}).inject(this.selector.node);
  194. var img = new Element("img", {"src": url, "styles": this.selector.css.filePreviewNode}).inject(this.previewNode);
  195. this.tooltip = new mBox.Tooltip({
  196. content: this.previewNode,
  197. setStyles: {content: {padding: 15, lineHeight: 20}},
  198. attach: this.node,
  199. position: {
  200. y: ['center'],
  201. x: ['left', 'outside']
  202. },
  203. transition: 'flyin'
  204. });
  205. }
  206. }
  207. }.bind(this),
  208. "mouseout": function(){
  209. this.outItem();
  210. }.bind(this),
  211. "click": function(){
  212. this.clickItem();
  213. }.bind(this)
  214. });
  215. },
  216. destroy: function(){
  217. if (this.tooltip) this.tooltip.destroy();
  218. this.node.destroy();
  219. }
  220. });
  221. MWF.xApplication.Selector.PortalFile.ItemCategory = new Class({
  222. Extends: MWF.xApplication.Selector.Process.ItemCategory,
  223. _getShowName: function(){
  224. return this.data.name;
  225. },
  226. createNode: function(){
  227. this.node = new Element("div", {
  228. "styles": this.selector.css.selectorItemCategory_department
  229. }).inject(this.container);
  230. },
  231. _setIcon: function(){
  232. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/applicationicon.png)");
  233. },
  234. afterLoad: function(){
  235. return true;
  236. },
  237. loadSub: function(callback){
  238. if (!this.loaded){
  239. this.selector.portalAction.listFile(this.data.id, function(subJson){
  240. subJson.data.each(function(subData){
  241. subData.applicationName = this.data.name;
  242. subData.application = this.data.id;
  243. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  244. this.selector.items.push( category );
  245. }.bind(this));
  246. this.loaded = true;
  247. if (callback) callback();
  248. }.bind(this), null, this.data.id);
  249. }else{
  250. if (callback) callback();
  251. }
  252. },
  253. _hasChild: function(){
  254. return true;
  255. },
  256. check: function(){}
  257. });