AttachmentController.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. MWF.require("MWF.widget.AttachmentController", null, false);
  2. MWF.xApplication.cms.FormDesigner = MWF.xApplication.cms.FormDesigner || {};
  3. MWF.xApplication.cms.FormDesigner.widget = MWF.xApplication.cms.FormDesigner.widget || {};
  4. MWF.xApplication.cms.FormDesigner.widget.AttachmentController = new Class({
  5. Extends: MWF.widget.AttachmentController,
  6. options: {
  7. "style": "default",
  8. "listStyle": "icon",
  9. "size": "max",
  10. "resize": true,
  11. "attachmentCount": 0,
  12. "isUpload": true,
  13. "isDelete": true,
  14. "isReplace": true,
  15. "isDownload": true,
  16. "isSizeChange": true,
  17. "readonly": false,
  18. "toolbarGroupHidden" : [], //edit read list view
  19. "images": ["bmp", "gif", "png", "jpeg", "jpg", "jpe", "ico"],
  20. "audios": ["mp3", "wav", "wma", "wmv"],
  21. "videos": ["avi", "mkv", "mov", "ogg", "mp4", "mpa", "mpe", "mpeg", "mpg", "rmvb"]
  22. },
  23. load: function(){
  24. if (this.options.size==="min"){
  25. this.loadMin();
  26. }else{
  27. this.loadMax();
  28. }
  29. },
  30. createTopNode: function(){
  31. if (this.options.title){
  32. if (!this.titleNode) this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.options.title}).inject(this.node);
  33. }
  34. if( !this.topNode ){
  35. this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  36. }else{
  37. this.topNode.empty();
  38. this.editActionBoxNode = null;
  39. this.editActionsGroupNode=null;
  40. this.topNode.setStyle("display","");
  41. if( this.isHiddenTop ){
  42. //this.container.setStyle("height", this.container.getSize().y + 45 );
  43. //this.node.setStyle("height", this.node.getSize().y + 45 );
  44. if( this.oldContentScrollNodeHeight ){
  45. this.contentScrollNode.setStyle("min-height",this.oldContentScrollNodeHeight);
  46. this.oldContentScrollNodeHeight = null;
  47. }
  48. this.isHiddenTop = false;
  49. }
  50. }
  51. var hiddenGroup = this.options.toolbarGroupHidden;
  52. if( hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("list") && hiddenGroup.contains("view")){
  53. //this.node.setStyle("height", this.node.getSize().y - 50 );
  54. //this.container.setStyle("height", this.container.getSize().y - 50 );
  55. this.oldContentScrollNodeHeight = this.contentScrollNode.getStyle("min-height");
  56. this.contentScrollNode.setStyle("min-height",this.node.getStyle("min-height"));
  57. this.topNode.setStyle("display","none");
  58. this.isHiddenTop = true;
  59. return;
  60. }
  61. if( !hiddenGroup.contains("edit") )this.createEditGroupActions();
  62. if( !hiddenGroup.contains("read") )this.createReadGroupActions();
  63. if( !hiddenGroup.contains("list") )this.createListGroupActions();
  64. if( !hiddenGroup.contains("view") )this.createViewGroupActions();
  65. },
  66. reloadTopNode : function(){
  67. //if(this.topNode){
  68. // this.topNode.empty();
  69. // this.editActionBoxNode = null;
  70. // this.editActionsGroupNode=null;
  71. //}
  72. this.createTopNode();
  73. },
  74. loadMax: function(){
  75. if (!this.node) this.node = new Element("div", {"styles": this.css.container});
  76. this.createTopNode();
  77. if (!this.contentScrollNode){
  78. //this.createTopNode();
  79. this.createContentNode();
  80. if (this.options.resize){
  81. this.createBottomNode();
  82. this.createResizeNode();
  83. }
  84. this.node.inject(this.container);
  85. //if (this.options.readonly) this.setReadonly();
  86. this.checkActions();
  87. this.setEvent();
  88. }else{
  89. this.contentScrollNode.setStyle("display", "block");
  90. if (this.bottomNode) this.bottomNode.setStyle("display", "block");
  91. if (this.titleNode) this.titleNode.setStyle("display", "block");
  92. //this.topNode.setStyle("display", "block");
  93. this.content.empty();
  94. }
  95. var atts = [];
  96. while (this.attachments.length){
  97. var att = this.attachments.shift();
  98. atts.push(new MWF.widget.AttachmentController.Attachment(att.data, this));
  99. }
  100. this.attachments = atts;
  101. },
  102. loadMin: function(){
  103. var hiddenGroup = this.options.toolbarGroupHidden;
  104. var flag = hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("view");
  105. if (!this.node) this.node = new Element("div", {"styles": this.css.container_min});
  106. if (!this.minActionAreaNode) {
  107. this.minActionAreaNode = new Element("div", {"styles": this.css.minActionAreaNode}).inject(this.node);
  108. }else {
  109. this.minActionAreaNode.setStyle("display","");
  110. this.minActionAreaNode.empty();
  111. }
  112. if( flag )this.minActionAreaNode.setStyle("display","none");
  113. if( !this.minContent ){
  114. this.minContent = new Element("div", {"styles": this.css.minContentNode}).inject(this.node);
  115. }else{
  116. this.minContent.setStyle("display", "block");
  117. this.minContent.empty();
  118. }
  119. if (!hiddenGroup.contains("edit")){
  120. this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", MWF.LP.widget.upload, function (e, node) {
  121. this.uploadAttachment(e, node);
  122. }.bind(this));
  123. this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", MWF.LP.widget["delete"], function (e, node) {
  124. this.deleteAttachment(e, node);
  125. }.bind(this));
  126. this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", MWF.LP.widget.replace, function (e, node) {
  127. this.replaceAttachment(e, node);
  128. }.bind(this));
  129. }
  130. if (!hiddenGroup.contains("read")){
  131. this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", MWF.LP.widget.download, function (e, node) {
  132. this.downloadAttachment(e, node);
  133. }.bind(this));
  134. }
  135. if( !hiddenGroup.contains("edit") || !hiddenGroup.contains("read") ) {
  136. this.createSeparate(this.minActionAreaNode);
  137. }
  138. if( !hiddenGroup.contains("view")){
  139. this.sizeAction = this.createAction(this.minActionAreaNode, "max", MWF.LP.widget.min, function(){
  140. this.changeControllerSize();
  141. }.bind(this));
  142. }
  143. this.node.inject(this.container);
  144. //if (this.options.readonly) this.setReadonly();
  145. this.checkActions();
  146. this.setEvent();
  147. var atts = [];
  148. while (this.attachments.length){
  149. var att = this.attachments.shift();
  150. atts.push(new MWF.widget.AttachmentController.AttachmentMin(att.data, this));
  151. }
  152. this.attachments = atts;
  153. },
  154. createEditGroupActions: function(){
  155. if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  156. if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
  157. this.uploadAction = this.createAction(this.editActionsGroupNode, "upload", MWF.LP.widget.upload, function(e, node){
  158. this.uploadAttachment(e, node);
  159. }.bind(this));
  160. this.deleteAction = this.createAction(this.editActionsGroupNode, "delete", MWF.LP.widget["delete"], function(e, node){
  161. this.deleteAttachment(e, node);
  162. }.bind(this));
  163. this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", MWF.LP.widget.replace, function(e, node){
  164. this.replaceAttachment(e, node);
  165. }.bind(this));
  166. if( !this.options.toolbarGroupHidden.contains("read") )this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode);
  167. },
  168. createReadGroupActions: function(){
  169. //this.readActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  170. //this.readActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.readActionBoxNode);
  171. if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  172. if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
  173. this.downloadAction = this.createAction(this.editActionsGroupNode, "download", MWF.LP.widget.download, function(){
  174. this.downloadAttachment();
  175. }.bind(this));
  176. //this.createAction(this.readActionsGroupNode, "share", MWF.LP.widget.share, function(){
  177. // this.transAttachment();
  178. //}.bind(this));
  179. //this.downloadAllAction = this.createAction(this.editActionsGroupNode, "downloadAll", MWF.LP.widget.downloadAll, function(){
  180. // this.downloadAllAttachment();
  181. //}.bind(this));
  182. },
  183. resetToolbarGroupHidden : function( hiddenGroup ){
  184. this.options.toolbarGroupHidden = hiddenGroup;
  185. if( this.options.size == "max" ){
  186. this.reloadTopNode();
  187. }else{
  188. this.loadMin();
  189. }
  190. }
  191. });