PortalFile.js 10 KB

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