AttachmentController.js 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521
  1. o2.widget = o2.widget || {};
  2. if( !o2.widget.UUID )o2.require("o2.widget.UUID", null, false);
  3. o2.widget.AttachmentController = o2.widget.ATTER = new Class({
  4. Extends: o2.widget.Common,
  5. Implements: [Options, Events],
  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. "isPreviewAtt": true,
  17. "isSizeChange": true,
  18. "isConfig": true,
  19. "isOrder": true,
  20. "readonly": false,
  21. "availableListStyles" : ["list","seq","icon","preview"],
  22. "toolbarGroupHidden" : [], //edit read list view
  23. "images": ["bmp", "gif", "png", "jpeg", "jpg", "jpe", "ico"],
  24. "audios": ["mp3", "wav", "wma", "wmv"],
  25. "videos": ["avi", "mkv", "mov", "ogg", "mp4", "mpa", "mpe", "mpeg", "mpg", "rmvb"],
  26. "actionShowText" : false
  27. },
  28. initialize: function(container, module, options){
  29. this.setOptions(options);
  30. this.pages = [];
  31. this.path = o2.session.path+"/widget/$AttachmentController/";
  32. this.cssPath = o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/css.wcss";
  33. this._loadCss();
  34. var iconUrl = this.options.iconConfigUrl ? this.options.iconConfigUrl : "../x_component_File/$Main/icon.json";
  35. o2.getJSON(iconUrl, function(json){
  36. this.icons = json;
  37. }.bind(this), false);
  38. this.module = module;
  39. this.actions = [];
  40. this.attachments = [];
  41. this.selectedAttachments = [];
  42. this.container = $(container);
  43. },
  44. load: function(){
  45. // if (!layout.mobile){
  46. if (this.options.size==="min"){
  47. this.loadMin();
  48. }else{
  49. this.loadMax();
  50. }
  51. // }else{
  52. // this.loadMobile();
  53. // }
  54. },
  55. reloadAttachments: function(){
  56. if (this.options.size==="min"){
  57. this.minContent.empty();
  58. var atts = this.attachments;
  59. this.attachments = [];
  60. while (atts.length){
  61. var att = atts.shift();
  62. this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(att.data, this));
  63. }
  64. }else{
  65. this.content.empty();
  66. var atts = this.attachments;
  67. this.attachments = [];
  68. while (atts.length){
  69. var att = atts.shift();
  70. this.attachments.push(new o2.widget.AttachmentController.Attachment(att.data, this));
  71. }
  72. }
  73. this.checkActions();
  74. },
  75. getAttachmentById: function(attId){
  76. for( var i=0; i<this.attachments.length; i++ ){
  77. if( this.attachments[i].data.id === attId ){
  78. return this.attachments[i];
  79. }
  80. }
  81. return null;
  82. },
  83. loadMax: function(){
  84. if (!this.node) this.node = new Element("div", {"styles": this.css.container});
  85. this.createTopNode();
  86. if (!this.contentScrollNode){
  87. //this.createTopNode();
  88. this.createContentNode();
  89. if (this.options.resize){
  90. this.createBottomNode();
  91. this.createResizeNode();
  92. }
  93. this.node.inject(this.container);
  94. //if (this.options.readonly) this.setReadonly();
  95. this.checkActions();
  96. this.setEvent();
  97. }else{
  98. this.contentScrollNode.setStyle("display", "block");
  99. if (this.bottomNode) this.bottomNode.setStyle("display", "block");
  100. if (this.titleNode) this.titleNode.setStyle("display", "block");
  101. //this.topNode.setStyle("display", "block");
  102. this.content.empty();
  103. }
  104. var atts = this.attachments;
  105. this.attachments = [];
  106. while (atts.length){
  107. var att = atts.shift();
  108. this.attachments.push(new o2.widget.AttachmentController.Attachment(att.data, this));
  109. }
  110. this.checkActions();
  111. //this.attachments = atts;
  112. if( layout.mobile ){
  113. this.checkActionsZoom();
  114. }
  115. },
  116. loadMin: function(){
  117. if (!this.node) this.node = new Element("div", {"styles": this.css.container_min});
  118. if (!this.minActionAreaNode){
  119. this.minActionAreaNode = new Element("div", {"styles": this.css.minActionAreaNode }).inject(this.node);
  120. //this.minContent = new Element("div", {"styles": this.css.minContentNode}).inject(this.node);
  121. this.loadMinActions();
  122. this.node.inject(this.container);
  123. //if (this.options.readonly) this.setReadonly();
  124. //this.checkActions();
  125. this.setEvent();
  126. }else{
  127. this.minActionAreaNode.setStyle("display", "");
  128. //this.minContent.setStyle("display", "block");
  129. //this.minContent.empty();
  130. this.minActionAreaNode.empty();
  131. this.loadMinActions();
  132. this.setEvent();
  133. }
  134. var hiddenGroup = this.options.toolbarGroupHidden;
  135. var flag = hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("view");
  136. if( flag )this.minActionAreaNode.setStyle("display","none");
  137. if( !this.minContent ){
  138. this.minContent = new Element("div", {"styles":
  139. layout.mobile ? this.css.minContentNode_mobile : this.css.minContentNode
  140. }).inject(this.node);
  141. if( layout.mobile ){
  142. this.minContent.setStyle("clear","both");
  143. }
  144. }else{
  145. this.minContent.setStyle("display", "block");
  146. this.minContent.empty();
  147. }
  148. var atts = this.attachments;
  149. this.attachments = [];
  150. while (atts.length){
  151. var att = atts.shift();
  152. this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(att.data, this));
  153. }
  154. this.checkActions();
  155. //this.attachments = atts;
  156. },
  157. loadMobile: function(){
  158. },
  159. loadMinActions: function(){
  160. var hiddenGroup = this.options.toolbarGroupHidden;
  161. if (!hiddenGroup.contains("edit")) {
  162. this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", o2.LP.widget.upload, function (e, node) {
  163. this.uploadAttachment(e, node);
  164. }.bind(this));
  165. this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", o2.LP.widget["delete"], function (e, node) {
  166. this.deleteAttachment(e, node);
  167. }.bind(this));
  168. if( !this.options.isReplaceHidden ){
  169. this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", o2.LP.widget.replace, function (e, node) {
  170. this.replaceAttachment(e, node);
  171. }.bind(this));
  172. }
  173. }
  174. if (!hiddenGroup.contains("read")) {
  175. this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", o2.LP.widget.download, function (e, node) {
  176. this.downloadAttachment(e, node);
  177. }.bind(this));
  178. }
  179. var hasChangeSize = this.options.isSizeChange && !hiddenGroup.contains("view");
  180. if( (!hiddenGroup.contains("edit") || !hiddenGroup.contains("read")) && hasChangeSize ) {
  181. this.createSeparate(this.minActionAreaNode);
  182. }
  183. if (hasChangeSize){
  184. this.sizeAction = this.createAction(this.minActionAreaNode, "max", o2.LP.widget.min, function () {
  185. this.changeControllerSize();
  186. }.bind(this));
  187. }
  188. },
  189. setEvent: function(){
  190. if (this.contentScrollNode && !this.isContentSetEvent){
  191. this.contentScrollNode.addEventListener("dragover", function( e ) {
  192. e.preventDefault();
  193. e.stopPropagation();
  194. }, false);
  195. this.contentScrollNode.addEventListener("drop", function( e ) {
  196. this.uploadAttachment(e, null, e.dataTransfer.files);
  197. event.preventDefault();
  198. }.bind(this), false);
  199. this.contentScrollNode.addEvents({
  200. "mousedown": this.unSelectedAttachments.bind(this)
  201. });
  202. this.isContentSetEvent = true;
  203. }
  204. if (this.minContent && !this.isMinContentSetEvent){
  205. this.minContent.addEventListener("dragover", function( e ) {
  206. e.preventDefault();
  207. e.stopPropagation();
  208. }, false);
  209. this.minContent.addEventListener("drop", function( e ) {
  210. this.uploadAttachment(e, null, e.dataTransfer.files);
  211. event.preventDefault();
  212. }.bind(this), false);
  213. this.minContent.addEvents({
  214. "mousedown": this.unSelectedAttachments.bind(this)
  215. });
  216. this.isMinContentSetEvent = true;
  217. }
  218. },
  219. resetToolbarGroupHidden : function( hiddenGroup ){
  220. this.options.toolbarGroupHidden = hiddenGroup;
  221. if( this.options.size == "max" ){
  222. this.reloadTopNode();
  223. }else{
  224. this.loadMin();
  225. }
  226. },
  227. resetToolbarAvailableListStyle : function( availableListStyle ){
  228. this.options.availableListStyles = availableListStyle;
  229. if( this.options.size == "max" ){
  230. this.reloadTopNode();
  231. }else{
  232. this.loadMin();
  233. }
  234. },
  235. createContentNode: function(){
  236. this.contentScrollNode = new Element("div.contentScrollNode", {"styles": this.css.contentScrollNode}).inject(this.node);
  237. this.content = new Element("div.content", {"styles": this.css.contentNode}).inject(this.contentScrollNode);
  238. o2.require("o2.widget.ScrollBar", function(){
  239. new o2.widget.ScrollBar(this.contentScrollNode, {
  240. "style":"attachment", "where": "before", "distance": 30, "friction": 4, "axis": {"x": false, "y": true}
  241. });
  242. }.bind(this));
  243. },
  244. createBottomNode: function(){
  245. this.bottomNode = new Element("div", {"styles": this.css.bottomNode}).inject(this.node);
  246. },
  247. createResizeNode: function(){
  248. this.resizeNode = new Element("div", {"styles": this.css.resizeNode}).inject(this.bottomNode);
  249. this.resizeDrag = new Drag(this.resizeNode, {
  250. "snap": "2",
  251. "onStart": function(el, e){
  252. el.store("startY", e.event.y);
  253. el.store("nodeHeight", this.node.getSize().y);
  254. var minHeight = this.node.getStyle("min-height");
  255. el.store("nodeMinHeight", minHeight ? minHeight.toFloat() : "");
  256. var contentScrollNodeMinHeight = this.contentScrollNode.getStyle("min-height");
  257. el.store("contentScrollNodeMinHeight", contentScrollNodeMinHeight ? contentScrollNodeMinHeight.toFloat() : "");
  258. if (!this.nodeHeight){
  259. this.nodeHeight = minHeight.toFloat();
  260. }
  261. }.bind(this),
  262. "onDrag": function(el, e){
  263. var y = el.retrieve("startY");
  264. var nodeHeight = el.retrieve("nodeHeight");
  265. var nodeMinHeight = el.retrieve("nodeMinHeight");
  266. var contentScrollNodeMinHeight = el.retrieve("contentScrollNodeMinHeight");
  267. var setY = (e.event.y-y)+nodeHeight;
  268. if( nodeMinHeight && setY < nodeMinHeight && e.event.y<y)return;
  269. if (setY<this.nodeHeight) setY = this.nodeHeight;
  270. var setContentY = setY-81;
  271. if( contentScrollNodeMinHeight && setContentY < contentScrollNodeMinHeight && e.event.y<y )return;
  272. this.node.setStyle("height", ""+setY+"px");
  273. this.contentScrollNode.setStyle("height", ""+setContentY+"px");
  274. }.bind(this)
  275. });
  276. },
  277. createTopNode: function(){
  278. if (this.options.title){
  279. if (!this.titleNode) this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.options.title}).inject(this.node);
  280. }
  281. if( !this.topNode ){
  282. this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  283. }else{
  284. this.topNode.empty();
  285. this.editActionBoxNode = null;
  286. this.editActionsGroupNode=null;
  287. this.topNode.setStyle("display","");
  288. if( this.isHiddenTop ){
  289. if( this.oldContentScrollNodeHeight && this.contentScrollNode ){
  290. this.contentScrollNode.setStyle("min-height",this.oldContentScrollNodeHeight);
  291. this.oldContentScrollNodeHeight = null;
  292. }
  293. this.isHiddenTop = false;
  294. }
  295. }
  296. var hiddenGroup = this.options.toolbarGroupHidden;
  297. if( hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("list") && hiddenGroup.contains("view")){
  298. if(this.contentScrollNode){
  299. this.oldContentScrollNodeHeight = this.contentScrollNode.getStyle("min-height");
  300. this.contentScrollNode.setStyle("min-height",this.node.getStyle("min-height"));
  301. this.topNode.setStyle("display","none");
  302. }
  303. this.isHiddenTop = true;
  304. return;
  305. }
  306. if( !hiddenGroup.contains("edit") )this.createEditGroupActions();
  307. if( !hiddenGroup.contains("read") )this.createReadGroupActions();
  308. if( !hiddenGroup.contains("list") )this.createListGroupActions();
  309. if( !hiddenGroup.contains("view") )this.createViewGroupActions();
  310. if( layout.mobile ){
  311. this.checkActionsZoom();
  312. }
  313. //this.topNode = new Element("div", {"styles": this.css.topNode}).inject(this.node);
  314. //this.createEditGroupActions();
  315. //this.createReadGroupActions();
  316. //this.createListGroupActions();
  317. //this.createViewGroupActions();
  318. //this.createConfigGroupActions();
  319. },
  320. checkActionsZoom: function(){
  321. var width = 0;
  322. this.topNode.getChildren().each(function( node ){
  323. if(node.offsetParent)width = width + node.getSize().x + this.getOffsetX(node)
  324. }.bind(this));
  325. var topSize = this.topNode.getSize();
  326. if( (topSize.x - 5) < width ){
  327. var zoom = this.getDecimals((topSize.x - 5) / width);
  328. this.topNode.setStyle( "zoom", zoom*100+"%" );
  329. }
  330. },
  331. getDecimals: function(v){ //截取两位小数
  332. var decimals = 4;
  333. var p = Math.pow(10,decimals);
  334. var f_x = Math.round(v*p)/p;
  335. var str = f_x.toString();
  336. if (decimals>0){
  337. var pos_decimal = str.indexOf('.');
  338. if (pos_decimal < 0){
  339. pos_decimal = str.length;
  340. str += '.';
  341. }
  342. var decimalStr = (str).substr(pos_decimal+1, (str).length);
  343. while (decimalStr.length < decimals){
  344. str += '0';
  345. decimalStr += 0;
  346. }
  347. }
  348. return str;
  349. },
  350. getOffsetX : function(node){
  351. return (node.getStyle("margin-left").toInt() || 0 ) +
  352. (node.getStyle("margin-right").toInt() || 0 ) +
  353. (node.getStyle("padding-left").toInt() || 0 ) +
  354. (node.getStyle("padding-right").toInt() || 0 )+
  355. (node.getStyle("border-left-width").toInt() || 0 ) +
  356. (node.getStyle("border-right-width").toInt() || 0 );
  357. },
  358. reloadTopNode : function(){
  359. this.createTopNode();
  360. },
  361. createEditGroupActions: function(){
  362. if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  363. if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
  364. this.uploadAction = this.createAction(this.editActionsGroupNode, "upload", o2.LP.widget.upload, function(e, node){
  365. this.uploadAttachment(e, node);
  366. }.bind(this));
  367. this.deleteAction = this.createAction(this.editActionsGroupNode, "delete", o2.LP.widget["delete"], function(e, node){
  368. this.deleteAttachment(e, node);
  369. }.bind(this));
  370. if( !this.options.isReplaceHidden ){
  371. this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", o2.LP.widget.replace, function(e, node){
  372. this.replaceAttachment(e, node);
  373. }.bind(this));
  374. }
  375. // this.officeAction = this.createAction(this.editActionsGroupNode, "office", o2.LP.widget.office, function(e, node){
  376. // this.openInOfficeControl(e, node);
  377. // }.bind(this));
  378. if( !this.options.toolbarGroupHidden.contains("read") )this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode);
  379. },
  380. createReadGroupActions: function(){
  381. //this.readActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  382. //this.readActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.readActionBoxNode);
  383. if(!this.editActionBoxNode)this.editActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  384. if(!this.editActionsGroupNode)this.editActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.editActionBoxNode);
  385. this.downloadAction = this.createAction(this.editActionsGroupNode, "download", o2.LP.widget.download, function(){
  386. this.downloadAttachment();
  387. }.bind(this));
  388. //this.createAction(this.readActionsGroupNode, "share", o2.LP.widget.share, function(){
  389. // this.transAttachment();
  390. //}.bind(this));
  391. //this.downloadAllAction = this.createAction(this.editActionsGroupNode, "downloadAll", o2.LP.widget.downloadAll, function(){
  392. // this.downloadAllAttachment();
  393. //}.bind(this));
  394. },
  395. createListGroupActions: function(){
  396. var availableListStyles = this.options.availableListStyles;
  397. if( availableListStyles && availableListStyles.length > 0 ){
  398. this.listActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  399. this.listActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.listActionBoxNode);
  400. if( availableListStyles.contains("list") ){
  401. this.listAction = this.createAction(this.listActionsGroupNode, "list", o2.LP.widget.list, function(){
  402. this.changeListStyle("list");
  403. }.bind(this));
  404. }
  405. if( availableListStyles.contains("seq") ) {
  406. this.sequenceAction = this.createAction(this.listActionsGroupNode, "seq", o2.LP.widget.sequence, function () {
  407. this.changeListStyle("sequence");
  408. }.bind(this));
  409. }
  410. if( availableListStyles.contains("icon") ) {
  411. this.iconAction = this.createAction(this.listActionsGroupNode, "icon", o2.LP.widget.icon, function () {
  412. this.changeListStyle("icon");
  413. }.bind(this));
  414. }
  415. if( availableListStyles.contains("preview") ) {
  416. this.previewAction = this.createAction(this.listActionsGroupNode, "preview", o2.LP.widget.preview, function () {
  417. this.changeListStyle("preview");
  418. }.bind(this));
  419. }
  420. }
  421. },
  422. createViewGroupActions: function(){
  423. if (this.options.isSizeChange){
  424. this.viewActionBoxNode = new Element("div", {"styles": this.css.actionsBoxNode}).inject(this.topNode);
  425. this.viewActionBoxNode.setStyles({"float": "right", "margin-right": "7px"});
  426. this.viewActionsGroupNode = new Element("div", {"styles": this.css.actionsGroupNode}).inject(this.viewActionBoxNode);
  427. this.sizeAction = this.createAction(this.viewActionsGroupNode, "min", o2.LP.widget.min, function(){
  428. this.changeControllerSize();
  429. }.bind(this));
  430. }
  431. },
  432. createSeparate: function(groupNode){
  433. var separateNode = new Element("div.separateNode", {"styles": this.css.separateNode}).inject(groupNode);
  434. return separateNode;
  435. },
  436. createAction: function(groupNode, img, title, click){
  437. var actionNode = new Element("div", {"styles": this.css.actionNode, "title": title}).inject(groupNode);
  438. var actionIconNode = new Element("div", {"styles": this.css.actionIconNode}).inject(actionNode);
  439. actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/icon/"+img+".png)");
  440. var _self = this;
  441. actionNode.addEvents({
  442. "mouseover": function(){
  443. if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.options.style+"/overbg.png)");
  444. },
  445. "mouseout": function(){
  446. if (!this.retrieve("disabled")) if (!this.retrieve("selected")) this.setStyle("background", "transparent");
  447. },
  448. "click": function(e){
  449. if (!this.retrieve("disabled")) _self.doAction(e, this, click);
  450. e.stopPropagation();
  451. }
  452. });
  453. this.actions.push(actionNode);
  454. return actionNode;
  455. },
  456. checkActions: function(){
  457. // if (this.options.readonly){
  458. // this.setReadonly();
  459. // }else{
  460. this.checkUploadAction();
  461. this.checkDeleteAction();
  462. this.checkReplaceAction();
  463. //this.checkOfficeAction();
  464. this.checkDownloadAction();
  465. this.checkSizeAction();
  466. this.checkListStyleAction();
  467. if( this.options.size === "max" ){
  468. this.checkEditActionBox();
  469. }
  470. },
  471. checkEditActionBox: function(){
  472. var isShowEdit = false;
  473. ["isUpload", "isDelete", "isReplace"].each(function( key ){
  474. if( key === "isReplace" && this.options.isReplaceHidden )return;
  475. if( this.options[key] !== "hidden" )isShowEdit = true;
  476. }.bind(this));
  477. var isShowRead = false;
  478. ["isDownload"].each(function( key ){
  479. if( this.options[key] !== "hidden" )isShowRead = true;
  480. }.bind(this));
  481. if(this.editActionSeparateNode)this.editActionSeparateNode.setStyle( "display", isShowEdit && isShowRead ? "" : "none" );
  482. if(this.editActionBoxNode )this.editActionBoxNode.setStyle( "display", isShowEdit || isShowRead ? "" : "none" );
  483. },
  484. checkUploadAction: function(){
  485. if (this.options.readonly) {
  486. if (this.options.isUpload === "hidden") {
  487. this.setActionHidden(this.uploadAction);
  488. this.setActionHidden(this.min_uploadAction);
  489. } else {
  490. this.setActionDisabled(this.uploadAction);
  491. this.setActionDisabled(this.min_uploadAction);
  492. }
  493. return false;
  494. }
  495. if (this.options.isUpload === "hidden" ){
  496. this.setActionHidden(this.uploadAction);
  497. this.setActionHidden(this.min_uploadAction);
  498. }else if (!this.options.isUpload){
  499. this.setActionDisabled(this.uploadAction);
  500. this.setActionDisabled(this.min_uploadAction);
  501. }else{
  502. if (this.options.attachmentCount.toInt() > 0){
  503. if (this.attachments.length>=this.options.attachmentCount.toInt()){
  504. this.setActionDisabled(this.uploadAction);
  505. this.setActionDisabled(this.min_uploadAction);
  506. }else{
  507. this.setActionEnabled(this.uploadAction);
  508. this.setActionEnabled(this.min_uploadAction);
  509. }
  510. }else{
  511. this.setActionEnabled(this.uploadAction);
  512. this.setActionEnabled(this.min_uploadAction);
  513. }
  514. }
  515. },
  516. checkDeleteAction: function(){
  517. if (this.options.readonly){
  518. if (this.options.isDelete === "hidden") {
  519. this.setActionHidden(this.deleteAction);
  520. this.setActionHidden(this.min_deleteAction);
  521. } else {
  522. this.setActionDisabled(this.deleteAction);
  523. this.setActionDisabled(this.min_deleteAction);
  524. }
  525. this.setAttachmentsAction("delete", false );
  526. return false;
  527. }
  528. if (this.options.isDelete === "hidden") {
  529. this.setActionHidden(this.deleteAction);
  530. this.setActionHidden(this.min_deleteAction);
  531. this.setAttachmentsAction("delete", false );
  532. } else if (!this.options.isDelete){
  533. this.setActionDisabled(this.deleteAction);
  534. this.setActionDisabled(this.min_deleteAction);
  535. this.setAttachmentsAction("delete", false );
  536. }else{
  537. if (this.selectedAttachments.length){
  538. this.setActionEnabled(this.deleteAction);
  539. this.setActionEnabled(this.min_deleteAction);
  540. }else{
  541. this.setActionDisabled(this.deleteAction);
  542. this.setActionDisabled(this.min_deleteAction);
  543. }
  544. this.setAttachmentsAction("delete", true );
  545. }
  546. },
  547. isAttDeleteAvailable : function( att ){
  548. if (this.options.readonly)return false;
  549. if( this.options.toolbarGroupHidden.contains("edit") )return false;
  550. return this.options.isDelete && this.options.isDelete !== "hidden";
  551. },
  552. isAttEditAvailable : function( att ){
  553. if (this.options.readonly)return false;
  554. if( this.options.toolbarGroupHidden.contains("edit") )return false;
  555. return this.options.isEditAtt && this.options.isEditAtt !== "hidden";
  556. },
  557. // checkOfficeAction: function(){
  558. // if (this.officeAction) this.officeAction.setStyle("display", "none");
  559. // if (this.min_officeAction) this.min_officeAction.setStyle("display", "none");
  560. // },
  561. checkReplaceAction: function(){
  562. if( this.options.isReplaceHidden )return;
  563. if (this.options.readonly){
  564. if( this.options.isReplace === "hidden" ){
  565. this.setActionHidden(this.replaceAction);
  566. this.setActionHidden(this.min_replaceAction);
  567. }else{
  568. this.setActionDisabled(this.replaceAction);
  569. this.setActionDisabled(this.min_replaceAction);
  570. }
  571. this.setAttachmentsAction("replace", false );
  572. return false;
  573. }
  574. if( this.options.isReplace === "hidden" ){
  575. this.setActionHidden(this.replaceAction);
  576. this.setActionHidden(this.min_replaceAction);
  577. this.setAttachmentsAction("replace", false );
  578. }else if (!this.options.isReplace){
  579. this.setActionDisabled(this.replaceAction);
  580. this.setActionDisabled(this.min_replaceAction);
  581. this.setAttachmentsAction("replace", false );
  582. }else{
  583. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  584. this.setActionEnabled(this.replaceAction);
  585. this.setActionEnabled(this.min_replaceAction);
  586. }else{
  587. this.setActionDisabled(this.replaceAction);
  588. this.setActionDisabled(this.min_replaceAction);
  589. }
  590. this.setAttachmentsAction("replace", true );
  591. }
  592. },
  593. isAttReplaceAvailable : function( att ){
  594. if (this.options.readonly)return false;
  595. if( this.options.toolbarGroupHidden.contains("edit") )return false;
  596. return this.options.isReplace && this.options.isReplace !== "hidden";
  597. },
  598. checkDownloadAction: function(){
  599. if( this.options.isDownload === "hidden" ){
  600. this.setActionHidden(this.downloadAction);
  601. this.setActionHidden(this.min_downloadAction);
  602. this.setActionHidden(this.downloadAllAction);
  603. this.setAttachmentsAction("download", false );
  604. }else if (!this.options.isDownload){
  605. this.setActionDisabled(this.downloadAction);
  606. this.setActionDisabled(this.min_downloadAction);
  607. this.setActionDisabled(this.downloadAllAction);
  608. this.setAttachmentsAction("download", false );
  609. }else{
  610. if (this.selectedAttachments.length){
  611. this.setActionEnabled(this.downloadAction);
  612. this.setActionEnabled(this.min_downloadAction);
  613. }else{
  614. this.setActionDisabled(this.downloadAction);
  615. this.setActionDisabled(this.min_downloadAction);
  616. }
  617. this.setActionEnabled(this.downloadAllAction);
  618. this.setAttachmentsAction("download", true );
  619. }
  620. },
  621. isAttDblclickAvailable : function( att ){
  622. return this.options.dblclick && this.options.dblclick !== "hidden";
  623. },
  624. isAttDownloadAvailable : function( att ){
  625. if( this.options.toolbarGroupHidden.contains("read") )return false;
  626. return this.options.isDownload && this.options.isDownload !== "hidden";
  627. },
  628. checkSizeAction: function(){
  629. if( this.sizeAction ){
  630. if (this.options.isSizeChange){
  631. this.setActionEnabled(this.sizeAction);
  632. }else{
  633. this.setActionDisabled(this.sizeAction);
  634. }
  635. }
  636. },
  637. checkListStyleAction: function(){
  638. switch (this.options.listStyle){
  639. case "list":
  640. this.setActionSelcted(this.listAction);
  641. this.setActionUnSelcted(this.iconAction);
  642. this.setActionUnSelcted(this.previewAction);
  643. this.setActionUnSelcted(this.sequenceAction);
  644. break;
  645. case "icon":
  646. this.setActionUnSelcted(this.listAction);
  647. this.setActionSelcted(this.iconAction);
  648. this.setActionUnSelcted(this.previewAction);
  649. this.setActionUnSelcted(this.sequenceAction);
  650. break;
  651. case "preview":
  652. this.setActionUnSelcted(this.listAction);
  653. this.setActionUnSelcted(this.iconAction);
  654. this.setActionSelcted(this.previewAction);
  655. this.setActionUnSelcted(this.sequenceAction);
  656. break;
  657. case "sequence":
  658. this.setActionUnSelcted(this.listAction);
  659. this.setActionUnSelcted(this.iconAction);
  660. this.setActionUnSelcted(this.previewAction);
  661. this.setActionSelcted(this.sequenceAction);
  662. break;
  663. }
  664. },
  665. setActionSelcted: function(action){
  666. if (action){
  667. if (!action.retrieve("selected")){
  668. action.setStyle("background", "url("+o2.session.path+"/widget/$AttachmentController/"+this.options.style+"/selectedbg.png)");
  669. action.store("selected", true);
  670. }
  671. }
  672. },
  673. setActionUnSelcted: function(action){
  674. if (action){
  675. if (action.retrieve("selected")){
  676. action.setStyle("background", "");
  677. action.store("selected", false);
  678. }
  679. }
  680. },
  681. setActionEnabled: function(action){
  682. if (action){
  683. action.show();
  684. if (action.retrieve("disabled")){
  685. var iconNode = action.getFirst();
  686. var icon = iconNode.getStyle("background-image");
  687. var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
  688. icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext;
  689. iconNode.setStyle("background-image", icon);
  690. action.store("disabled", false);
  691. }
  692. }
  693. },
  694. setActionDisabled: function(action){
  695. if (action){
  696. if (!action.retrieve("disabled")){
  697. var iconNode = action.getFirst();
  698. var icon = iconNode.getStyle("background-image");
  699. var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
  700. icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext;
  701. iconNode.setStyle("background-image", icon);
  702. action.store("disabled", true);
  703. }
  704. }
  705. },
  706. setActionHidden: function(action){
  707. if (action)action.hide();
  708. },
  709. setReadonly: function() {
  710. this.actions.each(function(action){
  711. this.setActionDisabled(action);
  712. this.setAttachmentsAction("all", false );
  713. }.bind(this));
  714. },
  715. setAttachmentsAction : function(type, enable){
  716. this.attachments.each( function( att ){
  717. this.setAttachmentAction( att, type, enable )
  718. }.bind(this))
  719. },
  720. setAttachmentAction : function(att, type, enable){
  721. var action;
  722. if( type === "all" ){
  723. ( att.actions || [] ).each( function(action){
  724. att[ enable ? "setActionEnabled" : "setActionDisabled" ](action);
  725. })
  726. }else{
  727. switch( type ){
  728. case "download" :
  729. action = att.downloadAction;
  730. break;
  731. case "config" :
  732. action = att.configAction;
  733. break;
  734. case "delete" :
  735. action = att.deleteAction;
  736. break;
  737. case "replace" :
  738. action = att.replaceAction;
  739. break;
  740. }
  741. if( !action )return;
  742. if( type === "config" ){
  743. var flag = enable;
  744. if( flag ){
  745. var user = layout.session.user.distinguishedName;
  746. if( !att.data.person && att.data.creatorUid )att.data.person = att.data.creatorUid;
  747. if ((!att.data.control.allowControl ) && att.data.person!==user){ //|| !att.data.control.allowEdit
  748. flag = false;
  749. }
  750. }
  751. att[ flag ? "setActionEnabled" : "setActionDisabled" ](action);
  752. }else{
  753. att[ enable ? "setActionEnabled" : "setActionDisabled" ](action);
  754. }
  755. }
  756. },
  757. doAction: function(e, node, action){
  758. if (action){
  759. action.apply(this, [e, node]);
  760. }
  761. },
  762. uploadAttachment: function(e, node, files){
  763. debugger;
  764. if (this.module) this.module.uploadAttachment(e, node, files);
  765. },
  766. doUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){
  767. if (this.options.isUpload && this.options.isUpload !== "hidden" ){
  768. if (FormData.expiredIE){
  769. this.doInputUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery);
  770. }else{
  771. this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files);
  772. }
  773. }else{
  774. var text = o2.LP.widget.notUploadNotice;
  775. if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
  776. }
  777. },
  778. addUploadMessage: function(fileName){
  779. var contentHTML = "";
  780. contentHTML = "<div style=\"overflow: hidden\"><div style=\"height: 2px; border:0px solid #999; margin: 3px 0px\">" +
  781. "<div style=\"height: 2px; background-color: #acdab9; width: 0px;\"></div></div>" +
  782. "<div style=\"height: 20px; line-height: 20px\">"+o2.LP.desktop.action.uploadTitle+"</div></div>" +
  783. "<iframe name='o2_upload_iframe' style='display:none'></iframe>" ;
  784. var msg = {
  785. "subject": o2.LP.desktop.action.uploadTitle,
  786. "content": fileName+"<br/>"+contentHTML
  787. };
  788. if (layout.desktop.message){
  789. var messageItem = layout.desktop.message.addMessage(msg);
  790. messageItem.close = function(callback, e){
  791. if (!messageItem.completed){
  792. }else{
  793. messageItem.closeItem(callback, e);
  794. }
  795. };
  796. }
  797. window.setTimeout(function(){
  798. if (layout.desktop.message) if (!layout.desktop.message.isShow) layout.desktop.message.show();
  799. }.bind(this), 300);
  800. return messageItem;
  801. },
  802. setMessageTitle: function(messageItem, text){
  803. if (messageItem) messageItem.subjectNode.set("text", text);
  804. },
  805. setMessageText: function(messageItem, text){
  806. if (messageItem){
  807. var progressNode = messageItem.contentNode.getFirst("div").getFirst("div");
  808. var progressPercentNode = progressNode.getFirst("div");
  809. var progressInforNode = messageItem.contentNode.getFirst("div").getLast("div");
  810. progressInforNode.set("text", text);
  811. messageItem.dateNode.set("text", (new Date()).format("db"));
  812. }
  813. },
  814. doInputUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, failureEvery){
  815. var restActions = action;
  816. if (typeOf(action)=="string"){
  817. restActions = o2.Actions.get(action).action;
  818. }
  819. restActions.getActions(function(){
  820. var url = restActions.actions[invokeUrl];
  821. url = restActions.address+url.uri;
  822. Object.each(parameter, function(v, k){
  823. url = url.replace("{"+k+"}", v);
  824. });
  825. var maskNode = this.module.content;
  826. if (!maskNode){
  827. if (this.module.form){
  828. maskNode = this.module.form.app.content;
  829. }
  830. }
  831. if (!maskNode) maskNode = this.node;
  832. //var maskNode = this.module.content || this.module.node;
  833. if (maskNode){
  834. maskNode.mask({
  835. "style": {
  836. "opacity": 0.7,
  837. "background-color": "#999"
  838. }
  839. });
  840. }
  841. this.inputUploadAreaNode = new Element("div", {"styles": this.css.inputUploadAreaNode}).inject(this.container);
  842. this.inputUploadAreaNode.position({
  843. relativeTo: this.module.content,
  844. position: "center"
  845. });
  846. var messageItem = null;
  847. document.O2UploadCallbackFun = function(str){
  848. var json = JSON.decode(str);
  849. messageItem.completed = true;
  850. if (json.type==="success"){
  851. if (every) every(json.data);
  852. this.setMessageTitle(messageItem, o2.LP.desktop.action.uploadComplete);
  853. this.setMessageText(messageItem, o2.LP.desktop.action.uploadComplete);
  854. if(finish) finish();
  855. }else{
  856. //formNode.unmask();
  857. // if(failureEvery)failureEvery(json);
  858. this.setMessageTitle(messageItem, o2.LP.desktop.action.sendError);
  859. this.setMessageText(messageItem, o2.LP.desktop.action.sendError+": "+json.message);
  860. o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
  861. }
  862. }.bind(this);
  863. var formNode = new Element("form", {
  864. "method": "POST",
  865. "action": url+"/callback/window.frameElement.ownerDocument.O2UploadCallbackFun",
  866. //"action": url,
  867. "enctype": "multipart/form-data",
  868. "target": "o2_upload_iframe"
  869. }).inject(this.inputUploadAreaNode);
  870. var titleNode = new Element("div", {"styles": this.css.inputUploadAreaTitleNode, "text": o2.LP.widget.uploadTitle}).inject(formNode);
  871. var inforNode = new Element("div", {"styles": this.css.inputUploadAreaInforNode, "text": o2.LP.widget.uploadInfor}).inject(formNode);
  872. var inputAreaNode = new Element("div", {"styles": this.css.inputUploadAreaInputAreaNode}).inject(formNode);
  873. var inputNode = new Element("input", {"name":"file", "type": "file", "styles": this.css.inputUploadAreaInputNode}).inject(inputAreaNode);
  874. var inputNameNode = new Element("input", {"type": "hidden", "name": "fileName"}).inject(inputAreaNode);
  875. Object.each(obj, function(v, k){
  876. new Element("input", {"type": "hidden", "name": k, "value": v}).inject(inputAreaNode);
  877. });
  878. var actionNode = new Element("div", {"styles": this.css.inputUploadActionNode}).inject(formNode);
  879. var cancelButton = new Element("button", {"styles": this.css.inputUploadCancelButton, "text": o2.LP.widget.cancel}).inject(actionNode);
  880. var okButton = new Element("input", {"type": "button", "styles": this.css.inputUploadOkButton, "value": o2.LP.widget.ok}).inject(actionNode);
  881. inputNode.addEvent("change", function(){
  882. var fileName = inputNode.get("value");
  883. if (fileName){
  884. var tmpv = fileName.replace(/\\/g, "/");
  885. var i = tmpv.lastIndexOf("/");
  886. var fname = (i===-1) ? tmpv : tmpv.substr(i+1, tmpv.length-i);
  887. inputNameNode.set("value", fname);
  888. }
  889. }.bind(this));
  890. cancelButton.addEvent("click", function(){
  891. if (maskNode) maskNode.unmask();
  892. this.inputUploadAreaNode.destroy();
  893. }.bind(this));
  894. okButton.addEvent("click", function(){
  895. formNode.mask({
  896. "style": {
  897. "opacity": 0.7,
  898. "background-color": "#999"
  899. }
  900. });
  901. var isContinue = true;
  902. if (beforeUpload) isContinue = beforeUpload([inputNameNode.get("value")]);
  903. if (isContinue){
  904. messageItem = this.addUploadMessage(inputNameNode.get("value"));
  905. formNode.submit();
  906. if (maskNode) maskNode.unmask();
  907. if (this.inputUploadAreaNode) this.inputUploadAreaNode.destroy();
  908. }
  909. }.bind(this));
  910. }.bind(this));
  911. },
  912. doFormDataUploadAttachment: function(obj, action, invokeUrl, parameter, finish, every, beforeUpload, multiple, accept, size, failureEvery, files){
  913. var uploadChange = function(uploadfiles){
  914. var files = uploadfiles || this.fileUploadNode.files;
  915. if (files.length){
  916. var count = files.length;
  917. var current = 0;
  918. var hasFailUpload = false;
  919. var restActions = action;
  920. if (typeOf(action)=="string"){
  921. restActions = o2.Actions.get(action).action;
  922. }
  923. //var url = restActions.action.actions[invokeUri];
  924. var callback = function(){
  925. if (current == count){
  926. if(finish) finish( hasFailUpload );
  927. }
  928. };
  929. var isContinue = true;
  930. if (beforeUpload) isContinue = beforeUpload(files);
  931. if (isContinue){
  932. var accepts = (accept) ? accept.split(o2.splitStr) : null;
  933. for (var i = 0; i < files.length; i++) {
  934. var file = files.item(i);
  935. var ext = file.name.substr(file.name.lastIndexOf("."), file.name.length);
  936. ext = ext.toLowerCase();
  937. if (accepts && (accepts.indexOf(ext)===-1 && accepts.indexOf("*")===-1 && accepts.indexOf("*/*")===-1)){
  938. var msg = {
  939. "subject": o2.LP.widget.refuseUpload,
  940. "content": o2.LP.widget.refuseUploadHTML.replace("{filename}", file.name)
  941. };
  942. if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
  943. if (layout.desktop.message) layout.desktop.message.addMessage(msg);
  944. var text = o2.LP.widget.refuseUploadNotice.replace("{filename}", file.name);
  945. if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
  946. }else if (size && file.size> size*1024*1024){
  947. var msg = {
  948. "subject": o2.LP.widget.refuseUpload,
  949. "content": o2.LP.widget.refuseUploadHTML_size.replace("{filename}", file.name).replace("{size}", size)
  950. };
  951. if (layout.desktop.message) layout.desktop.message.addTooltip(msg);
  952. if (layout.desktop.message) layout.desktop.message.addMessage(msg);
  953. var text = o2.LP.widget.refuseUploadNotice_size.replace("{filename}", file.name).replace("{size}", size);
  954. if (o2 && o2.xDesktop && o2.xDesktop.notice) o2.xDesktop.notice("info", {"x": "right", "y": "top"}, text, this.node);
  955. }else{
  956. var formData = new FormData();
  957. Object.each(obj, function(v, k){
  958. formData.append(k, v)
  959. });
  960. formData.append('file', file);
  961. if(parameter.fileMd5){
  962. o2.load("../o2_lib/CryptoJS/components/spark-md5-min.js", function(){
  963. var fileReader = new FileReader(), box = document.getElementById('box');
  964. var blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice;
  965. var chunkSize = 20971520;
  966. // read in chunks of 20MB
  967. var chunks = Math.ceil(file.size / chunkSize), currentChunk = 0, spark = new SparkMD5();
  968. fileReader.onload = function(e) {
  969. console.log("read chunk nr", currentChunk + 1, "of", chunks);
  970. spark.appendBinary(e.target.result);
  971. currentChunk++;
  972. if (currentChunk < chunks) {
  973. loadNext();
  974. } else {
  975. console.log("finished loading");
  976. var fileMd5 = spark.end();
  977. restActions.invoke({
  978. "name": "checkFileExist",
  979. "async": true,
  980. "parameter": {"fileMd5":fileMd5},
  981. "success": function(json){
  982. if(json.data.value){
  983. var formData2 = new FormData();
  984. formData2.append("fileMd5",fileMd5);
  985. formData2.append("fileName",file.name);
  986. restActions.invoke({
  987. "name": "addAttachmentMd5",
  988. "async": true,
  989. "data": formData2,
  990. "parameter": parameter,
  991. "success": function(json){
  992. current++;
  993. if (every) every(json, current, count);
  994. callback();
  995. },
  996. "failure": function (xhr) {
  997. var json = JSON.decode(xhr.responseText);
  998. if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
  999. current++;
  1000. hasFailUpload = true;
  1001. if (failureEvery) failureEvery(xhr, current, count);
  1002. callback();
  1003. }
  1004. });
  1005. }else{
  1006. restActions.invoke({
  1007. "name": invokeUrl,
  1008. "async": true,
  1009. "data": formData,
  1010. "file": file,
  1011. "parameter": parameter,
  1012. "success": function(json){
  1013. current++;
  1014. if (every) every(json, current, count);
  1015. callback();
  1016. },
  1017. "failure": function (xhr) {
  1018. var json = JSON.decode(xhr.responseText);
  1019. if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
  1020. current++;
  1021. hasFailUpload = true;
  1022. if (failureEvery) failureEvery(xhr, current, count);
  1023. callback();
  1024. }
  1025. });
  1026. }
  1027. }
  1028. });
  1029. // compute hash
  1030. }
  1031. };
  1032. function loadNext() {
  1033. var start = currentChunk * chunkSize, end = start + chunkSize >= file.size ? file.size : start + chunkSize;
  1034. fileReader.readAsBinaryString(blobSlice.call(file, start, end));
  1035. }
  1036. loadNext();
  1037. }.bind(this),null,false);
  1038. }else{
  1039. restActions.targetModule = {"module": this, "file": file};
  1040. restActions.invoke({
  1041. "name": invokeUrl,
  1042. "async": true,
  1043. "data": formData,
  1044. "file": file,
  1045. "parameter": parameter,
  1046. "success": function(json){
  1047. current++;
  1048. if (every) every(json, current, count);
  1049. callback();
  1050. },
  1051. "failure": function (xhr) {
  1052. var json = JSON.decode(xhr.responseText);
  1053. if( json && json.message )o2.xDesktop.notice("error", {x: "right", y:"top"}, json.message);
  1054. current++;
  1055. hasFailUpload = true;
  1056. if (failureEvery) failureEvery(xhr, current, count);
  1057. callback();
  1058. }
  1059. });
  1060. }
  1061. }
  1062. }
  1063. }
  1064. this.uploadFileAreaNode.destroy();
  1065. this.uploadFileAreaNode = null;
  1066. }
  1067. }.bind(this);
  1068. if (!this.uploadFileAreaNode){
  1069. this.uploadFileAreaNode = new Element("div");
  1070. var html = "<input name=\"file\" multiple type=\"file\" accept=\"*/*\"/>";
  1071. this.uploadFileAreaNode.set("html", html);
  1072. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  1073. this.fileUploadNode.addEvent("change", function(){
  1074. uploadChange();
  1075. });
  1076. }
  1077. this.fileUploadNode.set("accept", accept || "*/*");
  1078. this.fileUploadNode.set("multiple", (multiple!==false));
  1079. if (!files || !files.length){
  1080. this.fileUploadNode.click();
  1081. }else{
  1082. uploadChange(files)
  1083. }
  1084. },
  1085. addFormDataMessage: function(file){
  1086. return this.addAttachmentMessage(file);
  1087. },
  1088. addAttachmentMessage: function(file){
  1089. var messageItem;
  1090. if (this.options.size=="min"){
  1091. messageItem = new o2.widget.AttachmentController.AttachmentMessageMin(file, this);
  1092. }else{
  1093. messageItem = new o2.widget.AttachmentController.AttachmentMessage(file, this);
  1094. }
  1095. if (!this.messageItemList) this.messageItemList = {};
  1096. this.messageItemList[messageItem.data.id] = messageItem;
  1097. return messageItem;
  1098. },
  1099. openInOfficeControl: function(e, node){},
  1100. deleteAttachment: function(e, node){
  1101. if (this.selectedAttachments.length){
  1102. if (this.module) this.module.deleteAttachments(e, node, this.selectedAttachments);
  1103. }
  1104. },
  1105. replaceAttachment: function(e, node){
  1106. if (this.selectedAttachments.length && this.selectedAttachments.length==1){
  1107. if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
  1108. }
  1109. },
  1110. doReplaceAttachment: function(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size){
  1111. if (FormData.expiredIE){
  1112. this.doInputUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
  1113. }else{
  1114. this.doFormDataUploadAttachment(obj, action, invokeUrl, parameter, callback, multiple, accept, accept, size);
  1115. }
  1116. },
  1117. previewAttachment: function(e, node){
  1118. if (this.selectedAttachments.length){
  1119. if (this.module) this.module.previewAttachment(this.selectedAttachments);
  1120. }
  1121. },
  1122. editAttachment: function(e, node){
  1123. if (this.selectedAttachments.length){
  1124. if (this.module) this.module.editAttachment(this.selectedAttachments);
  1125. }
  1126. },
  1127. downloadAttachment: function(e, node){
  1128. if (this.selectedAttachments.length){
  1129. if (this.module) this.module.downloadAttachment(e, node, this.selectedAttachments);
  1130. }
  1131. },
  1132. openAttachment: function(e, node, attachment){
  1133. if( !this.options.dblclick ){
  1134. if( !this.options.isDownload || this.options.isDownload === "hidden" )return; //兼容以前的配置
  1135. }
  1136. if (attachment){
  1137. if (this.module) this.module.openAttachment(e, node, attachment);
  1138. }
  1139. },
  1140. dblclickAttachment: function(e, node, attachment){
  1141. if( !attachment || !this.module || this.options.dblclick === "disable" ){
  1142. return;
  1143. }else if( this.options.dblclick === "preview" ){
  1144. if( this.checkPreviewAttachment ){
  1145. this.checkPreviewAttachment(e, node, attachment);
  1146. }else{
  1147. this.module.openAttachment(e, node, attachment);
  1148. }
  1149. }else{
  1150. this.module.openAttachment(e, node, attachment);
  1151. }
  1152. },
  1153. downloadAllAttachment: function(e, node){
  1154. if (this.module) this.module.downloadAttachment(e, node, this.attachments);
  1155. },
  1156. changeListStyle: function(style){
  1157. this.options.listStyle = style;
  1158. this.listStyle = style;
  1159. this.attachments.each(function(attachment){
  1160. attachment.changeListStyle(style);
  1161. }.bind(this));
  1162. this.checkListStyleAction();
  1163. },
  1164. changeControllerSize: function(e, node){
  1165. if (this.options.size=="max"){
  1166. this.changeControllerSizeToMin();
  1167. }else{
  1168. this.changeControllerSizeToMax();
  1169. }
  1170. },
  1171. changeControllerSizeToMin: function(){
  1172. if (this.options.size!="min"){
  1173. if (this.contentScrollNode) this.contentScrollNode.setStyle("display", "none");
  1174. if (this.bottomNode) this.bottomNode.setStyle("display", "none");
  1175. if (this.topNode) this.topNode.setStyle("display", "none");
  1176. if (this.titleNode) this.titleNode.setStyle("display", "none");
  1177. if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100});
  1178. this.nodeMorph.start(this.css.container_min).chain(function(){
  1179. this.options.size = "min";
  1180. this.loadMin();
  1181. }.bind(this));
  1182. }
  1183. },
  1184. changeControllerSizeToMax: function(){
  1185. if (this.options.size!="max") {
  1186. if (this.minActionAreaNode) this.minActionAreaNode.setStyle("display", "none");
  1187. if (this.minContent) this.minContent.setStyle("display", "none");
  1188. if (!this.nodeMorph) this.nodeMorph = new Fx.Morph(this.node, {"duration": 100});
  1189. this.nodeMorph.start(this.css.container).chain(function () {
  1190. this.options.size = "max";
  1191. this.loadMax();
  1192. }.bind(this));
  1193. }
  1194. },
  1195. getAttachmentNames: function(){
  1196. var names = [];
  1197. this.attachments.each(function(attachment){
  1198. names.push(attachment.data.name);
  1199. });
  1200. return names;
  1201. },
  1202. addAttachment: function(data, messageId, isCheckPosition){
  1203. if (this.options.size=="min"){
  1204. this.attachments.push(new o2.widget.AttachmentController.AttachmentMin(data, this, messageId, isCheckPosition));
  1205. }else{
  1206. this.attachments.push(new o2.widget.AttachmentController.Attachment(data, this, messageId, isCheckPosition));
  1207. }
  1208. this.checkActions();
  1209. },
  1210. removeAttachment: function(attachment){
  1211. this.attachments.erase(attachment);
  1212. this.selectedAttachments.erase(attachment);
  1213. attachment.node.destroy();
  1214. delete attachment;
  1215. },
  1216. unSelectedAttachments: function(){
  1217. while (this.selectedAttachments.length){
  1218. var attachment = this.selectedAttachments.shift();
  1219. attachment.unSelected();
  1220. }
  1221. this.checkActions();
  1222. },
  1223. clear: function(){
  1224. this.selectedAttachments = [];
  1225. this.attachments.each(function(att){
  1226. att.node.destroy();
  1227. o2.release(att);
  1228. });
  1229. this.attachments = [];
  1230. var content = (this.minContent || this.content);
  1231. if (content) content.empty();
  1232. }
  1233. });
  1234. o2.widget.AttachmentController.Attachment = new Class({
  1235. Implements: [Events],
  1236. initialize: function(data, controller, messageId, isCheckPosition){
  1237. this.data = data;
  1238. if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
  1239. this.controller = controller;
  1240. this.css = this.controller.css;
  1241. this.listStyle = this.controller.options.listStyle;
  1242. this.content = this.controller.content;
  1243. this.isSelected = false;
  1244. this.seq = this.controller.attachments.length+1;
  1245. this.isCheckPosition = isCheckPosition;
  1246. this.actions = [];
  1247. if (messageId && this.controller.messageItemList) {
  1248. this.message = this.controller.messageItemList[messageId];
  1249. }
  1250. this.load();
  1251. },
  1252. _getLnkPar: function(url){
  1253. return {
  1254. "icon": this.getIcon(),
  1255. "title": this.data.name,
  1256. "par": "@url#"+url
  1257. };
  1258. },
  1259. isNumber : function( d ){
  1260. return parseFloat(d).toString() !== "NaN"
  1261. },
  1262. load: function(){
  1263. if( this.controller.module && this.controller.module.fireEvent ){
  1264. this.controller.module.fireEvent("beforeLoadAttachment", [this]);
  1265. }
  1266. if (this.message){
  1267. this.node = new Element("div").inject(this.message.node, "after");
  1268. this.message.node.destroy();
  1269. delete this.controller.messageItemList[this.message.data.id];
  1270. }else{
  1271. this.node = new Element("div").inject(this.content);
  1272. }
  1273. if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){
  1274. var attList = this.controller.attachments;
  1275. for( var i=0; i<attList.length; i++ ){
  1276. var att = attList[i];
  1277. if( !this.isNumber(att.data.orderNumber) || this.data.orderNumber < att.data.orderNumber ){
  1278. this.node.inject( att.node, "before" );
  1279. break;
  1280. }
  1281. }
  1282. }
  1283. switch (this.controller.options.listStyle){
  1284. case "list":
  1285. this.loadList();
  1286. break;
  1287. case "icon":
  1288. this.loadIcon();
  1289. break;
  1290. case "preview":
  1291. this.loadPreview();
  1292. break;
  1293. case "sequence":
  1294. this.loadSequence();
  1295. break;
  1296. }
  1297. this.controller.module.getAttachmentUrl(this, function(url){
  1298. this.node.makeLnk({
  1299. "par": this._getLnkPar(url)
  1300. });
  1301. }.bind(this));
  1302. this.createInforNode(function(){
  1303. if (!Browser.Platform.ios){
  1304. this.tooltip = new mBox.Tooltip({
  1305. content: this.inforNode,
  1306. setStyles: {content: {padding: 15, lineHeight: 20}},
  1307. attach: this.node,
  1308. transition: 'flyin'
  1309. });
  1310. }
  1311. }.bind(this));
  1312. this.setEvent();
  1313. if( this.controller.module && this.controller.module.fireEvent ){
  1314. this.controller.module.fireEvent("loadAttachment", [this]);
  1315. }
  1316. },
  1317. createInforNode: function(callback){
  1318. var size = "";
  1319. var k = this.data.length/1024;
  1320. if (k>1024){
  1321. var m = k/1024;
  1322. m = Math.round(m*100)/100;
  1323. size = m+"M";
  1324. }else{
  1325. k = Math.round(k*100)/100;
  1326. size = k+"K";
  1327. }
  1328. this.inforNode = new Element("div", {"styles": this.css.attachmentInforNode});
  1329. var html = "<div style='overflow:hidden; font-weight: bold'>"+this.data.name+"</div>";
  1330. html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.uploader+": </div><div style='width:120px; float:left; margin-left:10px'>"+( this.data.person || this.data.creatorUid )+"</div></div>";
  1331. html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.uploadTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.createTime+"</div></div>";
  1332. html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.modifyTime+": </div><div style='width:120px; float:left; margin-left:10px'>"+this.data.lastUpdateTime+"</div></div>";
  1333. if(this.data.activityName)html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.uploadActivity+": </div><div style='width:120px; float:left; margin-left:10px'>"+(this.data.activityName || o2.LP.widget.unknow)+"</div></div>";
  1334. html += "<div style='clear: both; overflow:hidden'><div style='width:40px; float:left; font-weight: bold'>"+o2.LP.widget.size+": </div><div style='width:120px; float:left; margin-left:10px'>"+size+"</div></div>";
  1335. this.inforNode.set("html", html);
  1336. if (callback) callback();
  1337. },
  1338. getIcon: function(){
  1339. if (!this.data.extension) this.data.extension="unkonw";
  1340. var iconName = this.controller.icons[this.data.extension.toLowerCase()] || this.controller.icons.unknow;
  1341. var iconFolderUrl = this.controller.options.iconFolderUrl ? this.controller.options.iconFolderUrl : "../x_component_File/$Main/default/file/";
  1342. return iconFolderUrl+iconName;
  1343. },
  1344. loadList: function(){
  1345. this.node.setStyles(this.css.attachmentNode_list);
  1346. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_list_selected);
  1347. this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node);
  1348. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
  1349. this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  1350. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1351. this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_list}).inject(this.node);
  1352. this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
  1353. // this.textTitleNode.set("text", this.data.name);
  1354. if (this.data.objectSecurityPromise){
  1355. this.data.objectSecurityPromise.then(function(label){
  1356. this.textTitleNode.set("text", "("+label+") " + this.data.name);
  1357. }.bind(this));
  1358. }else{
  1359. this.textTitleNode.set("text", this.data.name);
  1360. }
  1361. var size = "";
  1362. var k = this.data.length/1024;
  1363. if (k>1024){
  1364. var m = k/1024;
  1365. m = Math.round(m*100)/100;
  1366. size = m+"M";
  1367. }else{
  1368. k = Math.round(k*100)/100;
  1369. size = k+"K";
  1370. }
  1371. this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
  1372. this.textSizeNode.set("text", size);
  1373. this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
  1374. this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid ));
  1375. this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
  1376. this.textTimeNode.set("text", this.data.lastUpdateTime);
  1377. if(this.data.activityName){
  1378. this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
  1379. this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);
  1380. }
  1381. this.custom_List();
  1382. },
  1383. custom_List: function(){},
  1384. loadSequence: function(){
  1385. this.node.setStyles(this.css.attachmentNode_sequence);
  1386. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_sequence_selected);
  1387. this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node);
  1388. this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode_list}).inject(this.node);
  1389. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode_list}).inject(this.iconNode);
  1390. this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  1391. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1392. this.textNode = new Element("div", {"styles": this.css.attachmentTextNode_sequence}).inject(this.node);
  1393. this.textTitleNode = new Element("div", {"styles": this.css.attachmentTextTitleNode_list}).inject(this.textNode);
  1394. // this.textTitleNode.set("text", this.data.name);
  1395. if (this.data.objectSecurityPromise){
  1396. this.data.objectSecurityPromise.then(function(label){
  1397. this.textTitleNode.set("text", "("+label+") " + this.data.name);
  1398. }.bind(this));
  1399. }else{
  1400. this.textTitleNode.set("text", this.data.name);
  1401. }
  1402. var size = "";
  1403. var k = this.data.length/1024;
  1404. if (k>1024){
  1405. var m = k/1024;
  1406. m = Math.round(m*100)/100;
  1407. size = m+"M";
  1408. }else{
  1409. k = Math.round(k*100)/100;
  1410. size = k+"K";
  1411. }
  1412. this.textSizeNode = new Element("div", {"styles": this.css.attachmentTextSizeNode_list}).inject(this.textNode);
  1413. this.textSizeNode.set("text", size);
  1414. this.textUploaderNode = new Element("div", {"styles": this.css.attachmentTextUploaderNode_list}).inject(this.textNode);
  1415. this.textUploaderNode.set("text", o2.name.cn(this.data.person || this.data.creatorUid));
  1416. this.textTimeNode = new Element("div", {"styles": this.css.attachmentTextTimeNode_list}).inject(this.textNode);
  1417. this.textTimeNode.set("text", this.data.lastUpdateTime);
  1418. if(this.data.activityName){
  1419. this.textActivityNode = new Element("div", {"styles": this.css.attachmentTextActivityNode_list}).inject(this.textNode);
  1420. this.textActivityNode.set("text", this.data.activityName || o2.LP.widget.unknow);
  1421. }
  1422. this.custom_Sequence();
  1423. },
  1424. custom_Sequence: function(){},
  1425. loadIcon: function(){
  1426. this.node.setStyles(this.css.attachmentNode_icon);
  1427. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_icon_selected);
  1428. this.iconNode = new Element("div", {"styles": this.css.attachmentIconNode}).inject(this.node);
  1429. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentIconImgAreaNode}).inject(this.iconNode);
  1430. this.iconImgNode = new Element("img", {"styles": this.css.attachmentIconImgNode}).inject(this.iconImgAreaNode);
  1431. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1432. this.textNode = new Element("div", {"styles": this.css.attachmentTextNode}).inject(this.node);
  1433. if (this.data.objectSecurityPromise){
  1434. this.data.objectSecurityPromise.then(function(label){
  1435. this.textNode.set("text", "("+label+") " + this.data.name);
  1436. }.bind(this));
  1437. }else{
  1438. this.textNode.set("text", this.data.name);
  1439. }
  1440. this.custom_Icon();
  1441. },
  1442. custom_Icon: function(){},
  1443. loadPreview: function(){
  1444. this.node.setStyles(this.css.attachmentNode_preview);
  1445. if (this.isSelected) this.node.setStyles(this.css.attachmentNode_preview_selected);
  1446. this.iconNode = new Element("div", {"styles": this.css.attachmentPreviewIconNode}).inject(this.node);
  1447. this.iconImgAreaNode = new Element("div", {"styles": this.css.attachmentPreviewIconImgAreaNode}).inject(this.iconNode);
  1448. this.iconImgNode = new Element("img", {"styles": this.css.attachmentPreviewIconImgNode}).inject(this.iconImgAreaNode);
  1449. var icon = this.getIcon();
  1450. if (this.controller.options.images.indexOf(this.data.extension.toLowerCase())!==-1){
  1451. if (this.type!=="message") this.controller.module.getAttachmentUrl(this, function(url){
  1452. this.iconImgAreaNode.hide();
  1453. this.iconImgNode.hide();
  1454. this.iconNode.setStyles({
  1455. "background-image": "url("+url+")",
  1456. });
  1457. }.bind(this));
  1458. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  1459. if (this.data.objectSecurityPromise){
  1460. this.data.objectSecurityPromise.then(function(label){
  1461. this.textNode.set("text", "("+label+") " + this.data.name);
  1462. }.bind(this));
  1463. }else{
  1464. this.textNode.set("text", this.data.name);
  1465. }
  1466. // this.textNode.set("text", this.data.name);
  1467. }else if (this.controller.options.audios.indexOf(this.data.extension.toLowerCase())!==-1){
  1468. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  1469. if (this.data.objectSecurityPromise){
  1470. this.data.objectSecurityPromise.then(function(label){
  1471. this.textNode.set("text", "("+label+") " + this.data.name);
  1472. }.bind(this));
  1473. }else{
  1474. this.textNode.set("text", this.data.name);
  1475. }
  1476. // this.textNode.set("text", this.data.name);
  1477. this.controller.module.getAttachmentUrl(this, function(url){
  1478. this.iconImgNode.set({"src": icon, "border": 0});
  1479. this.iconAudioNode = new Element("div", {
  1480. "styles": this.css.attachmentPreviewAudioNode,
  1481. "html": "<audio preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+url+"\" type=\"audio/mpeg\"></source></audio>"
  1482. //"html": "<audio controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+o2.session.path+"/xApplication/File/$Main/qnyh.mp3\"></source></audio>"
  1483. }).inject(this.textNode, "after");
  1484. this.iconAudioNode.addEvent("dblclick", function(e){e.stopPropagation();});
  1485. }.bind(this));
  1486. }else if (this.controller.options.videos.indexOf(this.data.extension.toLowerCase())!==-1){
  1487. this.controller.module.getAttachmentUrl(this, function(url){
  1488. this.iconNode.empty();
  1489. this.iconVideoNode = new Element("div", {
  1490. "styles": this.css.attachmentPreviewVideoNode,
  1491. //"html": "<video preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+o2.session.path+"/xApplication/File/$Main/IMG_1615.MOV\"></source></video>"
  1492. "html": "<video preload=\"metadata\" controls=\"controls\" style=\"width: 100%; height: 100%\"><source src=\""+url+"\"></source></video>"
  1493. }).inject(this.iconNode);
  1494. this.iconVideoNode.addEvent("dblclick", function(e){e.stopPropagation();});
  1495. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  1496. if (this.data.objectSecurityPromise){
  1497. this.data.objectSecurityPromise.then(function(label){
  1498. this.textNode.set("text", "("+label+") " + this.data.name);
  1499. }.bind(this));
  1500. }else{
  1501. this.textNode.set("text", this.data.name);
  1502. }
  1503. // this.textNode.set("text", this.data.name);
  1504. }.bind(this));
  1505. }else{
  1506. this.iconImgNode.set({"src": icon, "border": 0});
  1507. this.textNode = new Element("div", {"styles": this.css.attachmentPreviewTextNode}).inject(this.node);
  1508. if (this.data.objectSecurityPromise){
  1509. this.data.objectSecurityPromise.then(function(label){
  1510. this.textNode.set("text", "("+label+") " + this.data.name);
  1511. }.bind(this));
  1512. }else{
  1513. this.textNode.set("text", this.data.name);
  1514. }
  1515. // this.textNode.set("text", this.data.name);
  1516. }
  1517. this.custom_Preview();
  1518. },
  1519. custom_Preview: function(){},
  1520. getPreviewImgSize: function(icon, callback){
  1521. var areaSize = this.iconNode.getSize();
  1522. var img = new Element("img", {"src": icon}).inject($(document.body));
  1523. img.set("src", icon);
  1524. var size = img.getSize();
  1525. img.destroy();
  1526. var x, y;
  1527. var zoom = areaSize.x/size.x;
  1528. var y = size.y*zoom;
  1529. if (y<=areaSize.y){
  1530. x = areaSize.x;
  1531. }else{
  1532. zoom = areaSize.y/size.y;
  1533. x = size.x*zoom;
  1534. y = areaSize.y;
  1535. }
  1536. var size = {"x": x, "y": y, "top": (areaSize.y-y)/2};
  1537. if (callback) callback(size);
  1538. },
  1539. setEvent: function(){
  1540. this.node.addEvents({
  1541. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"])}.bind(this),
  1542. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle])}.bind(this),
  1543. "mousedown": function(e){this.selected(e); e.stopPropagation();}.bind(this),
  1544. "click": function(e){e.stopPropagation();}.bind(this),
  1545. "dblclick": function(e){
  1546. if( this.controller.options.dblclick ){
  1547. this.controller.dblclickAttachment(e, null, [this]);
  1548. }else{
  1549. this.openAttachment(e);
  1550. }
  1551. }.bind(this)
  1552. });
  1553. if (this.iconImgNode){
  1554. this.iconImgNode.set("draggable", false);
  1555. }
  1556. },
  1557. selected: function(e){
  1558. if (!e.event.ctrlKey) this.controller.unSelectedAttachments();
  1559. //if (!this.isSelected){
  1560. this.controller.selectedAttachments.push(this);
  1561. this.isSelected = true;
  1562. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]);
  1563. //}
  1564. if( this.controller.module && this.controller.module.fireEvent ){
  1565. this.controller.module.fireEvent("select", [this]);
  1566. }
  1567. if (e) e.stopPropagation();
  1568. this.controller.checkActions();
  1569. },
  1570. unSelected: function(){
  1571. this.isSelected = false;
  1572. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
  1573. this.controller.selectedAttachments.erase(this);
  1574. if( this.controller.module && this.controller.module.fireEvent ){
  1575. this.controller.module.fireEvent("unselect", [this]);
  1576. }
  1577. },
  1578. changeListStyle: function(style){
  1579. if (this.listStyle!=style){
  1580. this.node.empty();
  1581. switch (style){
  1582. case "list":
  1583. this.loadList();
  1584. break;
  1585. case "icon":
  1586. this.loadIcon();
  1587. break;
  1588. case "preview":
  1589. this.loadPreview();
  1590. break;
  1591. case "sequence":
  1592. this.loadSequence();
  1593. break;
  1594. }
  1595. this.listStyle = style;
  1596. }
  1597. },
  1598. reload: function(){
  1599. var node = new Element("div").inject(this.node, "after");
  1600. this.inforNode.destroy();
  1601. this.inforNode = null;
  1602. if (this.tooltip) this.tooltip.destroy();
  1603. this.tooltip = null;
  1604. this.node.destroy();
  1605. delete this.node;
  1606. this.node = node;
  1607. switch (this.listStyle){
  1608. case "list":
  1609. this.loadList();
  1610. break;
  1611. case "icon":
  1612. this.loadIcon();
  1613. break;
  1614. case "preview":
  1615. this.loadPreview();
  1616. break;
  1617. case "sequence":
  1618. this.loadSequence();
  1619. break;
  1620. }
  1621. this.createInforNode();
  1622. if (!Browser.Platform.ios){
  1623. this.tooltip = new mBox.Tooltip({
  1624. content: this.inforNode,
  1625. setStyles: {content: {padding: 15, lineHeight: 20}},
  1626. attach: this.node,
  1627. transition: 'flyin'
  1628. });
  1629. }
  1630. this.setEvent();
  1631. },
  1632. openAttachment: function(e){
  1633. if( !this.controller.options.dblclick ){
  1634. if (!this.controller.options.isDownload || this.controller.options.isDownload === "hidden") return; //兼容以前的配置
  1635. }
  1636. if (this.controller.module) this.controller.module.openAttachment(e, null, [this]);
  1637. },
  1638. setActionEnabled: function(action){
  1639. if (action){
  1640. action.setStyle("display","");
  1641. action.store("disabled", false);
  1642. //if (action.retrieve("disabled")){
  1643. // var iconNode = action.getFirst();
  1644. // var icon = iconNode.getStyle("background-image");
  1645. // var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
  1646. // icon = icon.substr(0, icon.lastIndexOf("_gray"))+"."+ext;
  1647. // iconNode.setStyle("background-image", icon);
  1648. // action.store("disabled", false);
  1649. //}
  1650. }
  1651. },
  1652. setActionDisabled: function(action){
  1653. if (action){
  1654. action.setStyle("display","none");
  1655. action.store("disabled", true);
  1656. //if (!action.retrieve("disabled")){
  1657. // var iconNode = action.getFirst();
  1658. // var icon = iconNode.getStyle("background-image");
  1659. // var ext = icon.substr(icon.lastIndexOf(".")+1, icon.length);
  1660. // icon = icon.substr(0, icon.lastIndexOf("."))+"_gray."+ext;
  1661. // iconNode.setStyle("background-image", icon);
  1662. // action.store("disabled", true);
  1663. //}
  1664. }
  1665. },
  1666. createAction: function(node, img, img_over, title, click, text){
  1667. var actionNode;
  1668. if( this.controller.options.actionShowText ){
  1669. actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "text": text || title, "title" : title }).inject(node);
  1670. var _self = this;
  1671. actionNode.addEvents({
  1672. "mouseover": function( e ){
  1673. if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over){
  1674. actionNode.setStyles( _self.controller.css.minActionNode_over );
  1675. }
  1676. }.bind( { actionNode : actionNode } ),
  1677. "mouseout": function(){
  1678. if (!this.actionNode.retrieve("disabled") && _self.controller.css.minActionNode_over ){
  1679. actionNode.setStyles( _self.controller.css.minActionNode );
  1680. }
  1681. }.bind( { actionNode : actionNode } ),
  1682. "click": function(e){
  1683. if (!this.retrieve("disabled")){
  1684. click.apply(_self.controller, [e, this]);
  1685. e.stopPropagation();
  1686. }
  1687. }
  1688. });
  1689. }else{
  1690. actionNode = new Element("div", {"styles": this.controller.css.minActionNode, "title": title}).inject(node);
  1691. var actionIconNode = new Element("div", {"styles": this.controller.css.minActionIconNode}).inject(actionNode);
  1692. actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+this.controller.options.style+"/icon/"+img+".png)");
  1693. var _self = this;
  1694. actionNode.addEvents({
  1695. "mouseover": function( e ){
  1696. if (!this.actionNode.retrieve("disabled")){
  1697. this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)");
  1698. }
  1699. }.bind( { actionNode : actionNode, actionIconNode: actionIconNode, img : img_over } ),
  1700. "mouseout": function(){
  1701. if (!this.actionNode.retrieve("disabled")){
  1702. this.actionIconNode.setStyle("background-image", "url("+o2.session.path+"/widget/$AttachmentController/"+_self.controller.options.style+"/icon/"+this.img+".png)");
  1703. }
  1704. }.bind( { actionNode : actionNode, actionIconNode: actionIconNode, img : img } ),
  1705. "click": function(e){
  1706. if (!this.retrieve("disabled")){
  1707. click.apply(_self.controller, [e, this]);
  1708. e.stopPropagation();
  1709. }
  1710. }
  1711. });
  1712. }
  1713. if( !this.actions )this.actions = [];
  1714. this.actions.push(actionNode);
  1715. return actionNode;
  1716. }
  1717. });
  1718. o2.widget.AttachmentController.AttachmentMin = new Class({
  1719. Extends: o2.widget.AttachmentController.Attachment,
  1720. initialize: function(data, controller, messageId, isCheckPosition){
  1721. this.data = data;
  1722. if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
  1723. this.controller = controller;
  1724. this.css = this.controller.css;
  1725. this.listStyle = this.controller.options.listStyle;
  1726. this.content = this.controller.minContent;
  1727. this.isSelected = false;
  1728. this.isCheckPosition = isCheckPosition;
  1729. this.seq = this.controller.attachments.length+1;
  1730. if (messageId && this.controller.messageItemList) {
  1731. this.message = this.controller.messageItemList[messageId];
  1732. }
  1733. this.load();
  1734. },
  1735. load: function(){
  1736. if( this.controller.module && this.controller.module.fireEvent ){
  1737. this.controller.module.fireEvent("beforeLoadAttachment", [this]);
  1738. }
  1739. if (this.message){
  1740. this.node = new Element("div").inject(this.message.node, "after");
  1741. this.message.node.destroy();
  1742. delete this.controller.messageItemList[this.message.data.id];
  1743. }else{
  1744. this.node = new Element("div").inject(this.content);
  1745. }
  1746. if( this.isCheckPosition && this.isNumber(this.data.orderNumber) ){
  1747. var attList = this.controller.attachments;
  1748. for( var i=0; i<attList.length; i++ ){
  1749. var att = attList[i];
  1750. if( !this.isNumber(att.data.orderNumber) || this.data.orderNumber < att.data.orderNumber ){
  1751. this.node.inject( att.node, "before" );
  1752. break;
  1753. }
  1754. }
  1755. }
  1756. //this.node = new Element("div").inject(this.content);
  1757. //this.loadList();
  1758. switch (this.controller.options.listStyle){
  1759. case "list":
  1760. this.loadList();
  1761. break;
  1762. case "icon":
  1763. this.loadIcon();
  1764. break;
  1765. case "preview":
  1766. this.loadPreview();
  1767. break;
  1768. case "sequence":
  1769. this.loadSequence();
  1770. break;
  1771. }
  1772. this.createInforNode();
  1773. if (!Browser.Platform.ios && !layout.mobile){
  1774. this.tooltip = new mBox.Tooltip({
  1775. content: this.inforNode,
  1776. setStyles: {content: {padding: 15, lineHeight: 20}},
  1777. attach: this.iconImgNode,
  1778. transition: 'flyin'
  1779. });
  1780. }
  1781. this.setEvent();
  1782. if( this.controller.module && this.controller.module.fireEvent ){
  1783. this.controller.module.fireEvent("loadAttachment", [this]);
  1784. }
  1785. },
  1786. loadList: function() {
  1787. this.node.setStyles( layout.mobile ? this.css.minAttachmentNode_list_mobile : this.css.minAttachmentNode_list);
  1788. if( !layout.mobile ){
  1789. this.sepNode = new Element("div", {"styles": this.css.minAttachmentSepNode_list}).inject(this.node);
  1790. }
  1791. this.actionAreaNode = new Element("div", {"styles": this.css.minAttachmentActionAreaNode}).inject(this.node);
  1792. if( this.controller.isAttDblclickAvailable(this) ){
  1793. this.openAction = this.createAction(this.actionAreaNode, "open_single", "open_single_over", o2.LP.widget.open, function (e, node) {
  1794. this.controller.dblclickAttachment(e, node, [this]);
  1795. }.bind(this));
  1796. }
  1797. if ( this.controller.isAttDownloadAvailable(this) ) {
  1798. this.downloadAction = this.createAction(this.actionAreaNode, "download_single", "download_single_over", o2.LP.widget.download, function (e, node) {
  1799. this.controller.downloadAttachment(e, node);
  1800. }.bind(this));
  1801. }
  1802. //this.actions.push( this.downloadAction );
  1803. if ( this.controller.isAttDeleteAvailable(this) ) {
  1804. this.deleteAction = this.createAction(this.actionAreaNode, "delete_single", "delete_single_over", o2.LP.widget["delete"], function (e, node) {
  1805. this.controller.deleteAttachment(e, node);
  1806. }.bind(this));
  1807. }
  1808. if ( this.controller.isAttEditAvailable(this) ) {
  1809. this.editAction = this.createAction(this.actionAreaNode, "edit_single", "edit_single_over", o2.LP.widget["editAtt"], function (e, node) {
  1810. this.controller.editAttachment(e, node);
  1811. }.bind(this));
  1812. }
  1813. //this.actions.push( this.deleteAction );
  1814. if (this.controller.configAttachment) {
  1815. if ( this.controller.isAttConfigAvailable(this) ) {
  1816. this.configAction = this.createAction(this.actionAreaNode, "config_single", "config_single_over", o2.LP.widget.configAttachment, function (e, node) {
  1817. this.controller.configAttachment(e, node);
  1818. }.bind(this), o2.LP.widget.configAttachmentText );
  1819. //this.actions.push( this.configAction );
  1820. }
  1821. }
  1822. if (this.isSelected) this.node.setStyles(this.css.minAttachmentNode_list_selected);
  1823. this.iconNode = new Element("div", {"styles": this.css.minAttachmentIconNode_list}).inject(this.node);
  1824. this.iconImgAreaNode = new Element("div", {"styles": this.css.minAttachmentIconImgAreaNode_list}).inject(this.iconNode);
  1825. this.iconImgNode = new Element("img", {"styles": this.css.minAttachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  1826. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1827. this.textNode = new Element("div", {"styles": this.css.minAttachmentTextNode_list}).inject(this.node);
  1828. if (this.data.objectSecurityPromise){
  1829. this.data.objectSecurityPromise.then(function(label){
  1830. this.textNode.set("text", "("+label+") " + this.data.name);
  1831. }.bind(this));
  1832. }else{
  1833. this.textNode.set("text", this.data.name);
  1834. }
  1835. // this.textNode.set("text", this.data.name);
  1836. var size = "";
  1837. var k = this.data.length/1024;
  1838. if (k>1024){
  1839. var m = k/1024;
  1840. m = Math.round(m*100)/100;
  1841. size = m+"M";
  1842. }else{
  1843. k = Math.round(k*100)/100;
  1844. size = k+"K";
  1845. }
  1846. this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode);
  1847. this.textSizeNode.set("text", "("+size+")");
  1848. this.node.set("title",this.data.name + "("+size+")");
  1849. },
  1850. loadSequence: function(){
  1851. this.node.setStyles(this.css.minAttachmentNode_sequence);
  1852. this.actionAreaNode = new Element("div", {"styles":this.css.minAttachmentActionAreaNode}).inject(this.node);
  1853. if( this.controller.isAttDblclickAvailable(this) ){
  1854. this.openAction = this.createAction(this.actionAreaNode, "open_single", "open_single_over", o2.LP.widget.open, function (e, node) {
  1855. this.controller.dblclickAttachment(e, node, [this]);
  1856. }.bind(this));
  1857. }
  1858. if ( this.controller.isAttDownloadAvailable(this) ) {
  1859. this.downloadAction = this.createAction(this.actionAreaNode, "download_single", "download_single_over", o2.LP.widget.download, function (e, node) {
  1860. this.controller.downloadAttachment(e, node);
  1861. }.bind(this));
  1862. }
  1863. //this.actions.push( this.downloadAction );
  1864. if ( this.controller.isAttDeleteAvailable(this) ) {
  1865. this.deleteAction = this.createAction(this.actionAreaNode, "delete_single", "delete_single_over", o2.LP.widget["delete"], function (e, node) {
  1866. this.controller.deleteAttachment(e, node);
  1867. }.bind(this));
  1868. }
  1869. if ( this.controller.isAttEditAvailable(this) ) {
  1870. this.editAction = this.createAction(this.actionAreaNode, "edit_single", "edit_single_over", o2.LP.widget["editAtt"], function (e, node) {
  1871. this.controller.editAttachment(e, node);
  1872. }.bind(this));
  1873. }
  1874. //this.actions.push( this.deleteAction );
  1875. if (this.controller.configAttachment) {
  1876. if ( this.controller.isAttConfigAvailable(this) ) {
  1877. this.configAction = this.createAction(this.actionAreaNode, "config_single", "config_single_over", MWF.LP.widget.configAttachment, function (e, node) {
  1878. this.controller.configAttachment(e, node);
  1879. }.bind(this));
  1880. //this.actions.push( this.configAction );
  1881. }
  1882. }
  1883. if (this.isSelected) this.node.setStyles(this.css.minAttachmentNode_list_selected);
  1884. this.sequenceNode = new Element("div", {"styles": this.css.attachmentSeqNode_sequence, "text": (this.seq || 1)}).inject(this.node);
  1885. this.iconNode = new Element("div", {"styles": this.css.minAttachmentIconNode_list}).inject(this.node);
  1886. this.iconImgAreaNode = new Element("div", {"styles": this.css.minAttachmentIconImgAreaNode_list}).inject(this.iconNode);
  1887. this.iconImgNode = new Element("img", {"styles": this.css.minAttachmentIconImgNode_list}).inject(this.iconImgAreaNode);
  1888. this.iconImgNode.set({"src": this.getIcon(), "border": 0});
  1889. this.textNode = new Element("div", {"styles": this.css.minAttachmentTextNode_list}).inject(this.node);
  1890. if (this.data.objectSecurityPromise){
  1891. this.data.objectSecurityPromise.then(function(label){
  1892. this.textNode.set("text", "("+label+") " + this.data.name);
  1893. }.bind(this));
  1894. }else{
  1895. this.textNode.set("text", this.data.name);
  1896. }
  1897. // this.textNode.set("text", this.data.name);
  1898. var size = "";
  1899. var k = this.data.length/1024;
  1900. if (k>1024){
  1901. var m = k/1024;
  1902. m = Math.round(m*100)/100;
  1903. size = m+"M";
  1904. }else{
  1905. k = Math.round(k*100)/100;
  1906. size = k+"K";
  1907. }
  1908. this.textSizeNode = new Element("div", {"styles": this.css.minAttachmentSizeNode_list}).inject(this.textNode);
  1909. this.textSizeNode.set("text", "("+size+")");
  1910. },
  1911. setEvent: function(){
  1912. this.node.addEvents({
  1913. "mouseover": function(){
  1914. if (!this.isSelected){
  1915. if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
  1916. this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_over"]);
  1917. }else{
  1918. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_over"]);
  1919. }
  1920. }
  1921. }.bind(this),
  1922. "mouseout": function(){
  1923. if (!this.isSelected){
  1924. if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
  1925. var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
  1926. this.node.setStyles(this.css[cssKey]);
  1927. }else{
  1928. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
  1929. }
  1930. }
  1931. }.bind(this),
  1932. "mousedown": function(e){this.selected(e);e.stopPropagation();}.bind(this),
  1933. "click": function(e){e.stopPropagation();}.bind(this),
  1934. "dblclick": function(e){
  1935. if( this.controller.options.dblclick ){
  1936. this.controller.dblclickAttachment(e, null, [this]);
  1937. }else{
  1938. this.openAttachment(e);
  1939. }
  1940. }.bind(this)
  1941. });
  1942. if (this.iconImgNode){
  1943. this.iconImgNode.set("draggable", false);
  1944. }
  1945. },
  1946. selected: function(e){
  1947. if (!e.event.ctrlKey) this.controller.unSelectedAttachments();
  1948. //if (!this.isSelected){
  1949. this.controller.selectedAttachments.push(this);
  1950. this.isSelected = true;
  1951. if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
  1952. //this.node.setStyles(this.css["minAttachmentNode_list_selected"]);
  1953. this.node.setStyles(this.css["minAttachmentNode_"+this.controller.options.listStyle+"_selected"]);
  1954. }else{
  1955. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle+"_selected"]);
  1956. //this.node.setStyles(this.css["minAttachmentNode_list_selected"]);
  1957. }
  1958. if( this.controller.module && this.controller.module.fireEvent ){
  1959. this.controller.module.fireEvent("select", [this]);
  1960. }
  1961. //}
  1962. if (e) e.stopPropagation();
  1963. this.controller.checkActions();
  1964. },
  1965. reload: function(){
  1966. var node = new Element("div").inject(this.node, "after");
  1967. this.inforNode.destroy();
  1968. this.inforNode = null;
  1969. if (this.tooltip) this.tooltip.destroy();
  1970. this.tooltip = null;
  1971. this.node.destroy();
  1972. delete this.node;
  1973. this.node = node;
  1974. debugger;
  1975. switch (this.listStyle){
  1976. case "list":
  1977. this.loadList();
  1978. break;
  1979. case "icon":
  1980. this.loadIcon();
  1981. break;
  1982. case "preview":
  1983. this.loadPreview();
  1984. break;
  1985. case "sequence":
  1986. this.loadSequence();
  1987. break;
  1988. }
  1989. this.createInforNode();
  1990. if (!Browser.Platform.ios){
  1991. this.tooltip = new mBox.Tooltip({
  1992. content: this.inforNode,
  1993. setStyles: {content: {padding: 15, lineHeight: 20}},
  1994. attach: this.node,
  1995. transition: 'flyin'
  1996. });
  1997. }
  1998. this.setEvent();
  1999. },
  2000. unSelected: function(){
  2001. this.isSelected = false;
  2002. //this.node.setStyles(this.css["minAttachmentNode_list"]);
  2003. if (this.controller.options.listStyle==="list" || this.controller.options.listStyle==="sequence"){
  2004. var cssKey = "minAttachmentNode_"+this.controller.options.listStyle + ( layout.mobile ? "_mobile" : "" );
  2005. this.node.setStyles(this.css[cssKey]);
  2006. }else{
  2007. this.node.setStyles(this.css["attachmentNode_"+this.controller.options.listStyle]);
  2008. }
  2009. if( this.controller.module && this.controller.module.fireEvent ){
  2010. this.controller.module.fireEvent("unselect", [this]);
  2011. }
  2012. this.controller.selectedAttachments.erase(this);
  2013. }
  2014. });
  2015. o2.widget.AttachmentController.AttachmentMessage = new Class({
  2016. Extends: o2.widget.AttachmentController.Attachment,
  2017. Implements: [Events],
  2018. initialize: function(file, controller){
  2019. var d = (new Date).format("db");
  2020. var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length);
  2021. this.file = file;
  2022. this.type = "message";
  2023. this.data = {
  2024. activity: "",
  2025. activityName: "",
  2026. activityToken: "",
  2027. activityType: "manual",
  2028. application: "",
  2029. completed: false,
  2030. control: {allowRead:true, allowEdit:false, allowControl:false},
  2031. controllerIdentityList: [],
  2032. controllerUnitList: [],
  2033. createTime: d,
  2034. deepPath: false,
  2035. divisionList: [],
  2036. editIdentityList: [],
  2037. editUnitList: [],
  2038. extension: extension,
  2039. id: (new o2.widget.UUID()).toString(),
  2040. job: "",
  2041. lastUpdatePerson: (layout) ? layout.session.user.name : "",
  2042. lastUpdateTime: d,
  2043. length: file.size,
  2044. name: file.name,
  2045. person: (layout) ? layout.session.user.name : "",
  2046. process: "",
  2047. readIdentityList: [],
  2048. readUnitList: [],
  2049. site: "$doc",
  2050. storage: file.size,
  2051. type: "",
  2052. updateTime: d,
  2053. workCreateTime: ""
  2054. }
  2055. if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
  2056. this.controller = controller;
  2057. this.css = this.controller.css;
  2058. this.listStyle = this.controller.options.listStyle;
  2059. this.content = this.controller.content;
  2060. this.isSelected = false;
  2061. this.seq = this.controller.attachments.length+1;
  2062. this.actions = [];
  2063. this.load();
  2064. },
  2065. load: function(){
  2066. this.node = new Element("div").inject(this.content);
  2067. switch (this.controller.options.listStyle){
  2068. case "list":
  2069. this.loadList();
  2070. break;
  2071. case "icon":
  2072. this.loadIcon();
  2073. break;
  2074. case "preview":
  2075. this.loadPreview();
  2076. break;
  2077. case "sequence":
  2078. this.loadSequence();
  2079. break;
  2080. }
  2081. this.setEvent();
  2082. this.loadMessage();
  2083. },
  2084. loadMessage: function(){
  2085. var size = this.node.getSize();
  2086. this.node.setStyle("position", "relative");
  2087. this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node);
  2088. this.messageMaskNode.setStyles({
  2089. "width": ""+size.x+"px",
  2090. "height": ""+size.y+"px"
  2091. });
  2092. this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node);
  2093. switch (this.controller.options.listStyle){
  2094. case "list":
  2095. case "sequence":
  2096. this.messageNode.setStyles({
  2097. "width": "0px",
  2098. "height": ""+size.y+"px"
  2099. });
  2100. break;
  2101. case "icon":
  2102. case "preview":
  2103. this.messageNode.setStyles({
  2104. "width": ""+size.x+"px",
  2105. "height": ""+size.y+"px"
  2106. });
  2107. break;
  2108. }
  2109. this.messageText = new Element("div", {
  2110. "styles": this.css.messageText,
  2111. "text": "0%"
  2112. }).inject(this.node);
  2113. this.messageText.setStyles({
  2114. "width": ""+size.x+"px",
  2115. "height": ""+size.y+"px",
  2116. "line-height": ""+size.y+"px"
  2117. });
  2118. },
  2119. updateProgress: function(percent){
  2120. var size = this.node.getSize();
  2121. switch (this.controller.options.listStyle){
  2122. case "list":
  2123. case "sequence":
  2124. var w = size.x*(percent/100);
  2125. this.messageNode.setStyles({
  2126. "width":""+w+"px"
  2127. });
  2128. break;
  2129. case "icon":
  2130. case "preview":
  2131. var h = size.y*(1-percent/100);
  2132. this.messageNode.setStyle("height", ""+h+"px");
  2133. break;
  2134. }
  2135. var p = (percent*100).toInt()/100;
  2136. this.messageText.set("text", ""+p+"%")
  2137. },
  2138. transferComplete: function(){
  2139. this.messageText.set("text", "loading...")
  2140. }
  2141. });
  2142. o2.widget.AttachmentController.AttachmentMessageMin = new Class({
  2143. Extends: o2.widget.AttachmentController.AttachmentMin,
  2144. Implements: [Events],
  2145. initialize: function(file, controller){
  2146. var d = (new Date).format("db");
  2147. var extension = file.name.substring(file.name.lastIndexOf(".")+1, file.name.length);
  2148. this.file = file;
  2149. this.data = {
  2150. activity: "",
  2151. activityName: "",
  2152. activityToken: "",
  2153. activityType: "manual",
  2154. application: "",
  2155. completed: false,
  2156. control: {allowRead:true, allowEdit:false, allowControl:false},
  2157. controllerIdentityList: [],
  2158. controllerUnitList: [],
  2159. createTime: d,
  2160. deepPath: false,
  2161. divisionList: [],
  2162. editIdentityList: [],
  2163. editUnitList: [],
  2164. extension: extension,
  2165. id: (new o2.widget.UUID()).toString(),
  2166. job: "",
  2167. lastUpdatePerson: (layout) ? layout.session.user.name : "",
  2168. lastUpdateTime: d,
  2169. length: file.size,
  2170. name: file.name,
  2171. person: (layout) ? layout.session.user.name : "",
  2172. process: "",
  2173. readIdentityList: [],
  2174. readUnitList: [],
  2175. site: "$doc",
  2176. storage: file.size,
  2177. type: "",
  2178. updateTime: d,
  2179. workCreateTime: ""
  2180. }
  2181. if( !this.data.person && this.data.creatorUid )this.data.person = this.data.creatorUid;
  2182. this.controller = controller;
  2183. this.css = this.controller.css;
  2184. this.listStyle = this.controller.options.listStyle;
  2185. this.content = this.controller.minContent;
  2186. this.isSelected = false;
  2187. this.seq = this.controller.attachments.length+1;
  2188. this.actions = [];
  2189. this.load();
  2190. },
  2191. load: function(){
  2192. this.node = new Element("div").inject(this.content);
  2193. switch (this.controller.options.listStyle){
  2194. case "list":
  2195. this.loadList();
  2196. break;
  2197. case "icon":
  2198. this.loadIcon();
  2199. break;
  2200. case "preview":
  2201. this.loadPreview();
  2202. break;
  2203. case "sequence":
  2204. this.loadSequence();
  2205. break;
  2206. }
  2207. this.setEvent();
  2208. this.loadMessage();
  2209. },
  2210. loadMessage: function(){
  2211. var size = this.node.getSize();
  2212. this.node.setStyle("position", "relative");
  2213. this.messageMaskNode = new Element("div", { "styles": this.css.messageMaskNode }).inject(this.node);
  2214. this.messageMaskNode.setStyles({
  2215. "width": ""+size.x+"px",
  2216. "height": ""+size.y+"px"
  2217. });
  2218. this.messageNode = new Element("div", { "styles": this.css.messageNode }).inject(this.node);
  2219. switch (this.controller.options.listStyle){
  2220. case "list":
  2221. case "sequence":
  2222. this.messageNode.setStyles({
  2223. "width": "0px",
  2224. "height": ""+size.y+"px"
  2225. });
  2226. break;
  2227. case "icon":
  2228. case "preview":
  2229. this.messageNode.setStyles({
  2230. "width": ""+size.x+"px",
  2231. "height": ""+size.y+"px"
  2232. });
  2233. break;
  2234. }
  2235. this.messageText = new Element("div", {
  2236. "styles": this.css.messageText,
  2237. "text": "0%"
  2238. }).inject(this.node);
  2239. this.messageText.setStyles({
  2240. "width": ""+size.x+"px",
  2241. "height": ""+size.y+"px",
  2242. "line-height": ""+size.y+"px"
  2243. });
  2244. },
  2245. updateProgress: function(percent){
  2246. var size = this.node.getSize();
  2247. switch (this.controller.options.listStyle){
  2248. case "list":
  2249. case "sequence":
  2250. var w = size.x*(percent/100);
  2251. this.messageNode.setStyles({
  2252. "width":""+w+"px"
  2253. });
  2254. break;
  2255. case "icon":
  2256. case "preview":
  2257. var h = size.y*(1-percent/100);
  2258. this.messageNode.setStyle("height", ""+h+"px");
  2259. break;
  2260. }
  2261. var p = (percent*100).toInt()/100;
  2262. this.messageText.set("text", ""+p+"%")
  2263. },
  2264. transferComplete: function(){
  2265. this.messageText.set("text", "loading...")
  2266. }
  2267. });